Skip to content

Commit af5ea37

Browse files
committed
Make nestml_synapse_type() return a class, consistent with nestml_cell_type()
Previously the co-generation path returned a (synapse_class, neuron_class) tuple, while the non-co-generation path returned a single class. Now both paths return a single class; the co-generated neuron class is accessible via the synapse class's postsynaptic_cell_type attribute. Also fixes delay_variable/weight_variable being set only in the co-generation path. Updates the stdp.py example accordingly.
1 parent c1cad73 commit af5ea37

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

examples/nestml/stdp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
input_path = os.path.join(current_dir, "wb_cond_exp_neuron.nestml")
5454
# celltype_cls = sim.nestml.nestml_cell_type("wb_cond_exp_neuron", input_path)
5555

56-
synapse_type, post_cell_type = sim.nestml.nestml_synapse_type("stdp_synapse", "stdp_synapse.nestml", "iaf_psc_exp_neuron.nestml")
56+
synapse_type = sim.nestml.nestml_synapse_type("stdp_synapse", "stdp_synapse.nestml", "iaf_psc_exp_neuron.nestml")
57+
post_cell_type = synapse_type.postsynaptic_cell_type
5758

5859

5960
# === Build and instrument the network =======================================

pyNN/nest/nestml.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def nestml_cell_type(name, nestml_description):
6060
# todo: get units information from nestml_description, provide to "native_cell_type()"
6161
return native_cell_type(name)
6262

63+
6364
def _get_model_name(filename: str) -> str:
6465
"""Get the model filename from a NESTML model file"""
6566
with open(filename, "r") as fp:
@@ -68,11 +69,21 @@ def _get_model_name(filename: str) -> str:
6869

6970
return model_name
7071

71-
def nestml_synapse_type(synapse_name, nestml_description, postsynaptic_neuron_nestml_description=None, weight_variable="w", delay_variable="d"):
72+
73+
def nestml_synapse_type(
74+
synapse_name,
75+
nestml_description,
76+
postsynaptic_neuron_nestml_description=None,
77+
weight_variable="w",
78+
delay_variable="d"
79+
):
7280
"""
73-
Return a new NESTMLCellType subclass from a NESTML description.
81+
Return a new NativeSynapseType subclass from a NESTML description.
7482
75-
For plastic synapses, the synapse code needs to be generated in close combination with the postsynaptic neuron code. For this reason, for plastic synapses, it is necessary to specify the ``postsynaptic_neuron_nestml_description``.
83+
For plastic synapses, the synapse code needs to be generated in close combination with the
84+
postsynaptic neuron code. For this reason, for plastic synapses, it is necessary to specify
85+
``postsynaptic_neuron_nestml_description``. In this case the returned synapse class will have
86+
a ``postsynaptic_cell_type`` attribute containing the co-generated neuron class.
7687
"""
7788

7889
from pynestml.frontend.pynestml_frontend import generate_nest_target
@@ -143,11 +154,12 @@ def nestml_synapse_type(synapse_name, nestml_description, postsynaptic_neuron_ne
143154

144155
nest.Install(module_name)
145156

146-
# todo: get units information from nestml_description, provide to "native_cell_type()"
157+
# todo: get units information from nestml_description, provide to "native_synapse_type()"
158+
synapse_class = pyNN.nest.native_synapse_type(synapse_name)
159+
synapse_class.delay_variable = delay_variable
160+
synapse_class.weight_variable = weight_variable
161+
147162
if postsynaptic_neuron_nestml_description:
148-
synapse_instance = pyNN.nest.native_synapse_type(synapse_name)
149-
synapse_instance.delay_variable = delay_variable
150-
synapse_instance.weight_variable = weight_variable
151-
return synapse_instance, pyNN.nest.native_cell_type(neuron_name)
163+
synapse_class.postsynaptic_cell_type = pyNN.nest.native_cell_type(neuron_name)
152164

153-
return pyNN.nest.native_synapse_type(synapse_name)
165+
return synapse_class

0 commit comments

Comments
 (0)