From cc8212947308c251c0f46ceeecee1ccc0b8dde5f Mon Sep 17 00:00:00 2001 From: Jessica Mitchell Date: Wed, 25 Jun 2025 11:46:15 +0200 Subject: [PATCH 1/5] uses AI (cursor) --- .../sli2py_regressions/test_ticket_507.py | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 testsuite/pytests/sli2py_regressions/test_ticket_507.py diff --git a/testsuite/pytests/sli2py_regressions/test_ticket_507.py b/testsuite/pytests/sli2py_regressions/test_ticket_507.py new file mode 100644 index 0000000000..d4087b4e0e --- /dev/null +++ b/testsuite/pytests/sli2py_regressions/test_ticket_507.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +# +# test_ticket_507.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 Ticket #507. + +Ensure that spike_generator throws exception on SetStatus if off-grid times are set, +unless precise_times is set. +""" +import nest +import pytest + + +@pytest.fixture(autouse=True) +def prepare_kernel(): + nest.ResetKernel() + nest.resolution = 0.1 + + +def test_spike_generator_on_grid_time(): + """ + Setting a single on-grid spike time with precise_times=False should succeed. + """ + sg = nest.Create("spike_generator") + sg.set({"spike_times": [0.2], "precise_times": False}) + + +def test_spike_generator_off_grid_times_should_fail(): + """ + Setting multiple spike times, some off-grid, with precise_times=False should fail. + """ + sg = nest.Create("spike_generator") + with pytest.raises(nest.NESTError): + sg.set({"spike_times": [0.1, 0.123456789, 0.22345567854], "precise_times": False}) + + +def test_spike_generator_single_off_grid_time_should_fail(): + """ + Setting a single off-grid spike time with precise_times=False should fail. + """ + sg = nest.Create("spike_generator") + with pytest.raises(nest.NESTError): + sg.set({"spike_times": [0.123456789], "precise_times": False}) + + +def test_spike_generator_precise_times_true_should_pass(): + """ + Setting a single off-grid spike time with precise_times=True should succeed. + """ + sg = nest.Create("spike_generator") + sg.set({"spike_times": [0.123456789], "precise_times": True}) From 5f74bd460cebebc9762fb64abe3bf8058ef33ef1 Mon Sep 17 00:00:00 2001 From: Jessica Mitchell Date: Wed, 25 Jun 2025 12:07:55 +0200 Subject: [PATCH 2/5] remove sli file --- testsuite/regressiontests/ticket-507.sli | 75 ------------------------ 1 file changed, 75 deletions(-) delete mode 100644 testsuite/regressiontests/ticket-507.sli diff --git a/testsuite/regressiontests/ticket-507.sli b/testsuite/regressiontests/ticket-507.sli deleted file mode 100644 index a45af7b863..0000000000 --- a/testsuite/regressiontests/ticket-507.sli +++ /dev/null @@ -1,75 +0,0 @@ -/* - * ticket-507.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::ticket-507 - Ensure that spike_generator throws exception on SetStatus if precise (off-grid) spike times are set - -Synopsis: (ticket-507) run -> NEST exits if test fails - -Description: -Ensure that spike_generator throws exception on SetStatus if off-grid times are set, -unless precise_times is set. - -Author: Hans Ekkehard Plesser, 2011-03-18 - */ - -(unittest) run -/unittest using - -M_ERROR setverbosity - -% this should be fine -{ - ResetKernel - << /resolution 0.1 >> SetKernelStatus - /spike_generator Create - << /spike_times [0.2] /precise_times false >> SetStatus -} -pass_or_die - -% this should fail -{ - ResetKernel - << /resolution 0.1 >> SetKernelStatus - /spike_generator Create - << /spike_times [0.1 0.123456789 0.22345567854] /precise_times false >> SetStatus -} -fail_or_die - -% this should fail -{ - ResetKernel - << /resolution 0.1 >> SetKernelStatus - /spike_generator Create - << /spike_times [0.123456789] /precise_times false >> SetStatus -} -fail_or_die - -% this should pass as precise_times is true -{ - ResetKernel - << /resolution 0.1 >> SetKernelStatus - /spike_generator Create - << /spike_times [0.123456789] /precise_times true >> SetStatus -} -pass_or_die From 8317472b6b2480cae0950ddf646457a06c0bc102 Mon Sep 17 00:00:00 2001 From: jessica-mitchell Date: Fri, 7 Nov 2025 10:33:03 +0100 Subject: [PATCH 3/5] Update testsuite/pytests/sli2py_regressions/test_ticket_507.py --- testsuite/pytests/sli2py_regressions/test_ticket_507.py | 1 + 1 file changed, 1 insertion(+) diff --git a/testsuite/pytests/sli2py_regressions/test_ticket_507.py b/testsuite/pytests/sli2py_regressions/test_ticket_507.py index d4087b4e0e..986734b42d 100644 --- a/testsuite/pytests/sli2py_regressions/test_ticket_507.py +++ b/testsuite/pytests/sli2py_regressions/test_ticket_507.py @@ -22,6 +22,7 @@ """ Regression test for Ticket #507. +Test ported from SLI regression test Ensure that spike_generator throws exception on SetStatus if off-grid times are set, unless precise_times is set. """ From 78aee1c80e503a701ee910fbddb4813b515ffc2b Mon Sep 17 00:00:00 2001 From: Jessica Mitchell Date: Fri, 7 Nov 2025 15:20:56 +0100 Subject: [PATCH 4/5] readd --- .../sli2py_regressions/test_ticket_881.py | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 testsuite/pytests/sli2py_regressions/test_ticket_881.py diff --git a/testsuite/pytests/sli2py_regressions/test_ticket_881.py b/testsuite/pytests/sli2py_regressions/test_ticket_881.py new file mode 100644 index 0000000000..ba5fac4dd8 --- /dev/null +++ b/testsuite/pytests/sli2py_regressions/test_ticket_881.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# +# test_ticket_881.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 + +node_pos = [[0.0, 0.0]] * 4 +num_nodes = len(node_pos) +num_expected = num_nodes * num_nodes + +# Map SLI connection_type to NEST 3 rule/use_on_source +connection_specs = [ + # pairwise_bernoulli_on_source: use_on_source=True + {"rule": "pairwise_bernoulli", "use_on_source": True}, + # pairwise_bernoulli_on_target: use_on_source=False + {"rule": "pairwise_bernoulli", "use_on_source": False}, + # pairwise_bernoulli_on_source with number_of_connections + # {"rule": "pairwise_bernoulli", "use_on_source": True, "number_of_connections": num_nodes}, + # pairwise_bernoulli_on_target with number_of_connections + # {"rule": "pairwise_bernoulli", "use_on_source": False, "number_of_connections": num_nodes}, +] + + +@pytest.mark.parametrize("conn_spec", connection_specs) +def test_connectlayers_all_to_all(conn_spec): + """ + Regression test for Ticket #881. + + Ensure ConnectLayers creates the correct number of connections in all-to-all scenarios with multiple threads. + Uses NEST 3 idioms for pairwise_bernoulli connection rules. + """ + nest.ResetKernel() + nest.local_num_threads = 4 + layer = nest.Create("iaf_psc_alpha", positions=node_pos) + nest.Connect(layer, layer, conn_spec=conn_spec) + conns = nest.GetConnections() + assert len(conns) == num_expected, f"Expected {num_expected} connections, got {len(conns)}" From 551e4a55a2a043d72576e9c416cc540dcd417300 Mon Sep 17 00:00:00 2001 From: Jessica Mitchell Date: Wed, 12 Nov 2025 09:39:25 +0100 Subject: [PATCH 5/5] rm test 881 --- .../sli2py_regressions/test_ticket_881.py | 55 ------------------- 1 file changed, 55 deletions(-) delete mode 100644 testsuite/pytests/sli2py_regressions/test_ticket_881.py diff --git a/testsuite/pytests/sli2py_regressions/test_ticket_881.py b/testsuite/pytests/sli2py_regressions/test_ticket_881.py deleted file mode 100644 index ba5fac4dd8..0000000000 --- a/testsuite/pytests/sli2py_regressions/test_ticket_881.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -# -# test_ticket_881.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 - -node_pos = [[0.0, 0.0]] * 4 -num_nodes = len(node_pos) -num_expected = num_nodes * num_nodes - -# Map SLI connection_type to NEST 3 rule/use_on_source -connection_specs = [ - # pairwise_bernoulli_on_source: use_on_source=True - {"rule": "pairwise_bernoulli", "use_on_source": True}, - # pairwise_bernoulli_on_target: use_on_source=False - {"rule": "pairwise_bernoulli", "use_on_source": False}, - # pairwise_bernoulli_on_source with number_of_connections - # {"rule": "pairwise_bernoulli", "use_on_source": True, "number_of_connections": num_nodes}, - # pairwise_bernoulli_on_target with number_of_connections - # {"rule": "pairwise_bernoulli", "use_on_source": False, "number_of_connections": num_nodes}, -] - - -@pytest.mark.parametrize("conn_spec", connection_specs) -def test_connectlayers_all_to_all(conn_spec): - """ - Regression test for Ticket #881. - - Ensure ConnectLayers creates the correct number of connections in all-to-all scenarios with multiple threads. - Uses NEST 3 idioms for pairwise_bernoulli connection rules. - """ - nest.ResetKernel() - nest.local_num_threads = 4 - layer = nest.Create("iaf_psc_alpha", positions=node_pos) - nest.Connect(layer, layer, conn_spec=conn_spec) - conns = nest.GetConnections() - assert len(conns) == num_expected, f"Expected {num_expected} connections, got {len(conns)}"