34
34
"iaf_psc_exp_ps_lossless" ,
35
35
],
36
36
)
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 )])
51
38
@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 ):
53
40
"""
54
41
A DC current is injected for a finite duration. The membrane potential at
55
42
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):
71
58
to function print_details.
72
59
"""
73
60
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
+ }
75
71
76
72
neuron = nest .Create (model , params = params )
77
73
nest .Simulate (duration )
78
74
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" ]))
81
76
82
- assert math . fabs ( V_m - expected_V_m ) < tolerance
77
+ assert neuron . V_m - pytest . approx ( expected_vm , abs = tolerance )
83
78
84
79
85
80
@pytest .mark .parametrize (
@@ -91,22 +86,9 @@ def test_iaf_ps_dc_accuracy(model, resolution, params, duration, tolerance):
91
86
"iaf_psc_exp_ps_lossless" ,
92
87
],
93
88
)
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 )])
108
90
@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 ):
110
92
"""
111
93
A DC current is injected for a finite duration. The time of the first
112
94
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):
124
106
call to function print_details.
125
107
"""
126
108
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
+ }
128
119
129
120
neuron = nest .Create (model , params = params )
130
121
spike_recorder = nest .Create ("spike_recorder" )
131
122
nest .Connect (neuron , spike_recorder )
132
123
133
124
nest .Simulate (duration )
134
125
135
- spike_times = nest . GetStatus ( spike_recorder , "events" )[ 0 ][ "times" ]
126
+ spike_times = spike_recorder . get ( "events" , "times" )
136
127
assert len (spike_times ) == 1 , "Neuron did not spike exactly once."
137
128
138
129
t_spike = spike_times [0 ]
139
130
expected_t = - params ["tau_m" ] * math .log (1.0 - (params ["C_m" ] * params ["V_th" ]) / (params ["tau_m" ] * params ["I_e" ]))
140
131
141
- assert math . fabs ( t_spike - expected_t ) < tolerance
132
+ assert t_spike == pytest . approx ( expected_t , abs = tolerance )
0 commit comments