|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# test_issue_311.py |
| 4 | +# |
| 5 | +# This file is part of NEST. |
| 6 | +# |
| 7 | +# Copyright (C) 2004 The NEST Initiative |
| 8 | +# |
| 9 | +# NEST is free software: you can redistribute it and/or modify |
| 10 | +# it under the terms of the GNU General Public License as published by |
| 11 | +# the Free Software Foundation, either version 2 of the License, or |
| 12 | +# (at your option) any later version. |
| 13 | +# |
| 14 | +# NEST is distributed in the hope that it will be useful, |
| 15 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | +# GNU General Public License for more details. |
| 18 | +# |
| 19 | +# You should have received a copy of the GNU General Public License |
| 20 | +# along with NEST. If not, see <http://www.gnu.org/licenses/>. |
| 21 | + |
| 22 | +""" |
| 23 | +Regression test for Issue #311 (GitHub). |
| 24 | +
|
| 25 | +This test ensures that NEST behaves properly when a model triggers an exception |
| 26 | +during update. |
| 27 | +""" |
| 28 | + |
| 29 | +import nest |
| 30 | +import pytest |
| 31 | + |
| 32 | + |
| 33 | +def test_nest_behaves_well_after_exception_during_update(): |
| 34 | + # Pathological parameters to trigger numerical exception |
| 35 | + nrn = nest.Create("aeif_cond_alpha", params={"I_e": 10000000.0, "g_L": 0.01}) |
| 36 | + |
| 37 | + # Execute in try-except context so exception does not propagate out |
| 38 | + did_crash = False |
| 39 | + try: |
| 40 | + nest.Simulate(100.0) |
| 41 | + except nest.kernel.NESTErrors.NumericalInstability: |
| 42 | + did_crash = True |
| 43 | + pass |
| 44 | + |
| 45 | + # did_crash must be true, otherwise no exception was triggered |
| 46 | + assert did_crash |
| 47 | + |
| 48 | + # Test that we still can inspect the kernel after an exception |
| 49 | + nest.GetKernelStatus() |
| 50 | + |
| 51 | + # Test that we cannot continue simulation after an exception. |
| 52 | + # Set neuron parameters to values that should stabilize numerics |
| 53 | + nrn.set({"V_m": -70.0, "w": 0.0, "I_e": 0.0}) |
| 54 | + |
| 55 | + with pytest.raises(nest.kernel.NESTErrors.KernelException): |
| 56 | + nest.Simulate(0.1) |
| 57 | + |
| 58 | + # Test that we can simulate again after a ResetKernel |
| 59 | + nest.ResetKernel() |
| 60 | + nest.Create("aeif_cond_alpha", params={"I_e": 1000.0}) |
| 61 | + nest.Simulate(100.0) |
0 commit comments