From 7de0d78057fbf0609274e3e76fe40f7352916c2e Mon Sep 17 00:00:00 2001 From: Jessica Mitchell Date: Tue, 22 Apr 2025 14:18:12 +0200 Subject: [PATCH 1/3] sli2py -mistral --- .../sli2py_regressions/test_ticket_310.py | 76 +++++++++++++++++ testsuite/regressiontests/ticket-310.sli | 85 ------------------- 2 files changed, 76 insertions(+), 85 deletions(-) create mode 100644 testsuite/pytests/sli2py_regressions/test_ticket_310.py delete mode 100644 testsuite/regressiontests/ticket-310.sli diff --git a/testsuite/pytests/sli2py_regressions/test_ticket_310.py b/testsuite/pytests/sli2py_regressions/test_ticket_310.py new file mode 100644 index 0000000000..c080a1d714 --- /dev/null +++ b/testsuite/pytests/sli2py_regressions/test_ticket_310.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- +# +# test_ticket_310.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 + + +def test_ticket_310(): + """ + Regression test for Ticket #310. + + Ensure that all neuron models that have V_m and V_th permit + V_m to be set to >= V_th, and that they emit a spike with + time stamp == resolution in that case. + + Author: Hans Ekkehard Plesser, 2009-02-11 + """ + + # Use power-of-two resolution to avoid round-off problems + res = 2**-3 + + skip_list = [ + "iaf_chxk_2008", # non-standard spiking conditions + "correlospinmatrix_detector", # not a neuron + "eprop_iaf_bsshslm_2020", # no ArchivingNode, thus no t_spike + "eprop_iaf_adapt_bsshslm_2020", # no ArchivingNode, thus no t_spike + "eprop_readout_bsshslm_2020", # no ArchivingNode, thus no t_spike + "eprop_iaf", # no ArchivingNode, thus no t_spike + "eprop_iaf_adapt", # no ArchivingNode, thus no t_spike + "eprop_iaf_psc_delta", # no ArchivingNode, thus no t_spike + "eprop_iaf_psc_delta_adapt", # no ArchivingNode, thus no t_spike + "eprop_readout", # no ArchivingNode, thus no t_spike + ] + + node_models = nest.node_models + + results = [] + + for model in node_models: + if model not in skip_list: + nest.ResetKernel() + nest.SetKernelStatus({"resolution": res}) + n = nest.Create(model) + + # Check if V_m and V_th exist in the model's status + status = nest.GetStatus(n)[0] + if "V_m" in status and "V_th" in status: + nest.SetStatus(n, {"V_m": status["V_th"] + 15.0}) + nest.Simulate(res) + t_spike = nest.GetStatus(n, "t_spike")[0] + results.append(t_spike <= res) + else: + results.append(True) + else: + results.append(True) + + # Check if all entries are true + assert all(results), "Test failed for one or more models" diff --git a/testsuite/regressiontests/ticket-310.sli b/testsuite/regressiontests/ticket-310.sli deleted file mode 100644 index eed11a5b25..0000000000 --- a/testsuite/regressiontests/ticket-310.sli +++ /dev/null @@ -1,85 +0,0 @@ -/* - * ticket-310.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 . - * - */ - -/* - * Regression test for Ticket #310. - * - * Ensure that all neuron models that have V_m and V_th permit - * V_m to be set to >= V_th, and that they emit a spike with - * time stamp == resolution in that case. - * - * Hans Ekkehard Plesser, 2009-02-11 - * - */ - -(unittest) run -/unittest using - -% use power-of-two resolution to avoid roundof problems -/res -3 dexp def - -/skip_list [ /iaf_chxk_2008 % non-standard spiking conditions - /correlospinmatrix_detector % not a neuron - /eprop_iaf_bsshslm_2020 % no ArchivingNode, thus no t_spike - /eprop_iaf_adapt_bsshslm_2020 % no ArchivingNode, thus no t_spike - /eprop_readout_bsshslm_2020 % no ArchivingNode, thus no t_spike - /eprop_iaf % no ArchivingNode, thus no t_spike - /eprop_iaf_adapt % no ArchivingNode, thus no t_spike - /eprop_iaf_psc_delta % no ArchivingNode, thus no t_spike - /eprop_iaf_psc_delta_adapt % no ArchivingNode, thus no t_spike - /eprop_readout % no ArchivingNode, thus no t_spike - ] def - -{ - GetKernelStatus /node_models get - { - dup skip_list exch MemberQ not - { - /model Set - - ResetKernel - << /resolution res >> SetKernelStatus - model Create /n Set - - % see if we have V_m and V_th, otherwise return true - n GetStatus 0 get dup /V_m known exch /V_th known and - { - n << /V_m n /V_th get 15.0 add >> SetStatus - res Simulate - n /t_spike get res leq % works also for precise models - dup not { (FAILED: ) model cvs join == n ShowStatus } if - } - { true } - ifelse - } - { true } - ifelse - } - Map - - % see if all entries are true - true exch { and } Fold - -} -assert_or_die - -endusing From 7a86e0b7fe90728111c3ff65151191cf35341078 Mon Sep 17 00:00:00 2001 From: Hans Ekkehard Plesser Date: Tue, 24 Jun 2025 11:26:22 +0200 Subject: [PATCH 2/3] Nicely parameterize test --- .../sli2py_regressions/test_ticket_310.py | 71 +++++++++---------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/testsuite/pytests/sli2py_regressions/test_ticket_310.py b/testsuite/pytests/sli2py_regressions/test_ticket_310.py index c080a1d714..9e937c640f 100644 --- a/testsuite/pytests/sli2py_regressions/test_ticket_310.py +++ b/testsuite/pytests/sli2py_regressions/test_ticket_310.py @@ -13,7 +13,7 @@ # # 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 +0 # 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 @@ -22,8 +22,32 @@ import nest import pytest +# Models to skip to do given reasons +skip_list = [ + "correlospinmatrix_detector", # not a neuron + "eprop_iaf_bsshslm_2020", # no ArchivingNode, thus no t_spike + "eprop_iaf_adapt_bsshslm_2020", # no ArchivingNode, thus no t_spike + "eprop_readout_bsshslm_2020", # no ArchivingNode, thus no t_spike + "eprop_iaf", # no ArchivingNode, thus no t_spike + "eprop_iaf_adapt", # no ArchivingNode, thus no t_spike + "eprop_iaf_psc_delta", # no ArchivingNode, thus no t_spike + "eprop_iaf_psc_delta_adapt", # no ArchivingNode, thus no t_spike + "eprop_readout", # no ArchivingNode, thus no t_spike + "iaf_chxk_2008", # non-standard spiking conditions + "izhikevich", # generating output spike not reliably suppressed even for subthreshold V_m +] -def test_ticket_310(): + +def has_Vm_and_Vth(model): + params = nest.GetDefaults(model) + return "V_m" in params and "V_th" in params + + +relevant_models = [model for model in nest.node_models if model not in skip_list and has_Vm_and_Vth(model)] + + +@pytest.mark.parametrize("model", relevant_models) +def test_ticket_310(model): """ Regression test for Ticket #310. @@ -34,43 +58,14 @@ def test_ticket_310(): Author: Hans Ekkehard Plesser, 2009-02-11 """ - # Use power-of-two resolution to avoid round-off problems - res = 2**-3 - - skip_list = [ - "iaf_chxk_2008", # non-standard spiking conditions - "correlospinmatrix_detector", # not a neuron - "eprop_iaf_bsshslm_2020", # no ArchivingNode, thus no t_spike - "eprop_iaf_adapt_bsshslm_2020", # no ArchivingNode, thus no t_spike - "eprop_readout_bsshslm_2020", # no ArchivingNode, thus no t_spike - "eprop_iaf", # no ArchivingNode, thus no t_spike - "eprop_iaf_adapt", # no ArchivingNode, thus no t_spike - "eprop_iaf_psc_delta", # no ArchivingNode, thus no t_spike - "eprop_iaf_psc_delta_adapt", # no ArchivingNode, thus no t_spike - "eprop_readout", # no ArchivingNode, thus no t_spike - ] - - node_models = nest.node_models + time_resolution = 2**-3 # Use power-of-two resolution to avoid round-off problems - results = [] + nest.ResetKernel() + nest.resolution = time_resolution - for model in node_models: - if model not in skip_list: - nest.ResetKernel() - nest.SetKernelStatus({"resolution": res}) - n = nest.Create(model) + nrn = nest.Create(model) + nrn.V_m = nrn.V_th + 15 - # Check if V_m and V_th exist in the model's status - status = nest.GetStatus(n)[0] - if "V_m" in status and "V_th" in status: - nest.SetStatus(n, {"V_m": status["V_th"] + 15.0}) - nest.Simulate(res) - t_spike = nest.GetStatus(n, "t_spike")[0] - results.append(t_spike <= res) - else: - results.append(True) - else: - results.append(True) + nest.Simulate(time_resolution) - # Check if all entries are true - assert all(results), "Test failed for one or more models" + assert 0 < nrn.t_spike <= time_resolution # for precise neurons, < is possible; -1 if never spiked From 00e6947a0627b35d41170111d60907e4299bf298 Mon Sep 17 00:00:00 2001 From: Hans Ekkehard Plesser Date: Tue, 24 Jun 2025 20:38:26 +0200 Subject: [PATCH 3/3] Fix typo. --- testsuite/pytests/sli2py_regressions/test_ticket_310.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/pytests/sli2py_regressions/test_ticket_310.py b/testsuite/pytests/sli2py_regressions/test_ticket_310.py index 9e937c640f..d6bd5eb74c 100644 --- a/testsuite/pytests/sli2py_regressions/test_ticket_310.py +++ b/testsuite/pytests/sli2py_regressions/test_ticket_310.py @@ -13,7 +13,7 @@ # # NEST is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of -0 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# 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