def test_solve_odes_and_shapes(self):
        input_path = str(os.path.realpath(os.path.join(os.path.dirname(__file__), os.path.join(
            os.pardir, 'models', 'iaf_psc_alpha.nestml'))))
        compilation_unit = ModelParser.parse_model(input_path)
        assert len(compilation_unit.get_neuron_list()) == 1
        ast_neuron = compilation_unit.get_neuron_list()[0]

        nestCodeGenerator = NESTCodeGenerator()
        ast_neuron = nestCodeGenerator.transform_shapes_and_odes(ast_neuron, {})
Esempio n. 2
0
    def test_iaf_psc_alpha(self):
        input_path = str(
            os.path.realpath(
                os.path.join(
                    os.path.dirname(__file__),
                    os.path.join(os.pardir, 'models',
                                 'iaf_psc_alpha.nestml'))))

        params = list()
        params.append('--input_path')
        params.append(input_path)
        params.append('--logging_level')
        params.append('INFO')
        params.append('--target_path')
        params.append(self.target_path)
        params.append('--dev')
        FrontendConfiguration.parse_config(params)

        compilation_unit = ModelParser.parse_model(input_path)

        nestCodeGenerator = NESTCodeGenerator()
        nestCodeGenerator.generate_code(compilation_unit.get_neuron_list())
    def test_vector_code_generation(self):
        input_path = str(
            os.path.realpath(
                os.path.join(
                    os.path.dirname(__file__),
                    os.path.join('valid',
                                 'VectorsDeclarationAndAssignment.nestml'))))

        params = list()
        params.append('--input_path')
        params.append(input_path)
        params.append('--logging_level')
        params.append('INFO')
        params.append('--target_path')
        params.append(self.target_path)
        params.append('--dev')
        FrontendConfiguration.parse_config(params)

        compilation_unit = ModelParser.parse_model(input_path)

        nestCodeGenerator = NESTCodeGenerator()
        nestCodeGenerator.generate_code(compilation_unit.get_neuron_list())
Esempio n. 4
0
 def from_target_name(
         target_name: str,
         options: Optional[Mapping[str, Any]] = None) -> CodeGenerator:
     """Static factory method that returns a new instance of a child class of CodeGenerator"""
     assert target_name.upper() in CodeGenerator.get_known_targets(
     ), "Unknown target platform requested: \"" + str(target_name) + "\""
     if target_name.upper() == "NEST":
         from pynestml.codegeneration.nest_codegenerator import NESTCodeGenerator
         return NESTCodeGenerator(options)
     elif target_name.upper() == "AUTODOC":
         from pynestml.codegeneration.autodoc_codegenerator import AutoDocCodeGenerator
         assert options is None or options == {}, "\"autodoc\" code generator does not support options"
         return AutoDocCodeGenerator()
     elif target_name == "":
         # dummy/null target: user requested to not generate any code
         code, message = Messages.get_no_code_generated()
         Logger.log_message(None, code, message, None, LoggingLevel.INFO)
         return CodeGenerator("", options)
     assert False  # cannot reach here due to earlier assert -- silence static checker warnings
Esempio n. 5
0
    def generate_code(self, neurons):
        """
        Generate code for the given neurons and (depending on the target) generate an index page, module entrypoint or
        similar that incorporates an enumeration of all neurons.

        :param neurons: a list of neurons.
        :type neurons: List[ASTNode]
        """
        if self._target.upper() == "NEST":
            from pynestml.codegeneration.nest_codegenerator import NESTCodeGenerator
            _codeGenerator = NESTCodeGenerator()
            _codeGenerator.generate_code(neurons)
        elif self._target.upper() == "AUTODOC":
            from pynestml.codegeneration.autodoc_codegenerator import AutoDocCodeGenerator
            _codeGenerator = AutoDocCodeGenerator()
            _codeGenerator.generate_code(neurons)
        else:
            # dummy/null target: user requested to not generate any code
            assert self._target == ""
            code, message = Messages.get_no_code_generated()
            Logger.log_message(None, code, message, None, LoggingLevel.INFO)
    def test_model_preparation(self):
        input_path = str(os.path.realpath(os.path.join(os.path.dirname(__file__), os.path.join(
            os.pardir, 'models', 'iaf_psc_alpha.nestml'))))
        compilation_unit = ModelParser.parse_model(input_path)
        assert len(compilation_unit.get_neuron_list()) == 1
        ast_neuron = compilation_unit.get_neuron_list()[0]
        equations_block = ast_neuron.get_equations_block()
        # the idea here is to go through the rhs, print expressions, use the same mechanism as before, and reread them
        # again
        # TODO: add tests for this function
        # this function changes stuff inplace
        nestCodeGenerator = NESTCodeGenerator()
        nestCodeGenerator.make_functions_self_contained(equations_block.get_ode_functions())

        nestCodeGenerator.replace_functions_through_defining_expressions(equations_block.get_ode_equations(),
                                                       equations_block.get_ode_functions())

        json_representation = nestCodeGenerator.transform_ode_and_shapes_to_json(equations_block)
        self.assertTrue("convolve(I_shape_in, in_spikes)" in json_representation["odes"][0]["definition"])
        self.assertTrue("convolve(I_shape_ex, ex_spikes)" in json_representation["odes"][0]["definition"])