Skip to content

Commit

Permalink
Handle non-availability of certain simulators
Browse files Browse the repository at this point in the history
(e.g. NEST on Windows)
  • Loading branch information
apdavison committed Oct 14, 2022
1 parent d2d72ce commit 151fdd4
Show file tree
Hide file tree
Showing 18 changed files with 257 additions and 188 deletions.
29 changes: 29 additions & 0 deletions test/system/scenarios/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

import pytest

available_modules = {}

try:
import pyNN.neuron
available_modules["neuron"] = pyNN.neuron
except ImportError:
pass

try:
import pyNN.nest
available_modules["nest"] = pyNN.nest
except ImportError:
pass

try:
import pyNN.brian2
available_modules["brian2"] = pyNN.brian2
except ImportError:
pass


def get_simulator(sim_name):
if sim_name in available_modules:
return available_modules[sim_name]
else:
pytest.skip(f"{sim_name} not available")
44 changes: 25 additions & 19 deletions test/system/scenarios/test_cell_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
import quantities as pq
from pyNN.parameters import Sequence
from pyNN.errors import InvalidParameterValueError
import pyNN.nest
import pyNN.neuron
import pyNN.brian2
from .fixtures import get_simulator
import pytest


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_EIF_cond_alpha_isfa_ista(sim, plot_figure=False):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_EIF_cond_alpha_isfa_ista(sim_name, plot_figure=False):
sim = get_simulator(sim_name)
sim.setup(timestep=0.01, min_delay=0.1, max_delay=4.0)
ifcell = sim.create(sim.EIF_cond_alpha_isfa_ista(
i_offset=1.0, tau_refrac=2.0, v_spike=-40))
Expand All @@ -39,8 +38,9 @@ def test_EIF_cond_alpha_isfa_ista(sim, plot_figure=False):
return data


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_HH_cond_exp(sim, plot_figure=False):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_HH_cond_exp(sim_name, plot_figure=False):
sim = get_simulator(sim_name)
sim.setup(timestep=0.001, min_delay=0.1)
cellparams = {
'gbar_Na': 20.0,
Expand Down Expand Up @@ -72,8 +72,9 @@ def test_HH_cond_exp(sim, plot_figure=False):


# exclude brian2 - see issue 370
@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron))
def issue367(sim, plot_figure=False):
@pytest.mark.parametrize("sim_name", ("nest", "neuron"))
def issue367(sim_name, plot_figure=False):
sim = get_simulator(sim_name)
# AdEx dynamics for delta_T=0
sim.setup(timestep=0.001, min_delay=0.1, max_delay=4.0)
v_thresh = -50
Expand Down Expand Up @@ -103,8 +104,9 @@ def issue367(sim, plot_figure=False):
return data


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_SpikeSourcePoisson(sim, plot_figure=False):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_SpikeSourcePoisson(sim_name, plot_figure=False):
sim = get_simulator(sim_name)
try:
from scipy.stats import kstest
except ImportError:
Expand Down Expand Up @@ -152,12 +154,13 @@ def test_SpikeSourcePoisson(sim, plot_figure=False):
return data


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron))
def test_SpikeSourceGamma(sim, plot_figure=False):
@pytest.mark.parametrize("sim_name", ("nest", "neuron"))
def test_SpikeSourceGamma(sim_name, plot_figure=False):
try:
from scipy.stats import kstest
except ImportError:
pytest.skip("scipy not available")
sim = get_simulator(sim_name)
sim.setup()
params = {
"beta": [100.0, 200.0, 1000.0],
Expand Down Expand Up @@ -208,12 +211,13 @@ def test_SpikeSourceGamma(sim, plot_figure=False):
return data


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron))
def test_SpikeSourcePoissonRefractory(sim, plot_figure=False):
@pytest.mark.parametrize("sim_name", ("nest", "neuron"))
def test_SpikeSourcePoissonRefractory(sim_name, plot_figure=False):
try:
from scipy.stats import kstest
except ImportError:
pytest.skip("scipy not available")
sim = get_simulator(sim_name)
sim.setup()
params = {
"rate": [100, 100, 50.0],
Expand Down Expand Up @@ -266,17 +270,19 @@ def test_SpikeSourcePoissonRefractory(sim, plot_figure=False):
return data


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_issue511(sim):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_issue511(sim_name):
"""Giving SpikeSourceArray an array of non-ordered spike times should produce an InvalidParameterValueError error"""
sim = get_simulator(sim_name)
sim.setup()
celltype = sim.SpikeSourceArray(spike_times=[[2.4, 4.8, 6.6, 9.4], [3.5, 6.8, 9.6, 8.3]])
with pytest.raises(InvalidParameterValueError):
sim.Population(2, celltype)


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_update_SpikeSourceArray(sim, plot_figure=False):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_update_SpikeSourceArray(sim_name, plot_figure=False):
sim = get_simulator(sim_name)
sim.setup()
sources = sim.Population(2, sim.SpikeSourceArray(spike_times=[]))
sources.record('spikes')
Expand Down
30 changes: 16 additions & 14 deletions test/system/scenarios/test_connection_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
Tests of the fine-grained connection API
"""

from numpy.testing import assert_array_equal
import numpy as np
from pyNN import common
import pyNN.nest
import pyNN.neuron
import pyNN.brian2
from .fixtures import get_simulator
import pytest


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_connections_attribute(sim):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_connections_attribute(sim_name):
sim = get_simulator(sim_name)
sim.setup()
p1 = sim.Population(4, sim.SpikeSourceArray())
p2 = sim.Population(3, sim.IF_cond_exp())
Expand All @@ -25,8 +23,9 @@ def test_connections_attribute(sim):
assert isinstance(connections[0], common.Connection)


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_connection_access_weight_and_delay(sim):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_connection_access_weight_and_delay(sim_name):
sim = get_simulator(sim_name)
sim.setup()
p1 = sim.Population(4, sim.SpikeSourceArray())
p2 = sim.Population(3, sim.IF_cond_exp())
Expand All @@ -47,11 +46,12 @@ def test_connection_access_weight_and_delay(sim):
target)


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_issue672(sim):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_issue672(sim_name):
"""
Check that creating new Projections does not mess up existing ones.
"""
sim = get_simulator(sim_name)
sim.setup(verbosity="error")

p1 = sim.Population(5, sim.IF_curr_exp())
Expand All @@ -70,8 +70,9 @@ def test_issue672(sim):
assert_array_equal(wA, wB)


# @pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
# def test_update_synaptic_plasticity_parameters(sim):
# @pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
# def test_update_synaptic_plasticity_parameters(sim_name):
# sim = get_simulator(sim_name)
# sim.setup()
# p1 = sim.Population(3, sim.IF_cond_exp(), label="presynaptic")
# p2 = sim.Population(2, sim.IF_cond_exp(), label="postsynaptic")
Expand All @@ -92,9 +93,10 @@ def test_issue672(sim):
# np.array([[0.01, 0.011], [0.012, 0.013], [0.014, 0.015]]))


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron))
def test_issue652(sim):
@pytest.mark.parametrize("sim_name", ("nest", "neuron"))
def test_issue652(sim_name):
"""Correctly handle A_plus = 0 in SpikePairRule."""
sim = get_simulator(sim_name)
sim.setup()

neural_population1 = sim.Population(10, sim.IF_cond_exp())
Expand Down
54 changes: 31 additions & 23 deletions test/system/scenarios/test_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from numpy.testing import assert_array_equal, assert_allclose
from pyNN.random import NumpyRNG, RandomDistribution
from pyNN.utility import connection_plot, init_logging
import pyNN.nest
import pyNN.neuron
import pyNN.brian2
from .fixtures import get_simulator
import pytest


Expand All @@ -15,8 +13,9 @@
# TODO: add some tests with projections between Assemblies and PopulationViews


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_all_to_all_static_no_self(sim):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_all_to_all_static_no_self(sim_name):
sim = get_simulator(sim_name)
sim.setup()
p = sim.Population(5, sim.IF_cond_exp())
synapse_type = sim.StaticSynapse(weight=RandomDistribution('gamma', k=2.0, theta=0.5), delay="0.2+0.3*d")
Expand All @@ -30,8 +29,9 @@ def test_all_to_all_static_no_self(sim):
sim.end()


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_all_to_all_tsodyksmarkram(sim):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_all_to_all_tsodyksmarkram(sim_name):
sim = get_simulator(sim_name)
sim.setup()
p1 = sim.Population(5, sim.IF_cond_exp())
p2 = sim.Population(7, sim.IF_cond_exp())
Expand All @@ -48,8 +48,9 @@ def test_all_to_all_tsodyksmarkram(sim):
sim.end()


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_fixed_number_pre_no_replacement(sim):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_fixed_number_pre_no_replacement(sim_name):
sim = get_simulator(sim_name)
sim.setup()
p1 = sim.Population(5, sim.IF_cond_exp())
p2 = sim.Population(7, sim.IF_cond_exp())
Expand Down Expand Up @@ -79,8 +80,9 @@ def test_fixed_number_pre_no_replacement(sim):
sim.end()


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_fixed_number_pre_with_replacement(sim):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_fixed_number_pre_with_replacement(sim_name):
sim = get_simulator(sim_name)
sim.setup()
p1 = sim.Population(5, sim.IF_cond_exp())
p2 = sim.Population(7, sim.IF_cond_exp())
Expand All @@ -96,8 +98,9 @@ def test_fixed_number_pre_with_replacement(sim):
assert column.sum() == 1.5


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_fixed_number_pre_with_replacement_heterogeneous_parameters(sim):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_fixed_number_pre_with_replacement_heterogeneous_parameters(sim_name):
sim = get_simulator(sim_name)
sim.setup()
p1 = sim.Population(5, sim.IF_cond_exp())
p2 = sim.Population(7, sim.IF_cond_exp())
Expand All @@ -116,8 +119,9 @@ def test_fixed_number_pre_with_replacement_heterogeneous_parameters(sim):
sim.end()


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_fixed_number_post_no_replacement(sim):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_fixed_number_post_no_replacement(sim_name):
sim = get_simulator(sim_name)
sim.setup()
p1 = sim.Population(5, sim.IF_cond_exp())
p2 = sim.Population(7, sim.IF_cond_exp())
Expand Down Expand Up @@ -146,8 +150,9 @@ def test_fixed_number_post_no_replacement(sim):
sim.end()


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_fixed_number_post_with_replacement(sim):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_fixed_number_post_with_replacement(sim_name):
sim = get_simulator(sim_name)
sim.setup()
p1 = sim.Population(5, sim.IF_cond_exp())
p2 = sim.Population(7, sim.IF_cond_exp())
Expand All @@ -169,8 +174,9 @@ def test_fixed_number_post_with_replacement(sim):
assert row.sum() == (row.size - n_nan)*0.5


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_fixed_number_post_with_replacement_heterogeneous_parameters(sim):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_fixed_number_post_with_replacement_heterogeneous_parameters(sim_name):
sim = get_simulator(sim_name)
sim.setup()
p1 = sim.Population(5, sim.IF_cond_exp())
p2 = sim.Population(7, sim.IF_cond_exp())
Expand All @@ -189,9 +195,10 @@ def test_fixed_number_post_with_replacement_heterogeneous_parameters(sim):
sim.end()


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron, pyNN.brian2))
def test_issue309(sim):
@pytest.mark.parametrize("sim_name", ("nest", "neuron", "brian2"))
def test_issue309(sim_name):
# check that FixedProbability(1) gives the same results as AllToAll
sim = get_simulator(sim_name)
sim.setup()
p = sim.Population(5, sim.IF_cond_exp())
synapse_type = sim.StaticSynapse(weight=0.1, delay="0.2+0.3*d")
Expand All @@ -205,8 +212,9 @@ def test_issue309(sim):
sim.end()


@pytest.mark.parametrize("sim", (pyNN.nest, pyNN.neuron))
def test_issue622(sim):
@pytest.mark.parametrize("sim_name", ("nest", "neuron"))
def test_issue622(sim_name):
sim = get_simulator(sim_name)
sim.setup()
pop = sim.Population(10, sim.IF_cond_exp, {}, label="pop")

Expand Down

0 comments on commit 151fdd4

Please sign in to comment.