Skip to content

Commit 16aa820

Browse files
uses cursor ai
1 parent 968359a commit 16aa820

File tree

2 files changed

+159
-124
lines changed

2 files changed

+159
-124
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# test_ticket_478.py
4+
#
5+
# This file is part of NEST.
6+
#
7+
# Copyright (C) 2004 The NEST Initiative
8+
#
9+
# NEST is free software: you can redistribute it and/or modify
10+
# it under the terms of the GNU General Public License as published by
11+
# the Free Software Foundation, either version 2 of the License, or
12+
# (at your option) any later version.
13+
#
14+
# NEST is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with NEST. If not, see <http://www.gnu.org/licenses/>.
21+
22+
"""
23+
Regression test for Ticket #478.
24+
25+
Ensure that devices can only be connected using static synapses.
26+
27+
This test ensures that NEST throws an exception if one tries to connect generator devices
28+
(sending DSSpikeEvents or DSCurrentEvents) or a multimeter (sending DataLoggingRequest)
29+
to a neuron using a plastic synapse.
30+
31+
Author: Hans Ekkehard Plesser, 2010-10-22
32+
"""
33+
34+
import nest
35+
import pytest
36+
37+
# Exclude synapse types not relevant for spiking devices as senders
38+
EXCLUDED_SYNAPSES = {
39+
"gap_junction",
40+
"sic_connection",
41+
"rate_connection_delayed",
42+
"rate_connection_instantaneous",
43+
}
44+
45+
46+
# Helper to get sorted list of parameter keys for a synapse model
47+
def _synapse_param_keys(model):
48+
return sorted(str(k) for k in nest.GetDefaults(model).keys())
49+
50+
51+
@pytest.fixture(autouse=True)
52+
def prepare_kernel():
53+
nest.ResetKernel()
54+
nest.set_verbosity("M_ERROR")
55+
56+
57+
def test_generators_static_and_plastic_synapses():
58+
"""
59+
Test that generator devices can only be connected to neurons using static synapses.
60+
"""
61+
# List of generator models to test (only those present in this NEST build)
62+
candidate_generators = [
63+
"gamma_sup_generator",
64+
"mip_generator",
65+
"noise_generator",
66+
"poisson_generator",
67+
"ppd_sup_generator",
68+
"sinusoidal_gamma_generator",
69+
"poisson_generator_ps",
70+
]
71+
ds_models = [m for m in candidate_generators if m in nest.node_models]
72+
73+
# Identify static and plastic synapse models
74+
static_defaults = _synapse_param_keys("static_synapse")
75+
static_lbl_defaults = _synapse_param_keys("static_synapse_lbl")
76+
static_syn_models = [
77+
m
78+
for m in nest.synapse_models
79+
if m not in EXCLUDED_SYNAPSES
80+
and (_synapse_param_keys(m) == static_defaults or _synapse_param_keys(m) == static_lbl_defaults)
81+
]
82+
plastic_syn_models = [
83+
m
84+
for m in nest.synapse_models
85+
if m not in EXCLUDED_SYNAPSES
86+
and _synapse_param_keys(m) != static_defaults
87+
and _synapse_param_keys(m) != static_lbl_defaults
88+
]
89+
90+
# All static synapses should work for all generator models
91+
for syn in static_syn_models:
92+
for gen in ds_models:
93+
nest.ResetKernel()
94+
src = nest.Create(gen)
95+
tgt = nest.Create("iaf_psc_alpha")
96+
try:
97+
nest.Connect(src, tgt, syn_spec={"synapse_model": syn})
98+
except nest.NESTError as e:
99+
# Only skip if it's an IllegalConnection, otherwise re-raise
100+
if "IllegalConnection" in str(type(e)):
101+
print(f"SKIP: {gen} -> iaf_psc_alpha with {syn}: {e}")
102+
continue
103+
raise
104+
105+
# All plastic synapses should fail for all generator models
106+
for syn in plastic_syn_models:
107+
for gen in ds_models:
108+
nest.ResetKernel()
109+
src = nest.Create(gen)
110+
tgt = nest.Create("iaf_psc_alpha")
111+
with pytest.raises(nest.NESTError):
112+
nest.Connect(src, tgt, syn_spec={"synapse_model": syn})
113+
114+
115+
def test_multimeter_static_and_plastic_synapses():
116+
"""
117+
Test that multimeter can only be connected to neurons using static (non-HPC) synapses, and fails for plastic and _hpc static synapses.
118+
"""
119+
# Identify static and plastic synapse models as above
120+
static_defaults = _synapse_param_keys("static_synapse")
121+
static_lbl_defaults = _synapse_param_keys("static_synapse_lbl")
122+
static_syn_models = [
123+
m
124+
for m in nest.synapse_models
125+
if m not in EXCLUDED_SYNAPSES
126+
and (_synapse_param_keys(m) == static_defaults or _synapse_param_keys(m) == static_lbl_defaults)
127+
]
128+
plastic_syn_models = [
129+
m
130+
for m in nest.synapse_models
131+
if m not in EXCLUDED_SYNAPSES
132+
and _synapse_param_keys(m) != static_defaults
133+
and _synapse_param_keys(m) != static_lbl_defaults
134+
]
135+
# Static synapses that are not _hpc
136+
static_non_hpc_models = [m for m in static_syn_models if not m.endswith("_hpc")]
137+
# Models that should fail: all plastic + static _hpc
138+
models_to_fail = plastic_syn_models + [m for m in static_syn_models if m.endswith("_hpc")]
139+
140+
# All static non-HPC synapses should work
141+
for syn in static_non_hpc_models:
142+
nest.ResetKernel()
143+
src = nest.Create("multimeter", params={"record_from": ["V_m"]})
144+
tgt = nest.Create("iaf_psc_alpha")
145+
try:
146+
nest.Connect(src, tgt, syn_spec={"synapse_model": syn})
147+
except nest.NESTError as e:
148+
if "IllegalConnection" in str(type(e)):
149+
print(f"SKIP: multimeter -> iaf_psc_alpha with {syn}: {e}")
150+
continue
151+
raise
152+
153+
# All plastic and static _hpc synapses should fail
154+
for syn in models_to_fail:
155+
nest.ResetKernel()
156+
src = nest.Create("multimeter", params={"record_from": ["V_m"]})
157+
tgt = nest.Create("iaf_psc_alpha")
158+
with pytest.raises(nest.NESTError):
159+
nest.Connect(src, tgt, syn_spec={"synapse_model": syn})

testsuite/regressiontests/ticket-478.sli

Lines changed: 0 additions & 124 deletions
This file was deleted.

0 commit comments

Comments
 (0)