Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port test_multiple_multimeter from SLI-2-Py #2754

Merged
merged 9 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions testsuite/pytests/sli2py_neurons/test_add_freeze_thaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import numpy as np
import pytest

import nest


Expand Down
13 changes: 11 additions & 2 deletions testsuite/pytests/sli2py_recording/test_multimeter_freeze_thaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.

import nest
import numpy as np
import numpy.testing as nptest
import pytest

import nest


def build_net(num_neurons):
"""
Expand Down Expand Up @@ -62,6 +61,16 @@ def simulate_freeze_thaw(num_neurons):
return mm


def test_multimeter_freeze():
"""
Ensure that frozen parameter can be set to False but not True on multimeter.
"""

nest.Create("multimeter", params={"frozen": False})
with pytest.raises(Exception):
nest.Create("multimeter", params={"frozen": True})


def test_freeze_thaw_simulation_against_only_thawed_simulation():
"""
Verify identical results from freeze/thaw and non-freeze simulation.
Expand Down
96 changes: 59 additions & 37 deletions testsuite/pytests/test_multimeter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,74 @@
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.

import numpy.testing as nptest
import pytest

import nest

# Obtain all models with non-empty recordables list
all_models_with_rec = [model for model in nest.node_models if nest.GetDefaults(model).get("recordables")]


@pytest.fixture(autouse=True)
def reset_kernel():
nest.ResetKernel()

@pytest.fixture
def set_resolution():

def test_connect_multimeter_twice():
"""
Set resolution to power of two to avoid rounding issues.
Ensure one multimeter can only be connected once to one neuron.

First, we check that a multimeter can be connected to a neuron once. Then,
we check that that we cannot connect the multimeter more than once.
"""

nest.ResetKernel()
nest.resolution = 2**-3
nrn = nest.Create("iaf_psc_alpha")
mm = nest.Create("multimeter")
nest.Connect(mm, nrn)

with pytest.raises(nest.kernel.NESTErrors.IllegalConnection):
nest.Connect(mm, nrn)

# Obtain all models with non-empty recordables list
models = [model for model in nest.node_models if nest.GetDefaults(model).get("recordables")]

@pytest.mark.parametrize("model", all_models_with_rec)
def test_receptors_with_multiple_multimeters(model):
"""
Test receptors when connecting to multiple multimeters.

This test is to ensure that connections from two multimeters get
receptors 1 and 2 for all models with recordables.
"""

nrn = nest.Create(model)
mm1 = nest.Create("multimeter", {"record_from": nrn.recordables})
mm2 = nest.Create("multimeter", {"record_from": nrn.recordables})
nest.Connect(mm1, nrn)
nest.Connect(mm2, nrn)

mm1_receptor = nest.GetConnections(mm1).get("receptor")
mm2_receptor = nest.GetConnections(mm2).get("receptor")

@pytest.mark.parametrize("model", models)
def test_recordables_are_recorded(set_resolution, model):
assert mm1_receptor == 1
assert mm2_receptor == 2


@pytest.mark.parametrize("model", all_models_with_rec)
def test_recordables_are_recorded(model):
"""
Test that recordables are recorded.

For each model with recordables, set up minimal simulation
recording from all recordables and test that data is provided.
I also checks that the recording interval can be set.
For each model with recordables, set up minimal simulation recording
from all recordables and test that data is provided. The test checks
that the correct of amount of data is collected for each recordable.
It also checks that the recording interval can be set.

.. note::
This test does not check if the data is meaningful.
"""

nest.resolution = 2**-3 # Set to power of two to avoid rounding issues

recording_interval = 2
simtime = 10
num_data_expected = simtime / recording_interval - 1
Expand All @@ -68,42 +104,28 @@ def test_recordables_are_recorded(set_resolution, model):
assert len(result[r]) == num_data_expected


@pytest.mark.parametrize("model", models)
def test_correct_amount_data_collected(model):
@pytest.mark.parametrize("model", all_models_with_rec)
def test_identical_recording_from_multiple_multimeters(model):
nicolossus marked this conversation as resolved.
Show resolved Hide resolved
"""
Test that the correct of amount of data is collected for each recordable.

For all models providing a 'recordables' entry in their status dict, this
test checks whether the correct amount of data is collected for each
recordable quantity.
Test identical recordings from multimeters with same configurations.

.. note::
This test does not check the content of the data collected.
In this test two identical multimeters are connected to the same neuron.
They should record identical data.
"""

nest.ResetKernel()

nrn = nest.Create(model)

# if the model is compartmental, we need to add at least a root compartment
if "compartments" in nest.GetDefaults(model):
nrn.compartments = {"parent_idx": -1}

recordables = nrn.recordables
mm = nest.Create("multimeter", {"record_from": recordables})
mm1 = nest.Create("multimeter", {"record_from": recordables})
mm2 = nest.Create("multimeter", {"record_from": recordables})

nest.Connect(mm1, nrn)
nest.Connect(mm2, nrn)

nest.Connect(mm, nrn)
nest.Simulate(10.0)

for recordable in recordables:
assert len(mm.events[recordable]) == 9


def test_multimeter_freeze():
"""
Ensure that frozen parameter can be set to False but not True on multimeter.
"""

nest.Create("multimeter", params={"frozen": False})
with pytest.raises(Exception):
nest.Create("multimeter", params={"frozen": True})
nptest.assert_array_equal(mm1.events[recordable], mm2.events[recordable])
156 changes: 0 additions & 156 deletions testsuite/unittests/test_multiple_multimeter.sli

This file was deleted.

Loading