-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2964 from nicolossus/port_issue_311
Port `issue-311` from SLI-2-Py
- Loading branch information
Showing
2 changed files
with
61 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
|
||
""" | ||
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) |
This file was deleted.
Oops, something went wrong.