Skip to content

Commit 32f0390

Browse files
Merge pull request #3683 from jessica-mitchell/test_threaded_multimeter
Convert unittest test_threaded_multimeter to Pytest
2 parents ce217f3 + d2f0cbd commit 32f0390

File tree

2 files changed

+79
-84
lines changed

2 files changed

+79
-84
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# test_threaded_multimeter.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+
BeginDocumentation
24+
Name: testsuite::test_threaded_multimeter - test support for multimeter
25+
26+
Synopsis: (test_threaded_multimeter.sli) run -> dies if assertion fails
27+
28+
Description:
29+
Tests that multimeter works when we use threads.
30+
31+
Test ported from SLI unit test.
32+
33+
Author: Stine B. Vennemo
34+
FirstVersion: June 2017
35+
SeeAlso: test_treaded_spike_recorder.sli
36+
"""
37+
38+
import nest
39+
import numpy as np
40+
import pytest
41+
42+
43+
@pytest.mark.skipif_missing_threads
44+
def test_threaded_multimeter():
45+
"""
46+
Test that multimeter works correctly with multiple threads.
47+
"""
48+
N = 10 # should not be divisible by thread number
49+
50+
def run_multimeter(n_threads):
51+
nest.ResetKernel()
52+
# Distributed setting not covered
53+
assert nest.num_processes == 1
54+
nest.set(local_num_threads=n_threads)
55+
56+
# Create neurons with different initial V_m
57+
nrns = nest.Create("iaf_psc_alpha", N, params={"I_e": 40.0})
58+
for i, nrn in enumerate(nrns):
59+
v_m = -90.0 + 30.0 * i / N
60+
nrn.set({"V_m": v_m})
61+
62+
# Create multimeter
63+
ac = nest.Create("multimeter", params={"record_from": ["V_m"], "interval": 1.0})
64+
65+
nest.Connect(ac, nrns)
66+
67+
nest.Simulate(5.0)
68+
69+
# Obtain data
70+
events = ac.get("events")
71+
return events["V_m"], events["senders"]
72+
73+
# Run with 1 and 3 threads
74+
r1V, r1s = run_multimeter(1)
75+
r3V, r3s = run_multimeter(3)
76+
77+
# Sort and compare - results should be identical regardless of thread count
78+
assert np.array_equal(np.sort(r1V), np.sort(r3V))
79+
assert np.array_equal(np.sort(r1s), np.sort(r3s))

testsuite/unittests/test_threaded_multimeter.sli

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

0 commit comments

Comments
 (0)