def test_print_statement_with_variables(self):
        input_path = str(
            os.path.realpath(
                os.path.join(
                    os.path.dirname(__file__),
                    os.path.join('resources',
                                 'PrintStatementWithVariables.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())

        with open(
                str(
                    os.path.realpath(
                        os.path.join(
                            os.path.dirname(__file__),
                            os.path.join(os.pardir, 'target',
                                         'print_test_variables.cpp')))),
                'r') as reader:
            self.assertEqual(reader.read().count('std::cout'), 2)
Ejemplo n.º 2
0
 def generate_code(self, neurons):
     if self._target == "NEST":
         from pynestml.codegeneration.nest_codegenerator import NESTCodeGenerator
         _codeGenerator = NESTCodeGenerator()
         _codeGenerator.generate_code(neurons)
     elif self._target == "":
         # 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)
Ejemplo n.º 3
0
    def test_iaf_psc_alpha_with_codegen_opts(self):
        input_path = str(
            os.path.realpath(
                os.path.join(
                    os.path.dirname(__file__),
                    os.path.join(os.pardir, 'models', 'neurons',
                                 'iaf_psc_alpha.nestml'))))

        code_opts_path = str(
            os.path.realpath(
                os.path.join(os.path.dirname(__file__),
                             os.path.join('resources', 'code_options.json'))))
        codegen_opts = {
            "templates": {
                "path":
                "point_neuron",
                "model_templates": {
                    "neuron":
                    ['NeuronClass.cpp.jinja2', 'NeuronHeader.h.jinja2'],
                    "synapse": []
                },
                "module_templates": [
                    'setup/CMakeLists.txt.jinja2',
                    'setup/ModuleHeader.h.jinja2',
                    'setup/ModuleClass.cpp.jinja2'
                ]
            }
        }

        with open(code_opts_path, 'w+') as f:
            json.dump(codegen_opts, f)

        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')
        params.append('--codegen_opts')
        params.append(code_opts_path)
        FrontendConfiguration.parse_config(params)

        compilation_unit = ModelParser.parse_model(input_path)

        nestCodeGenerator = NESTCodeGenerator(codegen_opts)
        nestCodeGenerator.generate_code(compilation_unit.get_neuron_list(),
                                        list())
    def test_expressions(self):
        input_path = str(
            os.path.realpath(
                os.path.join(
                    os.path.dirname(__file__),
                    os.path.join('resources', 'ExpressionTypeTest.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())
Ejemplo 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)
Ejemplo n.º 6
0
    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())
Ejemplo n.º 7
0
    def test_iaf_psc_delta(self):
        input_path = str(
            os.path.realpath(
                os.path.join(
                    os.path.dirname(__file__),
                    os.path.join(os.pardir, 'models', 'neurons',
                                 'iaf_psc_delta.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(),
                                        compilation_unit.get_synapse_list())
Ejemplo n.º 8
0
    def test_iaf_cond_alpha_functional(self):
        input_path = str(
            os.path.realpath(
                os.path.join(
                    os.path.dirname(__file__),
                    os.path.join(os.pardir, 'models',
                                 'iaf_cond_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)
        iaf_cond_alpha_functional = list()
        iaf_cond_alpha_functional.append(compilation_unit.get_neuron_list()[0])

        nestCodeGenerator = NESTCodeGenerator()
        nestCodeGenerator.generate_code(iaf_cond_alpha_functional, [])