Skip to content

Commit

Permalink
Merge pull request #2767 from nicolossus/port_test_issue_77
Browse files Browse the repository at this point in the history
Port `issue-77.sli` from SLI-2-Py
  • Loading branch information
heplesser committed Aug 30, 2023
2 parents 3f1fa5f + 96d2613 commit ee92833
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
the spikes have arrived must be identical in both cases.
"""

import nest
import pytest
import numpy as np
import numpy.testing as nptest
import pytest

import nest

# The following models will not be tested:
skip_list = [
"ginzburg_neuron", # binary neuron
"mcculloch_pitts_neuron", # binary neuron
Expand Down Expand Up @@ -87,7 +89,10 @@ def test_spike_multiplicity_parrot_neuron():
nest.ResetKernel()
multiplicities = [1, 3, 2]
spikes = [1.0, 2.0, 3.0]
sg = nest.Create("spike_generator", {"spike_times": spikes, "spike_multiplicities": multiplicities})
sg = nest.Create(
"spike_generator",
{"spike_times": spikes, "spike_multiplicities": multiplicities},
)
pn = nest.Create("parrot_neuron")
sr = nest.Create("spike_recorder")

Expand All @@ -112,7 +117,6 @@ def test_spike_multiplicity_parrot_neuron():
],
)
def test_spike_multiplicity(model):
print("model name:", model)
nest.ResetKernel()

n1 = nest.Create(model)
Expand Down
54 changes: 28 additions & 26 deletions testsuite/pytests/sli2py_recording/test_multimeter_stepping.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,37 @@

import nest

# The following models will not be tested:
skip_models = [
"gauss_rate_ipn",
"lin_rate_ipn",
"sigmoid_rate_ipn",
"sigmoid_rate_gg_1998_ipn",
"tanh_rate_ipn",
"threshold_lin_rate_ipn",
"lin_rate_opn",
"tanh_rate_opn",
"threshold_lin_rate_opn",
"rate_transformer_gauss",
"rate_transformer_lin",
"rate_transformer_sigmoid",
"rate_transformer_sigmoid_gg_1998",
"rate_transformer_tanh",
"rate_transformer_threshold_lin",
"ac_generator",
"dc_generator",
"noise_generator",
"step_current_generator",
"step_rate_generator",
"sinusoidal_poisson_generator",
"erfc_neuron",
"ginzburg_neuron",
"mcculloch_pitts_neuron",
"sinusoidal_gamma_generator",
"siegert_neuron",
"erfc_neuron", # binary neuron
"ginzburg_neuron", # binary neuron
"mcculloch_pitts_neuron", # binary neuron
"gauss_rate_ipn", # rate neuron
"lin_rate_ipn", # rate neuron
"lin_rate_opn", # rate neuron
"siegert_neuron", # rate neuron
"sigmoid_rate_gg_1998_ipn", # rate neuron
"sigmoid_rate_ipn", # rate neuron
"tanh_rate_ipn", # rate neuron
"tanh_rate_opn", # rate neuron
"threshold_lin_rate_ipn", # rate neuron
"threshold_lin_rate_opn", # rate neuron
"rate_transformer_gauss", # rate transformer
"rate_transformer_lin", # rate transformer
"rate_transformer_sigmoid", # rate transformer
"rate_transformer_sigmoid_gg_1998", # rate transformer
"rate_transformer_tanh", # rate transformer
"rate_transformer_threshold_lin", # rate transformer
"ac_generator", # generator device, does not support spike input
"dc_generator", # generator device, does not support spike input
"noise_generator", # generator device, does not support spike input
"step_current_generator", # generator device, does not support spike input
"step_rate_generator", # generator device, does not support spike input
"sinusoidal_poisson_generator", # generator device, does not support spike input
"sinusoidal_gamma_generator", # generator device, does not support spike input
]

# The following models require connections to rport 1:
extra_params = {
"iaf_psc_alpha_multisynapse": {"receptor_type": 1},
"iaf_psc_exp_multisynapse": {"receptor_type": 1},
Expand Down
149 changes: 149 additions & 0 deletions testsuite/pytests/sli2py_regressions/test_issue_77.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# -*- coding: utf-8 -*-
#
# test_issue_77.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/>.

"""
Regression test for Issue #77 (GitHub).
"""

import pytest

import nest

# The following models will not be tested:
skip_models = [
"erfc_neuron", # binary neuron
"ginzburg_neuron", # binary neuron
"mcculloch_pitts_neuron", # binary neuron
"gif_pop_psc_exp", # population model, not suitable for STDP
"gauss_rate_ipn", # rate neuron
"lin_rate_ipn", # rate neuron
"lin_rate_opn", # rate neuron
"siegert_neuron", # rate neuron
"sigmoid_rate_gg_1998_ipn", # rate neuron
"sigmoid_rate_ipn", # rate neuron
"tanh_rate_ipn", # rate neuron
"tanh_rate_opn", # rate neuron
"threshold_lin_rate_ipn", # rate neuron
"threshold_lin_rate_opn", # rate neuron
"rate_transformer_gauss", # rate transformer
"rate_transformer_lin", # rate transformer
"rate_transformer_sigmoid", # rate transformer
"rate_transformer_sigmoid_gg_1998", # rate transformer
"rate_transformer_tanh", # rate transformer
"rate_transformer_threshold_lin", # rate transformer
"spike_train_injector", # generator neuron, does not support spike input
"music_cont_in_proxy", # MUSIC device
"music_cont_out_proxy", # MUSIC device
"music_event_in_proxy", # MUSIC device
"music_event_out_proxy", # MUSIC device
"music_message_in_proxy", # MUSIC device
"music_rate_in_proxy", # MUSIC device
"music_rate_out_proxy", # MUSIC device
]

# The following models require connections to rport 1 or other specific parameters:
extra_params = {
"aeif_psc_alpha": {"initial_weight": 80.0},
"aeif_psc_delta": {"initial_weight": 80.0},
"aeif_psc_exp": {"initial_weight": 80.0},
"aeif_cond_alpha_multisynapse": {
"params": {"E_rev": [-20.0], "tau_syn": [2.0]},
"receptor_type": 1,
},
"aeif_cond_beta_multisynapse": {
"params": {"E_rev": [-20.0], "tau_rise": [1.0], "tau_decay": [2.0]},
"receptor_type": 1,
},
"iaf_cond_alpha_mc": {"receptor_type": 1},
"iaf_psc_alpha_multisynapse": {"params": {"tau_syn": [1.0]}, "receptor_type": 1},
"iaf_psc_exp_multisynapse": {"params": {"tau_syn": [1.0]}, "receptor_type": 1},
"gif_cond_exp_multisynapse": {"params": {"tau_syn": [1.0]}, "receptor_type": 1},
"gif_psc_exp_multisynapse": {"params": {"tau_syn": [1.0]}, "receptor_type": 1},
"glif_cond": {"params": {"tau_syn": [0.2], "E_rev": [0.0]}, "receptor_type": 1},
"glif_psc": {"params": {"tau_syn": [1.0]}, "receptor_type": 1},
"ht_neuron": {"receptor_type": 1},
"pp_cond_exp_mc_urbanczik": {"receptor_type": 1},
}

models = [
model
for model in nest.node_models
if (nest.GetDefaults(model, "element_type") == "neuron") and model not in skip_models
]


@pytest.mark.parametrize("model", models)
def test_register_outgoing_spikes(model):
"""
Ensure that all neuron models register outgoing spikes with archiving node.
The test sends a very high-rate Poisson spike train into the neuron that
should make any type of model neuron fire and checks both `t_spike` entry
of the neuron (>0 if neuron has spiked) and checks that the connection
weight differs from the initial value 1.0.
"""
nest.ResetKernel()

nrn = nest.Create(model)

if model in extra_params:
if "params" in extra_params[model]:
nrn.set(extra_params[model].get("params"))

# if the model is compartmental, we need to add at least a root compartment
if "compartments" in nest.GetDefaults(model):
nrn.compartments = {"parent_idx": -1}
nrn.receptors = {"comp_idx": 0, "receptor_type": "AMPA"}

pg = nest.Create("poisson_generator", params={"rate": 1e5})
parrot = nest.Create("parrot_neuron_ps")
srec = nest.Create("spike_recorder")

# need to connect via parrot since generators cannot connect with
# plastic synapses.
nest.Connect(pg, parrot)

receptor_type = 0
initial_weight = 10.0
if model in extra_params:
if "receptor_type" in extra_params[model]:
receptor_type = extra_params[model].get("receptor_type")
if "initial_weight" in extra_params[model]:
initial_weight = extra_params[model].get("initial_weight")

syn_spec = {
"synapse_model": "stdp_synapse",
"weight": initial_weight,
"receptor_type": receptor_type,
}

nest.Connect(parrot, nrn, "one_to_one", syn_spec)
nest.Connect(nrn, srec)

nest.Simulate(100.0)

num_spikes = srec.n_events
t_last_spike = nrn.t_spike
weight_after_sim = nest.GetConnections(parrot).get("weight")

assert num_spikes > 0
assert t_last_spike > 0
assert weight_after_sim != initial_weight
4 changes: 1 addition & 3 deletions testsuite/pytests/test_multimeter.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ def test_correct_amount_data_collected(model):

# if the model is compartmental, we need to add at least a root compartment
if "compartments" in nest.GetDefaults(model):
nrn.compartments = {
"parent_idx": -1,
}
nrn.compartments = {"parent_idx": -1}

recordables = nrn.recordables
mm = nest.Create("multimeter", {"record_from": recordables})
Expand Down
Loading

0 comments on commit ee92833

Please sign in to comment.