nest / nestml

A domain specific language for neuron and synapse models in spiking neural network simulation
GNU General Public License v2.0
44 stars 46 forks source link

neuromodulated_stdp nestml file does not compile #1065

Open Geenetto opened 3 weeks ago

Geenetto commented 3 weeks ago

Using the released nestml 7.0.2 version and nest 3.7.0, I am trying to compile the following nestml file: the neuromodulated_stdp model. Using python 3.10.12:

from pynestml.frontend.pynestml_frontend import generate_target

generate_target(
    input_path="nestml_folder/",
    target_platform="NEST",
    target_path="build_directory/",
    module_name="my_module",
)

This script results in the following error:

File ~/Documenti/workspace/bsb-nest/lib/python3.10/site-packages/pynestml/frontend/pynestml_frontend.py:190, in generate_target(input_path, target_platform, target_path, install_path, logging_level, module_name, store_log, suffix, dev, codegen_opts)
    162 r"""Generate and build code for the given target platform.
    163 
    164 Parameters
   (...)
    185     A dictionary containing additional options for the target code generator.
    186 """
    188 configure_front_end(input_path, target_platform, target_path, install_path, logging_level,
    189                     module_name, store_log, suffix, dev, codegen_opts)
--> 190 if not process() == 0:
    191     raise Exception("Error(s) occurred while processing the model")

File ~/Documenti/workspace/bsb-nest/lib/python3.10/site-packages/pynestml/frontend/pynestml_frontend.py:476, in process()
    474 if not errors_occurred:
    475     models = transform_models(transformers, models)
--> 476     generate_code(code_generator, models)
    478     # perform build
    479     if _builder is not None:

File ~/Documenti/workspace/bsb-nest/lib/python3.10/site-packages/pynestml/frontend/pynestml_frontend.py:445, in generate_code(code_generators, models)
    444 def generate_code(code_generators, models):
--> 445     code_generators.generate_code(models)

File ~/Documenti/workspace/bsb-nest/lib/python3.10/site-packages/pynestml/codegeneration/nest_code_generator.py:234, in NESTCodeGenerator.generate_code(self, models)
    232 self.analyse_transform_synapses(synapses)
    233 self.generate_neurons(neurons)
--> 234 self.generate_synapses(synapses)
    235 self.generate_module_code(neurons, synapses)
    237 for astnode in neurons + synapses:

File ~/Documenti/workspace/bsb-nest/lib/python3.10/site-packages/pynestml/codegeneration/code_generator.py:179, in CodeGenerator.generate_synapses(self, synapses)
    177 if Logger.logging_level == LoggingLevel.INFO:
    178     print("Generating code for the synapse {}.".format(synapse.get_name()))
--> 179 self.generate_synapse_code(synapse)
    180 code, message = Messages.get_code_generated(synapse.get_name(), FrontendConfiguration.get_target_path())
    181 Logger.log_message(synapse, code, message, synapse.get_source_position(), LoggingLevel.INFO)

File ~/Documenti/workspace/bsb-nest/lib/python3.10/site-packages/pynestml/codegeneration/code_generator.py:231, in CodeGenerator.generate_synapse_code(self, synapse)
    228 def generate_synapse_code(self, synapse: ASTNeuron) -> None:
    229     self.generate_model_code(synapse.get_name(),
    230                              model_templates=self._model_templates["synapse"],
--> 231                              template_namespace=self._get_synapse_model_namespace(synapse),
    232                              model_name_escape_string="@SYNAPSE_NAME@")

File ~/Documenti/workspace/bsb-nest/lib/python3.10/site-packages/pynestml/codegeneration/nest_code_generator.py:489, in NESTCodeGenerator._get_synapse_model_namespace(self, synapse)
    485 else:
    486     # separate (not neuron+synapse co-generated)
    487     namespace["pre_ports"] = all_input_port_names
--> 489 assert len(namespace["pre_ports"]) <= 1, "Synapses only support one spiking input port"
    491 namespace["synapseName"] = synapse.get_name()
    492 namespace["synapse"] = synapse

AssertionError: Synapses only support one spiking input port

Is this issue related to NEST or NESTML? Should I use the latest version of NESTML (master branch)?

pnbabu commented 3 weeks ago

@Geenetto thank you for writing in!

You will need to pass additional options (codegen_opts) to the generate_target() function for NESTML to know for which neuron the synapse should be paired. You could do this as follows:

from pynestml.frontend.pynestml_frontend import generate_target

generate_target(
    input_path="nestml_folder/",
    target_platform="NEST",
    target_path="build_directory/",
    module_name="my_module",
    codegen_opts = {"neuron_synapse_pairs": [{"neuron": "iaf_psc_exp",
                                              "synapse": "neuromodulated_stdp",
                                              "vt_ports": ["dopa_spikes"]}]
                   })

The above code generates the code for iaf_psc_exp paired with the neuromodulated_stdp synapse. You could replace iaf_psc_exp with the neuron model of your choice.

All the information can also be found in our docs: https://nestml.readthedocs.io/en/latest/nestml_language/synapses_in_nestml.html#id9

We are working on the docs to make this easily reachable. Hope this helps!