diff --git a/testsuite/pytests/sli2py_regressions/test_issue_665.py b/testsuite/pytests/sli2py_regressions/test_issue_665.py new file mode 100644 index 0000000000..db30a0c3d2 --- /dev/null +++ b/testsuite/pytests/sli2py_regressions/test_issue_665.py @@ -0,0 +1,117 @@ +# -*- coding: utf-8 -*- +# +# test_issue_665.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 . +""" +Regression test for Issue #665 (GitHub). + +This test ensures that ConnectLayers correctly handles devices with thread +siblings as sources and targets. +""" + +import nest +import pytest + + +@pytest.mark.skipif_not_threaded +def test_connect_layers_with_devices(): + """ + Test that ConnectLayers correctly handles devices with thread siblings. + """ + # Define connection specifications + connspec = {"connection_type": "pairwise_bernoulli_on_source"} + + # Reset the kernel and set the number of threads + nest.ResetKernel() + nest.SetKernelStatus({"local_num_threads": 4}) + + # Create layers + pgl = nest.CreateLayer({"elements": "poisson_generator", "shape": [1, 1]}) + nnl = nest.CreateLayer({"elements": "iaf_psc_alpha", "shape": [2, 2]}) + + # Connect layers + nest.ConnectLayers(pgl, nnl, connspec) + + # Get connections and targets + src = nest.GetNodes(pgl)[0] + tgts = nest.GetNodes(nnl) + conns = nest.GetConnections(source=src) + ctgts = sorted(conn[1] for conn in conns) + + # Check if targets match expected + assert tgts == ctgts + + # Test different connection types + for conn_type in ["pairwise_bernoulli_on_source", "pairwise_bernoulli_on_target"]: + connspec["connection_type"] = conn_type + nest.ConnectLayers(pgl, nnl, connspec) + conns = nest.GetConnections(source=src) + ctgts = sorted(conn[1] for conn in conns) + assert tgts == ctgts + + # Test with specific number of connections + connspec["connection_type"] = "pairwise_bernoulli_on_source" + connspec["number_of_connections"] = 1 + nest.ConnectLayers(pgl, nnl, connspec) + conns = nest.GetConnections(source=src) + ctgts = sorted(conn[1] for conn in conns) + assert tgts == ctgts + + connspec["connection_type"] = "pairwise_bernoulli_on_target" + connspec["number_of_connections"] = 4 + connspec["allow_multapses"] = False + nest.ConnectLayers(pgl, nnl, connspec) + conns = nest.GetConnections(source=src) + ctgts = sorted(conn[1] for conn in conns) + assert tgts == ctgts + + # Second set of tests: Neuron layer to single recorder + srl = nest.CreateLayer({"elements": "spike_recorder", "shape": [1, 1]}) + nest.ConnectLayers(nnl, srl, connspec) + + tgt = nest.GetNodes(srl)[0] + srcs = nest.GetNodes(nnl) + conns = nest.GetConnections(target=tgt) + csrcs = sorted(conn[0] for conn in conns) + + assert srcs == csrcs + + # Test different connection types for layer to recorder + for conn_type in ["pairwise_bernoulli_on_source", "pairwise_bernoulli_on_target"]: + connspec["connection_type"] = conn_type + nest.ConnectLayers(nnl, srl, connspec) + conns = nest.GetConnections(target=tgt) + csrcs = sorted(conn[0] for conn in conns) + assert srcs == csrcs + + # Test with specific number of connections for layer to recorder + connspec["connection_type"] = "pairwise_bernoulli_on_source" + connspec["number_of_connections"] = 4 + connspec["allow_multapses"] = False + nest.ConnectLayers(nnl, srl, connspec) + conns = nest.GetConnections(target=tgt) + csrcs = sorted(conn[0] for conn in conns) + assert srcs == csrcs + + connspec["connection_type"] = "pairwise_bernoulli_on_target" + connspec["number_of_connections"] = 1 + nest.ConnectLayers(nnl, srl, connspec) + conns = nest.GetConnections(target=tgt) + csrcs = sorted(conn[0] for conn in conns) + assert srcs == csrcs diff --git a/testsuite/regressiontests/issue-665.sli b/testsuite/regressiontests/issue-665.sli deleted file mode 100644 index 6117697dfc..0000000000 --- a/testsuite/regressiontests/issue-665.sli +++ /dev/null @@ -1,160 +0,0 @@ -/* - * issue-665.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 . - * - */ - - - /** @BeginDocumentation -Name: testsuite::issue-665 - -Synopsis: (issue-665) run -> NEST exits if test fails - -Description: -This test ensures that ConnectLayers correctly handles devices with thread -siblings as sources and targets. - -Author: Hans Ekkehard Plesser -FirstVersion: February 2017 -SeeAlso: -*/ - -(unittest) run -/unittest using - -skip_if_not_threaded - -% First set of tests: Single generator to neuron layer -/gen_to_layer_test -{ - /connspec Set - - ResetKernel - << /local_num_threads 4 >> SetKernelStatus - - /pgl - << /elements /poisson_generator - /shape [ 1 1 ] >> - CreateLayer def - - /nnl - << /elements /iaf_psc_alpha - /shape [ 2 2 ] >> - CreateLayer def - - pgl nnl connspec ConnectLayers - - /src pgl [1] Take def - /tgts nnl def - - /conns << /source src >> GetConnections def - /ctgts conns { cva 1 get } Map Sort def - - tgts cva ctgts eq -} -def - -{ - << /connection_type /pairwise_bernoulli_on_source >> gen_to_layer_test -} -assert_or_die - -{ - << /connection_type /pairwise_bernoulli_on_target >> gen_to_layer_test -} -assert_or_die - -{ - % one incoming connection to each neuron in layer - << /connection_type /pairwise_bernoulli_on_source - /number_of_connections 1 >> gen_to_layer_test -} -assert_or_die - -{ - % four outgoing connections, one to each neuron in layer - % prohibit multapses to ensure consistent result - << /connection_type /pairwise_bernoulli_on_target - /number_of_connections 4 - /allow_multapses false >> gen_to_layer_test -} -assert_or_die - -% ----------------------------------------------- - -% Second set of tests: Neuron layer to single recorder -/layer_to_det_test -{ - /connspec Set - - ResetKernel - << /local_num_threads 4 >> SetKernelStatus - - /nnl - << /elements /iaf_psc_alpha - /shape [ 2 2 ] >> - CreateLayer def - - /srl - << /elements /spike_recorder - /shape [ 1 1 ] >> - CreateLayer def - - nnl srl connspec ConnectLayers - - /tgt srl [1] Take def - /srcs nnl def - - /conns << /target tgt >> GetConnections def - /csrcs conns { cva 0 get } Map Sort def - - srcs cva csrcs eq -} -def - -{ - << /connection_type /pairwise_bernoulli_on_source >> layer_to_det_test -} -assert_or_die - -{ - << /connection_type /pairwise_bernoulli_on_target >> layer_to_det_test -} -fail_or_die -clear - -{ - % four incoming connections, one to each neuron in layer - % prohibit multapses to ensure consistent result - << /connection_type /pairwise_bernoulli_on_source - /number_of_connections 4 - /allow_multapses false >> layer_to_det_test -} -fail_or_die -clear - -{ - % one outgoing connection from each neuron in layer - << /connection_type /pairwise_bernoulli_on_target - /number_of_connections 1 >> layer_to_det_test -} -fail_or_die -clear - -endusing