Skip to content

Commit

Permalink
ensure compatibility with NESTML custom as well as NEST built-in syna…
Browse files Browse the repository at this point in the history
…ptic plasticity models
  • Loading branch information
C.A.P. Linssen committed Jun 20, 2024
1 parent 101f4f0 commit f0c2845
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 15 deletions.
1 change: 1 addition & 0 deletions pynestml/codegeneration/nest_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def __init__(self, options: Optional[Mapping[str, Any]] = None):
def run_nest_target_specific_cocos(self, neurons: Sequence[ASTModel], synapses: Sequence[ASTModel]):
for synapse in synapses:
synapse_name_stripped = removesuffix(removesuffix(synapse.name.split("_with_")[0], "_"), FrontendConfiguration.suffix)
assert synapse_name_stripped in self.get_option("delay_variable").keys(), "Please specify a ``delay_variable`` for the synapse '" + synapse_name_stripped + "'"
delay_variable = self.get_option("delay_variable")[synapse_name_stripped]
CoCoNESTSynapseDelayNotAssignedTo.check_co_co(delay_variable, synapse)
if Logger.has_errors(synapse):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
neuron iaf_psc_exp_nonlineardendrite:
"""
iaf_psc_exp_nonlineardendrite_alternate.nestml
##############################################


Copyright statement
+++++++++++++++++++

This file is part of NEST.

Copyright (C) 2004 The NEST Initiative

NEST is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

NEST is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with NEST. If not, see <http://www.gnu.org/licenses/>.
"""
model iaf_psc_exp_nonlineardendrite_neuron:

state:
V_m mV = 0mV # membrane potential in mV
Expand All @@ -8,7 +33,6 @@ neuron iaf_psc_exp_nonlineardendrite:
ref_counts integer = 0

equations:

# exponential shaped postsynaptic current kernel
kernel I_kernel1 = exp(-1/tau_syn1*t)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
"""
stdsp_no_permanence_synapse.nestml
##################################

synapse stdsp_synapse_no_permanence:

Copyright statement
+++++++++++++++++++

This file is part of NEST.

Copyright (C) 2004 The NEST Initiative

NEST is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

NEST is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with NEST. If not, see <http://www.gnu.org/licenses/>.
"""
model stdsp_no_permanence_synapse:

state:
w real = 1. @nest::weight
t_last_pre_spike ms = -1ms
w real = 1
t_last_pre_spike ms = -1 ms

parameters:
d ms = 2.0 ms @nest::delay # !!! cannot have a variable called "delay"
d ms = 2.0 ms
lambda real = .01
lambda_minus real = .01
tau_tr_pre ms = 20 ms
Expand Down Expand Up @@ -54,5 +78,7 @@ synapse stdsp_synapse_no_permanence:
w = max(Wmin, w_)

# deliver spike to postsynaptic partner
deliver_spike(w, d)
emit_spike(w, d)

update:
integrate_odes()
15 changes: 7 additions & 8 deletions tests/nest_tests/test_built_in_and_nestml_plastic_synapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@
class TestBuiltInAndNESTMLPlasticSynapse:
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."""

neuron_model = "iaf_psc_exp_nonlineardendrite"
synapse_model = "stdsp_synapse_no_permanence"
neuron_model = "iaf_psc_exp_nonlineardendrite_neuron"
synapse_model = "stdsp_no_permanence_synapse"

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

generate_nest_target(
input_path=input_path,
target_path="module",
logging_level="DEBUG",
module_name=f"nestml_{TestBuiltInAndNESTMLPlasticSynapse.neuron_model}_{TestBuiltInAndNESTMLPlasticSynapse.synapse_model}_module",
suffix="_nestml",
Expand All @@ -57,12 +56,11 @@ def setup_nest(self):
"post_ports": ["post_spikes", ["z_post", "z"]],
}
],
},
"delay_variable": {"stdsp_no_permanence_synapse": "d"},
"weight_variable": {"stdsp_no_permanence_synapse": "w"}
}
)

# install custom neuron models
nest.Install(f"nestml_{TestBuiltInAndNESTMLPlasticSynapse.neuron_model}_{TestBuiltInAndNESTMLPlasticSynapse.synapse_model}_module")

def _test_plasticity(self, neuron_model, synapse_model):

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

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

# create pre and post neurons
pre_neuron = nest.Create(neuron_model)
Expand Down

0 comments on commit f0c2845

Please sign in to comment.