-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and add test for second-order integration in neuromodulated synap…
…se (#905)
- Loading branch information
Showing
5 changed files
with
227 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# dopa_synapse_second_order_tests.py | ||
# | ||
# 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/>. | ||
|
||
import numpy as np | ||
import os | ||
import pytest | ||
|
||
import nest | ||
|
||
from pynestml.codegeneration.nest_tools import NESTTools | ||
from pynestml.frontend.pynestml_frontend import generate_nest_target | ||
|
||
try: | ||
import matplotlib | ||
matplotlib.use("Agg") | ||
import matplotlib.ticker | ||
import matplotlib.pyplot as plt | ||
TEST_PLOTS = True | ||
except Exception: | ||
TEST_PLOTS = False | ||
|
||
|
||
class TestDopaSecondOrder: | ||
r""" | ||
Test second-order integration in a neuromodulated synapse. | ||
""" | ||
|
||
neuron_model_name = "iaf_psc_exp_nestml__with_dopa_synapse_second_order_nestml" | ||
synapse_model_name = "dopa_synapse_second_order_nestml__with_iaf_psc_exp_nestml" | ||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def setUp(self): | ||
r"""generate code for neuron and synapse and build NEST user module""" | ||
files = [os.path.join("models", "neurons", "iaf_psc_exp.nestml"), | ||
os.path.join("tests", "nest_tests", "resources", "dopa_synapse_second_order.nestml")] | ||
input_path = [os.path.realpath(os.path.join(os.path.dirname(__file__), os.path.join( | ||
os.pardir, os.pardir, s))) for s in files] | ||
generate_nest_target(input_path=input_path, | ||
logging_level="DEBUG", | ||
module_name="nestmlmodule", | ||
suffix="_nestml", | ||
codegen_opts={"neuron_parent_class": "StructuralPlasticityNode", | ||
"neuron_parent_class_include": "structural_plasticity_node.h", | ||
"neuron_synapse_pairs": [{"neuron": "iaf_psc_exp", | ||
"synapse": "dopa_synapse_second_order", | ||
"vt_ports": ["dopa_spikes"]}]}) | ||
|
||
@pytest.mark.skipif(NESTTools.detect_nest_version().startswith("v2"), | ||
reason="This test does not support NEST 2") | ||
def test_nest_stdp_synapse(self): | ||
|
||
resolution = .25 # [ms] | ||
delay = 1. # [ms] | ||
t_stop = 250. # [ms] | ||
|
||
nest.ResetKernel() | ||
nest.SetKernelStatus({"resolution": resolution}) | ||
nest.Install("nestmlmodule") | ||
|
||
# create spike_generator | ||
vt_sg = nest.Create("poisson_generator", | ||
params={"rate": 20.}) | ||
|
||
# create volume transmitter | ||
vt = nest.Create("volume_transmitter") | ||
vt_parrot = nest.Create("parrot_neuron") | ||
nest.Connect(vt_sg, vt_parrot) | ||
nest.Connect(vt_parrot, vt, syn_spec={"synapse_model": "static_synapse", | ||
"weight": 1., | ||
"delay": 1.}) # delay is ignored! | ||
vt_gid = vt.get("global_id") | ||
|
||
# set up custom synapse model | ||
wr = nest.Create("weight_recorder") | ||
nest.CopyModel(self.synapse_model_name, "stdp_nestml_rec", | ||
{"weight_recorder": wr[0], "d": delay, "receptor_type": 0, | ||
"vt": vt_gid}) | ||
|
||
# create parrot neurons and connect spike_generators | ||
pre_neuron = nest.Create("parrot_neuron") | ||
post_neuron = nest.Create(self.neuron_model_name) | ||
nest.Connect(pre_neuron, post_neuron, syn_spec={"synapse_model": "stdp_nestml_rec"}) | ||
|
||
syn = nest.GetConnections(pre_neuron, post_neuron) | ||
syn.tau_dopa = 25. # [ms] | ||
|
||
log = {"t": [0.], | ||
"dopa_rate": [syn.dopa_rate], | ||
"dopa_rate_d": [syn.dopa_rate_d]} | ||
|
||
n_timesteps = int(np.ceil(t_stop / resolution)) | ||
for timestep in range(n_timesteps): | ||
nest.Simulate(resolution) | ||
log["t"].append(nest.biological_time) | ||
log["dopa_rate"].append(syn.dopa_rate) | ||
log["dopa_rate_d"].append(syn.dopa_rate_d) | ||
|
||
if TEST_PLOTS: | ||
fig, ax = plt.subplots(nrows=2, dpi=300) | ||
ax[0].plot(log["t"], log["dopa_rate"], label="dopa_rate") | ||
ax[1].plot(log["t"], log["dopa_rate_d"], label="dopa_rate_d") | ||
for _ax in ax: | ||
_ax.legend() | ||
fig.savefig("/tmp/dopa_synapse_second_order_tests.png") | ||
plt.close(fig) | ||
|
||
np.testing.assert_allclose(log["dopa_rate"][-1], 0.6834882070000989) |
57 changes: 57 additions & 0 deletions
57
tests/nest_tests/resources/dopa_synapse_second_order.nestml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
dopa_synapse_second_order | ||
######################### | ||
|
||
|
||
Description | ||
+++++++++++ | ||
|
||
This model is used to test second-order integration of dopamine spikes. | ||
|
||
|
||
|
||
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/>. | ||
""" | ||
synapse dopa_synapse_second_order: | ||
state: | ||
dopa_rate real = 0. | ||
dopa_rate_d real = 0. | ||
|
||
parameters: | ||
tau_dopa ms = 100 ms | ||
d ms = 1 ms @nest::delay | ||
|
||
equations: | ||
dopa_rate' = dopa_rate_d / ms | ||
dopa_rate_d' = -dopa_rate / tau_dopa**2 * ms - 2 * dopa_rate_d / tau_dopa | ||
|
||
input: | ||
pre_spikes real <- spike | ||
dopa_spikes real <- spike | ||
|
||
output: | ||
spike | ||
|
||
onReceive(dopa_spikes): | ||
dopa_rate_d += 1. / tau_dopa | ||
|
||
onReceive(pre_spikes): | ||
deliver_spike(1., 1 ms) |