From f69d534e9c13919d1435e170f1582c4262a610d6 Mon Sep 17 00:00:00 2001 From: Nicolai Haug Date: Wed, 24 May 2023 15:14:02 +0200 Subject: [PATCH 1/2] Port issue-1212.sli to pytest --- .../sli2py_regressions/test_issue_1212.py | 60 ++++++++++++++++++ testsuite/regressiontests/issue-1212.sli | 63 ------------------- 2 files changed, 60 insertions(+), 63 deletions(-) create mode 100644 testsuite/pytests/sli2py_regressions/test_issue_1212.py delete mode 100644 testsuite/regressiontests/issue-1212.sli diff --git a/testsuite/pytests/sli2py_regressions/test_issue_1212.py b/testsuite/pytests/sli2py_regressions/test_issue_1212.py new file mode 100644 index 0000000000..261bb82620 --- /dev/null +++ b/testsuite/pytests/sli2py_regressions/test_issue_1212.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# +# test_issue_1212.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 #1212 (GitHub). + +Test that a weight recorder can be used with a probabilistic synapse. +""" + +import nest + + +def test_weight_recorder_with_probabilistic_synapse(): + """ + Ensure that a `weight_recorder` can be used with the probabilistic `bernoulli_synapse`. + + This test ensures that using a weight recorder with a probabilistic synapse + that drops a spike doesn't result in a segfault. + """ + + sgen = nest.Create("spike_generator") + src_parrot = nest.Create("parrot_neuron") + tgt_parrot = nest.Create("parrot_neuron") + wrec = nest.Create("weight_recorder") + + nest.CopyModel( + "bernoulli_synapse", "bernoulli_synapse_wrec", {"weight_recorder": wrec} + ) + + nest.Connect(sgen, src_parrot) + nest.Connect( + src_parrot, + tgt_parrot, + conn_spec={"rule": "one_to_one"}, + syn_spec={ + "synapse_model": "bernoulli_synapse_wrec", + "p_transmit": 0.0, + "weight": 1.0, + }, + ) + + nest.Simulate(20.0) diff --git a/testsuite/regressiontests/issue-1212.sli b/testsuite/regressiontests/issue-1212.sli deleted file mode 100644 index 0c44fd7917..0000000000 --- a/testsuite/regressiontests/issue-1212.sli +++ /dev/null @@ -1,63 +0,0 @@ -/* - * issue-1212.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-1212 - -Synopsis: (issue-1212) run -> NEST exits if test fails - -Description: -This test makes sure that using a weight recorder with a probabilistic -synapse that drops a spike doesn't result in a segfault. - -Author: Håkon Mørk -FirstVersion: January 2020 -*/ - -(unittest) run -/unittest using - -M_ERROR setverbosity - -{ - /sg /spike_generator << /spike_times [ 10. ] >> Create def - /source_parrot /parrot_neuron Create def - /target_parrot /parrot_neuron Create def - /wr /weight_recorder Create def - - /bernoulli_synapse /bernoulli_synapse_wr << /weight_recorder wr >> CopyModel - - sg source_parrot Connect - - source_parrot target_parrot - << /rule /one_to_one >> - << /synapse_model /bernoulli_synapse_wr - /p_transmit 0.0 - /weight 1.0 >> - Connect - - 20. Simulate -} -pass_or_die - -endusing From 0d051fd8bc3c227c2053ac358d9db5fc9053bb4e Mon Sep 17 00:00:00 2001 From: Nicolai Haug Date: Tue, 27 Jun 2023 19:42:15 +0200 Subject: [PATCH 2/2] Black formatting --- testsuite/pytests/sli2py_regressions/test_issue_1212.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/testsuite/pytests/sli2py_regressions/test_issue_1212.py b/testsuite/pytests/sli2py_regressions/test_issue_1212.py index 261bb82620..d3abc6b084 100644 --- a/testsuite/pytests/sli2py_regressions/test_issue_1212.py +++ b/testsuite/pytests/sli2py_regressions/test_issue_1212.py @@ -41,9 +41,7 @@ def test_weight_recorder_with_probabilistic_synapse(): tgt_parrot = nest.Create("parrot_neuron") wrec = nest.Create("weight_recorder") - nest.CopyModel( - "bernoulli_synapse", "bernoulli_synapse_wrec", {"weight_recorder": wrec} - ) + nest.CopyModel("bernoulli_synapse", "bernoulli_synapse_wrec", {"weight_recorder": wrec}) nest.Connect(sgen, src_parrot) nest.Connect(