Skip to content

Commit 1ab2e5a

Browse files
authored
Merge pull request #2752 from clinssen/sli_tests_to_py_aeif_cond_beta_multisynapse
Port `aeif_cond_beta_multisynapse_test` from SLI-2-Py and add test for `..._alpha_...`
2 parents ca63748 + c92d270 commit 1ab2e5a

File tree

4 files changed

+449
-544
lines changed

4 files changed

+449
-544
lines changed

testsuite/pytests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test_gsl():
3232
"""
3333

3434
import dataclasses
35+
import os
3536
import pathlib
3637
import sys
3738

@@ -79,6 +80,11 @@ def have_threads():
7980
return nest.ll_api.sli_func("is_threaded")
8081

8182

83+
@pytest.fixture(scope="session")
84+
def report_dir() -> pathlib.Path:
85+
return pathlib.Path(os.environ.get("REPORTDIR", ""))
86+
87+
8288
@pytest.fixture(autouse=True)
8389
def skipif_missing_threads(request, have_threads):
8490
"""

testsuite/pytests/test_aeif_cond_alpha_multisynapse.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,38 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with NEST. If not, see <http://www.gnu.org/licenses/>.
2121

22-
"""
23-
This test creates a multisynapse neuron and first checks if time constants
24-
can be set correctly.
25-
26-
Afterwards, it simulates the mutisynapse neuron with n (n=4) different time
27-
constants and records the neuron's synaptic current. At the same time, it simulates
28-
n (n=4) single synapse neurons with according parameters.
29-
At the end, it compares the multisynapse neuron currents with each according single
30-
synapse current.
31-
"""
32-
3322
import nest
3423
import numpy as np
3524
import pytest
3625

3726

3827
@pytest.mark.skipif_missing_gsl
3928
class TestAeifCondAlphaMultisynapse:
40-
def test_single_multi_synapse_equivalence(self, have_plotting):
41-
simulation_t = 2500.0 # ms
29+
r"""
30+
This test creates a multisynapse neuron and first checks if time constants
31+
can be set correctly.
32+
33+
Afterwards, it simulates the mutisynapse neuron with n (n=4) different time
34+
constants and records the neuron's synaptic current. At the same time, it simulates
35+
n (n=4) single synapse neurons with according parameters.
36+
At the end, it compares the multisynapse neuron currents with each according single
37+
synapse current.
38+
"""
4239

43-
dt = 0.1
40+
def test_single_multi_synapse_equivalence(self, have_plotting, report_dir):
41+
simulation_t = 2500.0 # total simulation time [ms]
4442

45-
E_ex = 0.0 # mV
46-
E_in = -85.0 # mV
47-
V_peak = 0.0
43+
dt = 0.1 # time step [ms]
44+
45+
E_ex = 0.0 # excitatory reversal potential [mV]
46+
E_in = -85.0 # inhibitory reversal potential [mV]
47+
V_peak = 0.0 # spike detection threshold [mV]
4848
a = 4.0
4949
b = 80.5
50-
tau_syn = [0.2, 0.5, 1.0, 10.0]
51-
weight = [1.0, 5.0, 1.0, -1.0]
52-
E_rev = [E_ex, E_ex, E_ex, E_in]
53-
spike_time = 1.0
50+
tau_syn = [0.2, 0.5, 1.0, 10.0] # synaptic times [ms]
51+
weight = [1.0, 5.0, 1.0, -1.0] # synaptic weights
52+
E_rev = [E_ex, E_ex, E_ex, E_in] # synaptic reversal potentials [mV]
53+
spike_time = 1.0 # time at which the single spike occurs [ms]
5454

5555
# The delays have to be ordered and needs enough space between them to avoid one PSC from affecting the next
5656
delays = [1.0, 500.0, 1500.0, 2250.0] # ms
@@ -147,12 +147,14 @@ def test_single_multi_synapse_equivalence(self, have_plotting):
147147
_ax.legend()
148148

149149
ax[-1].semilogy(multisynapse_neuron_vm.get("events")["times"], error, label="errror")
150-
fig.savefig("test_aeif_cond_alpha_multisynapse.png")
150+
151+
fig.savefig(report_dir / "test_aeif_cond_alpha_multisynapse.png")
151152

152153
# compare with a large tolerance because previous PSPs affect subsequent PSPs in the multisynapse neuron
153154
np.testing.assert_allclose(error, 0, atol=1e-6)
154155

155156
def test_recordables(self):
157+
r"""Test that the right number of recordables are created when setting ``record_from``."""
156158
nest.ResetKernel()
157159

158160
nrn = nest.Create("aeif_cond_alpha_multisynapse")
@@ -166,7 +168,7 @@ def test_recordables(self):
166168
assert len(nrn.recordables) == 3
167169

168170
def test_resize_recordables(self):
169-
"""Test that the recordable g's change when changing the number of receptor ports"""
171+
r"""Test that the recordable g's change when changing the number of receptor ports"""
170172
nest.ResetKernel()
171173

172174
E_rev1 = [0.0, 0.0, -85.0]
@@ -185,8 +187,8 @@ def test_resize_recordables(self):
185187
nrn.set({"E_rev": E_rev3, "tau_syn": tau_syn3})
186188
assert len(nrn.recordables) == 6
187189

188-
def test_g_alpha_dynamics(self, have_plotting):
189-
"""Test that g has alpha function dynamics"""
190+
def test_g_alpha_dynamics(self, have_plotting, report_dir):
191+
r"""Test that g has alpha function dynamics"""
190192

191193
dt = 0.1 # time step
192194

@@ -196,7 +198,7 @@ def test_g_alpha_dynamics(self, have_plotting):
196198
E_rev = [0.0, 0.0, -85.0, 20.0] # synaptic reversal potentials
197199
tau_syn = [40.0, 20.0, 30.0, 25.0] # synaptic time constants
198200
weight = [1.0, 0.5, 2.0, 1.0] # synaptic weights
199-
delays = [1.0, 3.0, 10.0, 10.0] # ms - synaptic delays
201+
delays = [1.0, 3.0, 10.0, 10.0] # synaptic delays [ms]
200202
spike_time = 10.0 # time at which the single spike occurs
201203
total_t = 500.0 # total simulation time
202204

@@ -258,6 +260,6 @@ def alpha_function(t, W=1.0, tau=1.0, t0=0.0):
258260
for _ax in ax:
259261
_ax.legend()
260262

261-
fig.savefig("test_aeif_cond_alpha_multisynapse_psc_shape_ " + str(i) + ".png")
263+
fig.savefig(report_dir / f"test_aeif_cond_alpha_multisynapse_psc_shape_{i}.png")
262264

263265
np.testing.assert_allclose(sim_g, theo_g)

0 commit comments

Comments
 (0)