diff --git a/testsuite/pytests/sli2py_synapses/test_hh_psc_alpha_gap.py b/testsuite/pytests/sli2py_synapses/test_hh_psc_alpha_gap.py new file mode 100644 index 0000000000..fe4d184f72 --- /dev/null +++ b/testsuite/pytests/sli2py_synapses/test_hh_psc_alpha_gap.py @@ -0,0 +1,133 @@ +# -*- coding: utf-8 -*- +# +# test_hh_psc_alpha_gap.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 . + +""" +test_hh_psc_alpha_gap.sli is an overall test of the hh_psc_alpha_gap model connected +by gap_junction connection. + +Two neurons of whom one receives an constant input current of 200 pA are connected +by gap_junction with an (unrealistic) high gap weight. The accurate functionality +of the gap_junction feature is tested by measuring the membrane potential of the +neuron without input current. + +Although 0.1 cannot be represented in the IEEE double data type, it +is safe to simulate with a resolution (computation step size) of 0.1 +ms because by default nest is built with a timebase enabling exact +representation of 0.1 ms. +""" + +import nest +import pytest + +pytestmark = pytest.mark.skipif_missing_gsl + + +@pytest.fixture(autouse=True) +def prepare(): + nest.ResetKernel() + nest.set(local_num_threads=1, resolution=0.1, + use_wfr=True, wfr_tol=0.0001, + wfr_interpolation_order=3, wfr_max_iterations=10, + wfr_comm_interval=1.0) + + +@pytest.fixture() +def prepare_voltmeter(): + n1, n2 = nest.Create("hh_psc_alpha_gap", 2) + n1.set(I_e=200.) + + vm = nest.Create("voltmeter") + vm.set(time_in_steps=True, interval=nest.resolution) + + conn_rule = {"rule": "one_to_one", "make_symmetric": True} + syn_dict = {"synapse_model": "gap_junction", "weight": 20.0} + + nest.Connect(n1, n2, conn_rule, syn_dict) + nest.Connect(vm, n2, syn_spec={"weight": 1.0, "delay": nest.resolution}) + + nest.Simulate(20) + + return vm + + +@pytest.fixture() +def reference_data(): + return [ + [1, -69.592], + [2, -69.559], + [3, -69.507], + [4, -69.439], + [5, -69.357], + [6, -69.264], + [7, - 69.162], + [8, -69.051], + [9, -68.933], + [10, -68.809], + [11, -68.681], + [12, -68.548], + [13, -68.413], + [14, -68.276], + [15, -68.136], + + [117, -33.771], + [118, -24.103], + [119, 8.7117], + [120, 62.019], + [121, 39.042], + [122, 27.485], + [123, 18.856], + [124, 11.201], + [125, 3.6210], + [126, -4.6956], + [127, -15.006], + [128, -29.464], + [129, -49.786], + [130, -71.323], + [131, -83.787], + + [190, -71.023], + [191, -70.833], + [192, -70.647], + [193, -70.466], + [194, -70.289], + [195, -70.116], + [196, -69.948], + [197, -69.783], + [198, -69.622], + [199, -69.464]] + + +def test_hh_cond_beta_gap(prepare_voltmeter, reference_data): + + vm = prepare_voltmeter + reference_data = dict(reference_data) + + events = vm.get("events") + recorded_times = events["times"] + recorded_vm = events["V_m"] + + actual_data = dict(zip(recorded_times, recorded_vm)) + actual_data = {k: actual_data[k] for k in reference_data.keys()} + + actual_data = list(actual_data.values()) + reference_data = list(reference_data.values()) + + assert actual_data == pytest.approx(reference_data, rel=1e-4) diff --git a/testsuite/unittests/test_hh_psc_alpha_gap.sli b/testsuite/unittests/test_hh_psc_alpha_gap.sli deleted file mode 100644 index 83847f9e91..0000000000 --- a/testsuite/unittests/test_hh_psc_alpha_gap.sli +++ /dev/null @@ -1,165 +0,0 @@ -/* - * test_hh_psc_alpha_gap.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 . - * - */ - -% SLI2PYComplexity: Low - - /** @BeginDocumentation - Name: testsuite::test_hh_psc_alpha_gap - sli script for overall test of hh_psc_alpha_gap model - with gap_junction connection - - Synopsis: (test_hh_psc_alpha_gap) run -> compares response to current step with reference data - - Description: - test_hh_psc_alpha_gap.sli is an overall test of the hh_psc_alpha_gap model connected - by gap_junction connection. - - Two neurons of whom one receives an constant input current of 200 pA are connected - by gap_junction with an (unrealistic) high gap weight. The accurate functionality - of the gap_junction feature is tested by measuring the membrane potential of the - neuron without input current. - - Although 0.1 cannot be represented in the IEEE double data type, it - is safe to simulate with a resolution (computation step size) of 0.1 - ms because by default nest is built with a timebase enabling exact - representation of 0.1 ms. - - The expected output is documented at the end of - the script. - - Author: October 2015, Hahne - SeeAlso: testsuite::test_gap_junction, hh_psc_alpha_gap, gap_junction -*/ - -(unittest) run -/unittest using - -% The following test needs the model hh_psc_alpha_gap, so -% this test should only run if we have GSL -skip_if_without_gsl - -0.1 /h Set - -ResetKernel - -<< - /local_num_threads 1 - /resolution h - /use_wfr true - /wfr_tol 0.0001 - /wfr_interpolation_order 3 - /wfr_max_iterations 10 - /wfr_comm_interval 1.0 - >> SetKernelStatus - -/hh_psc_alpha_gap Create /neuron1 Set -/hh_psc_alpha_gap Create /neuron2 Set - -neuron1 -<< - /I_e 200. ->> SetStatus - -/voltmeter Create /vm Set -vm << /time_in_steps true /interval h >> SetStatus - -neuron1 neuron2 -<< /rule /one_to_one /make_symmetric true >> -<< /synapse_model /gap_junction /weight 20.0 >> -Connect -vm neuron2 1.0 h Connect - -% The following call to GetConnections makes Simulate crash -% or generate results containing NaNs, see #2614. -<< >> GetConnections ; - -20 Simulate - -{ % reference data - dup Transpose First /test_times Set % times of reference - - vm [/events [/times /V_m]] get cva % array of recorded data - 5 ToUnitTestPrecision % to precision of reference - Transpose % all recorded tuples - {First test_times exch MemberQ } Select % those with reference - eq % compare -} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% Expected output of this program: -% -% The output send to std::cout is a superposition of -% the output of the voltmeter. -% -% time (in steps) voltage (in mV) -[ -[ 1 -69.592 ] -[ 2 -69.559 ] -[ 3 -69.507 ] -[ 4 -69.439 ] -[ 5 -69.357 ] -[ 6 -69.264 ] -[ 7 -69.162 ] -[ 8 -69.051 ] -[ 9 -68.933 ] -[ 10 -68.809 ] -[ 11 -68.681 ] -[ 12 -68.548 ] -[ 13 -68.413 ] -[ 14 -68.276 ] -[ 15 -68.136 ] -% -% ... -% -[ 117 -33.771 ] -[ 118 -24.103 ] -[ 119 8.7117 ] -[ 120 62.019 ] -[ 121 39.042 ] -[ 122 27.485 ] -[ 123 18.856 ] -[ 124 11.201 ] -[ 125 3.6210 ] -[ 126 -4.6956 ] -[ 127 -15.006 ] -[ 128 -29.464 ] -[ 129 -49.786 ] -[ 130 -71.323 ] -[ 131 -83.787 ] -% -% ... -% -[ 190 -71.023 ] -[ 191 -70.833 ] -[ 192 -70.647 ] -[ 193 -70.466 ] -[ 194 -70.289 ] -[ 195 -70.116 ] -[ 196 -69.948 ] -[ 197 -69.783 ] -[ 198 -69.622 ] -[ 199 -69.464 ] -] - -exch assert_or_die - -