From 3fdea73f887c17b45d44c376a27331ba607e177b Mon Sep 17 00:00:00 2001 From: Hans Ekkehard Plesser Date: Tue, 18 Nov 2025 23:42:10 +0100 Subject: [PATCH 1/4] Port tests of spatial connectivity from SLI to Py --- ..._to_layer_pairwise_bernoulli_on_source.sli | 76 ------------- ..._to_layer_pairwise_bernoulli_on_target.sli | 76 ------------- ...test_free_layer_to_layer_source_driven.sli | 76 ------------- ...test_free_layer_to_layer_target_driven.sli | 76 ------------- ..._mpi_test_pairwise_bernoulli_on_source.sli | 100 ------------------ ..._mpi_test_pairwise_bernoulli_on_target.sli | 100 ------------------ .../sli2py_mpi/test_spatial_connections.py | 80 ++++++++++++++ 7 files changed, 80 insertions(+), 504 deletions(-) delete mode 100644 testsuite/mpitests/topo_mpi_test_free_layer_to_layer_pairwise_bernoulli_on_source.sli delete mode 100644 testsuite/mpitests/topo_mpi_test_free_layer_to_layer_pairwise_bernoulli_on_target.sli delete mode 100644 testsuite/mpitests/topo_mpi_test_free_layer_to_layer_source_driven.sli delete mode 100644 testsuite/mpitests/topo_mpi_test_free_layer_to_layer_target_driven.sli delete mode 100644 testsuite/mpitests/topo_mpi_test_pairwise_bernoulli_on_source.sli delete mode 100644 testsuite/mpitests/topo_mpi_test_pairwise_bernoulli_on_target.sli create mode 100644 testsuite/pytests/sli2py_mpi/test_spatial_connections.py diff --git a/testsuite/mpitests/topo_mpi_test_free_layer_to_layer_pairwise_bernoulli_on_source.sli b/testsuite/mpitests/topo_mpi_test_free_layer_to_layer_pairwise_bernoulli_on_source.sli deleted file mode 100644 index 335823ce11..0000000000 --- a/testsuite/mpitests/topo_mpi_test_free_layer_to_layer_pairwise_bernoulli_on_source.sli +++ /dev/null @@ -1,76 +0,0 @@ -/* - * topo_mpi_test_free_layer_to_layer_pairwise_bernoulli_on_source.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 . - * - */ - - - /* -Author: Håkon Mørk -FirstVersion: 16. November 2017 -*/ - -(unittest) run -/unittest using - -skip_if_not_threaded - -/test_connection -{ - /connspec Set - - ResetKernel - << /total_num_virtual_procs 4 >> SetKernelStatus - - [-0.5 0.5 0.25] Range - { /x Set [0.5 -0.5 -0.25] Range { x exch 2 arraystore } Map } Map 1 Flatten - /pos Set - - /layer_spec_a - << /positions pos - /extent [1.25 1.25] - /edge_wrap false - /elements /iaf_psc_alpha - >> def - - /layer_spec_b - << /positions pos - /extent [1.25 1.25] - /edge_wrap false - /elements /iaf_psc_alpha - >> def - - /layer_a layer_spec_a CreateLayer def - /layer_b layer_spec_b CreateLayer def - - layer_a layer_b connspec ConnectLayers - - /src layer_a 1 Take def - /tgts layer_b def - /conns << /source src >> GetConnections def - /ctgts conns { cva 1 get } Map def - - ctgts cva - -} def - -[1 2 4] -{ - << /connection_type /pairwise_bernoulli_on_source /number_of_connections 10 >> test_connection -} distributed_process_invariant_collect_assert_or_die diff --git a/testsuite/mpitests/topo_mpi_test_free_layer_to_layer_pairwise_bernoulli_on_target.sli b/testsuite/mpitests/topo_mpi_test_free_layer_to_layer_pairwise_bernoulli_on_target.sli deleted file mode 100644 index ec4822b7f1..0000000000 --- a/testsuite/mpitests/topo_mpi_test_free_layer_to_layer_pairwise_bernoulli_on_target.sli +++ /dev/null @@ -1,76 +0,0 @@ -/* - * topo_mpi_test_free_layer_to_layer_pairwise_bernoulli_on_target.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 . - * - */ - - - /* -Author: Håkon Mørk -FirstVersion: 16. November 2017 -*/ - -(unittest) run -/unittest using - -skip_if_not_threaded - -/test_connection -{ - /connspec Set - - ResetKernel - << /total_num_virtual_procs 4 >> SetKernelStatus - - [-0.5 0.5 0.25] Range - { /x Set [0.5 -0.5 -0.25] Range { x exch 2 arraystore } Map } Map 1 Flatten - /pos Set - - /layer_spec_a - << /positions pos - /extent [1.25 1.25] - /edge_wrap false - /elements /iaf_psc_alpha - >> def - - /layer_spec_b - << /positions pos - /extent [1.25 1.25] - /edge_wrap false - /elements /iaf_psc_alpha - >> def - - /layer_a layer_spec_a CreateLayer def - /layer_b layer_spec_b CreateLayer def - - layer_a layer_b connspec ConnectLayers - - /src layer_a 1 Take def - /tgts layer_b def - /conns << /source src >> GetConnections def - /ctgts conns { cva 1 get } Map def - - ctgts cva - -} def - -[1 2 4] -{ - << /connection_type /pairwise_bernoulli_on_target /number_of_connections 10 >> test_connection -} distributed_process_invariant_collect_assert_or_die diff --git a/testsuite/mpitests/topo_mpi_test_free_layer_to_layer_source_driven.sli b/testsuite/mpitests/topo_mpi_test_free_layer_to_layer_source_driven.sli deleted file mode 100644 index 2883545f84..0000000000 --- a/testsuite/mpitests/topo_mpi_test_free_layer_to_layer_source_driven.sli +++ /dev/null @@ -1,76 +0,0 @@ -/* - * topo_mpi_test_free_layer_to_layer_source_driven.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 . - * - */ - - - /* -Author: Håkon Mørk -FirstVersion: 16. November 2017 -*/ - -(unittest) run -/unittest using - -skip_if_not_threaded - -/test_connection -{ - /connspec Set - - ResetKernel - << /total_num_virtual_procs 4 >> SetKernelStatus - - [-0.5 0.5 0.25] Range - { /x Set [0.5 -0.5 -0.25] Range { x exch 2 arraystore } Map } Map 1 Flatten - /pos Set - - /layer_spec_a - << /positions pos - /extent [1.25 1.25] - /edge_wrap false - /elements /iaf_psc_alpha - >> def - - /layer_spec_b - << /positions pos - /extent [1.25 1.25] - /edge_wrap false - /elements /iaf_psc_alpha - >> def - - /layer_a layer_spec_a CreateLayer def - /layer_b layer_spec_b CreateLayer def - - layer_a layer_b connspec ConnectLayers - - /src layer_a 1 Take def - /tgts layer_b def - /conns << /source src >> GetConnections def - /ctgts conns { cva 1 get } Map def - - ctgts cva - -} def - -[1 2 4] -{ - << /connection_type /pairwise_bernoulli_on_target >> test_connection -} distributed_process_invariant_collect_assert_or_die diff --git a/testsuite/mpitests/topo_mpi_test_free_layer_to_layer_target_driven.sli b/testsuite/mpitests/topo_mpi_test_free_layer_to_layer_target_driven.sli deleted file mode 100644 index 5983670a52..0000000000 --- a/testsuite/mpitests/topo_mpi_test_free_layer_to_layer_target_driven.sli +++ /dev/null @@ -1,76 +0,0 @@ -/* - * topo_mpi_test_free_layer_to_layer_target_driven.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 . - * - */ - - - /* -Author: Håkon Mørk -FirstVersion: 16. November 2017 -*/ - -(unittest) run -/unittest using - -skip_if_not_threaded - -/test_connection -{ - /connspec Set - - ResetKernel - << /total_num_virtual_procs 4 >> SetKernelStatus - - [-0.5 0.5 0.25] Range - { /x Set [0.5 -0.5 -0.25] Range { x exch 2 arraystore } Map } Map 1 Flatten - /pos Set - - /layer_spec_a - << /positions pos - /extent [1.25 1.25] - /edge_wrap false - /elements /iaf_psc_alpha - >> def - - /layer_spec_b - << /positions pos - /extent [1.25 1.25] - /edge_wrap false - /elements /iaf_psc_alpha - >> def - - /layer_a layer_spec_a CreateLayer def - /layer_b layer_spec_b CreateLayer def - - layer_a layer_b connspec ConnectLayers - - /src layer_a 1 Take def - /tgts layer_b def - /conns << /source src >> GetConnections def - /ctgts conns { cva 1 get } Map def - - ctgts cva - -} def - -[1 2 4] -{ - << /connection_type /pairwise_bernoulli_on_source >> test_connection -} distributed_process_invariant_collect_assert_or_die diff --git a/testsuite/mpitests/topo_mpi_test_pairwise_bernoulli_on_source.sli b/testsuite/mpitests/topo_mpi_test_pairwise_bernoulli_on_source.sli deleted file mode 100644 index 347577941f..0000000000 --- a/testsuite/mpitests/topo_mpi_test_pairwise_bernoulli_on_source.sli +++ /dev/null @@ -1,100 +0,0 @@ -/* - * topo_mpi_test_pairwise_bernoulli_on_source.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 . - * - */ - -skip_if_not_threaded - -(unittest) run -/unittest using - -% pairwise_bernoulli_on_source test -[1 2 4] -{ - ResetKernel - << /total_num_virtual_procs 4 >> SetKernelStatus - /layer_specs << /shape [ 4 4 ] /elements /iaf_psc_alpha /edge_wrap true >> def - /l1 layer_specs CreateLayer def - /l2 layer_specs CreateLayer def - - << /constant << /value 1.0 >> >> CreateParameter - << /constant << /value -0.02 >> >> CreateParameter - << /distance << >> >> CreateParameter - mul add /linear_parameter Set - - /conns << /connection_type (pairwise_bernoulli_on_source) - /mask << /circular << /radius 0.25 >> /anchor [ 0.0 0.0 ] >> - /weight linear_parameter - >> def - l1 l2 conns ConnectLayers - - /ofile tmpnam (_) join Rank 1 add cvs join (_of_) join NumProcesses cvs join def - ofile (w) file - l1 DumpLayerNodes - l2 DumpLayerNodes - l1 l2 /static_synapse DumpLayerConnections close - ofile -} -{ - /result_files Set - result_files == - - % Use the first result as reference - /ref [] def - result_files First 0 get dup /ref_filename Set (r) file - { - getline not - {exit} if % exit loop if EOF - ref exch append - /ref Set - } loop - close - (Num elements: ) ref length_a cvs join = - - % Compare the reference to the other results - /other_results [] def - result_files Rest - { - /result [] def - /n_elements 0 def - { - dup /filename Set - (r) file - { - getline - not {exit} if % exit loop if EOF - dup ref exch MemberQ dup /invariant Set - not {cvs ( not in ref ) join ref_filename join = exit} if % break out of loop if element not in reference - result exch append - /result Set - /n_elements n_elements 1 add def - } loop - close - invariant not {exit} if - } forall - n_elements ref length_a eq not - {/invariant false def (Lengths not equal, ) n_elements cvs join ( and ) join ref length_a cvs join = } if - invariant not {exit} if - /other_results other_results result append def - } forall - - invariant % true if all runs produce the same elements - -} distributed_collect_assert_or_die diff --git a/testsuite/mpitests/topo_mpi_test_pairwise_bernoulli_on_target.sli b/testsuite/mpitests/topo_mpi_test_pairwise_bernoulli_on_target.sli deleted file mode 100644 index 7fa6025d98..0000000000 --- a/testsuite/mpitests/topo_mpi_test_pairwise_bernoulli_on_target.sli +++ /dev/null @@ -1,100 +0,0 @@ -/* - * topo_mpi_test_pairwise_bernoulli_on_target.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 . - * - */ - -skip_if_not_threaded - -(unittest) run -/unittest using - -% pairwise_bernoulli_on_target test -[1 2 4] -{ - ResetKernel - << /total_num_virtual_procs 4 >> SetKernelStatus - /layer_specs << /shape [ 4 4 ] /elements /iaf_psc_alpha /edge_wrap true >> def - /l1 layer_specs CreateLayer def - /l2 layer_specs CreateLayer def - - << /constant << /value 1.0 >> >> CreateParameter - << /constant << /value -0.02 >> >> CreateParameter - << /distance << >> >> CreateParameter - mul add /linear_parameter Set - - /conns << /connection_type (pairwise_bernoulli_on_target) - /mask << /circular << /radius 0.25 >> /anchor [ 0.0 0.0 ] >> - /weight linear_parameter - >> def - l1 l2 conns ConnectLayers - - /ofile tmpnam (_) join Rank 1 add cvs join (_of_) join NumProcesses cvs join def - ofile (w) file - l1 DumpLayerNodes - l2 DumpLayerNodes - l1 l2 /static_synapse DumpLayerConnections close - ofile -} -{ - /result_files Set - result_files == - - % Use the first result as reference - /ref [] def - result_files First 0 get dup /ref_filename Set (r) file - { - getline not - {exit} if % exit loop if EOF - ref exch append - /ref Set - } loop - close - (Num elements: ) ref length_a cvs join = - - % Compare the reference to the other results - /other_results [] def - result_files Rest - { - /result [] def - /n_elements 0 def - { - dup /filename Set - (r) file - { - getline - not {exit} if % exit loop if EOF - dup ref exch MemberQ dup /invariant Set - not {cvs ( not in ref ) join ref_filename join = exit} if % break out of loop if element not in reference - result exch append - /result Set - /n_elements n_elements 1 add def - } loop - close - invariant not {exit} if - } forall - n_elements ref length_a eq not - {/invariant false def (Lengths not equal, ) n_elements cvs join ( and ) join ref length_a cvs join = } if - invariant not {exit} if - /other_results other_results result append def - } forall - - invariant % true if all runs produce the same elements - -} distributed_collect_assert_or_die diff --git a/testsuite/pytests/sli2py_mpi/test_spatial_connections.py b/testsuite/pytests/sli2py_mpi/test_spatial_connections.py new file mode 100644 index 0000000000..4aea8b11c9 --- /dev/null +++ b/testsuite/pytests/sli2py_mpi/test_spatial_connections.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- +# +# test_spatial_connections.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 pytest +from mpi_test_wrapper import MPITestAssertEqual + + +# We cannot use nest or numpy outside the test function itself, so we need to create +# the free positions with basic Python commands. +@pytest.mark.skipif_incompatible_mpi +@pytest.mark.parametrize( + "geometry", + [ + ("free", {"pos": [(x, y) for x in range(-2, 3) for y in range(-2, 3)], "extent": [6, 6], "edge_wrap": True}), + ("grid", {"shape": [5, 5], "extent": [6, 6], "edge_wrap": True}), + ], +) +@pytest.mark.parametrize( + "conn_spec", + [ + {"rule": "fixed_indegree", "indegree": 10}, + {"rule": "fixed_outdegree", "outdegree": 10}, + {"rule": "pairwise_bernoulli", "p": 0.5, "use_on_source": False}, + {"rule": "pairwise_bernoulli", "p": 0.5, "use_on_source": True}, + ], +) +@MPITestAssertEqual([1, 2, 4], debug=False) +def test_spatial_connections(geometry, conn_spec): + """ + Confirm that spatial connections are created consistently for fixed VP. + + The test is performed on connection data written to OTHER_LABEL. + """ + + import nest + import numpy as np + import pandas as pd + + nest.ResetKernel() + nest.total_num_virtual_procs = 4 + + kind, specs = geometry + if kind == "free": + pos = nest.spatial.free(**specs) + else: + assert kind == "grid" + pos = nest.spatial.grid(**specs) + lyr = nest.Create("parrot_neuron", positions=pos) + + nest.Connect( + lyr, + lyr, + {**conn_spec, "mask": {"circular": {"radius": 2.5}}}, + { + "weight": nest.spatial_distributions.gaussian(10 * nest.spatial.distance, std=2), + "delay": 0.1 + 0.2 * nest.spatial.distance, + }, + ) + + conns = nest.GetConnections() + df = pd.DataFrame.from_dict(conns.get(["source", "target", "weight", "delay"])) + df.to_csv(OTHER_LABEL.format(nest.num_processes, nest.Rank()), index=False, sep="\t") # noqa: F821 From f856ce425614b94a645965a1979b05c5a67836c7 Mon Sep 17 00:00:00 2001 From: Hans Ekkehard Plesser Date: Wed, 19 Nov 2025 08:38:45 +0100 Subject: [PATCH 2/4] Include connections from generators in test --- ..._to_layer_pairwise_bernoulli_on_source.sli | 78 ------------------- ..._to_layer_pairwise_bernoulli_on_target.sli | 78 ------------------- ...pi_test_free_pg_to_layer_source_driven.sli | 78 ------------------- ...pi_test_free_pg_to_layer_target_driven.sli | 78 ------------------- .../sli2py_mpi/test_spatial_connections.py | 23 +++++- 5 files changed, 19 insertions(+), 316 deletions(-) delete mode 100644 testsuite/mpitests/topo_mpi_test_free_pg_to_layer_pairwise_bernoulli_on_source.sli delete mode 100644 testsuite/mpitests/topo_mpi_test_free_pg_to_layer_pairwise_bernoulli_on_target.sli delete mode 100644 testsuite/mpitests/topo_mpi_test_free_pg_to_layer_source_driven.sli delete mode 100644 testsuite/mpitests/topo_mpi_test_free_pg_to_layer_target_driven.sli diff --git a/testsuite/mpitests/topo_mpi_test_free_pg_to_layer_pairwise_bernoulli_on_source.sli b/testsuite/mpitests/topo_mpi_test_free_pg_to_layer_pairwise_bernoulli_on_source.sli deleted file mode 100644 index e9bf861e74..0000000000 --- a/testsuite/mpitests/topo_mpi_test_free_pg_to_layer_pairwise_bernoulli_on_source.sli +++ /dev/null @@ -1,78 +0,0 @@ -/* - * topo_mpi_test_free_pg_to_layer_pairwise_bernoulli_on_source.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 . - * - */ - - - /* -Author: Håkon Mørk -FirstVersion: 16. November 2017 -*/ - -(unittest) run -/unittest using - -skip_if_not_threaded - -/test_connection -{ - /connspec Set - - ResetKernel - << /total_num_virtual_procs 4 >> SetKernelStatus - - [-0.5 0.5 0.25] Range - { /x Set [0.5 -0.5 -0.25] Range { x exch 2 arraystore } Map } Map 1 Flatten - /pos Set - - /layer_spec_a - << - /positions [[0.0 0.0]] - /extent [1.0 1.0] - /edge_wrap false - /elements /poisson_generator - >> def - - - /layer_spec_b - << /positions pos - /extent [1.25 1.25] - /edge_wrap false - /elements /iaf_psc_alpha - >> def - - /layer_a layer_spec_a CreateLayer def - /layer_b layer_spec_b CreateLayer def - - layer_a layer_b connspec ConnectLayers - - /src layer_a 1 Take def - /tgts layer_b def - /conns << /source src >> GetConnections def - /ctgts conns { cva 1 get } Map def - - ctgts cva - -} def - -[1 2 4] -{ - << /connection_type /pairwise_bernoulli_on_source /number_of_connections 10 >> test_connection -} distributed_process_invariant_collect_assert_or_die diff --git a/testsuite/mpitests/topo_mpi_test_free_pg_to_layer_pairwise_bernoulli_on_target.sli b/testsuite/mpitests/topo_mpi_test_free_pg_to_layer_pairwise_bernoulli_on_target.sli deleted file mode 100644 index 083c92a82b..0000000000 --- a/testsuite/mpitests/topo_mpi_test_free_pg_to_layer_pairwise_bernoulli_on_target.sli +++ /dev/null @@ -1,78 +0,0 @@ -/* - * topo_mpi_test_free_pg_to_layer_pairwise_bernoulli_on_target.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 . - * - */ - - - /* -Author: Håkon Mørk -FirstVersion: 16. November 2017 -*/ - -(unittest) run -/unittest using - -skip_if_not_threaded - -/test_connection -{ - /connspec Set - - ResetKernel - << /total_num_virtual_procs 4 >> SetKernelStatus - - [-0.5 0.5 0.25] Range - { /x Set [0.5 -0.5 -0.25] Range { x exch 2 arraystore } Map } Map 1 Flatten - /pos Set - - /layer_spec_a - << - /positions [[0.0 0.0]] - /extent [1.0 1.0] - /edge_wrap false - /elements /poisson_generator - >> def - - - /layer_spec_b - << /positions pos - /extent [1.25 1.25] - /edge_wrap false - /elements /iaf_psc_alpha - >> def - - /layer_a layer_spec_a CreateLayer def - /layer_b layer_spec_b CreateLayer def - - layer_a layer_b connspec ConnectLayers - - /src layer_a 1 Take def - /tgts layer_b def - /conns << /source src >> GetConnections def - /ctgts conns { cva 1 get } Map def - - ctgts cva - -} def - -[1 2 4] -{ - << /connection_type /pairwise_bernoulli_on_target /number_of_connections 10 >> test_connection -} distributed_process_invariant_collect_assert_or_die diff --git a/testsuite/mpitests/topo_mpi_test_free_pg_to_layer_source_driven.sli b/testsuite/mpitests/topo_mpi_test_free_pg_to_layer_source_driven.sli deleted file mode 100644 index a4159fba55..0000000000 --- a/testsuite/mpitests/topo_mpi_test_free_pg_to_layer_source_driven.sli +++ /dev/null @@ -1,78 +0,0 @@ -/* - * topo_mpi_test_free_pg_to_layer_source_driven.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 . - * - */ - - - /* -Author: Håkon Mørk -FirstVersion: 16. November 2017 -*/ - -(unittest) run -/unittest using - -skip_if_not_threaded - -/test_connection -{ - /connspec Set - - ResetKernel - << /total_num_virtual_procs 4 >> SetKernelStatus - - [-0.5 0.5 0.25] Range - { /x Set [0.5 -0.5 -0.25] Range { x exch 2 arraystore } Map } Map 1 Flatten - /pos Set - - /layer_spec_a - << - /positions [[0.0 0.0]] - /extent [1.0 1.0] - /edge_wrap false - /elements /poisson_generator - >> def - - - /layer_spec_b - << /positions pos - /extent [1.25 1.25] - /edge_wrap false - /elements /iaf_psc_alpha - >> def - - /layer_a layer_spec_a CreateLayer def - /layer_b layer_spec_b CreateLayer def - - layer_a layer_b connspec ConnectLayers - - /src layer_a 1 Take def - /tgts layer_b def - /conns << /source src >> GetConnections def - /ctgts conns { cva 1 get } Map def - - ctgts cva - -} def - -[1 2 4] -{ - << /connection_type /pairwise_bernoulli_on_target >> test_connection -} distributed_process_invariant_collect_assert_or_die diff --git a/testsuite/mpitests/topo_mpi_test_free_pg_to_layer_target_driven.sli b/testsuite/mpitests/topo_mpi_test_free_pg_to_layer_target_driven.sli deleted file mode 100644 index 4468c0a151..0000000000 --- a/testsuite/mpitests/topo_mpi_test_free_pg_to_layer_target_driven.sli +++ /dev/null @@ -1,78 +0,0 @@ -/* - * topo_mpi_test_free_pg_to_layer_target_driven.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 . - * - */ - - - /* -Author: Håkon Mørk -FirstVersion: 16. November 2017 -*/ - -(unittest) run -/unittest using - -skip_if_not_threaded - -/test_connection -{ - /connspec Set - - ResetKernel - << /total_num_virtual_procs 4 >> SetKernelStatus - - [-0.5 0.5 0.25] Range - { /x Set [0.5 -0.5 -0.25] Range { x exch 2 arraystore } Map } Map 1 Flatten - /pos Set - - /layer_spec_a - << - /positions [[0.0 0.0]] - /extent [1.0 1.0] - /edge_wrap false - /elements /poisson_generator - >> def - - - /layer_spec_b - << /positions pos - /extent [1.25 1.25] - /edge_wrap false - /elements /iaf_psc_alpha - >> def - - /layer_a layer_spec_a CreateLayer def - /layer_b layer_spec_b CreateLayer def - - layer_a layer_b connspec ConnectLayers - - /src layer_a 1 Take def - /tgts layer_b def - /conns << /source src >> GetConnections def - /ctgts conns { cva 1 get } Map def - - ctgts cva - -} def - -[1 2 4] -{ - << /connection_type /pairwise_bernoulli_on_source >> test_connection -} distributed_process_invariant_collect_assert_or_die diff --git a/testsuite/pytests/sli2py_mpi/test_spatial_connections.py b/testsuite/pytests/sli2py_mpi/test_spatial_connections.py index 4aea8b11c9..c0df2adcf6 100644 --- a/testsuite/pytests/sli2py_mpi/test_spatial_connections.py +++ b/testsuite/pytests/sli2py_mpi/test_spatial_connections.py @@ -22,10 +22,24 @@ import pytest from mpi_test_wrapper import MPITestAssertEqual +""" +Confirm that spatial connections are created consistently for fixed VP. + +This test is parameterized at three levels: +- Neuron and generator as source +- Free and grid layers +- Different spatial connection rules + +Connections to recorders are handled in a separate test, as they do not work +with fixed_indegree and there is no elegant way of filtering that case out. +""" + # We cannot use nest or numpy outside the test function itself, so we need to create # the free positions with basic Python commands. @pytest.mark.skipif_incompatible_mpi +@pytest.mark.skipif_missing_threads +@pytest.mark.parametrize("source_model", ["poisson_generator", "parrot_neuron"]) @pytest.mark.parametrize( "geometry", [ @@ -43,7 +57,7 @@ ], ) @MPITestAssertEqual([1, 2, 4], debug=False) -def test_spatial_connections(geometry, conn_spec): +def test_spatial_connections(source_model, geometry, conn_spec): """ Confirm that spatial connections are created consistently for fixed VP. @@ -63,11 +77,12 @@ def test_spatial_connections(geometry, conn_spec): else: assert kind == "grid" pos = nest.spatial.grid(**specs) - lyr = nest.Create("parrot_neuron", positions=pos) + source_layer = nest.Create(source_model, positions=pos) + target_layer = nest.Create("parrot_neuron", positions=pos) nest.Connect( - lyr, - lyr, + source_layer, + target_layer, {**conn_spec, "mask": {"circular": {"radius": 2.5}}}, { "weight": nest.spatial_distributions.gaussian(10 * nest.spatial.distance, std=2), From 5de77b83b0e9c271fdaf1c3197f82e922103d76f Mon Sep 17 00:00:00 2001 From: Hans Ekkehard Plesser Date: Wed, 19 Nov 2025 08:45:49 +0100 Subject: [PATCH 3/4] Port test for spatial connections to recorders. --- ...pi_test_free_layer_to_sd_target_driven.sli | 77 ------------------ .../sli2py_mpi/test_spatial_connections.py | 4 +- .../test_spatial_connections_to_generator.py | 80 +++++++++++++++++++ 3 files changed, 82 insertions(+), 79 deletions(-) delete mode 100644 testsuite/mpitests/topo_mpi_test_free_layer_to_sd_target_driven.sli create mode 100644 testsuite/pytests/sli2py_mpi/test_spatial_connections_to_generator.py diff --git a/testsuite/mpitests/topo_mpi_test_free_layer_to_sd_target_driven.sli b/testsuite/mpitests/topo_mpi_test_free_layer_to_sd_target_driven.sli deleted file mode 100644 index 364e528752..0000000000 --- a/testsuite/mpitests/topo_mpi_test_free_layer_to_sd_target_driven.sli +++ /dev/null @@ -1,77 +0,0 @@ -/* - * topo_mpi_test_free_layer_to_sd_target_driven.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 . - * - */ - - - /* -Author: Håkon Mørk -FirstVersion: 16. November 2017 -*/ - -(unittest) run -/unittest using - -skip_if_not_threaded - -/test_connection -{ - /connspec Set - - ResetKernel - << /total_num_virtual_procs 4 >> SetKernelStatus - - [-0.5 0.5 0.25] Range - { /x Set [0.5 -0.5 -0.25] Range { x exch 2 arraystore } Map } Map 1 Flatten - /pos Set - - /layer_spec_a - << /positions pos - /extent [1.25 1.25] - /edge_wrap false - /elements /iaf_psc_alpha - >> def - - /layer_spec_b - << - /positions [[0.0 0.0]] - /extent [1.0 1.0] - /edge_wrap false - /elements /spike_recorder - >> def - - /layer_a layer_spec_a CreateLayer def - /layer_b layer_spec_b CreateLayer def - - layer_a layer_b connspec ConnectLayers - - /src layer_a 1 Take def - /tgts layer_b def - /conns << /source src >> GetConnections def - /ctgts conns { cva 1 get } Map def - - ctgts cva - -} def - -[1 2 4] -{ - << /connection_type /pairwise_bernoulli_on_source >> test_connection -} distributed_process_invariant_collect_assert_or_die diff --git a/testsuite/pytests/sli2py_mpi/test_spatial_connections.py b/testsuite/pytests/sli2py_mpi/test_spatial_connections.py index c0df2adcf6..e9af97e059 100644 --- a/testsuite/pytests/sli2py_mpi/test_spatial_connections.py +++ b/testsuite/pytests/sli2py_mpi/test_spatial_connections.py @@ -30,8 +30,8 @@ - Free and grid layers - Different spatial connection rules -Connections to recorders are handled in a separate test, as they do not work -with fixed_indegree and there is no elegant way of filtering that case out. +Connections to recorders are handled in a separate test, as they only work with +the pairwise-bernoulli-on-source connection rule. """ diff --git a/testsuite/pytests/sli2py_mpi/test_spatial_connections_to_generator.py b/testsuite/pytests/sli2py_mpi/test_spatial_connections_to_generator.py new file mode 100644 index 0000000000..9347b9da23 --- /dev/null +++ b/testsuite/pytests/sli2py_mpi/test_spatial_connections_to_generator.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- +# +# test_spatial_connections.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 pytest +from mpi_test_wrapper import MPITestAssertEqual + +""" +Confirm that spatial connections to a generator are created consistently for fixed VP. + +This test is parameterized over free and grid layers. Only pairwise-bernoulli-on-source +is suitable as probabilistic connection rule when connecting to a device. +""" + + +# We cannot use nest or numpy outside the test function itself, so we need to create +# the free positions with basic Python commands. +@pytest.mark.skipif_incompatible_mpi +@pytest.mark.skipif_missing_threads +@pytest.mark.parametrize( + "geometry", + [ + ("free", {"pos": [(x, y) for x in range(-2, 3) for y in range(-2, 3)], "extent": [6, 6], "edge_wrap": True}), + ("grid", {"shape": [5, 5], "extent": [6, 6], "edge_wrap": True}), + ], +) +@MPITestAssertEqual([1, 2, 4], debug=False) +def test_spatial_connections(geometry): + """ + Confirm that spatial connections are created consistently for fixed VP. + + The test is performed on connection data written to OTHER_LABEL. + """ + + import nest + import numpy as np + import pandas as pd + + nest.ResetKernel() + nest.total_num_virtual_procs = 4 + + kind, specs = geometry + if kind == "free": + pos = nest.spatial.free(**specs) + else: + assert kind == "grid" + pos = nest.spatial.grid(**specs) + source_layer = nest.Create("parrot_neuron", positions=pos) + target_layer = nest.Create("spike_recorder", positions=pos) + + nest.Connect( + source_layer, + target_layer, + {"rule": "pairwise_bernoulli", "p": 0.5, "use_on_source": True, "mask": {"circular": {"radius": 2.5}}}, + { + "weight": nest.spatial_distributions.gaussian(10 * nest.spatial.distance, std=2), + "delay": 0.1 + 0.2 * nest.spatial.distance, + }, + ) + + conns = nest.GetConnections() + df = pd.DataFrame.from_dict(conns.get(["source", "target", "weight", "delay"])) + df.to_csv(OTHER_LABEL.format(nest.num_processes, nest.Rank()), index=False, sep="\t") # noqa: F821 From 7dd256d3be94dc900dc52772d55af85205b7aa9e Mon Sep 17 00:00:00 2001 From: Hans Ekkehard Plesser Date: Wed, 19 Nov 2025 08:58:12 +0100 Subject: [PATCH 4/4] Fix copyright header --- .../pytests/sli2py_mpi/test_spatial_connections_to_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/pytests/sli2py_mpi/test_spatial_connections_to_generator.py b/testsuite/pytests/sli2py_mpi/test_spatial_connections_to_generator.py index 9347b9da23..306ffb06e3 100644 --- a/testsuite/pytests/sli2py_mpi/test_spatial_connections_to_generator.py +++ b/testsuite/pytests/sli2py_mpi/test_spatial_connections_to_generator.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# test_spatial_connections.py +# test_spatial_connections_to_generator.py # # This file is part of NEST. #