From 617d796476169c0c4089aa789d12ac34f28c9d75 Mon Sep 17 00:00:00 2001 From: Hans Ekkehard Plesser Date: Mon, 3 Jun 2024 22:14:10 +0200 Subject: [PATCH 1/3] Fix issue breaking GetConnections() in certain situations --- nestkernel/node_collection.cpp | 4 +- .../pytests/test_regression_issue-3213.py | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 testsuite/pytests/test_regression_issue-3213.py diff --git a/nestkernel/node_collection.cpp b/nestkernel/node_collection.cpp index f3be96c75c..86b80d540c 100644 --- a/nestkernel/node_collection.cpp +++ b/nestkernel/node_collection.cpp @@ -1337,9 +1337,9 @@ NodeCollectionComposite::get_nc_index( const size_t node_id ) const } } - assert( lower == upper ); + assert( lower >= upper ); - if ( node_id < parts_[ lower ][ 0 ] or parts_[ lower ][ parts_[ lower ].size() - 1 ] < node_id ) + if ( lower > upper or node_id < parts_[ lower ][ 0 ] or parts_[ lower ][ parts_[ lower ].size() - 1 ] < node_id ) { // node_id is in a gap of nc return -1; diff --git a/testsuite/pytests/test_regression_issue-3213.py b/testsuite/pytests/test_regression_issue-3213.py new file mode 100644 index 0000000000..2e13f9aac7 --- /dev/null +++ b/testsuite/pytests/test_regression_issue-3213.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# +# test_regression_issue-3213.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 nest +import pytest + +""" +Test that GetConnections works if NodeCollection with gaps is provided as source arg. +""" + + +def test_get_conns_works(): + """Main concern is that GetConnections() passes, expected number of connections based on all-to-all.""" + + num_n = 12 + n = nest.Create("parrot_neuron", num_n) + nest.Connect(n, n) + pick = [3, 7, 9, 11] + conns = nest.GetConnections(source=n[pick]) + assert len(conns) == num_n * len(pick) From 98a2aef44fab5674524c80ae9621324816da72f7 Mon Sep 17 00:00:00 2001 From: Hans Ekkehard Plesser Date: Mon, 3 Jun 2024 22:15:07 +0200 Subject: [PATCH 2/3] Fix typo in readme --- testsuite/pytests/sli2py_mpi/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/pytests/sli2py_mpi/README.md b/testsuite/pytests/sli2py_mpi/README.md index cb48da01fc..6f9abee576 100644 --- a/testsuite/pytests/sli2py_mpi/README.md +++ b/testsuite/pytests/sli2py_mpi/README.md @@ -2,4 +2,4 @@ Test in this directory run NEST with different numbers of MPI ranks and compare results. -See documentation in mpi_test_wrappe.py for details. +See documentation in mpi_test_wrapper.py for details. From 6e35ed17fb1dfac8146a20ef065a989e2f4feeac Mon Sep 17 00:00:00 2001 From: Hans Ekkehard Plesser Date: Tue, 4 Jun 2024 09:44:54 +0200 Subject: [PATCH 3/3] Add comment --- nestkernel/node_collection.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nestkernel/node_collection.cpp b/nestkernel/node_collection.cpp index 86b80d540c..b4323921f4 100644 --- a/nestkernel/node_collection.cpp +++ b/nestkernel/node_collection.cpp @@ -1337,6 +1337,8 @@ NodeCollectionComposite::get_nc_index( const size_t node_id ) const } } + // If node_id is not in the NodeCollection, lower may pass upper in the loop above + // See test_regression_issue-3213.py for an example case. assert( lower >= upper ); if ( lower > upper or node_id < parts_[ lower ][ 0 ] or parts_[ lower ][ parts_[ lower ].size() - 1 ] < node_id )