Skip to content

Commit e5bdbd3

Browse files
author
C.A.P. Linssen
committed
ensure compatibility with NESTML custom as well as NEST built-in synaptic plasticity models
1 parent 101f4f0 commit e5bdbd3

File tree

4 files changed

+65
-15
lines changed

4 files changed

+65
-15
lines changed

pynestml/codegeneration/nest_code_generator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ def __init__(self, options: Optional[Mapping[str, Any]] = None):
169169
def run_nest_target_specific_cocos(self, neurons: Sequence[ASTModel], synapses: Sequence[ASTModel]):
170170
for synapse in synapses:
171171
synapse_name_stripped = removesuffix(removesuffix(synapse.name.split("_with_")[0], "_"), FrontendConfiguration.suffix)
172+
assert synapse_name_stripped in self.get_option("delay_variable").keys(), "Please specify a ``delay_variable`` for the synapse '" + synapse_name_stripped + "'"
172173
delay_variable = self.get_option("delay_variable")[synapse_name_stripped]
173174
CoCoNESTSynapseDelayNotAssignedTo.check_co_co(delay_variable, synapse)
174175
if Logger.has_errors(synapse):

tests/nest_tests/resources/iaf_psc_exp_nonlineardendrite_alternate.nestml renamed to tests/nest_tests/resources/iaf_psc_exp_nonlineardendrite_neuron.nestml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
1-
neuron iaf_psc_exp_nonlineardendrite:
1+
"""
2+
iaf_psc_exp_nonlineardendrite_alternate.nestml
3+
##############################################
4+
5+
6+
Copyright statement
7+
+++++++++++++++++++
8+
9+
This file is part of NEST.
10+
11+
Copyright (C) 2004 The NEST Initiative
12+
13+
NEST is free software: you can redistribute it and/or modify
14+
it under the terms of the GNU General Public License as published by
15+
the Free Software Foundation, either version 2 of the License, or
16+
(at your option) any later version.
17+
18+
NEST is distributed in the hope that it will be useful,
19+
but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
GNU General Public License for more details.
22+
23+
You should have received a copy of the GNU General Public License
24+
along with NEST. If not, see <http://www.gnu.org/licenses/>.
25+
"""
26+
model iaf_psc_exp_nonlineardendrite_neuron:
227

328
state:
429
V_m mV = 0mV # membrane potential in mV
@@ -8,7 +33,6 @@ neuron iaf_psc_exp_nonlineardendrite:
833
ref_counts integer = 0
934

1035
equations:
11-
1236
# exponential shaped postsynaptic current kernel
1337
kernel I_kernel1 = exp(-1/tau_syn1*t)
1438

tests/nest_tests/resources/stdsp_synapse_no_permanence.nestml renamed to tests/nest_tests/resources/stdsp_no_permanence_synapse.nestml

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
1+
"""
2+
stdsp_no_permanence_synapse.nestml
3+
##################################
14

2-
synapse stdsp_synapse_no_permanence:
5+
6+
Copyright statement
7+
+++++++++++++++++++
8+
9+
This file is part of NEST.
10+
11+
Copyright (C) 2004 The NEST Initiative
12+
13+
NEST is free software: you can redistribute it and/or modify
14+
it under the terms of the GNU General Public License as published by
15+
the Free Software Foundation, either version 2 of the License, or
16+
(at your option) any later version.
17+
18+
NEST is distributed in the hope that it will be useful,
19+
but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
GNU General Public License for more details.
22+
23+
You should have received a copy of the GNU General Public License
24+
along with NEST. If not, see <http://www.gnu.org/licenses/>.
25+
"""
26+
model stdsp_no_permanence_synapse:
327

428
state:
5-
w real = 1. @nest::weight
6-
t_last_pre_spike ms = -1ms
29+
w real = 1
30+
t_last_pre_spike ms = -1 ms
731

832
parameters:
9-
d ms = 2.0 ms @nest::delay # !!! cannot have a variable called "delay"
33+
d ms = 2.0 ms
1034
lambda real = .01
1135
lambda_minus real = .01
1236
tau_tr_pre ms = 20 ms
@@ -54,5 +78,7 @@ synapse stdsp_synapse_no_permanence:
5478
w = max(Wmin, w_)
5579

5680
# deliver spike to postsynaptic partner
57-
deliver_spike(w, d)
81+
emit_spike(w, d)
5882

83+
update:
84+
integrate_odes()

tests/nest_tests/test_built_in_and_nestml_plastic_synapse.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,16 @@
3535
class TestBuiltInAndNESTMLPlasticSynapse:
3636
r"""Test that synaptic plasticity works with both a NEST built-in plastic synapse and a NESTML custom plastic synapse attached to the same neuron."""
3737

38-
neuron_model = "iaf_psc_exp_nonlineardendrite"
39-
synapse_model = "stdsp_synapse_no_permanence"
38+
neuron_model = "iaf_psc_exp_nonlineardendrite_neuron"
39+
synapse_model = "stdsp_no_permanence_synapse"
4040

4141
def setup_nest(self):
42-
files = [f"{TestBuiltInAndNESTMLPlasticSynapse.neuron_model}_alternate.nestml",
42+
files = [f"{TestBuiltInAndNESTMLPlasticSynapse.neuron_model}.nestml",
4343
f"{TestBuiltInAndNESTMLPlasticSynapse.synapse_model}.nestml"]
4444
input_path = [os.path.realpath(os.path.join(os.path.dirname(__file__), "resources", s)) for s in files]
4545

4646
generate_nest_target(
4747
input_path=input_path,
48-
target_path="module",
4948
logging_level="DEBUG",
5049
module_name=f"nestml_{TestBuiltInAndNESTMLPlasticSynapse.neuron_model}_{TestBuiltInAndNESTMLPlasticSynapse.synapse_model}_module",
5150
suffix="_nestml",
@@ -57,12 +56,11 @@ def setup_nest(self):
5756
"post_ports": ["post_spikes", ["z_post", "z"]],
5857
}
5958
],
60-
},
59+
"delay_variable": {"stdsp_no_permanence_synapse": "d"},
60+
"weight_variable": {"stdsp_no_permanence_synapse": "w"}
61+
}
6162
)
6263

63-
# install custom neuron models
64-
nest.Install(f"nestml_{TestBuiltInAndNESTMLPlasticSynapse.neuron_model}_{TestBuiltInAndNESTMLPlasticSynapse.synapse_model}_module")
65-
6664
def _test_plasticity(self, neuron_model, synapse_model):
6765

6866
print("testing plasticity for synapse mode " + str(synapse_model))
@@ -73,6 +71,7 @@ def _test_plasticity(self, neuron_model, synapse_model):
7371
initial_weight = 123.
7472

7573
nest.ResetKernel()
74+
nest.Install(f"nestml_{TestBuiltInAndNESTMLPlasticSynapse.neuron_model}_{TestBuiltInAndNESTMLPlasticSynapse.synapse_model}_module")
7675

7776
# create pre and post neurons
7877
pre_neuron = nest.Create(neuron_model)

0 commit comments

Comments
 (0)