Skip to content

Commit 57e0d29

Browse files
committed
use modern nest notations
1 parent e11a6b9 commit 57e0d29

File tree

3 files changed

+39
-46
lines changed

3 files changed

+39
-46
lines changed

testsuite/pytests/sli2py_neurons/test_iaf_ps_dc_accuracy.py

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,9 @@
3434
"iaf_psc_exp_ps_lossless",
3535
],
3636
)
37-
@pytest.mark.parametrize("resolution", [2**i for i in range(0, -14, -1)])
38-
@pytest.mark.parametrize(
39-
"params",
40-
[
41-
{
42-
"E_L": 0.0, # resting potential in mV
43-
"V_m": 0.0, # initial membrane potential in mV
44-
"V_th": 2000.0, # spike threshold in mV
45-
"I_e": 1000.0, # DC current in pA
46-
"tau_m": 10.0, # membrane time constant in ms
47-
"C_m": 250.0, # membrane capacity in pF
48-
}
49-
],
50-
)
37+
@pytest.mark.parametrize("resolution", [2 ** i for i in range(0, -14, -1)])
5138
@pytest.mark.parametrize("duration, tolerance", [(5.0, 1e-13), (500.0, 1e-9)])
52-
def test_iaf_ps_dc_accuracy(model, resolution, params, duration, tolerance):
39+
def test_iaf_ps_dc_accuracy(model, resolution, duration, tolerance):
5340
"""
5441
A DC current is injected for a finite duration. The membrane potential at
5542
the end of the simulated interval is compared to the theoretical value for
@@ -71,15 +58,23 @@ def test_iaf_ps_dc_accuracy(model, resolution, params, duration, tolerance):
7158
to function print_details.
7259
"""
7360
nest.ResetKernel()
74-
nest.SetKernelStatus({"tics_per_ms": 2**14, "resolution": resolution})
61+
nest.set(tics_per_ms=2 ** 14, resolution=resolution)
62+
63+
params = {
64+
"E_L": 0.0, # resting potential in mV
65+
"V_m": 0.0, # initial membrane potential in mV
66+
"V_th": 2000.0, # spike threshold in mV
67+
"I_e": 1000.0, # DC current in pA
68+
"tau_m": 10.0, # membrane time constant in ms
69+
"C_m": 250.0, # membrane capacity in pF
70+
}
7571

7672
neuron = nest.Create(model, params=params)
7773
nest.Simulate(duration)
7874

79-
V_m = nest.GetStatus(neuron, "V_m")[0]
80-
expected_V_m = params["I_e"] * params["tau_m"] / params["C_m"] * (1.0 - math.exp(-duration / params["tau_m"]))
75+
expected_vm = params["I_e"] * params["tau_m"] / params["C_m"] * (1.0 - math.exp(-duration / params["tau_m"]))
8176

82-
assert math.fabs(V_m - expected_V_m) < tolerance
77+
assert neuron.V_m - pytest.approx(expected_vm, abs=tolerance)
8378

8479

8580
@pytest.mark.parametrize(
@@ -91,22 +86,9 @@ def test_iaf_ps_dc_accuracy(model, resolution, params, duration, tolerance):
9186
"iaf_psc_exp_ps_lossless",
9287
],
9388
)
94-
@pytest.mark.parametrize("resolution", [2**i for i in range(0, -14, -1)])
95-
@pytest.mark.parametrize(
96-
"params",
97-
[
98-
{
99-
"E_L": 0.0, # resting potential in mV
100-
"V_m": 0.0, # initial membrane potential in mV
101-
"V_th": 15.0, # spike threshold in mV
102-
"I_e": 1000.0, # DC current in pA
103-
"tau_m": 10.0, # membrane time constant in ms
104-
"C_m": 250.0, # membrane capacity in pF
105-
}
106-
],
107-
)
89+
@pytest.mark.parametrize("resolution", [2 ** i for i in range(0, -14, -1)])
10890
@pytest.mark.parametrize("duration, tolerance", [(5.0, 1e-13)])
109-
def test_iaf_ps_dc_t_accuracy(model, resolution, params, duration, tolerance):
91+
def test_iaf_ps_dc_t_accuracy(model, resolution, duration, tolerance):
11092
"""
11193
A DC current is injected for a finite duration. The time of the first
11294
spike is compared to the theoretical value for different computation
@@ -124,18 +106,27 @@ def test_iaf_ps_dc_t_accuracy(model, resolution, params, duration, tolerance):
124106
call to function print_details.
125107
"""
126108
nest.ResetKernel()
127-
nest.SetKernelStatus({"tics_per_ms": 2**14, "resolution": resolution})
109+
nest.set(tics_per_ms=2 ** 14, resolution=resolution)
110+
111+
params = {
112+
"E_L": 0.0, # resting potential in mV
113+
"V_m": 0.0, # initial membrane potential in mV
114+
"V_th": 15.0, # spike threshold in mV
115+
"I_e": 1000.0, # DC current in pA
116+
"tau_m": 10.0, # membrane time constant in ms
117+
"C_m": 250.0, # membrane capacity in pF
118+
}
128119

129120
neuron = nest.Create(model, params=params)
130121
spike_recorder = nest.Create("spike_recorder")
131122
nest.Connect(neuron, spike_recorder)
132123

133124
nest.Simulate(duration)
134125

135-
spike_times = nest.GetStatus(spike_recorder, "events")[0]["times"]
126+
spike_times = spike_recorder.get("events", "times")
136127
assert len(spike_times) == 1, "Neuron did not spike exactly once."
137128

138129
t_spike = spike_times[0]
139130
expected_t = -params["tau_m"] * math.log(1.0 - (params["C_m"] * params["V_th"]) / (params["tau_m"] * params["I_e"]))
140131

141-
assert math.fabs(t_spike - expected_t) < tolerance
132+
assert t_spike == pytest.approx(expected_t, abs=tolerance)

testsuite/pytests/sli2py_neurons/test_iaf_psc_alpha.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def test_iaf_psc_alpha_i0_refractory(resolution):
235235
duration = 8.0
236236

237237
nest.ResetKernel()
238-
nest.SetKernelStatus({"resolution": resolution})
238+
nest.resolution = resolution
239239

240240
neuron = nest.Create("iaf_psc_alpha", params={"I_e": 1450.0})
241241
voltmeter = nest.Create("voltmeter", params={"interval": resolution})
@@ -246,9 +246,8 @@ def test_iaf_psc_alpha_i0_refractory(resolution):
246246

247247
nest.Simulate(duration)
248248

249-
events = voltmeter.events
250-
times = events["times"]
251-
V_m = events["V_m"]
249+
times = voltmeter.events["times"]
250+
V_m = voltmeter.events["V_m"]
252251
results = np.column_stack((times, V_m))
253252

254253
actual, expected = testutil.get_comparable_timesamples(

testsuite/pytests/sli2py_neurons/test_iaf_psc_alpha_fudge.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,17 @@ def test_iaf_psc_alpha_fudge():
6969
C_m = 250.0
7070

7171
# Set neuron parameters
72-
nest.SetStatus(neuron, {"tau_m": tau_m, "tau_syn_ex": tau_syn, "tau_syn_in": tau_syn, "C_m": C_m})
72+
neuron.tau_m = tau_m
73+
neuron.tau_syn_ex = tau_syn
74+
neuron.tau_syn_in = tau_syn
75+
neuron.C_m = C_m
7376

7477
# Compute fudge factors
7578
a = tau_m / tau_syn
7679
b = 1.0 / tau_syn - 1.0 / tau_m
7780
t_max = (1.0 / b) * (-lambertw(-math.exp(-1.0 / a) / a, k=-1) - 1.0 / a).real
7881

79-
V_max = (
82+
v_max = (
8083
math.exp(1)
8184
/ (tau_syn * C_m * b)
8285
* ((math.exp(-t_max / tau_m) - math.exp(-t_max / tau_syn)) / b - t_max * math.exp(-t_max / tau_syn))
@@ -92,16 +95,16 @@ def test_iaf_psc_alpha_fudge():
9295
)
9396

9497
# Connect spike generator to neuron
95-
nest.Connect(spike_gen, neuron, syn_spec={"weight": float(1.0 / V_max), "delay": delay})
98+
nest.Connect(spike_gen, neuron, syn_spec={"weight": float(1.0 / v_max), "delay": delay})
9699

97100
# Simulate
98101
nest.Simulate(duration)
99102

100103
# Extract membrane potential trace
101104
volt_data = voltmeter.events
102105
times = volt_data["times"]
103-
V_m = volt_data["V_m"]
104-
results = np.column_stack((times, V_m))
106+
v_m = volt_data["V_m"]
107+
results = np.column_stack((times, v_m))
105108

106109
# Find time of peak voltage
107110
actual_t_max = results[np.argmax(results[:, 1]), 0]

0 commit comments

Comments
 (0)