From 330820d42dd51356f9502ec0ac00467144e0e67f Mon Sep 17 00:00:00 2001 From: Hans Ekkehard Plesser Date: Wed, 11 Dec 2024 16:01:05 +0100 Subject: [PATCH] Port test_count_connections from SLI to Py --- .../sli2py_connect/test_count_connections.py | 63 ++++++++++++++++ .../unittests/test_count_connections.sli | 71 ------------------- 2 files changed, 63 insertions(+), 71 deletions(-) create mode 100644 testsuite/pytests/sli2py_connect/test_count_connections.py delete mode 100644 testsuite/unittests/test_count_connections.sli diff --git a/testsuite/pytests/sli2py_connect/test_count_connections.py b/testsuite/pytests/sli2py_connect/test_count_connections.py new file mode 100644 index 0000000000..a020a28f0c --- /dev/null +++ b/testsuite/pytests/sli2py_connect/test_count_connections.py @@ -0,0 +1,63 @@ +# test_count_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 nest +import pytest + +pytestmark = pytest.mark.skipif_missing_threads + + +@pytest.fixture(autouse=True) +def prepare(): + nest.ResetKernel() + + +def test_count_connections(): + """ + Test that correct number of connections is created for fixed_indegree. + + Description: + This test uses fixed-indegree Connect to connect a net of 100 neurons + to itself, with 89 connections per neuron, a total of 8900 connections. + It is checked whether the total number of connections and the number of + static connections equals 8900. Then additional 8900 connections of type + stdp_synapse are created. It is checked whether the total number of + connections is 17800 and the number of stdp connections is 8900. + + Author: Susanne Kunkel, 2013-03-25 + """ + + num_neurons = 100 + indegree = 89 + n_vp = 4 + expected_num_conns = num_neurons * indegree + + nest.total_num_virtual_procs = 4 + + n = nest.Create("parrot_neuron", n=num_neurons) + nest.Connect(n, n, conn_spec={"rule": "fixed_indegree", "indegree": indegree}, syn_spec="static_synapse") + + assert nest.num_connections == expected_num_conns + assert nest.GetDefaults("static_synapse")["num_connections"] == expected_num_conns + + nest.Connect(n, n, conn_spec={"rule": "fixed_indegree", "indegree": indegree}, syn_spec="stdp_synapse") + + assert nest.num_connections == 2 * expected_num_conns + assert nest.GetDefaults("static_synapse")["num_connections"] == expected_num_conns + assert nest.GetDefaults("stdp_synapse")["num_connections"] == expected_num_conns diff --git a/testsuite/unittests/test_count_connections.sli b/testsuite/unittests/test_count_connections.sli deleted file mode 100644 index dc3a149df1..0000000000 --- a/testsuite/unittests/test_count_connections.sli +++ /dev/null @@ -1,71 +0,0 @@ -/* - * test_count_connections.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 . - * - */ - -% SLI2PYComplexity: Low - -/** @BeginDocumentation - -Name: testsuite::test_count_connections - Test connection counting for total -number of connections and specific types of connections. - -Synopsis: (test_count_connections) run -> NEST exits if test fails - -Description: -This test uses fixed-indegree Connect to connect a net of 100 neurons -to itself, with 100 connections per neuron, a total of 10000 connections. -It is checked whether the total number of connections and the number of -static connections equals 10000. Then additional 10000 connections of type -stdp_synapse are created. It is checked whether the total number of -connections is 20000 and the number of stdp connections is 10000. - -Author: Susanne Kunkel, 2013-03-25 -*/ - -(unittest) run -/unittest using - -% don't run this test if we didn't compile with OpenMP -skip_if_not_threaded - -M_ERROR setverbosity - -/N 100 def % number of neurons -/C 100 def % number of connections per neuron -/N_VP 4 def % number of virtual processes -/ConnExpected N C mul def - -ResetKernel - -<< /total_num_virtual_procs N_VP >> SetKernelStatus - -/nodes /iaf_psc_alpha N Create def - -nodes nodes << /rule /fixed_indegree /indegree C >> Connect -{ GetKernelStatus /num_connections get ConnExpected eq } assert_or_die -{ /static_synapse GetDefaults /num_connections get ConnExpected eq } assert_or_die - -nodes nodes << /rule /fixed_indegree /indegree C >> << /synapse_model /stdp_synapse >> Connect - -{ GetKernelStatus /num_connections get ConnExpected 2 mul eq } assert_or_die -{ /stdp_synapse GetDefaults /num_connections get ConnExpected eq } assert_or_die - -endusing