diff --git a/testsuite/mpitests/test_parallel_conn_and_rand.sli b/testsuite/mpitests/test_parallel_conn_and_rand.sli deleted file mode 100644 index b4c7ab6a7d..0000000000 --- a/testsuite/mpitests/test_parallel_conn_and_rand.sli +++ /dev/null @@ -1,99 +0,0 @@ -/* - * test_parallel_conn_and_rand.sli - * - * This file is part of NEST. - * - * Copyright (C) 2004 The NEST Initiative - * - * NEST is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * NEST is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with NEST. If not, see . - * - */ - -/* - Parallel Connect and Randomize Test Script - - This script creates a neuron population to itself, randomizing - weight, delay, receptor type and one synaptic parameter. It runs - with a fixed number of virtual processes, and checks that connections - are invariant on executing with a varying number of MPI processes. - - Hans Ekkehard Plesser -*/ - -(unittest) run -/unittest using - -skip_if_not_threaded - -%%% PARAMETER SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -% define all relevant parameters: changes should be made here -% all data is place in the userdict dictionary - -/num_neurons 10 def -%/num_neurons 1000 def - -/connspec << /rule /fixed_indegree /indegree 1 >> def -%/connspec << /rule /fixed_outdegree /outdegree 100 >> def - -/num_vps 16 def - -/simtime 10.0 def % simulation time [ms] -/dt 0.1 def % simulation step length [ms] - -%%% CONSTRUCTION SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -[1 2 4] -{ - ResetKernel % clear all existing network elements - M_WARNING setverbosity - - % set resolution, total/local number of threads, rng seed - << - /resolution dt - /total_num_virtual_procs num_vps - /rng_seed 123 - >> SetKernelStatus - - (Creating the network.) = - - % setup to allow us to randomize receptor_type - /tau_syns [0.2 1.0 0.1] Range def - /receptor_min 1 def - /receptor_max tau_syns length def - /iaf_psc_alpha_multisynapse << /tau_syn tau_syns >> SetDefaults - - /population /iaf_psc_alpha_multisynapse num_neurons Create def - - (Connecting neurons.) = - population population connspec - << /synapse_model /stdp_synapse - /delay << /uniform << /min 0.5 /max 1.5 >> >> CreateParameter - /weight << /normal << /mean 10.0 /std 5.0 >> >> CreateParameter 0.0 max - /receptor_type << /uniform_int << /max receptor_max 1 add receptor_min sub >> >> CreateParameter - << /constant << /value 1.0 >> >> CreateParameter add - /alpha << /uniform << /min 0.1 /max 2.3 >> >> CreateParameter - /tau_plus << /uniform << /min 1.5 /max 5.0 >> >> CreateParameter - >> - Connect - - (Done connecting.) = - - /conn_arr 0 array def - << /synapse_model /stdp_synapse >> GetConnections - { - [[/source /target /weight /delay /alpha /tau_plus]] get conn_arr exch append /conn_arr Set - } forall - conn_arr -} distributed_process_invariant_collect_assert_or_die diff --git a/testsuite/pytests/sli2py_mpi/test_parallel_conn_and_rand.py b/testsuite/pytests/sli2py_mpi/test_parallel_conn_and_rand.py new file mode 100644 index 0000000000..60b1fb1870 --- /dev/null +++ b/testsuite/pytests/sli2py_mpi/test_parallel_conn_and_rand.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- +# +# test_parallel_conn_and_rand.py +# +# This file is part of NEST. +# +# Copyright (C) 2004 The NEST Initiative +# +# NEST is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# NEST is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with NEST. If not, see . + +import numpy as np +import pandas as pd +import pytest +from mpi_test_wrapper import MPITestAssertEqual + +# Functions to be passed via decorators must be in module namespace without qualifiers +from numpy import meshgrid + + +@pytest.mark.skipif_incompatible_mpi +@pytest.mark.skipif_missing_threads +@MPITestAssertEqual([1, 2, 4], debug=False) +def test_parallel_cond_and_rand(): + """ + This test connects a neuron population to itself, randomizing + weight, delay, receptor type and one synaptic parameter. It runs + with a fixed number of virtual processes, and checks that connections + are invariant on executing with a varying number of MPI processes. + """ + + import nest + import pandas as pd # noqa: F811 + + nest.total_num_virtual_procs = 16 + nest.rng_seed = 123 + + num_neurons = 100 + tau_syns = np.linspace(0.2, 1.0, 9) + receptor_min = 1 + receptor_max = len(tau_syns) + + pop = nest.Create("iaf_psc_alpha_multisynapse", num_neurons, {"tau_syn": tau_syns}) + + nest.Connect( + pop, + pop, + {"rule": "fixed_indegree", "indegree": 23}, + { + "synapse_model": "stdp_synapse", + "delay": nest.random.uniform(0.5, 1.5), + "weight": nest.math.max(nest.random.normal(10, 5), 0), + "receptor_type": 1 + nest.random.uniform_int(receptor_max + 1 - receptor_min), + "alpha": nest.random.uniform(0.1, 2.3), + "tau_plus": nest.random.uniform(1.5, 5.0), + }, + ) + + conns = pd.DataFrame.from_dict( + nest.GetConnections().get(["source", "target", "weight", "delay", "alpha", "tau_plus"]) + ) + + conns.to_csv(OTHER_LABEL.format(nest.num_processes, nest.Rank()), index=False, sep="\t") # noqa: F821