Ejemplo n.º 1
0
 def visit_neuron(self, node):
     """
     Private method: Used to visit a single neuron and create the corresponding global as well as local scopes.
     :return: a single neuron.
     :rtype: ast_neuron
     """
     # set current processed neuron
     Logger.set_current_neuron(node)
     code, message = Messages.get_start_building_symbol_table()
     Logger.log_message(neuron=node,
                        code=code,
                        error_position=node.get_source_position(),
                        message=message,
                        log_level=LoggingLevel.INFO)
     # before starting the work on the neuron, make everything which was implicit explicit
     # but if we have a model without an equations block, just skip this step
     if node.get_equations_blocks() is not None:
         make_implicit_odes_explicit(node.get_equations_blocks())
     scope = Scope(scope_type=ScopeType.GLOBAL,
                   source_position=node.get_source_position())
     node.update_scope(scope)
     node.get_body().update_scope(scope)
     # now first, we add all predefined elements to the scope
     variables = PredefinedVariables.get_variables()
     functions = PredefinedFunctions.get_function_symbols()
     types = PredefinedTypes.get_types()
     for symbol in variables.keys():
         node.get_scope().add_symbol(variables[symbol])
     for symbol in functions.keys():
         node.get_scope().add_symbol(functions[symbol])
     for symbol in types.keys():
         node.get_scope().add_symbol(types[symbol])
Ejemplo n.º 2
0
 def endvisit_neuron(self, node):
     # before following checks occur, we need to ensure several simple properties
     CoCosManager.post_symbol_table_builder_checks(
         node, skip_check_correct_usage_of_shapes=self.after_ast_rewrite_)
     # the following part is done in order to mark conductance based buffers as such.
     if node.get_input_blocks() is not None and node.get_equations_blocks() is not None and \
             len(node.get_equations_blocks().get_declarations()) > 0:
         # this case should be prevented, since several input blocks result in  a incorrect model
         if isinstance(node.get_input_blocks(), list):
             buffers = (buffer for bufferA in node.get_input_blocks()
                        for buffer in bufferA.get_input_lines())
         else:
             buffers = (
                 buffer
                 for buffer in node.get_input_blocks().get_input_lines())
         from pynestml.meta_model.ast_ode_shape import ASTOdeShape
         # todo by KP: ode declarations are not used, is this correct?
         # ode_declarations = (decl for decl in node.get_equations_blocks().get_declarations() if
         #                    not isinstance(decl, ASTOdeShape))
         mark_conductance_based_buffers(input_lines=buffers)
     # now update the equations
     if node.get_equations_blocks() is not None and len(
             node.get_equations_blocks().get_declarations()) > 0:
         equation_block = node.get_equations_blocks()
         assign_ode_to_variables(equation_block)
     if not self.after_ast_rewrite_:
         CoCosManager.post_ode_specification_checks(node)
     Logger.set_current_neuron(None)
     return
Ejemplo n.º 3
0
 def visit_neuron(self, node):
     """
     Private method: Used to visit a single neuron and create the corresponding global as well as local scopes.
     :return: a single neuron.
     :rtype: ast_neuron
     """
     # set current processed neuron
     Logger.set_current_neuron(node)
     code, message = Messages.get_start_building_symbol_table()
     Logger.log_message(neuron=node, code=code, error_position=node.get_source_position(),
                        message=message, log_level=LoggingLevel.INFO)
     # before starting the work on the neuron, make everything which was implicit explicit
     # but if we have a model without an equations block, just skip this step
     if node.get_equations_blocks() is not None:
         make_implicit_odes_explicit(node.get_equations_blocks())
     scope = Scope(scope_type=ScopeType.GLOBAL, source_position=node.get_source_position())
     node.update_scope(scope)
     node.get_body().update_scope(scope)
     # now first, we add all predefined elements to the scope
     variables = PredefinedVariables.get_variables()
     functions = PredefinedFunctions.get_function_symbols()
     types = PredefinedTypes.get_types()
     for symbol in variables.keys():
         node.get_scope().add_symbol(variables[symbol])
     for symbol in functions.keys():
         node.get_scope().add_symbol(functions[symbol])
     for symbol in types.keys():
         node.get_scope().add_symbol(types[symbol])
Ejemplo n.º 4
0
 def visit_neuron(self, node):
     """
     Private method: Used to visit a single neuron and create the corresponding global as well as local scopes.
     :return: a single neuron.
     :rtype: ast_neuron
     """
     # set current processed neuron
     Logger.set_current_neuron(node)
     code, message = Messages.get_start_building_symbol_table()
     Logger.log_message(neuron=node,
                        code=code,
                        error_position=node.get_source_position(),
                        message=message,
                        log_level=LoggingLevel.INFO)
     scope = Scope(scope_type=ScopeType.GLOBAL,
                   source_position=node.get_source_position())
     node.update_scope(scope)
     node.get_body().update_scope(scope)
     # now first, we add all predefined elements to the scope
     variables = PredefinedVariables.get_variables()
     functions = PredefinedFunctions.get_function_symbols()
     types = PredefinedTypes.get_types()
     for symbol in variables.keys():
         node.get_scope().add_symbol(variables[symbol])
     for symbol in functions.keys():
         node.get_scope().add_symbol(functions[symbol])
     for symbol in types.keys():
         node.get_scope().add_symbol(types[symbol])
 def test(self):
     Logger.init_logger(LoggingLevel.INFO)
     model = ModelParser.parse_model(
         os.path.join(os.path.realpath(os.path.join(os.path.dirname(__file__),
                                                    'resources', 'ExpressionTypeTest.nestml'))))
     Logger.set_current_neuron(model.get_neuron_list()[0])
     model.accept(ExpressionTestVisitor())
     # ExpressionTestVisitor().handle(model)
     Logger.set_current_neuron(None)
     self.assertEqual(len(Logger.get_all_messages_of_level_and_or_neuron(model.get_neuron_list()[0],
                                                                         LoggingLevel.ERROR)), 2)
 def test(self):
     Logger.init_logger(LoggingLevel.INFO)
     model = ModelParser.parse_model(
         os.path.join(os.path.realpath(os.path.join(os.path.dirname(__file__),
                                                    'resources', 'ExpressionTypeTest.nestml'))))
     Logger.set_current_neuron(model.get_neuron_list()[0])
     model.accept(ExpressionTestVisitor())
     # ExpressionTestVisitor().handle(model)
     Logger.set_current_neuron(None)
     self.assertEqual(len(Logger.get_all_messages_of_level_and_or_neuron(model.get_neuron_list()[0],
                                                                         LoggingLevel.ERROR)), 2)
Ejemplo n.º 7
0
 def visitNeuron(self, ctx):
     name = str(ctx.NAME()) if ctx.NAME() is not None else None
     body = self.visit(ctx.body()) if ctx.body() is not None else None
     # after we have constructed the meta_model of the neuron,
     # we can ensure some basic properties which should always hold
     # we have to check if each type of block is defined at most once (except for function), and that input,output
     # and update are defined once
     if hasattr(ctx.start.source[1], 'fileName'):
         artifact_name = ntpath.basename(ctx.start.source[1].fileName)
     else:
         artifact_name = 'parsed from string'
     neuron = ASTNodeFactory.create_ast_neuron(name=name, body=body, source_position=create_source_pos(ctx),
                                               artifact_name=artifact_name)
     # update the comments
     update_node_comments(neuron, self.__comments.visit(ctx))
     # in order to enable the logger to print correct messages set as the source the corresponding neuron
     Logger.set_current_neuron(neuron)
     CoCoEachBlockUniqueAndDefined.check_co_co(node=neuron)
     Logger.set_current_neuron(neuron)
     # now the meta_model seems to be correct, return it
     return neuron
Ejemplo n.º 8
0
 def endvisit_neuron(self, node):
     # before following checks occur, we need to ensure several simple properties
     CoCosManager.post_symbol_table_builder_checks(node, skip_check_correct_usage_of_shapes=self.after_ast_rewrite_)
     # the following part is done in order to mark conductance based buffers as such.
     if node.get_input_blocks() is not None and node.get_equations_blocks() is not None and \
             len(node.get_equations_blocks().get_declarations()) > 0:
         # this case should be prevented, since several input blocks result in  a incorrect model
         if isinstance(node.get_input_blocks(), list):
             buffers = (buffer for bufferA in node.get_input_blocks() for buffer in bufferA.get_input_lines())
         else:
             buffers = (buffer for buffer in node.get_input_blocks().get_input_lines())
         from pynestml.meta_model.ast_ode_shape import ASTOdeShape
         # todo by KP: ode declarations are not used, is this correct?
         # ode_declarations = (decl for decl in node.get_equations_blocks().get_declarations() if
         #                    not isinstance(decl, ASTOdeShape))
         mark_conductance_based_buffers(input_lines=buffers)
     # now update the equations
     if node.get_equations_blocks() is not None and len(node.get_equations_blocks().get_declarations()) > 0:
         equation_block = node.get_equations_blocks()
         assign_ode_to_variables(equation_block)
     if not self.after_ast_rewrite_:
         CoCosManager.post_ode_specification_checks(node)
     Logger.set_current_neuron(None)
     return