From fc791b86a4eeee7fa23229ddd7fcf8d7eec1f71b Mon Sep 17 00:00:00 2001 From: Nicolai Haug Date: Mon, 8 May 2023 01:55:03 +0200 Subject: [PATCH 1/2] Port issue-105.sli to pytest --- .../sli2py_regressions/test_issue_105.py | 136 ++++++++++++ testsuite/regressiontests/issue-105.sli | 194 ------------------ 2 files changed, 136 insertions(+), 194 deletions(-) create mode 100644 testsuite/pytests/sli2py_regressions/test_issue_105.py delete mode 100644 testsuite/regressiontests/issue-105.sli diff --git a/testsuite/pytests/sli2py_regressions/test_issue_105.py b/testsuite/pytests/sli2py_regressions/test_issue_105.py new file mode 100644 index 0000000000..cc5662e809 --- /dev/null +++ b/testsuite/pytests/sli2py_regressions/test_issue_105.py @@ -0,0 +1,136 @@ +# -*- coding: utf-8 -*- +# +# test_issue_105.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 #105 (GitHub). +""" + +import pytest + +import nest + + +@pytest.fixture(autouse=True) +def set_resolution(): + nest.ResetKernel() + nest.resolution = 0.1 + + +@pytest.mark.parametrize("delay", [0.81, 0.82, 0.8499]) +def test_min_delay_on_fresh_connection(delay): + """ + Ensure that NEST sets `min_delay` correctly from delay in `syn_spec`. + + This test ensures that `min_delay` is set correctly for delays + that are not multiples of the resolution. + """ + + nrn = nest.Create("iaf_psc_alpha") + conn = nest.Connect( + nrn, nrn, "one_to_one", {"delay": delay}, return_synapsecollection=True + ) + + expected_delay = 0.8 + assert conn.delay == expected_delay + assert nest.min_delay == expected_delay + + +@pytest.mark.parametrize("delay", [0.81, 0.82, 0.8499]) +def test_min_delay_on_synapsecollection_set(delay): + """ + Ensure that NEST sets `min_delay` correctly on `SynapseCollection` set. + + This test ensures that `min_delay` is set correctly for delays + that are not multiples of the resolution. + """ + + nrn = nest.Create("iaf_psc_alpha") + conn = nest.Connect(nrn, nrn, "one_to_one", return_synapsecollection=True) + conn.delay = delay + + expected_delay = 0.8 + assert conn.delay == expected_delay + assert nest.min_delay == expected_delay + + +@pytest.mark.parametrize("delay", [0.85, 0.86, 0.8999]) +def test_max_delay_on_fresh_connection(delay): + """ + Ensure that NEST sets `max_delay` correctly from delay in `syn_spec`. + + This test ensures that `max_delay` is set correctly for delays + that are not multiples of the resolution. + """ + + nrn = nest.Create("iaf_psc_alpha") + conn = nest.Connect( + nrn, nrn, "one_to_one", {"delay": delay}, return_synapsecollection=True + ) + + expected_delay = 0.9 + assert conn.delay == expected_delay + assert nest.max_delay == expected_delay + + +@pytest.mark.parametrize("delay", [1.95, 1.96, 1.999]) +def test_max_delay_on_synapsecollection_set(delay): + """ + Ensure that NEST sets `max_delay` correctly on `SynapseCollection` set. + + This test ensures that `max_delay` is set correctly for delays + that are not multiples of the resolution. + """ + + nrn = nest.Create("iaf_psc_alpha") + conn = nest.Connect(nrn, nrn, "one_to_one", return_synapsecollection=True) + conn.delay = delay + + expected_delay = 2.0 + assert conn.delay == expected_delay + assert nest.max_delay == expected_delay + + +@pytest.mark.parametrize("min_delay", [0.81, 0.89]) +def test_min_and_max_delay_on_set_kernel_status(min_delay): + """ + Test setting `min_delay` and `max_delay` on kernel set. + + Test that setting `min_delay` and `max_delay` works so that setting certain + min/max values will allow those values to be used in subsequent connections. + Note that effects can only be seen in the kernel status after a connection + has been created. + + We expect that both `min_delay` values are rounded to 0.8 and the + `max_delay` value is rounded to 1.5. + """ + + max_delay = 1.49 + + nest.set(min_delay=min_delay, max_delay=max_delay) + + nrn = nest.Create("iaf_psc_alpha") + nest.Connect(nrn, nrn, "one_to_one", {"delay": min_delay}) + nest.Connect(nrn, nrn, "one_to_one", {"delay": max_delay}) + + expected_min_delay = 0.8 + expected_max_delay = 1.5 + assert nest.min_delay == expected_min_delay + assert nest.max_delay == expected_max_delay diff --git a/testsuite/regressiontests/issue-105.sli b/testsuite/regressiontests/issue-105.sli deleted file mode 100644 index 40e2734047..0000000000 --- a/testsuite/regressiontests/issue-105.sli +++ /dev/null @@ -1,194 +0,0 @@ -/* - * issue-105.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-105 Ensure that min_delay and max_delay are set correctly - -Synopsis: (issue-105) run -> NEST exits if test fails - -Description: -This ticket ensures that NEST sets min_delay and max_delay correctly also for -delays that are not multiples of the resolution. - -Author: Hans E Plesser, 2015-12-01 based on material by Jafet Diaz - */ - -(unittest) run -/unittest using - -M_ERROR setverbosity - -% Test min_delay on fresh connection -{ - ResetKernel - - << /resolution 0.1 >> SetKernelStatus - - /n /iaf_psc_alpha Create def - - [ 0.81 0.82 0.8499 ] - { - /delay Set - n dup /one_to_one << /delay delay >> Connect - } forall - - << >> GetConnections { /delay get } Map - - % should all be 0.8 - dup true exch { 0.8 eq and } Fold - exch - 0 get - GetKernelStatus /min_delay get - eq - and -} assert_or_die - -% Test min_delay on SetStatus -{ - ResetKernel - - << /resolution 0.1 >> SetKernelStatus - - /n /iaf_psc_alpha Create def - - /delays [ 0.81 0.82 0.8499 ] def - - delays - { - ; - n dup Connect - } forall - - [ << >> GetConnections delays ] - { /d Set << /delay d >> SetStatus } - ScanThread - - << >> GetConnections { GetStatus /delay get } Map - - % should all be 0.8 - dup true exch { 0.8 eq and } Fold - exch - 0 get - GetKernelStatus /min_delay get - eq - and -} assert_or_die - -% Test max_delay on fresh connection -{ - ResetKernel - - << /resolution 0.1 >> SetKernelStatus - - /n /iaf_psc_alpha Create def - - [ 0.85 0.86 0.8999 ] - { - /delay Set - n dup /one_to_one << /delay delay >> Connect - } forall - - << >> GetConnections { /delay get } Map - - % should all be 0.9 - dup true exch { 0.9 eq and } Fold - exch - 0 get - GetKernelStatus /max_delay get - eq - and -} assert_or_die - -% Test max_delay on SetStatus -{ - ResetKernel - - << /resolution 0.1 >> SetKernelStatus - - /n /iaf_psc_alpha Create def - - % test delays must be longer than 1.0, since we - % first create default connections with delay 1 - /delays [ 1.95 1.96 1.9999 ] def - - delays - { - ; - n dup Connect - } forall - - [ << >> GetConnections delays ] - { /d Set << /delay d >> SetStatus } - ScanThread - - << >> GetConnections { GetStatus /delay get } Map - - % should all be 2.0 - dup true exch { 2.0 eq and } Fold - exch - 0 get - GetKernelStatus /max_delay get - eq - and -} assert_or_die - -% Test that setting min_delay and max_delay works so that setting certain -% min/max values will allow those values to be used in subsequent connections. -% Note that effects can only be seen in the kernel status after a connection -% has been created. - -{ - ResetKernel - - /min_delay 0.81 def % rounded to 0.8 - /max_delay 1.49 def % rounded to 1.5 - - << /min_delay min_delay /max_delay max_delay >> SetKernelStatus - - /n /iaf_psc_alpha Create def - - n dup /one_to_one << /delay min_delay >> Connect - n dup /one_to_one << /delay max_delay >> Connect - - GetKernelStatus /min_delay get 0.8 eq - GetKernelStatus /max_delay get 1.5 eq - and -} assert_or_die - -{ - ResetKernel - - /min_delay 0.89 def % rounded to 0.8 - /max_delay 1.41 def % rounded to 1.5 - - << /min_delay min_delay /max_delay max_delay >> SetKernelStatus - - /n /iaf_psc_alpha Create def - - n dup /one_to_one << /delay min_delay >> Connect - n dup /one_to_one << /delay max_delay >> Connect - - GetKernelStatus /min_delay get 0.8 eq - GetKernelStatus /max_delay get 1.5 eq - and -} assert_or_die From 7c68f4eae5033c3beb06c62fb235e0194ccb9139 Mon Sep 17 00:00:00 2001 From: Nicolai Haug Date: Tue, 27 Jun 2023 22:15:47 +0200 Subject: [PATCH 2/2] Black formatting --- testsuite/pytests/sli2py_regressions/test_issue_105.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/testsuite/pytests/sli2py_regressions/test_issue_105.py b/testsuite/pytests/sli2py_regressions/test_issue_105.py index cc5662e809..2c6aa62f15 100644 --- a/testsuite/pytests/sli2py_regressions/test_issue_105.py +++ b/testsuite/pytests/sli2py_regressions/test_issue_105.py @@ -44,9 +44,7 @@ def test_min_delay_on_fresh_connection(delay): """ nrn = nest.Create("iaf_psc_alpha") - conn = nest.Connect( - nrn, nrn, "one_to_one", {"delay": delay}, return_synapsecollection=True - ) + conn = nest.Connect(nrn, nrn, "one_to_one", {"delay": delay}, return_synapsecollection=True) expected_delay = 0.8 assert conn.delay == expected_delay @@ -81,9 +79,7 @@ def test_max_delay_on_fresh_connection(delay): """ nrn = nest.Create("iaf_psc_alpha") - conn = nest.Connect( - nrn, nrn, "one_to_one", {"delay": delay}, return_synapsecollection=True - ) + conn = nest.Connect(nrn, nrn, "one_to_one", {"delay": delay}, return_synapsecollection=True) expected_delay = 0.9 assert conn.delay == expected_delay