diff --git a/testsuite/pytests/sli2py_regressions/test_issue_311.py b/testsuite/pytests/sli2py_regressions/test_issue_311.py new file mode 100644 index 0000000000..3a3b001d10 --- /dev/null +++ b/testsuite/pytests/sli2py_regressions/test_issue_311.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# +# test_issue_311.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 #311 (GitHub). + +This test ensures that NEST behaves properly when a model triggers an exception +during update. +""" + +import nest +import pytest + + +def test_nest_behaves_well_after_exception_during_update(): + # Pathological parameters to trigger numerical exception + nrn = nest.Create("aeif_cond_alpha", params={"I_e": 10000000.0, "g_L": 0.01}) + + # Execute in try-except context so exception does not propagate out + did_crash = False + try: + nest.Simulate(100.0) + except nest.kernel.NESTErrors.NumericalInstability: + did_crash = True + pass + + # did_crash must be true, otherwise no exception was triggered + assert did_crash + + # Test that we still can inspect the kernel after an exception + nest.GetKernelStatus() + + # Test that we cannot continue simulation after an exception. + # Set neuron parameters to values that should stabilize numerics + nrn.set({"V_m": -70.0, "w": 0.0, "I_e": 0.0}) + + with pytest.raises(nest.kernel.NESTErrors.KernelException): + nest.Simulate(0.1) + + # Test that we can simulate again after a ResetKernel + nest.ResetKernel() + nest.Create("aeif_cond_alpha", params={"I_e": 1000.0}) + nest.Simulate(100.0) diff --git a/testsuite/regressiontests/issue-311.sli b/testsuite/regressiontests/issue-311.sli deleted file mode 100644 index 803b85f40b..0000000000 --- a/testsuite/regressiontests/issue-311.sli +++ /dev/null @@ -1,76 +0,0 @@ -/* - * issue-311.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-311 Ensure NEST behaves well after exception during update - -Synopsis: (issue-311) run -> NEST exits if test fails - -Description: -This test ensures that NEST behaves properly when a model triggers and -exception during update. - -Author: Hans Ekkehard Plesser, 2016-11-02 - */ - -(unittest) run -/unittest using - -M_ERROR setverbosity - -GetKernelStatus /node_models get /aeif_cond_alpha MemberQ not -{ /skipped exit_test_gracefully } if - -% Execute in stopped context so exception does not propagate out -% pathological parameters to trigger numerical exception -/nrn /aeif_cond_alpha << /I_e 10000000. /g_L 0.01 >> Create def -{ - { - 100 Simulate - } - stopped -} assert_or_die % stopped must return true, otherwise no exception was triggered - -% clean up after error -errordict begin /newerror false def end -clear - -% Test 1: We can still inspect the kernel after an exception -{ - % this calls get_time() and triggers assertion prior to fix for #311 - GetKernelStatus ; -} pass_or_die - -% Test 2: We cannot continue simulation after an exception -{ - % set neuron parameters to values that should stabilize numerics - nrn << /V_m -70.0 /w 0.0 /I_e 0.0 >> SetStatus - 0.1 Simulate -} fail_or_die - -% Test 3: We can simulate again after a ResetKernel -ResetKernel -{ - /aeif_cond_alpha << /I_e 1000. >> Create ; - 100 Simulate -} pass_or_die