Skip to content

Commit

Permalink
Rearrange the nest.Install() calls in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pnbabu committed Jan 8, 2024
1 parent 39a8c6d commit e386bce
Show file tree
Hide file tree
Showing 19 changed files with 24 additions and 43 deletions.
2 changes: 1 addition & 1 deletion tests/nest_tests/fir_filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def test_fir_filter(self):
resolution = 0.1

nest.set_verbosity("M_ALL")
nest.Install(module_name)

nest.ResetKernel()
nest.Install(module_name)

# Create a fir_filter node
neuron = nest.Create(nestml_model_name, {"N": 256})
Expand Down
6 changes: 1 addition & 5 deletions tests/nest_tests/nest_delay_based_variables_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ def plot_fig(times, recordable_events_delay: dict, recordable_events: dict, file
def run_simulation(neuron_model_name: str, module_name: str, recordables: List[str], delay: float):
nest.set_verbosity("M_ALL")
nest.ResetKernel()

try:
nest.Install(module_name)
except BaseException:
pass
nest.Install(module_name)

neuron = nest.Create(neuron_model_name)
neuron.set({"delay": delay})
Expand Down
2 changes: 0 additions & 2 deletions tests/nest_tests/nest_instantiability_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def test_nest_instantiability(self):
nestml_unit_test_models = [
neuron_model_name for neuron_model_name in _neuron_models if neuron_model_name.endswith("_nestml")]

nest.ResetKernel()

for neuron_model in nestml_unit_test_models:
print("Instantiating neuron model: " + str(neuron_model))
nest.Create(neuron_model)
Expand Down
8 changes: 3 additions & 5 deletions tests/nest_tests/nest_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,7 @@ def test_nest_integration(self):

nest.ResetKernel()
nest.set_verbosity("M_ALL")
try:
nest.Install("nestml_allmodels_module")
except Exception:
self.generate_all_models()
nest.Install("nestml_allmodels_module")
nest.Install("nestml_allmodels_module")

s = "Models library\n==============\n\n"

Expand Down Expand Up @@ -359,6 +355,7 @@ def _test_model_subthreshold(self, referenceModel, testant, gsl_error_tol, toler
for i, I_stim in enumerate(I_stim_vec):

nest.ResetKernel()
nest.Install("nestml_allmodels_module")
neuron1 = nest.Create(referenceModel, params=nest_ref_model_opts)
neuron2 = nest.Create(testant, params=custom_model_opts)
if model_initial_state is not None:
Expand Down Expand Up @@ -463,6 +460,7 @@ def _test_model(self, referenceModel, testant, gsl_error_tol, tolerance=0.000001
spike_weights = [1., -1.]

nest.ResetKernel()
nest.Install("nestml_allmodels_module")
neuron1 = nest.Create(referenceModel, params=nest_ref_model_opts)
neuron2 = nest.Create(testant, params=custom_model_opts)

Expand Down
1 change: 1 addition & 0 deletions tests/nest_tests/nest_loops_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def test_for_and_while_loop(self):
np.testing.assert_almost_equal(v_m[-1], 16.6)

nest.ResetKernel()
nest.Install("nestmlmodule")
nrn = nest.Create("while_loop_nestml")

mm = nest.Create("multimeter")
Expand Down
5 changes: 2 additions & 3 deletions tests/nest_tests/nest_multithreading_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,11 @@ def nestml_generate_target(self) -> None:
codegen_opts={"neuron_parent_class": "ArchivingNode",
"neuron_parent_class_include": "archiving_node.h"})

nest.Install(self.neuron_module)
nest.Install(self.neuron_synapse_module)

@pytest.mark.skipif(NESTTools.detect_nest_version().startswith("v2"),
reason="This test does not support NEST 2")
def test_neuron_multithreading(self, number_of_threads: int) -> None:
nest.ResetKernel()
nest.Install(self.neuron_module)
nest.resolution = 0.1
nest.local_num_threads = number_of_threads
spike_times = np.array([2., 4., 7., 8., 12., 13., 19., 23., 24., 28., 29., 30., 33., 34.,
Expand Down Expand Up @@ -114,6 +112,7 @@ def test_neuron_synapse_multithreading(self, number_of_threads: int) -> None:
48., 49., 50., 54., 56., 57., 59., 60., 61., 62., 67., 74.])

nest.ResetKernel()
nest.Install(self.neuron_synapse_module)
nest.resolution = 0.1
nest.local_num_threads = number_of_threads

Expand Down
1 change: 0 additions & 1 deletion tests/nest_tests/noisy_synapse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def run_synapse_test(self, neuron_model_name,

post_weights = {'parrot': []}

nest.ResetKernel()
nest.SetKernelStatus({'resolution': resolution})

wr = nest.Create('weight_recorder')
Expand Down
1 change: 0 additions & 1 deletion tests/nest_tests/stdp_nn_pre_centered_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def run_synapse_test(self, neuron_model_name,

post_weights = {'parrot': []}

nest.ResetKernel()
nest.SetKernelStatus({'resolution': resolution})

wr = nest.Create('weight_recorder')
Expand Down
2 changes: 0 additions & 2 deletions tests/nest_tests/stdp_nn_restr_symm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ def run_synapse_test(self, neuron_model_name,
nest.set_verbosity("M_WARNING")

post_weights = {'parrot': []}

nest.ResetKernel()
nest.SetKernelStatus({'resolution': resolution})

wr = nest.Create('weight_recorder')
Expand Down
1 change: 0 additions & 1 deletion tests/nest_tests/stdp_nn_synapse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def run_synapse_test(self, neuron_model_name,

post_weights = {'parrot': []}

nest.ResetKernel()
nest.SetKernelStatus({'resolution': resolution})

wr = nest.Create('weight_recorder')
Expand Down
10 changes: 4 additions & 6 deletions tests/nest_tests/stdp_synapse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ def generate_model_code(self):
suffix="_nestml_non_jit",
codegen_opts=non_jit_codegen_opts)

# load the generated modules into NEST
nest.Install("nestml_jit_module")
nest.Install("nestml_non_jit_module")

@pytest.mark.parametrize("delay", [1., 1.5])
@pytest.mark.parametrize("resolution", [.1, .5, 1.])
@pytest.mark.parametrize("pre_spike_times,post_spike_times", [
Expand Down Expand Up @@ -150,15 +146,17 @@ def run_synapse_test(self, neuron_model_name,
nest.set_verbosity("M_ALL")
nest.ResetKernel()

# load the generated modules into NEST
nest.Install("nestml_jit_module")
nest.Install("nestml_non_jit_module")

print("Pre spike times: " + str(pre_spike_times))
print("Post spike times: " + str(post_spike_times))

# nest.set_verbosity("M_WARNING")
nest.set_verbosity("M_ERROR")

post_weights = {"parrot": []}

nest.ResetKernel()
nest.SetKernelStatus({"resolution": resolution})

wr = nest.Create("weight_recorder")
Expand Down
2 changes: 1 addition & 1 deletion tests/nest_tests/stdp_window_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def nestml_generate_target():
{"neuron": "izhikevich",
"synapse": "stdp",
"post_ports": ["post_spikes"]}]})
nest.Install("nestmlmodule")


def run_stdp_network(pre_spike_time, post_spike_time,
Expand All @@ -75,6 +74,7 @@ def run_stdp_network(pre_spike_time, post_spike_time,
nest.set_verbosity("M_ALL")

nest.ResetKernel()
nest.Install("nestmlmodule")
nest.SetKernelStatus({"resolution": resolution})

wr = nest.Create("weight_recorder")
Expand Down
5 changes: 1 addition & 4 deletions tests/nest_tests/synapse_priority_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ def run_nest_simulation(self, neuron_model_name,
nest.set_verbosity("M_ALL")
# nest.set_verbosity("M_WARNING")
nest.ResetKernel()
try:
nest.Install("nestml_module")
except Exception:
pass
nest.Install("nestml_module")
nest.SetKernelStatus({'resolution': resolution})

print("Pre spike times: " + str(pre_spike_times))
Expand Down
8 changes: 5 additions & 3 deletions tests/nest_tests/test_forward_euler_integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ def generate_target(self, numeric_solver: str):
module_name="nestml" + numeric_solver.replace("-", "_") + "module",
codegen_opts={"numeric_solver": numeric_solver})

nest.Install("nestml" + numeric_solver.replace("-", "_") + "module")
return "nestml" + numeric_solver.replace("-", "_") + "module"

@pytest.mark.skipif(NESTTools.detect_nest_version().startswith("v2"),
reason="This test does not support NEST 2")
def test_forward_euler_integrator(self):
self.generate_target("forward-Euler")
self.generate_target("rk45")
forward_euler_module_name = self.generate_target("forward-Euler")
rk45_module_name = self.generate_target("rk45")

nest.ResetKernel()
nest.Install(forward_euler_module_name)
nest.Install(rk45_module_name)
nest.resolution = .001

nrn1 = nest.Create("izhikevich_rk45_nestml")
Expand Down
3 changes: 1 addition & 2 deletions tests/nest_tests/test_gap_junction.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ def generate_code(self, neuron_model: str):
suffix="_nestml",
codegen_opts=codegen_opts)

nest.Install("nestml_gap_" + neuron_model + "_module")

return neuron_model

def _test_gap_junction_effect_on_membrane_potential(self, neuron_model, wfr_interpolation_order: int):
Expand All @@ -74,6 +72,7 @@ def _test_gap_junction_effect_on_membrane_potential(self, neuron_model, wfr_inte

nest.set_verbosity("M_ALL")
nest.ResetKernel()
nest.Install("nestml_gap_" + neuron_model + "_module")

nest.resolution = resolution
nest.wfr_comm_interval = 2. # [ms]
Expand Down
2 changes: 1 addition & 1 deletion tests/nest_tests/test_ignore_and_fire.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def setUp(self):
logging_level="DEBUG",
suffix="_nestml",
codegen_opts=codegen_opts)
nest.Install("nestmlmodule")

@pytest.mark.skipif(NESTTools.detect_nest_version().startswith("v2"),
reason="This test does not support NEST 2")
Expand All @@ -69,6 +68,7 @@ def test_ignore_and_fire_with_stdp(self, resolution: float):

nest.set_verbosity("M_ALL")
nest.ResetKernel()
nest.Install("nestmlmodule")
nest.SetKernelStatus({"resolution": resolution})

pre_neuron = nest.Create(self.neuron_model_name)
Expand Down
2 changes: 1 addition & 1 deletion tests/nest_tests/test_static_synapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def setUp(self):
logging_level="DEBUG",
module_name="nestmlmodule",
suffix="_nestml")
nest.Install("nestmlmodule")

@pytest.mark.parametrize("synapse_model_name", ["static_synapse_nestml", "noisy_synapse_nestml"])
def test_static_synapse(self, synapse_model_name: str):
Expand All @@ -59,6 +58,7 @@ def test_static_synapse(self, synapse_model_name: str):
nest.ResetKernel()
nest.set_verbosity("M_ALL")
nest.SetKernelStatus({"resolution": .1})
nest.Install("nestmlmodule")

# create spike_generators with these times
pre_sg = nest.Create("spike_generator",
Expand Down
4 changes: 2 additions & 2 deletions tests/nest_tests/test_time_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def setUp(self):
os.path.join(os.path.realpath(os.path.join(os.path.dirname(__file__), "resources", "TimeVariableSynapse.nestml")))]
target_path = "target"
logging_level = "INFO"
module_name = "nestmlmodule"
suffix = "_nestml"

nest.set_verbosity("M_ALL")
Expand All @@ -48,10 +47,10 @@ def setUp(self):
logging_level=logging_level,
module_name=module_name,
suffix=suffix)
nest.Install(module_name)

def test_time_variable_neuron(self):
nest.ResetKernel()
nest.Install("nestmlmodule")
nrn = nest.Create("time_variable_neuron_nestml")
mm = nest.Create("multimeter")
nest.SetStatus(mm, {"record_from": ["x", "y"]})
Expand All @@ -69,6 +68,7 @@ def test_time_variable_neuron(self):
def test_time_variable_synapse(self):
"""a synapse is only updated when presynaptic spikes arrive"""
nest.ResetKernel()
nest.Install("nestmlmodule")
nrn = nest.Create("iaf_psc_delta", 2)
nrn[0].I_e = 1000. # [pA]
sr = nest.Create("spike_recorder")
Expand Down
2 changes: 0 additions & 2 deletions tests/nest_tests/third_factor_stdp_synapse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ def run_synapse_test(self, neuron_model_name,
print("Post spike times: " + str(post_spike_times))

nest.set_verbosity("M_WARNING")

nest.ResetKernel()
nest.SetKernelStatus({"resolution": resolution})

wr = nest.Create("weight_recorder")
Expand Down

0 comments on commit e386bce

Please sign in to comment.