From 1bbf42c62fab528859166ffd946acd45264e9937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20M=C3=B8rk?= Date: Mon, 8 May 2017 15:57:41 +0200 Subject: [PATCH 01/20] Updated and moved some of the tests from "manualtests" folder --- pynest/nest/tests/test_facetshw_stdp.py | 158 +++++++++++++ pynest/nest/tests/test_pp_psc_delta.py | 219 ++++++++++++++++++ testsuite/manualtests/test_facetshw_stdp.py | 140 ----------- .../manualtests/test_hh_cond_exp_traub.sli | 121 ---------- testsuite/manualtests/test_pp_psc_delta.py | 207 ----------------- .../test_sinusoidal_poisson_generator_5.sli | 11 +- .../test_sinusoidal_poisson_generator_6.sli | 11 +- .../model_node_init.sli | 15 +- .../test_compare_delta.sli | 29 +-- .../unittests/test_hh_cond_exp_traub.sli | 150 ++++++++++++ 10 files changed, 558 insertions(+), 503 deletions(-) create mode 100644 pynest/nest/tests/test_facetshw_stdp.py create mode 100644 pynest/nest/tests/test_pp_psc_delta.py delete mode 100644 testsuite/manualtests/test_facetshw_stdp.py delete mode 100644 testsuite/manualtests/test_hh_cond_exp_traub.sli delete mode 100644 testsuite/manualtests/test_pp_psc_delta.py rename testsuite/{manualtests => mpitests}/test_sinusoidal_poisson_generator_5.sli (95%) rename testsuite/{manualtests => mpitests}/test_sinusoidal_poisson_generator_6.sli (96%) rename testsuite/{manualtests => unittests}/model_node_init.sli (89%) rename testsuite/{manualtests => unittests}/test_compare_delta.sli (73%) create mode 100644 testsuite/unittests/test_hh_cond_exp_traub.sli diff --git a/pynest/nest/tests/test_facetshw_stdp.py b/pynest/nest/tests/test_facetshw_stdp.py new file mode 100644 index 0000000000..338a39f7d0 --- /dev/null +++ b/pynest/nest/tests/test_facetshw_stdp.py @@ -0,0 +1,158 @@ +# -*- coding: utf-8 -*- +# +# test_facetshw_stdp.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 . + +# author: Thomas Pfeil +# date of 1st version: 21.01.2013 + +# This script is testing the accumulation of spike pairs and +# the weight update mechanism as implemented in the FACETS hardware + +import nest +import numpy as np +import unittest + +class FacetsTestCase(unittest.TestCase): + + def test_facetshw_stdp(self): + + modelName = 'stdp_facetshw_synapse_hom' + + ############## + # parameters # + # homogen parameters for all synapses # + Wmax = 100.0 + # see *.cpp file of synapse model and Pfeil et al. 2012 for LUT configuration + lut_0 = [2, 3, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14, 15] + lut_1 = [0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13] + lut_2 = range(16) # identity + config_0 = [0, 0, 1, 0] + config_1 = [0, 1, 0, 0] + reset_pattern = 6 * [1] # reset all + + # individual parameters for each synapse # + lut_th_causal = 21.835 # reached every 36 runs (e^(-10/20)=21.83510375) + lut_th_acausal = lut_th_causal + + # other parameters # + startWeight = 0 # as digital value [0,1,...,15] + tau = 20.0 + + timeBetweenPairs = 100.0 + delay = 5.0 # frequency_of_pairs=10Hz => delta_t(+)=10ms, delta_t(-)=90ms + spikesIn = np.arange(10.0, 60000.0, timeBetweenPairs) + + synapseDict = {'tau_plus': tau, + 'tau_minus_stdp': tau, + 'Wmax': Wmax, + 'synapses_per_driver': 50, + 'driver_readout_time': 15.0, + 'lookuptable_0': lut_0, + 'lookuptable_1': lut_1, + 'lookuptable_2': lut_2, + 'configbit_0': config_0, + 'configbit_1': config_1, + 'reset_pattern': reset_pattern, + + 'a_thresh_th': lut_th_causal, + 'a_thresh_tl': lut_th_acausal} + + ################# + # build network # + stim = nest.Create('spike_generator') + neuronA = nest.Create('parrot_neuron') + neuronB = nest.Create('parrot_neuron') + # recorder = nest.Create('spike_detector') + nest.SetStatus(stim, [{'spike_times': spikesIn}]) + + nest.SetDefaults(modelName, synapseDict) + + # check if Get returns same values as have been Set + synapseDictGet = nest.GetDefaults(modelName) + for key in synapseDict.keys(): + self.assertTrue(all(np.atleast_1d(synapseDictGet[key] == synapseDict[key]))) + + nest.Connect(stim, neuronA) + nest.Connect(neuronA, neuronB, syn_spec={ + 'weight': float(startWeight) / 15.0 * Wmax, + 'delay': delay, 'model': modelName}) + # nest.Connect(neuronA, recorder) + # nest.Connect(neuronB, recorder) + + nest.Simulate(50.0) + weightTrace = [] + for run in range(len(spikesIn)): + nest.Simulate(timeBetweenPairs) + + connections = nest.GetConnections(neuronA) + for i in range(len(connections)): + if nest.GetStatus([connections[i]])[0]['synapse_model'] == modelName: + weightTrace.append( + [run, nest.GetStatus([connections[i]])[0]['weight'], + nest.GetStatus([connections[i]])[0]['a_causal'], + nest.GetStatus([connections[i]])[0]['a_acausal']]) + + ############ + # analysis # + weightTrace = np.array(weightTrace) + + weightTraceMod36pre = weightTrace[35::36] # just before theoretical updates + weightTraceMod36 = weightTrace[::36] # just after theoretical updates + + weightIndex = int(startWeight) + for i in range(len(weightTraceMod36pre)): + # check weight value before update (after spike pair w index 35, 71, ...) + self.assertTrue(np.allclose(weightTraceMod36pre[i][1], + 1.0 / 15.0 * weightIndex * Wmax, + atol=1e-6)) + weightIndex = lut_0[weightIndex] + + weightIndex = int(startWeight) + for i in range(len(weightTraceMod36)): + # check weight value after update (after spike pair w index 0, 36, 72, ...) + self.assertTrue(np.allclose(weightTraceMod36[i][1], + 1.0 / 15.0 * weightIndex * Wmax, + atol=1e-6)) + # check charge on causal capacitor + self.assertTrue(np.allclose(weightTraceMod36[i][2], + np.ones_like(weightTraceMod36[i][2]) * + np.exp(-2 * delay / tau), atol=1e-6)) + weightIndex = lut_0[weightIndex] + + # check charge on anti-causal capacitor after each pair + for i in range(len(weightTrace) - 1): + # TODO: global params + self.assertTrue(np.allclose(weightTrace[i, 3], ((i % 36) + 1) * + np.exp(-(timeBetweenPairs - 2 * delay) / tau), + atol=1e-6)) + + +def suite(): + suite = unittest.makeSuite(FacetsTestCase, 'test') + return suite + + +def run(): + runner = unittest.TextTestRunner(verbosity=2) + runner.run(suite()) + +if __name__ == "__main__": + run() + diff --git a/pynest/nest/tests/test_pp_psc_delta.py b/pynest/nest/tests/test_pp_psc_delta.py new file mode 100644 index 0000000000..9f67d6c680 --- /dev/null +++ b/pynest/nest/tests/test_pp_psc_delta.py @@ -0,0 +1,219 @@ +# -*- coding: utf-8 -*- +# +# test_pp_psc_delta.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 . + +# +# tests for pp_psc_delta +# + +import unittest +import nest + + +# 1) check for reasonable firing rate +# 2) check if fixed dead-time is respected + + +class PpPscDeltaTestCase(unittest.TestCase): + + def test_rate_and_fixed_dead_time(self): + # test parameters + d = 25.0 + lam = 10.0 + T = 10000.0 + + nest.ResetKernel() + nrn = nest.Create('pp_psc_delta') + + params = {'tau_m': 10.0, + 'C_m': 250.0, + 'dead_time': d, + 'dead_time_random': False, + 'dead_time_shape': 1, + 'with_reset': False, + 'tau_sfa': 34.0, + 'q_sfa': 0.0, # // mV, reasonable default is 7 mV + 'c_1': 0.0, + 'c_2': lam, + 'c_3': 0.25, + 'I_e': 0.0, + 't_ref_remaining': 0.0 + } + + nest.SetStatus(nrn, params) + + sd = nest.Create('spike_detector') + nest.Connect(nrn, sd) + nest.Simulate(T) + + spikes = nest.GetStatus(sd)[0]['events']['times'] + rate_sim = len(spikes) / (T * 1e-3) + rate_ana = 1. / (1. / lam + d * 1e-3) + ratio = rate_sim / rate_ana + + # This could fail due to bad luck. However, if it passes once, + # then it should always do so, since the random numbers are + # reproducible in NEST. + self.assertLess(0.5, ratio) + self.assertLess(ratio, 1.5) + + isi = [] + for i in xrange(1, len(spikes)): + isi.append(spikes[i] - spikes[i - 1]) + + self.assertGreaterEqual(min(isi), d) + + # 3) check if random dead-time moments are respected + + def test_random_dead_time(self): + # test parameters + d = 50.0 + n = 10 + lam = 1.0e6 + T = 10000.0 + + nest.ResetKernel() + nrn = nest.Create('pp_psc_delta') + + params = {'tau_m': 10.0, + 'C_m': 250.0, + 'dead_time': d, + 'dead_time_random': True, + 'dead_time_shape': 10, + 'with_reset': False, + 'tau_sfa': 34.0, + 'q_sfa': 0.0, # // mV, reasonable default is 7 mV + 'c_1': 0.0, + 'c_2': lam, + 'c_3': 0.25, + 'I_e': 0.0, + 't_ref_remaining': 0.0 + } + + nest.SetStatus(nrn, params) + + sd = nest.Create('spike_detector') + nest.Connect(nrn, sd) + nest.Simulate(T) + + spikes = nest.GetStatus(sd)[0]['events']['times'] + rate_sim = len(spikes) / (T * 1e-3) + rate_ana = 1. / (1. / lam + d * 1e-3) + ratio = rate_sim / rate_ana + + # This could fail due to bad luck. However, if it passes once, + # then it should always do so, since the random numbers are + # reproducible in NEST. + self.assertLess(0.5, ratio) + self.assertLess(ratio, 1.5) + + isi = [] + for i in xrange(1, len(spikes)): + isi.append(spikes[i] - spikes[i - 1]) + + # compute moments of ISI to get mean and variance + isi_m1 = 0. + isi_m2 = 0. + for t in isi: + isi_m1 += t + isi_m2 += t ** 2 + + isi_mean = isi_m1 / len(isi) + isi_var = isi_m2 / len(isi) - isi_mean ** 2 + ratio_mean = isi_mean / d + self.assertLessEqual(0.5, ratio_mean) + self.assertLessEqual(ratio_mean, 1.5) + + isi_var_th = n / (n / d) ** 2 + ratio_var = isi_var / isi_var_th + self.assertLessEqual(0.5, ratio_var) + self.assertLessEqual(ratio_var, 1.5) + + # 4) check if threshold adaptation works by looking for negative + # serial correlation of ISI. + def test_adapting_threshold(self): + # test parameters + d = 1e-8 + lam = 30.0 + T = 10000.0 + + nest.ResetKernel() + nrn = nest.Create('pp_psc_delta') + + params = {'tau_m': 10.0, + 'C_m': 250.0, + 'dead_time': d, + 'dead_time_random': False, + 'dead_time_shape': 1, + 'with_reset': False, + 'tau_sfa': 34.0, + 'q_sfa': 7.0, # // mV, reasonable default is 7 mV + 'c_1': 0.0, + 'c_2': lam, + 'c_3': 0.25, + 'I_e': 0.0, + 't_ref_remaining': 0.0 + } + + nest.SetStatus(nrn, params) + + sd = nest.Create('spike_detector') + nest.Connect(nrn, sd) + nest.Simulate(T) + + spikes = nest.GetStatus(sd)[0]['events']['times'] + + # This could fail due to bad luck. However, if it passes once, + # then it should always do so, since the random numbers are + # reproducible in NEST. Adaptive threshold changes rate, thus + # the ratio is not asserted here. + isi = [] + for i in xrange(1, len(spikes)): + isi.append(spikes[i] - spikes[i - 1]) + + # compute moments of ISI to get mean and variance + isi_m1 = isi[-1] + isi_m2 = isi[-1] ** 2 + isi_12 = 0. + for t, t1 in zip(isi[:-1], isi[1:]): + isi_m1 += t + isi_m2 += t ** 2 + isi_12 += t * t1 + + isi_mean = isi_m1 / len(isi) + isi_var = (isi_m2 - isi_m1) ** 2 / len(isi) + isi_corr = (isi_12 / (len(isi) - 1) - isi_mean ** 2) / isi_var + + self.assertLessEqual(-1.0, isi_corr) + self.assertLessEqual(isi_corr, 0.0) + + +def suite(): + suite = unittest.makeSuite(PpPscDeltaTestCase, 'test') + return suite + + +def run(): + runner = unittest.TextTestRunner(verbosity=2) + runner.run(suite()) + + +if __name__ == "__main__": + run() diff --git a/testsuite/manualtests/test_facetshw_stdp.py b/testsuite/manualtests/test_facetshw_stdp.py deleted file mode 100644 index c546415dcd..0000000000 --- a/testsuite/manualtests/test_facetshw_stdp.py +++ /dev/null @@ -1,140 +0,0 @@ -# -*- coding: utf-8 -*- -# -# test_facetshw_stdp.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 . - -# author: Thomas Pfeil -# date of 1st version: 21.01.2013 - -# This script is testing the accumulation of spike pairs and -# the weight update mechanism as implemented in the FACETS hardware - -import nest -import numpy as np - -modelName = 'stdp_facetshw_synapse_hom' - -############## -# parameters # -# homogen parameters for all synapses # -Wmax = 100.0 -# see *.cpp file of synapse model and Pfeil et al. 2012 for LUT configuration -lut_0 = [2, 3, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14, 15] -lut_1 = [0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13] -lut_2 = range(16) # identity -config_0 = [0, 0, 1, 0] -config_1 = [0, 1, 0, 0] -reset_pattern = 6 * [1] # reset all - -# individual parameters for each synapse # -lut_th_causal = 21.835 # reached every 36 runs (e^(-10/20)=21.83510375) -lut_th_acausal = lut_th_causal - -# other parameters # -startWeight = 0 # as digital value [0,1,...,15] -tau = 20.0 - -timeBetweenPairs = 100.0 -delay = 5.0 # frequency_of_pairs=10Hz => delta_t(+)=10ms, delta_t(-)=90ms -spikesIn = np.arange(10.0, 60000.0, timeBetweenPairs) - -synapseDict = {'tau_plus': tau, - 'tau_minus_stdp': tau, - 'Wmax': Wmax, - 'synapses_per_driver': 50, - 'driver_readout_time': 15.0, - 'lookuptable_0': lut_0, - 'lookuptable_1': lut_1, - 'lookuptable_2': lut_2, - 'configbit_0': config_0, - 'configbit_1': config_1, - 'reset_pattern': reset_pattern, - - 'a_thresh_th': lut_th_causal, - 'a_thresh_tl': lut_th_acausal} - -################# -# build network # -stim = nest.Create('spike_generator') -neuronA = nest.Create('parrot_neuron') -neuronB = nest.Create('parrot_neuron') -# recorder = nest.Create('spike_detector') -nest.SetStatus(stim, [{'spike_times': spikesIn}]) - -nest.SetDefaults(modelName, synapseDict) - -# check if Get returns same values as have been Set -synapseDictGet = nest.GetDefaults(modelName) -for key in synapseDict.keys(): - assert (all(np.atleast_1d(synapseDictGet[key] == synapseDict[key]))) - -nest.Connect(stim, neuronA) -nest.Connect(neuronA, neuronB, syn_spec={ - 'weight': float(startWeight) / 15.0 * Wmax, - 'delay': delay, 'model': modelName}) -# nest.Connect(neuronA, recorder) -# nest.Connect(neuronB, recorder) - -nest.Simulate(50.0) -weightTrace = [] -for run in range(len(spikesIn)): - nest.Simulate(timeBetweenPairs) - - connections = nest.GetConnections(neuronA) - for i in range(len(connections)): - if nest.GetStatus([connections[i]])[0]['synapse_model'] == modelName: - weightTrace.append( - [run, nest.GetStatus([connections[i]])[0]['weight'], - nest.GetStatus([connections[i]])[0]['a_causal'], - nest.GetStatus([connections[i]])[0]['a_acausal']]) - -############ -# analysis # -weightTrace = np.array(weightTrace) - -weightTraceMod36pre = weightTrace[35::36] # just before theoretical updates -weightTraceMod36 = weightTrace[::36] # just after theoretical updates - -weightIndex = int(startWeight) -for i in range(len(weightTraceMod36pre)): - # check weight value before update (after spike pair w index 35, 71, ...) - assert (np.allclose(weightTraceMod36pre[i][1], - 1.0 / 15.0 * weightIndex * Wmax, - atol=1e-6)) - weightIndex = lut_0[weightIndex] - -weightIndex = int(startWeight) -for i in range(len(weightTraceMod36)): - # check weight value after update (after spike pair w index 0, 36, 72, ...) - assert (np.allclose(weightTraceMod36[i][1], - 1.0 / 15.0 * weightIndex * Wmax, - atol=1e-6)) - # check charge on causal capacitor - assert (np.allclose(weightTraceMod36[i][2], - np.ones_like(weightTraceMod36[i][2]) * - np.exp(-2 * delay / tau), atol=1e-6)) - weightIndex = lut_0[weightIndex] - -# check charge on anti-causal capacitor after each pair -for i in range(len(weightTrace) - 1): - assert (np.allclose(weightTrace[i, 3], ((i % 36) + 1) * - np.exp(-(timeBetweenPairs - 2 * delay) / tau), - atol=1e-6)) # TODO: global params - -print('test successful') diff --git a/testsuite/manualtests/test_hh_cond_exp_traub.sli b/testsuite/manualtests/test_hh_cond_exp_traub.sli deleted file mode 100644 index bd79e1612f..0000000000 --- a/testsuite/manualtests/test_hh_cond_exp_traub.sli +++ /dev/null @@ -1,121 +0,0 @@ -/* - * test_hh_cond_exp_traub.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::test_hh_cond_exp_traub - sli script for overall test of hh_cond_exp_traub model - - Synopsis: (test_hh_cond_exp_traub) run -> - - Description: - - Author: - SeeAlso: -*/ - -(unittest) run -/unittest using - -0.1 /h Set - -ResetKernel - -0 << - /local_num_threads 1 - /resolution h - >> SetStatus - -%% Test: Node creation - -/hh_cond_exp_traub Create /neuron Set - -%% Test: Set/GetStatus - -<< /V_m 10.0 - /g_Na 19000.0 - /g_K 5000.0 - /g_L 9.0 - /C_m 100.0 - /E_Na 40.0 - /E_K -80.0 - /E_L -70.0 - %/U_tr -60.0 - /E_ex 1.0 - /E_in -90.0 - /tau_syn_ex 0.3 - /tau_syn_in 3.0 - /I_e 1.0 ->> /hh_params Set - -neuron hh_params SetStatus -neuron GetStatus /result Set - -result /V_m get 6 ToUnitTestPrecision 10 eq assert_or_die -result /g_Na get 6 ToUnitTestPrecision 19000 eq assert_or_die -result /g_K get 6 ToUnitTestPrecision 5000 eq assert_or_die -result /g_L get 6 ToUnitTestPrecision 9 eq assert_or_die -result /C_m get 6 ToUnitTestPrecision 100 eq assert_or_die -result /E_Na get 6 ToUnitTestPrecision 40 eq assert_or_die -result /E_K get 6 ToUnitTestPrecision -80 eq assert_or_die -result /E_L get 6 ToUnitTestPrecision -70 eq assert_or_die -result /E_ex get 6 ToUnitTestPrecision 1 eq assert_or_die -result /E_in get 6 ToUnitTestPrecision -90 eq assert_or_die -result /tau_syn_ex get 6 ToUnitTestPrecision 0.3 eq assert_or_die -result /tau_syn_in get 6 ToUnitTestPrecision 3 eq assert_or_die -result /I_e get 6 ToUnitTestPrecision 1 eq assert_or_die - -%% Test: Handling of events - -% CurrentEvent -/dc_generator Create /dc_gen Set -dc_gen << /amplitude 100.0 >> SetStatus - -% SpikeEvent -/spike_generator Create /sg Set -sg << /precise_times false /spike_times [0.1 1.2] >> SetStatus - -% PotentialRequest -/voltmeter Create /vm Set -vm << /withtime true /time_in_steps true /interval h >> SetStatus - -/spike_detector Create /sp_det Set -sp_det << /withtime true /withgid true /time_in_steps true >> SetStatus - -% SynapticConductanceRequest -/conductancemeter Create /cm Set -cm << /withtime true /time_in_steps true /interval h >> SetStatus - -sg neuron Connect -dc_gen neuron Connect -vm neuron Connect -cm neuron Connect -neuron sp_det Connect - -%% Test: Simulation -5 Simulate - -vm [/events [/times /V_m]] get cva % array of recorded data -6 ToUnitTestPrecision Transpose == % to precision of reference - -cm [/events [/times /g_exc /g_inh]] get cva % array of recorded data -6 ToUnitTestPrecision Transpose == % to precision of reference - -%% What about spike detector, is that included in the voltmeter output???? \ No newline at end of file diff --git a/testsuite/manualtests/test_pp_psc_delta.py b/testsuite/manualtests/test_pp_psc_delta.py deleted file mode 100644 index 76a39277a5..0000000000 --- a/testsuite/manualtests/test_pp_psc_delta.py +++ /dev/null @@ -1,207 +0,0 @@ -# -*- coding: utf-8 -*- -# -# test_pp_psc_delta.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 . - -# -# tests for pp_psc_delta -# - -import nest - - -# 1) check for reasonable firing rate -# 2) check if fixed dead-time is respected - -def check_rate_and_fixed_dead_time(): - # test parameters - d = 25.0 - lam = 10.0 - T = 10000.0 - - nest.ResetKernel() - nrn = nest.Create('pp_psc_delta') - - params = {'tau_m': 10.0, - 'C_m': 250.0, - 'dead_time': d, - 'dead_time_random': False, - 'dead_time_shape': 1, - 'with_reset': False, - 'tau_sfa': 34.0, - 'q_sfa': 0.0, # // mV, reasonable default is 7 mV - 'c_1': 0.0, - 'c_2': lam, - 'c_3': 0.25, - 'I_e': 0.0, - 't_ref_remaining': 0.0 - } - - nest.SetStatus(nrn, params) - - sd = nest.Create('spike_detector') - nest.Connect(nrn, sd) - nest.Simulate(T) - - spikes = nest.GetStatus(sd)[0]['events']['times'] - rate_sim = len(spikes) / (T * 1e-3) - rate_ana = 1. / (1. / lam + d * 1e-3) - ratio = rate_sim / rate_ana - - # This could fail due to bad luck. However, if it passes once, then it - # should always do so, since the random numbers are reproducible in NEST. - assert (0.5 < ratio < 1.5) - - isi = [] - for i in xrange(1, len(spikes)): - isi.append(spikes[i] - spikes[i - 1]) - - assert (min(isi) >= d) - - -# 3) check if random dead-time moments are respected - -def check_random_dead_time(): - # test parameters - d = 50.0 - n = 10 - lam = 1.0e6 - T = 10000.0 - - nest.ResetKernel() - nrn = nest.Create('pp_psc_delta') - - params = {'tau_m': 10.0, - 'C_m': 250.0, - 'dead_time': d, - 'dead_time_random': True, - 'dead_time_shape': 10, - 'with_reset': False, - 'tau_sfa': 34.0, - 'q_sfa': 0.0, # // mV, reasonable default is 7 mV - 'c_1': 0.0, - 'c_2': lam, - 'c_3': 0.25, - 'I_e': 0.0, - 't_ref_remaining': 0.0 - } - - nest.SetStatus(nrn, params) - - sd = nest.Create('spike_detector') - nest.Connect(nrn, sd) - nest.Simulate(T) - - spikes = nest.GetStatus(sd)[0]['events']['times'] - rate_sim = len(spikes) / (T * 1e-3) - rate_ana = 1. / (1. / lam + d * 1e-3) - ratio = rate_sim / rate_ana - - # This could fail due to bad luck. However, if it passes once, then it - # should always do so, since the random numbers are reproducible in NEST. - assert (0.5 < ratio < 1.5) - - isi = [] - for i in xrange(1, len(spikes)): - isi.append(spikes[i] - spikes[i - 1]) - - # compute moments of ISI to get mean and variance - isi_m1 = 0. - isi_m2 = 0. - for t in isi: - isi_m1 += t - isi_m2 += t ** 2 - - isi_mean = isi_m1 / len(isi) - isi_var = isi_m2 / len(isi) - isi_mean ** 2 - ratio_mean = isi_mean / d - assert (0.5 <= ratio_mean <= 1.5) - - isi_var_th = n / (n / d) ** 2 - ratio_var = isi_var / isi_var_th - assert (0.5 <= ratio_var <= 1.5) - - -# 4) check if threshold adaptation works by looking for negative serial -# correlation of ISI - -def check_adapting_threshold(): - # test parameters - d = 1e-8 - lam = 30.0 - T = 10000.0 - - nest.ResetKernel() - nrn = nest.Create('pp_psc_delta') - - params = {'tau_m': 10.0, - 'C_m': 250.0, - 'dead_time': d, - 'dead_time_random': False, - 'dead_time_shape': 1, - 'with_reset': False, - 'tau_sfa': 34.0, - 'q_sfa': 7.0, # // mV, reasonable default is 7 mV - 'c_1': 0.0, - 'c_2': lam, - 'c_3': 0.25, - 'I_e': 0.0, - 't_ref_remaining': 0.0 - } - - nest.SetStatus(nrn, params) - - sd = nest.Create('spike_detector') - nest.Connect(nrn, sd) - nest.Simulate(T) - - spikes = nest.GetStatus(sd)[0]['events']['times'] - rate_sim = len(spikes) / (T * 1e-3) - rate_ana = 1. / (1. / lam + d * 1e-3) - ratio = rate_sim / rate_ana - - # This could fail due to bad luck. However, if it passes once, then it - # should always do so, since the random numbers are reproducible in NEST. - # Adaptive threshold changes rate, thus not asserted here - # assert( 0.5> SetStatus + vm << /to_file false /to_memory true >> SetStatus 1000 Simulate @@ -83,7 +82,11 @@ Transpose arrayload pop /sdicts Set /volts Set -% don't know how to compare dictionaries, so test only voltage traces now -volts arrayload pop eq +% test status dictionaries and voltage traces +{ + sdicts arrayload pop cva_d exch cva_d eq +} assert_or_die -assert_or_die +{ + volts arrayload pop eq +} assert_or_die diff --git a/testsuite/manualtests/test_compare_delta.sli b/testsuite/unittests/test_compare_delta.sli similarity index 73% rename from testsuite/manualtests/test_compare_delta.sli rename to testsuite/unittests/test_compare_delta.sli index 59953f8c31..02a5499041 100644 --- a/testsuite/manualtests/test_compare_delta.sli +++ b/testsuite/unittests/test_compare_delta.sli @@ -20,29 +20,29 @@ * */ +(unittest) run +/unittest using + ResetKernel % compare iaf_psc_delta and iaf_psc_delta_canon % neurons are driven by spike_generator firing at % -% 1.0 2.0 3.0 4.0 5.0 10.5 11.75 +% 1.0 2.0 3.0 4.0 5.0 10.5 12.0 % % both neurons fire at 4.0, spike at 5.0 arrives during % the refractory period -% -% The spike at 11.75 is off-grid and leads to slightly -% different trajectories. << - /E_L 49.0 neg % resting membrane potential [mV] + /E_L 49.0 neg % resting membrane potential [mV] /V_m 60.0 neg - /V_th 50.0 neg % Threshold [mV] WRONG!! - /V_reset 60.0 neg % Reset Potential [mV] WRONG!! - /C_m 200.0 % Capacity of the membrane [pF] - /tau_m 20.0 % Membrane time constant [ms] + /V_th 50.0 neg % Threshold [mV] WRONG!! + /V_reset 60.0 neg % Reset Potential [mV] WRONG!! + /C_m 200.0 % Capacity of the membrane [pF] + /tau_m 20.0 % Membrane time constant [ms] - /t_ref 5.0 % duration of refractory period [ms] + /t_ref 5.0 % duration of refractory period [ms] >> /neuron_params Set @@ -58,12 +58,12 @@ canon neuron_params SetStatus /spike_detector Create /det Set -gen << /precise_times false /spike_times [ 1.0 2.0 3.0 4.0 5.0 10.5 11.75 ] >> SetStatus +gen << /precise_times false /spike_times [ 1.0 2.0 3.0 4.0 5.0 10.5 12.0 ] >> SetStatus /static_synapse << /delay 0.1 % synaptic delay, all connections [ms] - /weight 2.5 % [pA], excitatory + /weight 2.5 % [pA], excitatory >> SetDefaults [ plain canon ] @@ -81,4 +81,7 @@ gen << /precise_times false /spike_times [ 1.0 2.0 3.0 4.0 5.0 10.5 11.75 ] >> S %200.0 Simulate -det [/events [/senders /times]] get cva Transpose \ No newline at end of file +{ + det [/events [/senders /times]] get cva Transpose + [[2 4.1] [1 4.1]] eq +} assert_or_die diff --git a/testsuite/unittests/test_hh_cond_exp_traub.sli b/testsuite/unittests/test_hh_cond_exp_traub.sli new file mode 100644 index 0000000000..cc5eca69b0 --- /dev/null +++ b/testsuite/unittests/test_hh_cond_exp_traub.sli @@ -0,0 +1,150 @@ +/* + * test_hh_cond_exp_traub.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::test_hh_cond_exp_traub - sli script for overall test of hh_cond_exp_traub model + + Synopsis: (test_hh_cond_exp_traub) run -> + + Description: + + Author: + SeeAlso: +*/ + +(unittest) run +/unittest using + +0.1 /h Set + +ResetKernel + +0 << + /local_num_threads 1 + /resolution h + >> SetStatus + +%% Test: Node creation + +/hh_cond_exp_traub Create /neuron Set + +%% Test: Set/GetStatus + +<< /V_m 10.0 + /g_Na 19000.0 + /g_K 5000.0 + /g_L 9.0 + /C_m 110.0 + /E_Na 40.0 + /E_K -80.0 + /E_L -70.0 + %/U_tr -60.0 + /E_ex 1.0 + /E_in -90.0 + /tau_syn_ex 0.3 + /tau_syn_in 3.0 + /I_e 1.0 +>> /hh_params Set + +neuron hh_params SetStatus +neuron GetStatus /result Set + +{ + result /V_m get 6 ToUnitTestPrecision 10 eq + result /g_Na get 6 ToUnitTestPrecision 19000 eq and + result /g_K get 6 ToUnitTestPrecision 5000 eq and + result /g_L get 6 ToUnitTestPrecision 9 eq and + result /C_m get 6 ToUnitTestPrecision 110 eq and + result /E_Na get 6 ToUnitTestPrecision 40 eq and + result /E_K get 6 ToUnitTestPrecision -80 eq and + result /E_L get 6 ToUnitTestPrecision -70 eq and + result /E_ex get 6 ToUnitTestPrecision 1 eq and + result /E_in get 6 ToUnitTestPrecision -90 eq and + result /tau_syn_ex get 6 ToUnitTestPrecision 0.3 eq and + result /tau_syn_in get 6 ToUnitTestPrecision 3 eq and + result /I_e get 6 ToUnitTestPrecision 1 eq and +} assert_or_die + +%% Test: Handling of events + +% CurrentEvent +/dc_generator Create /dc_gen Set +dc_gen << /amplitude 100.0 >> SetStatus + +% SpikeEvent +/spike_generator Create /sg Set +sg << /precise_times false /spike_times [0.1 1.2] >> SetStatus + +% PotentialRequest +/voltmeter Create /vm Set +vm << /withtime true /time_in_steps true /interval h >> SetStatus + +/spike_detector Create /sp_det Set +sp_det << /withtime true /withgid true /time_in_steps true >> SetStatus + +% SynapticConductanceRequest +/multimeter Create /mm Set +mm << /withtime true /time_in_steps true /interval h /record_from [/g_ex /g_in] >> SetStatus + +sg neuron Connect +dc_gen neuron Connect +vm neuron Connect +mm neuron Connect +neuron sp_det Connect + +%% Test: Simulation +5 Simulate + +{ + vm [/events [/times /V_m]] get cva % array of recorded data + 6 ToUnitTestPrecision Transpose dup == % to precision of reference + [[1 3.919340e+01] [2 3.850370e+01] [3 3.315630e+01] [4 2.217610e+01] + [5 7.131720e+00] [6 -8.728460e+00] [7 -2.312210e+01] [8 -3.595260e+01] + [9 -5.182590e+01] [10 -6.699940e+01] [11 -7.398330e+01] [12 -7.647150e+01] + [13 -7.748650e+01] [14 -7.793770e+01] [15 -7.813580e+01] [16 -7.820390e+01] + [17 -7.819780e+01] [18 -7.814580e+01] [19 -7.806380e+01] [20 -7.796150e+01] + [21 -7.784520e+01] [22 -7.771910e+01] [23 -7.752600e+01] [24 -7.734640e+01] + [25 -7.717640e+01] [26 -7.701340e+01] [27 -7.685560e+01] [28 -7.670190e+01] + [29 -7.655140e+01] [30 -7.640350e+01] [31 -7.625770e+01] [32 -7.611370e+01] + [33 -7.597140e+01] [34 -7.583060e+01] [35 -7.569110e+01] [36 -7.555300e+01] + [37 -7.541600e+01] [38 -7.528030e+01] [39 -7.514570e+01] [40 -7.501230e+01]] + eq +} assert_or_die + +{ + mm [/events [/times /g_ex /g_in]] get cva % array of recorded data + 6 ToUnitTestPrecision Transpose dup == % to precision of reference + [[1 0 0] [2 0 0] [3 0 0] [4 0 0] [5 0 0] [6 0 0] [7 0 0] [8 0 0] [9 0 0] + [10 0 0] [11 1 0] [12 7.165310e-01 0] [13 5.134160e-01 0] [14 3.678790e-01 0] + [15 2.635960e-01 0] [16 1.888750e-01 0] [17 1.353340e-01 0] [18 9.697120e-02 0] + [19 6.948280e-02 0] [20 4.978650e-02 0] [21 3.567350e-02 0] [22 1.025560e+00 0] + [23 7.348450e-01 0] [24 5.265390e-01 0] [25 3.772810e-01 0] [26 2.703330e-01 0] + [27 1.937020e-01 0] [28 1.387930e-01 0] [29 9.944960e-02 0] [30 7.125860e-02 0] + [31 5.105890e-02 0] [32 3.658530e-02 0] [33 2.621440e-02 0] [34 1.878340e-02 0] + [35 1.345890e-02 0] [36 9.643710e-03 0] [37 6.910010e-03 0] [38 4.951230e-03 0] + [39 3.547710e-03 0] [40 2.542040e-03 0]] eq +} assert_or_die + +{ + sp_det [/events /times] get cva dup == + [2 3 4 5 6 7] eq +} assert_or_die From db522662d3c94ac71aaf0f93cf490701b1328db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20M=C3=B8rk?= Date: Fri, 30 Jun 2017 13:54:48 +0200 Subject: [PATCH 02/20] Fixed PEP 8 errors --- .../test_current_recording_generators.py | 40 +++++++++-------- pynest/nest/tests/test_facetshw_stdp.py | 44 ++++++++++++------- 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/pynest/nest/tests/test_current_recording_generators.py b/pynest/nest/tests/test_current_recording_generators.py index 2f3c794089..f1b7fdc827 100644 --- a/pynest/nest/tests/test_current_recording_generators.py +++ b/pynest/nest/tests/test_current_recording_generators.py @@ -69,7 +69,7 @@ def setUp(self): nest.Connect(self.dc, self.neuron) times = [self.t_start, self.t_next] - currents = [self.i_amp/4, self.i_amp/2] + currents = [self.i_amp / 4, self.i_amp / 2] params = {'amplitude_times': times, 'amplitude_values': currents, 'origin': self.t_origin, 'start': self.t_start, 'stop': self.t_stop} @@ -145,10 +145,10 @@ def test_RecordedCurrentVectors(self): # test to ensure current = 0 when device is inactive # and also to check current recorded when device is active - t_start_ind = numpy.where(t_ac == self.t_start+self.t_origin)[0][0] - t_stop_ind = numpy.where(t_ac == self.t_stop+self.t_origin)[0][0] - assert (numpy.all(i_ac[:t_start_ind]) == 0 - and numpy.all(i_ac[t_stop_ind:]) == 0), \ + t_start_ind = numpy.where(t_ac == self.t_start + self.t_origin)[0][0] + t_stop_ind = numpy.where(t_ac == self.t_stop + self.t_origin)[0][0] + assert (numpy.all(i_ac[:t_start_ind]) == 0 and + numpy.all(i_ac[t_stop_ind:]) == 0), \ "Current not zero when AC generator inactive" self.assertAlmostEqual(numpy.amax(i_ac[t_start_ind:t_stop_ind]), self.i_amp + self.i_off, @@ -159,30 +159,31 @@ def test_RecordedCurrentVectors(self): msg=("Current not correct " "when AC generator active")) - t_start_ind = numpy.where(t_dc == self.t_start+self.t_origin)[0][0] - t_stop_ind = numpy.where(t_dc == self.t_stop+self.t_origin)[0][0] - assert (numpy.all(i_dc[:t_start_ind]) == 0 - and numpy.all(i_dc[t_stop_ind:]) == 0), \ + t_start_ind = numpy.where(t_dc == self.t_start + self.t_origin)[0][0] + t_stop_ind = numpy.where(t_dc == self.t_stop + self.t_origin)[0][0] + assert (numpy.all(i_dc[:t_start_ind]) == 0 and + numpy.all(i_dc[t_stop_ind:]) == 0), \ "Current not zero when DC generator inactive" assert (numpy.allclose(i_dc[t_start_ind:t_stop_ind], self.i_amp)), \ "Current not correct when DC generator active" - t_start_ind = numpy.where(t_step == self.t_start+self.t_origin)[0][0] - t_stop_ind = numpy.where(t_step == self.t_stop+self.t_origin)[0][0] + t_start_ind = numpy.where(t_step == self.t_start + self.t_origin)[0][0] + t_stop_ind = numpy.where(t_step == self.t_stop + self.t_origin)[0][0] t_next_ind = numpy.where(t_step == self.t_next)[0][0] - assert (numpy.all(i_step[:t_start_ind]) == 0 - and numpy.all(i_step[t_stop_ind:]) == 0), \ + assert (numpy.all(i_step[:t_start_ind]) == 0 and + numpy.all(i_step[t_stop_ind:]) == 0), \ "Current not zero when step current generator inactive" assert (numpy.allclose(i_step[t_start_ind:t_next_ind], - self.i_amp/4) and + self.i_amp / 4) and numpy.allclose(i_step[t_next_ind:t_stop_ind], - self.i_amp/2)), \ + self.i_amp / 2)), \ "Current not correct when step current generator active" - t_start_ind = numpy.where(t_noise == self.t_start+self.t_origin)[0][0] - t_stop_ind = numpy.where(t_noise == self.t_stop+self.t_origin)[0][0] - assert (numpy.all(i_noise[:t_start_ind]) == 0 - and numpy.all(i_noise[t_stop_ind:]) == 0), \ + t_start_ind = numpy.where( + t_noise == self.t_start + self.t_origin)[0][0] + t_stop_ind = numpy.where(t_noise == self.t_stop + self.t_origin)[0][0] + assert (numpy.all(i_noise[:t_start_ind]) == 0 and + numpy.all(i_noise[t_stop_ind:]) == 0), \ "Current not zero when noise generator inactive" assert (numpy.allclose(i_noise[t_start_ind:t_stop_ind], self.i_amp)), \ @@ -197,5 +198,6 @@ def run(): runner = unittest.TextTestRunner(verbosity=2) runner.run(suite()) + if __name__ == "__main__": run() diff --git a/pynest/nest/tests/test_facetshw_stdp.py b/pynest/nest/tests/test_facetshw_stdp.py index 338a39f7d0..49a87b4f47 100644 --- a/pynest/nest/tests/test_facetshw_stdp.py +++ b/pynest/nest/tests/test_facetshw_stdp.py @@ -29,6 +29,7 @@ import numpy as np import unittest + class FacetsTestCase(unittest.TestCase): def test_facetshw_stdp(self): @@ -39,7 +40,8 @@ def test_facetshw_stdp(self): # parameters # # homogen parameters for all synapses # Wmax = 100.0 - # see *.cpp file of synapse model and Pfeil et al. 2012 for LUT configuration + # see *.cpp file of synapse model and Pfeil et al. 2012 for LUT + # configuration lut_0 = [2, 3, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14, 15] lut_1 = [0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13] lut_2 = range(16) # identity @@ -48,7 +50,8 @@ def test_facetshw_stdp(self): reset_pattern = 6 * [1] # reset all # individual parameters for each synapse # - lut_th_causal = 21.835 # reached every 36 runs (e^(-10/20)=21.83510375) + # reached every 36 runs (e^(-10/20)=21.83510375) + lut_th_causal = 21.835 lut_th_acausal = lut_th_causal # other parameters # @@ -56,7 +59,8 @@ def test_facetshw_stdp(self): tau = 20.0 timeBetweenPairs = 100.0 - delay = 5.0 # frequency_of_pairs=10Hz => delta_t(+)=10ms, delta_t(-)=90ms + # frequency_of_pairs=10Hz => delta_t(+)=10ms, delta_t(-)=90ms + delay = 5.0 spikesIn = np.arange(10.0, 60000.0, timeBetweenPairs) synapseDict = {'tau_plus': tau, @@ -87,7 +91,8 @@ def test_facetshw_stdp(self): # check if Get returns same values as have been Set synapseDictGet = nest.GetDefaults(modelName) for key in synapseDict.keys(): - self.assertTrue(all(np.atleast_1d(synapseDictGet[key] == synapseDict[key]))) + self.assertTrue( + all(np.atleast_1d(synapseDictGet[key] == synapseDict[key]))) nest.Connect(stim, neuronA) nest.Connect(neuronA, neuronB, syn_spec={ @@ -103,7 +108,8 @@ def test_facetshw_stdp(self): connections = nest.GetConnections(neuronA) for i in range(len(connections)): - if nest.GetStatus([connections[i]])[0]['synapse_model'] == modelName: + if (nest.GetStatus([connections[i]])[0]['synapse_model'] == + modelName): weightTrace.append( [run, nest.GetStatus([connections[i]])[0]['weight'], nest.GetStatus([connections[i]])[0]['a_causal'], @@ -113,35 +119,39 @@ def test_facetshw_stdp(self): # analysis # weightTrace = np.array(weightTrace) - weightTraceMod36pre = weightTrace[35::36] # just before theoretical updates + # just before theoretical updates + weightTraceMod36pre = weightTrace[35::36] weightTraceMod36 = weightTrace[::36] # just after theoretical updates weightIndex = int(startWeight) for i in range(len(weightTraceMod36pre)): - # check weight value before update (after spike pair w index 35, 71, ...) + # check weight value before update (after spike pair w index 35, + # 71, ...) self.assertTrue(np.allclose(weightTraceMod36pre[i][1], - 1.0 / 15.0 * weightIndex * Wmax, - atol=1e-6)) + 1.0 / 15.0 * weightIndex * Wmax, + atol=1e-6)) weightIndex = lut_0[weightIndex] weightIndex = int(startWeight) for i in range(len(weightTraceMod36)): - # check weight value after update (after spike pair w index 0, 36, 72, ...) + # check weight value after update (after spike pair w index 0, 36, + # 72, ...) self.assertTrue(np.allclose(weightTraceMod36[i][1], - 1.0 / 15.0 * weightIndex * Wmax, - atol=1e-6)) + 1.0 / 15.0 * weightIndex * Wmax, + atol=1e-6)) # check charge on causal capacitor self.assertTrue(np.allclose(weightTraceMod36[i][2], - np.ones_like(weightTraceMod36[i][2]) * - np.exp(-2 * delay / tau), atol=1e-6)) + np.ones_like(weightTraceMod36[i][2]) * + np.exp(-2 * delay / tau), atol=1e-6)) weightIndex = lut_0[weightIndex] # check charge on anti-causal capacitor after each pair for i in range(len(weightTrace) - 1): # TODO: global params self.assertTrue(np.allclose(weightTrace[i, 3], ((i % 36) + 1) * - np.exp(-(timeBetweenPairs - 2 * delay) / tau), - atol=1e-6)) + np.exp(-(timeBetweenPairs - + 2 * delay) / tau), + atol=1e-6)) def suite(): @@ -153,6 +163,6 @@ def run(): runner = unittest.TextTestRunner(verbosity=2) runner.run(suite()) + if __name__ == "__main__": run() - From ffe5b41af02ed19ed8a1637230c86a0ebffb97e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20M=C3=B8rk?= Date: Fri, 30 Jun 2017 17:20:27 +0200 Subject: [PATCH 03/20] Made requested changes. Removed unnecessary comments, printing; using numpy functions for efficiency; skipping if without GSL where needed. --- pynest/nest/tests/test_facetshw_stdp.py | 7 ++-- pynest/nest/tests/test_pp_psc_delta.py | 38 +++++-------------- .../test_sinusoidal_poisson_generator_5.sli | 11 +----- .../test_sinusoidal_poisson_generator_6.sli | 11 +----- .../unittests/test_hh_cond_exp_traub.sli | 4 ++ 5 files changed, 21 insertions(+), 50 deletions(-) diff --git a/pynest/nest/tests/test_facetshw_stdp.py b/pynest/nest/tests/test_facetshw_stdp.py index 49a87b4f47..1a92d59357 100644 --- a/pynest/nest/tests/test_facetshw_stdp.py +++ b/pynest/nest/tests/test_facetshw_stdp.py @@ -83,7 +83,6 @@ def test_facetshw_stdp(self): stim = nest.Create('spike_generator') neuronA = nest.Create('parrot_neuron') neuronB = nest.Create('parrot_neuron') - # recorder = nest.Create('spike_detector') nest.SetStatus(stim, [{'spike_times': spikesIn}]) nest.SetDefaults(modelName, synapseDict) @@ -98,8 +97,6 @@ def test_facetshw_stdp(self): nest.Connect(neuronA, neuronB, syn_spec={ 'weight': float(startWeight) / 15.0 * Wmax, 'delay': delay, 'model': modelName}) - # nest.Connect(neuronA, recorder) - # nest.Connect(neuronB, recorder) nest.Simulate(50.0) weightTrace = [] @@ -121,7 +118,9 @@ def test_facetshw_stdp(self): # just before theoretical updates weightTraceMod36pre = weightTrace[35::36] - weightTraceMod36 = weightTrace[::36] # just after theoretical updates + + # just after theoretical updates + weightTraceMod36 = weightTrace[::36] weightIndex = int(startWeight) for i in range(len(weightTraceMod36pre)): diff --git a/pynest/nest/tests/test_pp_psc_delta.py b/pynest/nest/tests/test_pp_psc_delta.py index 9f67d6c680..fb5de92d3b 100644 --- a/pynest/nest/tests/test_pp_psc_delta.py +++ b/pynest/nest/tests/test_pp_psc_delta.py @@ -25,6 +25,7 @@ import unittest import nest +import numpy as np # 1) check for reasonable firing rate @@ -74,9 +75,7 @@ def test_rate_and_fixed_dead_time(self): self.assertLess(0.5, ratio) self.assertLess(ratio, 1.5) - isi = [] - for i in xrange(1, len(spikes)): - isi.append(spikes[i] - spikes[i - 1]) + isi = np.diff(spikes) self.assertGreaterEqual(min(isi), d) @@ -124,19 +123,12 @@ def test_random_dead_time(self): self.assertLess(0.5, ratio) self.assertLess(ratio, 1.5) - isi = [] - for i in xrange(1, len(spikes)): - isi.append(spikes[i] - spikes[i - 1]) + isi = np.diff(spikes) # compute moments of ISI to get mean and variance - isi_m1 = 0. - isi_m2 = 0. - for t in isi: - isi_m1 += t - isi_m2 += t ** 2 - - isi_mean = isi_m1 / len(isi) - isi_var = isi_m2 / len(isi) - isi_mean ** 2 + isi_mean = np.mean(isi) + isi_var = np.var(isi) + ratio_mean = isi_mean / d self.assertLessEqual(0.5, ratio_mean) self.assertLessEqual(ratio_mean, 1.5) @@ -184,21 +176,11 @@ def test_adapting_threshold(self): # then it should always do so, since the random numbers are # reproducible in NEST. Adaptive threshold changes rate, thus # the ratio is not asserted here. - isi = [] - for i in xrange(1, len(spikes)): - isi.append(spikes[i] - spikes[i - 1]) + isi = np.diff(spikes) - # compute moments of ISI to get mean and variance - isi_m1 = isi[-1] - isi_m2 = isi[-1] ** 2 - isi_12 = 0. - for t, t1 in zip(isi[:-1], isi[1:]): - isi_m1 += t - isi_m2 += t ** 2 - isi_12 += t * t1 - - isi_mean = isi_m1 / len(isi) - isi_var = (isi_m2 - isi_m1) ** 2 / len(isi) + isi_mean = np.mean(isi) + isi_var = np.var(isi) + isi_12 = np.sum(np.multiply(isi[:-1], isi[1:])) isi_corr = (isi_12 / (len(isi) - 1) - isi_mean ** 2) / isi_var self.assertLessEqual(-1.0, isi_corr) diff --git a/testsuite/mpitests/test_sinusoidal_poisson_generator_5.sli b/testsuite/mpitests/test_sinusoidal_poisson_generator_5.sli index 5434efc309..45ab50c565 100644 --- a/testsuite/mpitests/test_sinusoidal_poisson_generator_5.sli +++ b/testsuite/mpitests/test_sinusoidal_poisson_generator_5.sli @@ -30,12 +30,6 @@ Description: single spike train to all of its targets and sends spikes to spike detectors. Ensures that all targets receive identical spike trains. - -NOTE: THIS TEST DOES NOT WORK AUTOMATICALLY, DUE TO PROBLEMS WITH UNITTEST. - You can run it manually and see if the output is as expected with - - mpirun -np 2 nest test_sinusoidal_poisson_generator_5.sli - Author: December 2012, May 2013, Plesser, based on test_poisson_generator.sli See also: test_sinusoidal_poisson_generator_{1,2,3,4,6}, test_sinusoidal_poisson_generator_nostat @@ -104,10 +98,9 @@ See also: test_sinusoidal_poisson_generator_{1,2,3,4,6}, test_sinusoidal_poisson % get events, replace vectors with SLI arrays % keep only non-empty arrays; empty ones are from off-process parrots (ALL LINES SHOULD BE EQUAL) == - sdets { [/events /times] get cva } Map { empty not exch ; } Select dup /spike_times Set - { == } forall + sdets { [/events /times] get cva } Map { empty not exch ; } Select % expect array with two arrays of spike times - spike_times all_equal + all_equal } distributed_collect_assert_or_die diff --git a/testsuite/mpitests/test_sinusoidal_poisson_generator_6.sli b/testsuite/mpitests/test_sinusoidal_poisson_generator_6.sli index ca7e23d80f..9320b20a2a 100644 --- a/testsuite/mpitests/test_sinusoidal_poisson_generator_6.sli +++ b/testsuite/mpitests/test_sinusoidal_poisson_generator_6.sli @@ -30,11 +30,6 @@ Description: individual spike train to each of its targets and sends spikes to spike detectors. Ensures that all targets receive identical spike trains. -NOTE: THIS TEST DOES NOT WORK AUTOMATICALLY, DUE TO PROBLEMS WITH UNITTEST. - You can run it manually and see if the output is as expected with - - mpirun -np 2 nest test_sinusoidal_poisson_generator_6.sli - Author: December 2012, May 2013, Plesser, based on test_poisson_generator.sli See also: test_sinusoidal_poisson_generator_{1,2,3,4,6}, test_sinusoidal_poisson_generator_nostat @@ -117,10 +112,8 @@ See also: test_sinusoidal_poisson_generator_{1,2,3,4,6}, test_sinusoidal_poisson % get events, replace vectors with SLI arrays % keep only non-empty arrays; empty ones are from off-process parrots (ALL LINES SHOULD BE DIFFERENT) == - sdets { [/events /times] get cva } Map { empty not exch ; } Select dup /sts Set - { == } forall - + sdets { [/events /times] get cva } Map { empty not exch ; } Select % expect array with two arrays of spike times - sts all_different + all_different } distributed_collect_assert_or_die diff --git a/testsuite/unittests/test_hh_cond_exp_traub.sli b/testsuite/unittests/test_hh_cond_exp_traub.sli index cc5eca69b0..41fcb8fb21 100644 --- a/testsuite/unittests/test_hh_cond_exp_traub.sli +++ b/testsuite/unittests/test_hh_cond_exp_traub.sli @@ -34,6 +34,10 @@ (unittest) run /unittest using +% The following test needs the model hh_cond_exp_traub, so +% this test should only run if we have GSL +skip_if_without_gsl + 0.1 /h Set ResetKernel From 96d3941ddd1e6a221a042bba0c1a66b171599d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20M=C3=B8rk?= Date: Mon, 3 Jul 2017 10:03:44 +0200 Subject: [PATCH 04/20] Small cleanup --- pynest/nest/tests/test_pp_psc_delta.py | 2 +- testsuite/mpitests/test_sinusoidal_poisson_generator_5.sli | 1 - testsuite/mpitests/test_sinusoidal_poisson_generator_6.sli | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pynest/nest/tests/test_pp_psc_delta.py b/pynest/nest/tests/test_pp_psc_delta.py index fb5de92d3b..3475264f90 100644 --- a/pynest/nest/tests/test_pp_psc_delta.py +++ b/pynest/nest/tests/test_pp_psc_delta.py @@ -180,7 +180,7 @@ def test_adapting_threshold(self): isi_mean = np.mean(isi) isi_var = np.var(isi) - isi_12 = np.sum(np.multiply(isi[:-1], isi[1:])) + isi_12 = np.sum(isi[:-1] * isi[1:]) isi_corr = (isi_12 / (len(isi) - 1) - isi_mean ** 2) / isi_var self.assertLessEqual(-1.0, isi_corr) diff --git a/testsuite/mpitests/test_sinusoidal_poisson_generator_5.sli b/testsuite/mpitests/test_sinusoidal_poisson_generator_5.sli index 45ab50c565..50264a82bd 100644 --- a/testsuite/mpitests/test_sinusoidal_poisson_generator_5.sli +++ b/testsuite/mpitests/test_sinusoidal_poisson_generator_5.sli @@ -97,7 +97,6 @@ See also: test_sinusoidal_poisson_generator_{1,2,3,4,6}, test_sinusoidal_poisson % get events, replace vectors with SLI arrays % keep only non-empty arrays; empty ones are from off-process parrots - (ALL LINES SHOULD BE EQUAL) == sdets { [/events /times] get cva } Map { empty not exch ; } Select % expect array with two arrays of spike times diff --git a/testsuite/mpitests/test_sinusoidal_poisson_generator_6.sli b/testsuite/mpitests/test_sinusoidal_poisson_generator_6.sli index 9320b20a2a..a9af8d74c0 100644 --- a/testsuite/mpitests/test_sinusoidal_poisson_generator_6.sli +++ b/testsuite/mpitests/test_sinusoidal_poisson_generator_6.sli @@ -111,7 +111,6 @@ See also: test_sinusoidal_poisson_generator_{1,2,3,4,6}, test_sinusoidal_poisson % get events, replace vectors with SLI arrays % keep only non-empty arrays; empty ones are from off-process parrots - (ALL LINES SHOULD BE DIFFERENT) == sdets { [/events /times] get cva } Map { empty not exch ; } Select % expect array with two arrays of spike times all_different From 46ee0e0d367202800c355aa0979e209538473c06 Mon Sep 17 00:00:00 2001 From: Jochen Martin Eppler Date: Thu, 6 Jul 2017 09:35:50 +0200 Subject: [PATCH 05/20] Minor changes to comments and formatting --- pynest/nest/tests/test_facetshw_stdp.py | 44 ++++++++++++------------- pynest/nest/tests/test_pp_psc_delta.py | 21 +++++------- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/pynest/nest/tests/test_facetshw_stdp.py b/pynest/nest/tests/test_facetshw_stdp.py index 1a92d59357..3beb6b7a66 100644 --- a/pynest/nest/tests/test_facetshw_stdp.py +++ b/pynest/nest/tests/test_facetshw_stdp.py @@ -19,27 +19,27 @@ # You should have received a copy of the GNU General Public License # along with NEST. If not, see . -# author: Thomas Pfeil -# date of 1st version: 21.01.2013 - -# This script is testing the accumulation of spike pairs and -# the weight update mechanism as implemented in the FACETS hardware - import nest import numpy as np import unittest class FacetsTestCase(unittest.TestCase): + """ + This script is testing the accumulation of spike pairs and + the weight update mechanism as implemented in the FACETS hardware. + + Author: Thomas Pfeil + Date of first version: 21.01.2013 + """ def test_facetshw_stdp(self): modelName = 'stdp_facetshw_synapse_hom' - ############## - # parameters # - # homogen parameters for all synapses # + # homogeneous parameters for all synapses Wmax = 100.0 + # see *.cpp file of synapse model and Pfeil et al. 2012 for LUT # configuration lut_0 = [2, 3, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14, 15] @@ -49,17 +49,17 @@ def test_facetshw_stdp(self): config_1 = [0, 1, 0, 0] reset_pattern = 6 * [1] # reset all - # individual parameters for each synapse # - # reached every 36 runs (e^(-10/20)=21.83510375) + # individual parameters for each synapse + # reached every 36 runs (e^(-10/20) = 21.83510375) lut_th_causal = 21.835 lut_th_acausal = lut_th_causal - # other parameters # - startWeight = 0 # as digital value [0,1,...,15] + # other parameters + startWeight = 0 # as digital value [0, 1, ..., 15] tau = 20.0 timeBetweenPairs = 100.0 - # frequency_of_pairs=10Hz => delta_t(+)=10ms, delta_t(-)=90ms + # frequency_of_pairs = 10Hz => delta_t(+) = 10ms, delta_t(-) = 90ms delay = 5.0 spikesIn = np.arange(10.0, 60000.0, timeBetweenPairs) @@ -78,8 +78,7 @@ def test_facetshw_stdp(self): 'a_thresh_th': lut_th_causal, 'a_thresh_tl': lut_th_acausal} - ################# - # build network # + # build network stim = nest.Create('spike_generator') neuronA = nest.Create('parrot_neuron') neuronB = nest.Create('parrot_neuron') @@ -87,7 +86,7 @@ def test_facetshw_stdp(self): nest.SetDefaults(modelName, synapseDict) - # check if Get returns same values as have been Set + # check if GetDefaults returns same values as have been set synapseDictGet = nest.GetDefaults(modelName) for key in synapseDict.keys(): self.assertTrue( @@ -112,8 +111,7 @@ def test_facetshw_stdp(self): nest.GetStatus([connections[i]])[0]['a_causal'], nest.GetStatus([connections[i]])[0]['a_acausal']]) - ############ - # analysis # + # analysis weightTrace = np.array(weightTrace) # just before theoretical updates @@ -124,8 +122,8 @@ def test_facetshw_stdp(self): weightIndex = int(startWeight) for i in range(len(weightTraceMod36pre)): - # check weight value before update (after spike pair w index 35, - # 71, ...) + # check weight value before update + # (after spike pair with index 35, 71, ...) self.assertTrue(np.allclose(weightTraceMod36pre[i][1], 1.0 / 15.0 * weightIndex * Wmax, atol=1e-6)) @@ -133,8 +131,8 @@ def test_facetshw_stdp(self): weightIndex = int(startWeight) for i in range(len(weightTraceMod36)): - # check weight value after update (after spike pair w index 0, 36, - # 72, ...) + # check weight value after update + # (after spike pair with index 0, 36, 72, ...) self.assertTrue(np.allclose(weightTraceMod36[i][1], 1.0 / 15.0 * weightIndex * Wmax, atol=1e-6)) diff --git a/pynest/nest/tests/test_pp_psc_delta.py b/pynest/nest/tests/test_pp_psc_delta.py index 3475264f90..87fcd5b227 100644 --- a/pynest/nest/tests/test_pp_psc_delta.py +++ b/pynest/nest/tests/test_pp_psc_delta.py @@ -19,22 +19,17 @@ # You should have received a copy of the GNU General Public License # along with NEST. If not, see . -# -# tests for pp_psc_delta -# - import unittest import nest import numpy as np -# 1) check for reasonable firing rate -# 2) check if fixed dead-time is respected - - class PpPscDeltaTestCase(unittest.TestCase): + """Tests for pp_psc_delta""" def test_rate_and_fixed_dead_time(self): + """Check for reasonable firing rate and if fixed dead-time is respected""" + # test parameters d = 25.0 lam = 10.0 @@ -79,9 +74,9 @@ def test_rate_and_fixed_dead_time(self): self.assertGreaterEqual(min(isi), d) - # 3) check if random dead-time moments are respected - def test_random_dead_time(self): + """Check if random dead-time moments are respected.""" + # test parameters d = 50.0 n = 10 @@ -138,9 +133,11 @@ def test_random_dead_time(self): self.assertLessEqual(0.5, ratio_var) self.assertLessEqual(ratio_var, 1.5) - # 4) check if threshold adaptation works by looking for negative - # serial correlation of ISI. def test_adapting_threshold(self): + """Check if threshold adaptation works by looking for negative serial + correlation of ISI.""" + + # test parameters d = 1e-8 lam = 30.0 From 568fd4afcef2c175d92532f52b34af51951d3753 Mon Sep 17 00:00:00 2001 From: Jochen Martin Eppler Date: Thu, 6 Jul 2017 10:27:11 +0200 Subject: [PATCH 06/20] pep8ify --- pynest/nest/tests/test_facetshw_stdp.py | 2 +- pynest/nest/tests/test_pp_psc_delta.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pynest/nest/tests/test_facetshw_stdp.py b/pynest/nest/tests/test_facetshw_stdp.py index 3beb6b7a66..1cee46343c 100644 --- a/pynest/nest/tests/test_facetshw_stdp.py +++ b/pynest/nest/tests/test_facetshw_stdp.py @@ -39,7 +39,7 @@ def test_facetshw_stdp(self): # homogeneous parameters for all synapses Wmax = 100.0 - + # see *.cpp file of synapse model and Pfeil et al. 2012 for LUT # configuration lut_0 = [2, 3, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14, 15] diff --git a/pynest/nest/tests/test_pp_psc_delta.py b/pynest/nest/tests/test_pp_psc_delta.py index 87fcd5b227..f84c3f2fcd 100644 --- a/pynest/nest/tests/test_pp_psc_delta.py +++ b/pynest/nest/tests/test_pp_psc_delta.py @@ -137,7 +137,6 @@ def test_adapting_threshold(self): """Check if threshold adaptation works by looking for negative serial correlation of ISI.""" - # test parameters d = 1e-8 lam = 30.0 From df6feaee254770bdaa11c0d2e54e7a16ce25d499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20M=C3=B8rk?= Date: Thu, 6 Jul 2017 10:49:07 +0200 Subject: [PATCH 07/20] Deleted manualtests that could not be fixed --- testsuite/manualtests/getnodes.sli | 31 -- testsuite/manualtests/memtest.sli | 67 ---- testsuite/manualtests/stdp.m | 51 --- testsuite/manualtests/stdp_prot.m | 34 -- .../manualtests/test_tsodyks_depr_fac.py | 44 --- testsuite/manualtests/ticket-458/README | 59 ---- testsuite/manualtests/ticket-458/cuba_458.sli | 121 ------- .../manualtests/ticket-458/cuba_ps_458.sli | 121 ------- .../ticket-458/run_benchmark_458.sli | 276 ---------------- .../ticket-458/run_benchmark_458_dumpVm.sli | 303 ------------------ .../manualtests/ticket-458/test_cuba_458.sh | 136 -------- .../ticket-458/test_cuba_458_dumpVm.sh | 124 ------- testsuite/manualtests/ticket-541.sli | 150 --------- 13 files changed, 1517 deletions(-) delete mode 100644 testsuite/manualtests/getnodes.sli delete mode 100644 testsuite/manualtests/memtest.sli delete mode 100644 testsuite/manualtests/stdp.m delete mode 100644 testsuite/manualtests/stdp_prot.m delete mode 100644 testsuite/manualtests/test_tsodyks_depr_fac.py delete mode 100644 testsuite/manualtests/ticket-458/README delete mode 100644 testsuite/manualtests/ticket-458/cuba_458.sli delete mode 100644 testsuite/manualtests/ticket-458/cuba_ps_458.sli delete mode 100644 testsuite/manualtests/ticket-458/run_benchmark_458.sli delete mode 100644 testsuite/manualtests/ticket-458/run_benchmark_458_dumpVm.sli delete mode 100644 testsuite/manualtests/ticket-458/test_cuba_458.sh delete mode 100644 testsuite/manualtests/ticket-458/test_cuba_458_dumpVm.sh delete mode 100644 testsuite/manualtests/ticket-541.sli diff --git a/testsuite/manualtests/getnodes.sli b/testsuite/manualtests/getnodes.sli deleted file mode 100644 index 9e2c1a2238..0000000000 --- a/testsuite/manualtests/getnodes.sli +++ /dev/null @@ -1,31 +0,0 @@ -/* - * getnodes.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 . - * - */ - -/iaf_neuron [5 6] LayoutNetwork /nw Set - -nw GetLocalNodes == -nw GetLocalLeaves == -nw GetLocalChildren == - -nw GetGlobalNodes == -nw GetGlobalLeaves == -nw GetGlobalChildren == diff --git a/testsuite/manualtests/memtest.sli b/testsuite/manualtests/memtest.sli deleted file mode 100644 index 8d77d57f4f..0000000000 --- a/testsuite/manualtests/memtest.sli +++ /dev/null @@ -1,67 +0,0 @@ -/* - * memtest.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 . - * - */ - -% Check for memory leak - -/N 1000 def -/laps 1000 def - -/BuildNetwork -{ - /iaf_neuron N Create pop - 1 1 N - { - /pre Set - 1 1 N - { - /post Set - pre post Connect - } for - } for -} def - -/TestMemory -{ - (Initializing ...\n) = - BuildNetwork - (Please look at the memory of the NEST process in top.) = - (The values should stay between some upper and lower value,)= - (but must not grow indefinitely.)= - (Press ctrl-c to quit the test.) = - - 1 1 laps - { - (Lap number :) =only = - { - ResetKernel BuildNetwork - } stopped - { - errordict begin /newerror false def end - clear - ResetKernel - (Done .) = - exit - } if - } for -} def - -(type TestMemory to see if nest has a memory leak.) = diff --git a/testsuite/manualtests/stdp.m b/testsuite/manualtests/stdp.m deleted file mode 100644 index d794730cc0..0000000000 --- a/testsuite/manualtests/stdp.m +++ /dev/null @@ -1,51 +0,0 @@ - -%% Synaptic dynamics for STDP synapses according to Abigail Morrison's -%% STDP model (see stdp_rec.pdf). -%% author: Moritz Helias, april 2006 -%% -function [w]=stdp(w_init, N, T, alpha, mu, lambda, tau, delay, delta_t) - w = w_init; - - K_plus=0.0; - K_minus=0.0; - - % take into accout dendritic delay - delta_t = delta_t + delay; - - if (delta_t > 0) % post after pre - dt_plus = delta_t; - dt_minus = T-delta_t; - else - dt_plus = T+delta_t; % pre after post - dt_minus = -delta_t; - end - - % repeat for N spike pairs - for i=1:N - - if (not(delta_t==0)) - - % here t = t_spike_post - % presyn spike was dt_plus ago - K_plus = K_plus*exp(-dt_plus/tau); - K_minus = K_minus*exp(-dt_plus/tau); - - w = w + lambda * w^mu * K_plus; - - K_minus = K_minus + 1.0; - - % here t = t_spike_pre - % postsyn spike was dt_minus ago - K_minus = K_minus*exp(-dt_minus/tau); - K_plus = K_plus*exp(-dt_minus/tau); - - w = w - lambda * alpha * w * K_minus; - - K_plus = K_plus + 1.0; - - end - - end - - w -end \ No newline at end of file diff --git a/testsuite/manualtests/stdp_prot.m b/testsuite/manualtests/stdp_prot.m deleted file mode 100644 index d2a8164395..0000000000 --- a/testsuite/manualtests/stdp_prot.m +++ /dev/null @@ -1,34 +0,0 @@ - -%% Test script to evaluate effect of spike pairing protocol on synaptic -%% strength of a STDP synapse. -%% Synaptic dynamics for STDP synapses according to Abigail Morrison's -%% STDP model (see stdp_rec.pdf). -%% author: Moritz Helias, april 2006 -%% -clear; - -deltaT=-50:1:50; - -lambda=0.1; -w_init=17.0; -alpha=0.11; -mu=0.4; -tau=20; -delay=1.0; - -T = 200; -N = 60; - -for i=1:length(deltaT) - w(i) = stdp(w_init, N, T, alpha, mu, lambda, tau, delay, deltaT(i)); -end - -plot(deltaT, 100*(w-w_init)/w_init, 'b'); -hold on; - -w_sim = load('weight.gdf'); - -plot(w_sim(:,1), 100*(w_sim(:,2)-w_init)/w_init,'r.'); -hold off; -xlabel('t_{post} - t_{pre} (ms)'); -ylabel('PSC change (%)'); \ No newline at end of file diff --git a/testsuite/manualtests/test_tsodyks_depr_fac.py b/testsuite/manualtests/test_tsodyks_depr_fac.py deleted file mode 100644 index 7a39ee2367..0000000000 --- a/testsuite/manualtests/test_tsodyks_depr_fac.py +++ /dev/null @@ -1,44 +0,0 @@ -# -*- coding: utf-8 -*- -# -# test_tsodyks_depr_fac.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 . - -from scipy import * -from matplotlib.pylab import * -from matplotlib.mlab import * - - -def plot_spikes(): - dt = 0.1 # time resolution - nbins = 1000 - N = 500 # number of neurons - - vm = load('voltmeter-0-0-4.dat') - - figure(1) - clf() - plot(vm[:, 0], vm[:, 1], 'r') - xlabel('time / ms') - ylabel('$V_m [mV]$') - - savefig('test_tsodyks_depressing.png') - - -plot_spikes() -show() diff --git a/testsuite/manualtests/ticket-458/README b/testsuite/manualtests/ticket-458/README deleted file mode 100644 index 192bfa1198..0000000000 --- a/testsuite/manualtests/ticket-458/README +++ /dev/null @@ -1,59 +0,0 @@ - -This directory contains test scripts related to ticket 458 -(lack of scaling for precise neurons). - -This test is currently not working as it has not been kept ajour with NEST. -Github issue #302 will address this. - - -Benchmarking tests ------------------- -These tests check scaling by simulating the CUBA network running at 4Hz for 10s. - -test_cuba_458.sh Shell script executing benchmark suite (includes PBS directives for Stallo) -cuba_458.sli Configuration for simulation with iaf_psc_exp -cuba_ps_458.sli Configuration for simulation with iaf_psc_exp_ps -run_benchmark_458.sli Script running single benchmark - -The test_cuba_458.sh executes the following tests in order - -iaf_psc_exp on-grid -iaf_psc_exp off-grid -iaf_psc_exp_ps on-grid -iaf_psc_exp_ps off-grid - -For each test, the following simulations are run in order -- single thread -- two threads -- two mpi procs @ one thread - -The best way to see the scaling results is to collect the output of test_cuba_458.sh into a file an - -grep 'Simulation time' FILENAME - -For each of the four tests you will get FOUR output lines - -simtime single thread -simtime two thread -simtime two mpi rank 0 (rank order is arbitrary) -simtime two mpi rank 1 - - -Quality tests -------------- -These tests run the CUBA benchmark with two threads or two mpi processes for 1s and compare the membrane -potentials of all neurons at the end. This tests whether the NEST concept that only the number of virtual -processes is relevant is respected. - -test_cuba_458_dumpVm.sh Shell script executing benchmark suite (includes PBS directives for Stallo) -cuba_458.sli Configuration for simulation with iaf_psc_exp -cuba_ps_458.sli Configuration for simulation with iaf_psc_exp_ps -run_benchmark_458_dumpVm.sli Script running single benchmark - -The test script merges, sorts and compares the voltage dumps from the 2-threads and 2-mpi runs and prints -OK or FAILED for each of the following cases (the non-precise case is labeled as "Plain") - -iaf_psc_exp on-grid -iaf_psc_exp off-grid -iaf_psc_exp_ps on-grid -iaf_psc_exp_ps off-grid diff --git a/testsuite/manualtests/ticket-458/cuba_458.sli b/testsuite/manualtests/ticket-458/cuba_458.sli deleted file mode 100644 index f283840c66..0000000000 --- a/testsuite/manualtests/ticket-458/cuba_458.sli +++ /dev/null @@ -1,121 +0,0 @@ -/* - * cuba_458.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 . - * - */ - -/* - Benchmark 2 of the simulator review - - The SLI code in this file creates a sparsely coupled network of - excitatory and inhibitory neurons which exhibits self-sustained - activity after an initial stimulus. Connections within and across - both populations are created at random. Both neuron populations - receive Poissonian background input. The spike output of 500 - neurons from each population are recorded. Neurons are modeled - as leaky integrate-and-fire neurons with conductance based synapses - (exponential functions). The model is based on - - T.P. Vogels & L.F. Abbott - Signal Propagation and Logic Gating in Networks of - Integrate-and-Fire Neurons - Journal of Neuroscience, 2005, vol 25, pp 10786-10795. - - Note that the simulation time is set 10 times longer than for - benchmark 2 (coba.sli) or benchmark 3 (hh_coba.sli). This is - necessary as the computational load here is much lower, so a - longer simulation time is necessary to make reasonable - measurements. - - Marc-Oliver Gewaltig, Abigail Morrison, Tobias Potjans -*/ - -%%% PARAMETER SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -% define all relevant parameters: changes should be made here -% all data is place in the userdict dictionary - -% A dictionary is a list of name value pairs, enclosed in << and >> -% Here we use dictionaries to encapsulate the parameters for the different -% benchmarks - -/cuba_params -<< - /model /iaf_psc_exp % the neuron model to use - - /model_params - << - /E_L -49.0 mV % resting membrane potential [mV] - /V_th -50.0 mV % Threshold [mV] - /V_reset -60.0 mV % Reset Potential [mV] - /C_m 200.0 pF % Capacity of the membrane [pF] - /tau_m 20.0 ms % Membrane time constant [ms] - /tau_syn_ex 5.0 ms % time const. postsynaptic excitatory currents [ms] - /tau_syn_in 10.0 ms % time const. postsynaptic inhibitory currents [ms] - /t_ref 5.0 ms % duration of refractory period [ms] - >> - - /delay 0.1 ms % synaptic delay, all connections [ms] - - % synaptic strengths, here peak current - /E_synapse_params - << - /weight 16.2 pA % excitatory PSC amplitude - >> - - /I_synapse_params - << - /weight -139.5 pA % inhibitory PSC amplitude - >> - - /stimulus /poisson_generator - /stimulus_params - << - /rate 300.0 Hz % rate of inital poisson stimulus - /start 1.0 ms % start of Poisson_generator [ms] - /stop 51.0 ms % stop of Poisson_generator [ms] - /origin 0.0 ms % origin of time, to calculate start_time [ms] - >> - - /detector /spike_detector - /detector_params - << - /withtime true - /withgid true - /to_file false - /label (cuba) - >> - - % number of neurons per population to record from - /Nrec 500 - - %number of neurons to stimulate - /Nstim 50 - /simtime 10000.0 ms % simulated time - /dt 0.1 ms % simulation step - - /NE 3200 % number of excitatory neurons - /NI 800 % number of inhibitory neurons - /epsilon 0.02 % Connection probability - -% /virtual_processes 1 % number of virtual processes to use - ->> def - -cuba_params using % here we activate the definitions in the dictionary diff --git a/testsuite/manualtests/ticket-458/cuba_ps_458.sli b/testsuite/manualtests/ticket-458/cuba_ps_458.sli deleted file mode 100644 index 85bf2eec48..0000000000 --- a/testsuite/manualtests/ticket-458/cuba_ps_458.sli +++ /dev/null @@ -1,121 +0,0 @@ -/* - * cuba_ps_458.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 . - * - */ - -/* - Benchmark 2 of the simulator review - - The SLI code in this file creates a sparsely coupled network of - excitatory and inhibitory neurons which exhibits self-sustained - activity after an initial stimulus. Connections within and across - both populations are created at random. Both neuron populations - receive Poissonian background input. The spike output of 500 - neurons from each population are recorded. Neurons are modeled - as leaky integrate-and-fire neurons with conductance based synapses - (exponential functions). The model is based on - - T.P. Vogels & L.F. Abbott - Signal Propagation and Logic Gating in Networks of - Integrate-and-Fire Neurons - Journal of Neuroscience, 2005, vol 25, pp 10786-10795. - - Note that the simulation time is set 10 times longer than for - benchmark 2 (coba.sli) or benchmark 3 (hh_coba.sli). This is - necessary as the computational load here is much lower, so a - longer simulation time is necessary to make reasonable - measurements. - - Marc-Oliver Gewaltig, Abigail Morrison, Tobias Potjans -*/ - -%%% PARAMETER SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -% define all relevant parameters: changes should be made here -% all data is place in the userdict dictionary - -% A dictionary is a list of name value pairs, enclosed in << and >> -% Here we use dictionaries to encapsulate the parameters for the different -% benchmarks - -/cuba_params -<< - /model /iaf_psc_exp_ps % the neuron model to use - - /model_params - << - /E_L -49.0 mV % resting membrane potential [mV] - /V_th -50.0 mV % Threshold [mV] - /V_reset -60.0 mV % Reset Potential [mV] - /C_m 200.0 pF % Capacity of the membrane [pF] - /tau_m 20.0 ms % Membrane time constant [ms] - /tau_syn_ex 5.0 ms % time const. postsynaptic excitatory currents [ms] - /tau_syn_in 10.0 ms % time const. postsynaptic inhibitory currents [ms] - /t_ref 5.0 ms % duration of refractory period [ms] - >> - - /delay 0.1 ms % synaptic delay, all connections [ms] - - % synaptic strengths, here peak current - /E_synapse_params - << - /weight 16.2 pA % excitatory PSC amplitude - >> - - /I_synapse_params - << - /weight -139.5 pA % inhibitory PSC amplitude - >> - - /stimulus /poisson_generator - /stimulus_params - << - /rate 300.0 Hz % rate of inital poisson stimulus - /start 1.0 ms % start of Poisson_generator [ms] - /stop 51.0 ms % stop of Poisson_generator [ms] - /origin 0.0 ms % origin of time, to calculate start_time [ms] - >> - - /detector /spike_detector - /detector_params - << - /withtime true - /withgid true - /to_file false - /label (cuba_ps) - >> - - % number of neurons per population to record from - /Nrec 500 - - %number of neurons to stimulate - /Nstim 50 - /simtime 10000.0 ms % simulated time - /dt 0.1 ms % simulation step - - /NE 3200 % number of excitatory neurons - /NI 800 % number of inhibitory neurons - /epsilon 0.02 % Connection probability - -% /virtual_processes 1 % number of virtual processes to use - ->> def - -cuba_params using % here we activate the definitions in the dictionary diff --git a/testsuite/manualtests/ticket-458/run_benchmark_458.sli b/testsuite/manualtests/ticket-458/run_benchmark_458.sli deleted file mode 100644 index a2dc4916ab..0000000000 --- a/testsuite/manualtests/ticket-458/run_benchmark_458.sli +++ /dev/null @@ -1,276 +0,0 @@ -/* - * run_benchmark_458.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 . - * - */ - -/* - Simulator review - - The SLI code in this file creates a sparsely coupled network of - excitatory and inhibitory neurons which exhibits self-sustained - activity after an initial stimulus. Connections within and across - both populations are created at random. Both neuron populations - receive Poissonian background input. The spike output of 500 - neurons from each population are recorded. The model is based on - - T.P. Vogels & L.F. Abbott - Signal Propagation and Logic Gating in Networks of - Integrate-and-Fire Neurons - Journal of Neuroscience, 2005, vol 25, pp 10786-10795. - - where neurons are described by the leaky integrate-and-fire - model with conductance based synapses. The synaptic conductances - are decaying exponentials. The Vogels & Abbott model is integrated - on a fixed time grid of 0.1 ms with spike times constrained to this - grid. - - The different benchmarks of the FACETS simulator review are variations - of the Vogels & Abbott network model with differences in the model of - the synapse and in the model of the somatic dynamics. The table below - provides an overview - - ----------------------------------------------------------------------------- - | | synapse model | - # | name | soma | quantity | time course | spike times - ----------------------------------------------------------------------------- - 1 | coba.sli | i&f | conductance | exponential | grid-constrained - 2 | cuba.sli | i&f | current | exponential | grid-constrained - 3 | hh_coba.sli | HH | conductance | exponential | grid-constrained - 4 | cuba_ps.sli | i&f | current | delta | off-grid - - Usage: - This file (run_benchmark.sli) must be used in conjunction with - one of the parameter files above, e.g - - nest coba.sli run_benchmark.sli - - If the number of threads is set to greater than one, the benchmarks can - be run in a distributed fashion using mpirun, e.g. -g - mpirun -np 2 nest coba.sli run_benchmark.sli - - In addition to the four official benchmarks of the FACETS review, a fifth - benchmark has been defined to demonstrate the capabilities of NEST in - simulating large networks with heterogeneous synaptic dynamics. This - benchmark is self contained and can be run from the nest command line - without this file. - - ----------------------------------------------------------------------------- - 5 | cuba_stdp.sli | i&f | stdp-current | exponential | grid-constrained - ----------------------------------------------------------------------------- - - - - Marc-Oliver Gewaltig, Abigail Morrison, Tobias Potjans -*/ - -%%% FUNCTION SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -% Take spike detector, find total number of spikes registered, -% return average rate per neuron in Hz. -% NOTE: If you are running with several MPI processes, this -% function only gives an approximation to the true rate. -% -% spike_det ComputeRate -> rate -/ComputeRate -{ - GetStatus /n_events get /nspikes Set - % We need to guess how many neurons we record from. - % This assumes an even distribution of nodes across - % processes, which is ok for the Brette_et_al_2007 - % benchmarks, but should not be considered a general - % solution. - Nrec cvd NumProcesses div - /nnrn Set - - nspikes nnrn simtime mul div - 1000 mul % convert from mHz to Hz, leave on stack - end -} bind % optional, improves performance -def - - -%%% CONSTRUCTION SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -/BuildNetwork -{ - % set global kernel parameters - 0 - << - /resolution dt - /total_num_virtual_procs virtual_processes - >> SetStatus - - tic % start timer on construction - - % Set initial parameters for all new neurons and devices - - model model_params SetDefaults - - (Creating excitatory population.) = % show message - /E_net model [ NE ] LayoutNetwork def - - (Creating inhibitory population.) = % show message - /I_net model [ NI ] LayoutNetwork def - - (Creating excitatory stimulus generator.) = - /E_stimulus stimulus Create def - E_stimulus stimulus_params SetStatus - - % one detector would in principle be enough, - % but by recording the populations separately, - % we save ourselves a lot of sorting work later - - (Creating excitatory spike detector.) = - /E_detector detector Create def - E_detector detector_params SetStatus - - (Creating inhibitory spike detector.) = - /I_detector detector Create def - I_detector detector_params SetStatus - - % some connecting functions need lists (arrays) over all - % neurons they should work on, so we need to extract these - % lists from the subnetworks - - % obtain array with GIDs of all excitatory neurons - /E_neurons E_net GetNodes def - - % obtain array with GIDs of all inhibitory neurons - /I_neurons I_net GetNodes def - - % all neurons - /allNeurons E_neurons I_neurons join def - - /N allNeurons length def - - /CE NE epsilon mul iround def %number of incoming excitatory connections - /CI NI epsilon mul iround def %number of incomining inhibitory connections - - % number of synapses---just so we know - /Nsyn - CE CI add % internal synapses - N mul - Nrec 2 mul % "synapses" to spike detectors - add - Nstim add % "synapses" from poisson generator - def - - % Create custom synapse types with appropriate values for - % our excitatory and inhibitory connections - /static_synapse << /delay delay >> SetDefaults - /static_synapse /syn_ex E_synapse_params CopyModel - /static_synapse /syn_in I_synapse_params CopyModel - - (Connecting excitatory population.) = - - E_neurons - { - /target Set - - % E -> E connections - % the following is a single call to fixed-indegree Connect - E_neurons % source population [we pick from this] - [ target ] % target neuron - << /rule fixed_indegree /indegree CE >> % number of source neurons to pick - << /model /syn_ex >> % synapse model - Connect - - % I -> E connections - % as above, but more compact - I_neurons [ target ] - << /rule fixed_indegree /indegree CI >> - << /model /syn_in >> Connect - - } bind forall % bind improves efficiency - - - (Connecting inhibitory population.) = - - % ... as above, just written more compactly - - I_neurons - { - /target Set - - E_neurons [ target ] - << /rule fixed_indegree /indegree CE >> - << /model /syn_in >> Connect - - I_neurons [ target ] - << /rule fixed_indegree /indegree CI >> - << /model /syn_in >> Connect - } bind forall - - %Add external stimulus - - (Connecting Poisson stimulus.) = - [ E_stimulus ] - E_neurons Nstim Take % pick the first Nstim neurons - /all_to_all /syn_ex - Connect - - - % Spike detectors are connected to the first Nrec neurons in each - % population. Since neurons are equal and connectivity is homogeneously - % randomized, this is equivalent to picking Nrec neurons at random - % from each population - - (Connecting spike detectors.) = - - E_neurons Nrec Take % pick the first Nrec neurons - [ E_detector ] Connect - - I_neurons Nrec Take % pick the first Nrec neurons - [ I_detector ] Connect - - % read out time used for building - - toc /BuildCPUTime Set -} def - -/RunSimulation -{ - BuildNetwork - - % ensure we are running off-grid if requeste - 0 << /off_grid_spiking off_grid >> SetStatus - - % run, measure computer time with tic-toc - tic - (Simulating...) = - simtime Simulate - toc /SimCPUTime Set - - % write a little report - (Simulation summary) = - (Number of Neurons : ) =only N = - (Number of Synapses: ) =only Nsyn = - (Excitatory rate : ) =only E_detector ComputeRate =only ( Hz) = - (Inhibitory rate : ) =only I_detector ComputeRate =only ( Hz) = - (Building time : ) =only BuildCPUTime =only ( s) = - (Simulation time : ) =only SimCPUTime =only ( s\n) = - (MPI Processes : ) =only NumProcesses = - (VPs : ) =only 0 /total_num_virtual_procs get = - (Off grid : ) =only 0 /off_grid_spiking get = - (Model : ) =only cuba_params/model :: cvs = -} def - -RunSimulation \ No newline at end of file diff --git a/testsuite/manualtests/ticket-458/run_benchmark_458_dumpVm.sli b/testsuite/manualtests/ticket-458/run_benchmark_458_dumpVm.sli deleted file mode 100644 index fe86a63fe7..0000000000 --- a/testsuite/manualtests/ticket-458/run_benchmark_458_dumpVm.sli +++ /dev/null @@ -1,303 +0,0 @@ -/* - * run_benchmark_458_dumpVm.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 . - * - */ - -/* - This version writes the GID and membrane potential of all neurons to file - at the end of the simulation. - - Simulates 1000ms. - - Filename: - model_offgrid_numvps_nummpi_rank.dat -*/ - -/* - Simulator review - - The SLI code in this file creates a sparsely coupled network of - excitatory and inhibitory neurons which exhibits self-sustained - activity after an initial stimulus. Connections within and across - both populations are created at random. Both neuron populations - receive Poissonian background input. The spike output of 500 - neurons from each population are recorded. The model is based on - - T.P. Vogels & L.F. Abbott - Signal Propagation and Logic Gating in Networks of - Integrate-and-Fire Neurons - Journal of Neuroscience, 2005, vol 25, pp 10786-10795. - - where neurons are described by the leaky integrate-and-fire - model with conductance based synapses. The synaptic conductances - are decaying exponentials. The Vogels & Abbott model is integrated - on a fixed time grid of 0.1 ms with spike times constrained to this - grid. - - The different benchmarks of the FACETS simulator review are variations - of the Vogels & Abbott network model with differences in the model of - the synapse and in the model of the somatic dynamics. The table below - provides an overview - - ----------------------------------------------------------------------------- - | | synapse model | - # | name | soma | quantity | time course | spike times - ----------------------------------------------------------------------------- - 1 | coba.sli | i&f | conductance | exponential | grid-constrained - 2 | cuba.sli | i&f | current | exponential | grid-constrained - 3 | hh_coba.sli | HH | conductance | exponential | grid-constrained - 4 | cuba_ps.sli | i&f | current | delta | off-grid - - Usage: - This file (run_benchmark.sli) must be used in conjunction with - one of the parameter files above, e.g - - nest coba.sli run_benchmark.sli - - If the number of threads is set to greater than one, the benchmarks can - be run in a distributed fashion using mpirun, e.g. -g - mpirun -np 2 nest coba.sli run_benchmark.sli - - In addition to the four official benchmarks of the FACETS review, a fifth - benchmark has been defined to demonstrate the capabilities of NEST in - simulating large networks with heterogeneous synaptic dynamics. This - benchmark is self contained and can be run from the nest command line - without this file. - - ----------------------------------------------------------------------------- - 5 | cuba_stdp.sli | i&f | stdp-current | exponential | grid-constrained - ----------------------------------------------------------------------------- - - - - Marc-Oliver Gewaltig, Abigail Morrison, Tobias Potjans -*/ - -% define shorted simtime -/simtime 1000. def - -%%% FUNCTION SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -% Take spike detector, find total number of spikes registered, -% return average rate per neuron in Hz. -% NOTE: If you are running with several MPI processes, this -% function only gives an approximation to the true rate. -% -% spike_det ComputeRate -> rate -/ComputeRate -{ - GetStatus /n_events get /nspikes Set - % We need to guess how many neurons we record from. - % This assumes an even distribution of nodes across - % processes, which is ok for the Brette_et_al_2007 - % benchmarks, but should not be considered a general - % solution. - Nrec cvd NumProcesses div - /nnrn Set - - nspikes nnrn simtime mul div - 1000 mul % convert from mHz to Hz, leave on stack - end -} bind % optional, improves performance -def - - -%%% CONSTRUCTION SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -/BuildNetwork -{ - % set global kernel parameters - 0 - << - /resolution dt - /total_num_virtual_procs virtual_processes - >> SetStatus - - tic % start timer on construction - - % Set initial parameters for all new neurons and devices - - model model_params SetDefaults - - (Creating excitatory population.) = % show message - /E_net model [ NE ] LayoutNetwork def - - (Creating inhibitory population.) = % show message - /I_net model [ NI ] LayoutNetwork def - - (Creating excitatory stimulus generator.) = - /E_stimulus stimulus Create def - E_stimulus stimulus_params SetStatus - - % one detector would in principle be enough, - % but by recording the populations separately, - % we save ourselves a lot of sorting work later - - (Creating excitatory spike detector.) = - /E_detector detector Create def - E_detector detector_params SetStatus - - (Creating inhibitory spike detector.) = - /I_detector detector Create def - I_detector detector_params SetStatus - - % some connecting functions need lists (arrays) over all - % neurons they should work on, so we need to extract these - % lists from the subnetworks - - % obtain array with GIDs of all excitatory neurons - /E_neurons E_net GetNodes def - - % obtain array with GIDs of all inhibitory neurons - /I_neurons I_net GetNodes def - - % all neurons - /allNeurons E_neurons I_neurons join def - - /N allNeurons length def - - /CE NE epsilon mul iround def %number of incoming excitatory connections - /CI NI epsilon mul iround def %number of incomining inhibitory connections - - % number of synapses---just so we know - /Nsyn - CE CI add % internal synapses - N mul - Nrec 2 mul % "synapses" to spike detectors - add - Nstim add % "synapses" from poisson generator - def - - % Create custom synapse types with appropriate values for - % our excitatory and inhibitory connections - /static_synapse << /delay delay >> SetDefaults - /static_synapse /syn_ex E_synapse_params CopyModel - /static_synapse /syn_in I_synapse_params CopyModel - - (Connecting excitatory population.) = - - E_neurons - { - /target Set - - % E -> E connections - % the following is a single call to fixed-indegree Connect - E_neurons % source population [we pick from this] - [ target ] % target neuron - << /rule fixed_indegree /indegree CE >> % number of source neurons to pick - << /model /syn_ex >> % synapse model - Connect - - % I -> E connections - % as above, but more compact - I_neurons [ target ] - << /rule fixed_indegree /indegree CI >> - << /model /syn_in >> Connect - - } bind forall % bind improves efficiency - - - (Connecting inhibitory population.) = - - % ... as above - - I_neurons - { - /target Set - - E_neurons [ target ] - << /rule fixed_indegree /indegree CE >> - << /model /syn_in >> Connect - - I_neurons [ target ] - << /rule fixed_indegree /indegree CI >> - << /model /syn_in >> Connect - } bind forall - - %Add external stimulus - - (Connecting Poisson stimulus.) = - [ E_stimulus ] - E_neurons Nstim Take % pick the first Nstim neurons - /all_to_all /syn_ex - Connect - - - % Spike detectors are connected to the first Nrec neurons in each - % population. Since neurons are equal and connectivity is homogeneously - % randomized, this is equivalent to picking Nrec neurons at random - % from each population - - (Connecting spike detectors.) = - - E_neurons Nrec Take % pick the first Nrec neurons - [ E_detector ] Connect - - I_neurons Nrec Take % pick the first Nrec neurons - [ I_detector ] Connect - - % read out time used for building - - toc /BuildCPUTime Set -} def - -/RunSimulation -{ - BuildNetwork - - % ensure we are running off-grid if requeste - 0 << /off_grid_spiking off_grid >> SetStatus - - % run, measure computer time with tic-toc - tic - (Simulating...) = - simtime Simulate - toc /SimCPUTime Set - - % write a little report - (Simulation summary) = - (Number of Neurons : ) =only N = - (Number of Synapses: ) =only Nsyn = - (Excitatory rate : ) =only E_detector ComputeRate =only ( Hz) = - (Inhibitory rate : ) =only I_detector ComputeRate =only ( Hz) = - (Building time : ) =only BuildCPUTime =only ( s) = - (Simulation time : ) =only SimCPUTime =only ( s\n) = - (MPI Processes : ) =only NumProcesses = - (VPs : ) =only 0 /total_num_virtual_procs get = - (Off grid : ) =only 0 /off_grid_spiking get = - (Model : ) =only cuba_params/model :: cvs = - - - % file name: model_offgrid_numvps_nummpi_rank.dat - /fname cuba_params/model :: cvs (_) join 0 /off_grid_spiking get cvs join (_) join - 0 /total_num_virtual_procs get cvs join (_) join NumProcesses cvs join (_) join - Rank cvs join (.dat) join def - (Voltage dump : ) =only fname == - - /of fname (w) file def - of 20 setprecision - allNeurons { dup /local get { [[/global_id /V_m]] get pprint endl } { pop } ifelse } forall - close - -} def - - -RunSimulation \ No newline at end of file diff --git a/testsuite/manualtests/ticket-458/test_cuba_458.sh b/testsuite/manualtests/ticket-458/test_cuba_458.sh deleted file mode 100644 index c0939fab17..0000000000 --- a/testsuite/manualtests/ticket-458/test_cuba_458.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/bin/bash - -# Some stuff for convenient testing on Stallo -#PBS -lnodes=1:ppn=2 -#PBS -lwalltime=00:10:00 -#PBS -lpmem=1000MB -#PBS -j oe -#PBS -m abe - -# PBS needs to change, normal script just does cd . -cd ${PBS_O_WORKDIR:-.} - -# replace with proper path to NEST exectutable -NEST=/home/plesser/NEST/trunk/ins/bin/nest - -conf="/virtual_processes 1 def /off_grid false def (cuba_458.sli) run" -echo "#################################################################" -echo $conf -echo "-----------------------------------------------------------------" -echo $conf > conf.sli -mpirun -np 1 $NEST conf.sli run_benchmark_458.sli - -echo "#################################################################" - -conf="/virtual_processes 2 def /off_grid false def (cuba_458.sli) run" -echo "#################################################################" -echo $conf -echo "-----------------------------------------------------------------" -echo $conf > conf.sli -mpirun -np 1 $NEST conf.sli run_benchmark_458.sli - -echo "#################################################################" - -conf="/virtual_processes 2 def /off_grid false def (cuba_458.sli) run" -echo "#################################################################" -echo $conf -echo "-----------------------------------------------------------------" -echo $conf > conf.sli -mpirun -np 2 $NEST conf.sli run_benchmark_458.sli - -echo "#################################################################" - -echo "********************************************************************" -echo "********************************************************************" -echo "********************************************************************" - -conf="/virtual_processes 1 def /off_grid true def (cuba_458.sli) run" -echo "#################################################################" -echo $conf -echo "-----------------------------------------------------------------" -echo $conf > conf.sli -mpirun -np 1 $NEST conf.sli run_benchmark_458.sli - -echo "#################################################################" - -conf="/virtual_processes 2 def /off_grid true def (cuba_458.sli) run" -echo "#################################################################" -echo $conf -echo "-----------------------------------------------------------------" -echo $conf > conf.sli -mpirun -np 1 $NEST conf.sli run_benchmark_458.sli - -echo "#################################################################" - -conf="/virtual_processes 2 def /off_grid true def (cuba_458.sli) run" -echo "#################################################################" -echo $conf -echo "-----------------------------------------------------------------" -echo $conf > conf.sli -mpirun -np 2 $NEST conf.sli run_benchmark_458.sli - -echo "#################################################################" - -echo "====================================================================" -echo "====================================================================" -echo "====================================================================" - -conf="/virtual_processes 1 def /off_grid false def (cuba_ps_458.sli) run" -echo "#################################################################" -echo $conf -echo "-----------------------------------------------------------------" -echo $conf > conf.sli -mpirun -np 1 $NEST conf.sli run_benchmark_458.sli - -echo "#################################################################" - -conf="/virtual_processes 2 def /off_grid false def (cuba_ps_458.sli) run" -echo "#################################################################" -echo $conf -echo "-----------------------------------------------------------------" -echo $conf > conf.sli -mpirun -np 1 $NEST conf.sli run_benchmark_458.sli - -echo "#################################################################" - -conf="/virtual_processes 2 def /off_grid false def (cuba_ps_458.sli) run" -echo "#################################################################" -echo $conf -echo "-----------------------------------------------------------------" -echo $conf > conf.sli -mpirun -np 2 $NEST conf.sli run_benchmark_458.sli - -echo "#################################################################" - -echo "********************************************************************" -echo "********************************************************************" -echo "********************************************************************" - -conf="/virtual_processes 1 def /off_grid true def (cuba_ps_458.sli) run" -echo "#################################################################" -echo $conf -echo "-----------------------------------------------------------------" -echo $conf > conf.sli -mpirun -np 1 $NEST conf.sli run_benchmark_458.sli - -echo "#################################################################" - -conf="/virtual_processes 2 def /off_grid true def (cuba_ps_458.sli) run" -echo "#################################################################" -echo $conf -echo "-----------------------------------------------------------------" -echo $conf > conf.sli -mpirun -np 1 $NEST conf.sli run_benchmark_458.sli - -echo "#################################################################" - -conf="/virtual_processes 2 def /off_grid true def (cuba_ps_458.sli) run" -echo "#################################################################" -echo $conf -echo "-----------------------------------------------------------------" -echo $conf > conf.sli -mpirun -np 2 $NEST conf.sli run_benchmark_458.sli - -echo "#################################################################" - -rm conf.sli diff --git a/testsuite/manualtests/ticket-458/test_cuba_458_dumpVm.sh b/testsuite/manualtests/ticket-458/test_cuba_458_dumpVm.sh deleted file mode 100644 index 1b3645dc6c..0000000000 --- a/testsuite/manualtests/ticket-458/test_cuba_458_dumpVm.sh +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/bash - -# This script runs the CUBA simulations once with two threads, -# once with two MPI processes, dumps membrane potentials at -# the end and compares the resulting files. -# -# If all goes well, output should look like (note the four OK lines) - -################################################################# -#/virtual_processes 2 def /off_grid false def (cuba_458.sli) run -#----------------------------------------------------------------- -#/virtual_processes 2 def /off_grid false def (cuba_458.sli) run -#----------------------------------------------------------------- -#Plain Offgrid OK -################################################################# -#/virtual_processes 2 def /off_grid true def (cuba_458.sli) run -#----------------------------------------------------------------- -#/virtual_processes 2 def /off_grid true def (cuba_458.sli) run -#----------------------------------------------------------------- -#Plain Ongrid OK -################################################################# -#/virtual_processes 2 def /off_grid false def (cuba_ps_458.sli) run -#----------------------------------------------------------------- -#/virtual_processes 2 def /off_grid false def (cuba_ps_458.sli) run -#----------------------------------------------------------------- -#PS Offgrid OK -################################################################# -#/virtual_processes 2 def /off_grid true def (cuba_ps_458.sli) run -#----------------------------------------------------------------- -#/virtual_processes 2 def /off_grid true def (cuba_ps_458.sli) run -#----------------------------------------------------------------- -#PS Ongrid OK - -# Hans Ekkehard Plesser, 2010-10-18 - - -# Some stuff for convenient testing on Stallo -#PBS -lnodes=1:ppn=2 -#PBS -lwalltime=00:10:00 -#PBS -lpmem=1000MB -#PBS -j oe -#PBS -m abe - -# PBS needs to change, normal script just does cd . -cd ${PBS_O_WORKDIR:-.} - -# replace with proper path to NEST exectutable -NEST=/home/plesser/NEST/trunk/ins/bin/nest - -echo "#################################################################" -conf="/virtual_processes 2 def /off_grid false def (cuba_458.sli) run" -echo $conf -echo $conf > conf.sli -mpirun -np 1 $NEST conf.sli run_benchmark_458_dumpVm.sli > /dev/null 2>&1 - -echo "-----------------------------------------------------------------" -conf="/virtual_processes 2 def /off_grid false def (cuba_458.sli) run" -echo $conf -echo $conf > conf.sli -mpirun -np 2 $NEST conf.sli run_benchmark_458_dumpVm.sli > /dev/null 2>&1 - -echo "-----------------------------------------------------------------" -sort iaf_psc_exp_false_2_1_0.dat > ts.dat -sort iaf_psc_exp_false_2_2_0.dat iaf_psc_exp_false_2_2_1.dat > ms.dat -diff ts.dat ms.dat && echo "Plain Offgrid OK" || echo "Plain Offgrid FAILED" -rm ts.dat ms.dat - -echo "#################################################################" -conf="/virtual_processes 2 def /off_grid true def (cuba_458.sli) run" -echo $conf -echo $conf > conf.sli -mpirun -np 1 $NEST conf.sli run_benchmark_458_dumpVm.sli > /dev/null 2>&1 - -echo "-----------------------------------------------------------------" -conf="/virtual_processes 2 def /off_grid true def (cuba_458.sli) run" -echo $conf -echo $conf > conf.sli -mpirun -np 2 $NEST conf.sli run_benchmark_458_dumpVm.sli > /dev/null 2>&1 - -echo "-----------------------------------------------------------------" -sort iaf_psc_exp_true_2_1_0.dat > ts.dat -sort iaf_psc_exp_true_2_2_0.dat iaf_psc_exp_true_2_2_1.dat > ms.dat -diff ts.dat ms.dat && echo "Plain Ongrid OK" || echo "Plain Ongrid FAILED" -rm ts.dat ms.dat - - -echo "#################################################################" -conf="/virtual_processes 2 def /off_grid false def (cuba_ps_458.sli) run" -echo $conf -echo $conf > conf.sli -mpirun -np 1 $NEST conf.sli run_benchmark_458_dumpVm.sli > /dev/null 2>&1 - -echo "-----------------------------------------------------------------" -conf="/virtual_processes 2 def /off_grid false def (cuba_ps_458.sli) run" -echo $conf -echo $conf > conf.sli -mpirun -np 2 $NEST conf.sli run_benchmark_458_dumpVm.sli > /dev/null 2>&1 - -echo "-----------------------------------------------------------------" -sort iaf_psc_exp_ps_false_2_1_0.dat > ts.dat -sort iaf_psc_exp_ps_false_2_2_0.dat iaf_psc_exp_ps_false_2_2_1.dat > ms.dat -diff ts.dat ms.dat && echo "PS Offgrid OK" || echo "PS Offgrid FAILED" -rm ts.dat ms.dat - -echo "#################################################################" -conf="/virtual_processes 2 def /off_grid true def (cuba_ps_458.sli) run" -echo $conf -echo $conf > conf.sli -mpirun -np 1 $NEST conf.sli run_benchmark_458_dumpVm.sli > /dev/null 2>&1 - -echo "-----------------------------------------------------------------" -conf="/virtual_processes 2 def /off_grid true def (cuba_ps_458.sli) run" -echo $conf -echo $conf > conf.sli -mpirun -np 2 $NEST conf.sli run_benchmark_458_dumpVm.sli > /dev/null 2>&1 - -echo "-----------------------------------------------------------------" -sort iaf_psc_exp_ps_true_2_1_0.dat > ts.dat -sort iaf_psc_exp_ps_true_2_2_0.dat iaf_psc_exp_ps_true_2_2_1.dat > ms.dat -diff ts.dat ms.dat && echo "PS Ongrid OK" || echo "PS Ongrid FAILED" -rm ts.dat ms.dat - -rm conf.sli -rm iaf_psc_exp*_2_*.dat diff --git a/testsuite/manualtests/ticket-541.sli b/testsuite/manualtests/ticket-541.sli deleted file mode 100644 index bcf220c002..0000000000 --- a/testsuite/manualtests/ticket-541.sli +++ /dev/null @@ -1,150 +0,0 @@ -/* - * ticket-541.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::ticket-541 - Regression test for aeif_cond_alpha reset - -Synopsis: (ticket-541) run -> NEST exits if test fails - -Description: -This test is based on an original Python demonstrator by Abigail Morrison -(see #541). -Per r10018, no-one can reproduce the error and the test is very slow. -Therefore, this test resides in manualtests. - -Author: Yury V. Zaytsev, Hans E. Plesser, 2012-11-29 - */ - -(unittest) run -/unittest using - -M_ERROR setverbosity - -/test_reset { - - /connect_neurons Set - /use_aeif Set - - ResetKernel - - 0 << - /resolution 0.1 - /print_time false - /rng_seeds [ 123 ] - /overwrite_files true - >> SetStatus - - /poisson_generator << /rate 10000. >> SetDefaults - /background /poisson_generator Create def - - /msn_model use_aeif { - << - /C_m 200. - /Delta_T 2. - /E_L -58. - /E_ex 0. - /E_in -64. - /I_e 0. - /V_peak 0. - /V_reset -46. - /V_th -50. - /a 1. - /b 100. - /g_L 10. - /t_ref 0. - /tau_syn_ex 0.3 - /tau_syn_in 2. - /tau_w 200. - /w 0. - /gsl_error_tol 1e-9 - >> /aeif_cond_alpha - } { - << - /V_th -55. - >> /iaf_psc_exp - } ifelse rollu CopyModel - - /neurons [ - background 1 add - /msn_model 500 Create - ] Range def - - connect_neurons { - neurons - neurons - << /rule /fixed_outdegree /outdegree 50 >> - << /weight 14500. -0.0003 mul /delay 2. >> - Connect - } if - - [background] - neurons - << /rule /all_to_all >> - << /weight 5000. 0.00346 mul /delay 1. >> - Connect - - /meter /spike_detector Create def - meter << - /withgid true - /withtime true - /to_file false - /to_memory true - >> SetStatus - - neurons [meter] Connect - - /run_simulation { - /label Set - ResetNetwork - 0 << /time 0.0 /rng_seeds [ 123 ] >> SetStatus - meter << /n_events 0 /label label >> SetStatus - 500 Simulate - /results meter GetStatus def - } def - - (sr1) run_simulation - /ev1 results/events/senders :: def - /st1 results/events/times :: def - - (sr2) run_simulation - /ev2 results/events/senders :: def - /st2 results/events/times :: def - - ev1 cva ev2 cva eq - st1 cva st2 cva eq - and -} def - -(true true) == -true true test_reset assert_or_die - -(true false) == -true false test_reset assert_or_die - -(false true) == -false true test_reset assert_or_die - -(false false) == -false false test_reset assert_or_die - -endusing From 2e8d285a47404ca73014decf8efb6d762b2ef418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20M=C3=B8rk?= Date: Fri, 7 Jul 2017 11:28:34 +0200 Subject: [PATCH 08/20] Switched back to old Ubuntu image --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index d3cc477932..02fa478825 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,7 @@ language: generic # Required for Ubuntu Trusty (14.04 LTS). sudo: required dist: trusty +group: deprecated-2017Q2 env: matrix: From 5e9fc81f0af3b80d774303861c6a7f618af58de7 Mon Sep 17 00:00:00 2001 From: Stine Vennemo Date: Fri, 7 Jul 2017 12:52:36 +0200 Subject: [PATCH 09/20] Converted hh_phaseplane.m and test_hh_phaseplane.sli to PyNEST hh_phaseplane.py example. --- pynest/examples/hh_phaseplane.py | 164 +++++++++++++++++++ testsuite/manualtests/hh_phaseplane.m | 78 --------- testsuite/manualtests/test_hh_phaseplane.sli | 121 -------------- 3 files changed, 164 insertions(+), 199 deletions(-) create mode 100644 pynest/examples/hh_phaseplane.py delete mode 100644 testsuite/manualtests/hh_phaseplane.m delete mode 100644 testsuite/manualtests/test_hh_phaseplane.sli diff --git a/pynest/examples/hh_phaseplane.py b/pynest/examples/hh_phaseplane.py new file mode 100644 index 0000000000..7f051e55c1 --- /dev/null +++ b/pynest/examples/hh_phaseplane.py @@ -0,0 +1,164 @@ +# -*- coding: utf-8 -*- +# +# hh_phaseplane.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 . + +''' + hh_phaseplane makes a numerical phase-plane analysis of the Hodgkin-Huxley + neuron (iaf_psc_alpha). Dynamics is investigated in the V-n space (see remark + below). A constant DC can be specified and its influence on the nullclines + can be studied. + + REMARK + To make the two-dimensional analysis possible, the (four-dimensional) + Hodgkin-Huxley formalism needs to be artificially reduced to two dimensions, + in this case by 'clamping' the two other variables, m an h, to + constant values (m_eq and h_eq). +''' + +import nest +from matplotlib import pyplot as plt + +amplitude = 100. # Set externally applied current amplitude in pA +dt = 0.1 # simulation step length [ms] + +nest.ResetKernel() +nest.set_verbosity('M_ERROR') + +nest.SetKernelStatus({'resolution': dt}) +neuron = nest.Create('hh_psc_alpha') + +# Numerically obtain equilibrium state +nest.Simulate(1000) + +m_eq = nest.GetStatus(neuron)[0]['Act_m'] +h_eq = nest.GetStatus(neuron)[0]['Act_h'] + +nest.SetStatus(neuron, {'I_e': amplitude}) # Apply external current + +# Scan state space +print('Scanning phase space') + +V_new_vec = []; +n_new_vec = []; +# x will contain the phase-plane data as a vector field +x = [] +count = 0 +for V in range(-100, 42, 2): + n_V = [] + n_n = [] + for n in range(10, 81): + # Set V_m and n + nest.SetStatus(neuron, {'V_m': V*1.0, 'Inact_n': n/100.0, + 'Act_m': m_eq, 'Act_h': h_eq}) + # Find state + V_m = nest.GetStatus(neuron)[0]['V_m'] + Inact_n = nest.GetStatus(neuron)[0]['Inact_n'] + + # Simulate a short while + nest.Simulate(dt) + + # Find difference between new state and old state + V_m_new = nest.GetStatus(neuron)[0]['V_m'] - V*1.0 + Inact_n_new = nest.GetStatus(neuron)[0]['Inact_n'] - n/100.0 + + # Store in vector for later analysis + n_V.append(abs(V_m_new)) + n_n.append(abs(Inact_n_new)) + x.append([V_m, Inact_n, V_m_new, Inact_n_new]) + + if count % 10 == 0: + # Write updated state next to old state + print('') + print('Vm: \t', V_m) + print('new Vm:\t', V_m_new) + print('Inact_n:', Inact_n) + print('new Inact_n:', Inact_n_new) + + count += 1 + # Store in vector for later analysis + V_new_vec.append(n_V) + n_new_vec.append(n_n) + + +# Set state for AP generation +nest.SetStatus(neuron, {'V_m': -34., 'Inact_n': 0.2, + 'Act_m': m_eq, 'Act_h': h_eq}) + +print('') +print('AP-trajectory') +# ap will contain the trace of a single action potential as one possible +# numerical solution in the vector field +ap = [] +for i in range(1, 1001): + # Find state + V_m = nest.GetStatus(neuron)[0]['V_m'] + Inact_n = nest.GetStatus(neuron)[0]['Inact_n'] + + if i % 10 == 0: + # Write new state next to old state + print('Vm: \t', V_m) + print('Inact_n:', Inact_n) + ap.append([V_m, Inact_n]) + + # Simulate again + nest.SetStatus(neuron, {'Act_m': m_eq, 'Act_h': h_eq}) + nest.Simulate(dt) + +# Make analysis +print('') +print('Plot analysis') + +V_matrix = [list(x) for x in zip(*V_new_vec)] +n_matrix = [list(x) for x in zip(*n_new_vec)] +n_vec = [x/100. for x in range(10, 81)] +V_vec = [x*1. for x in range(-100, 42, 2)] + +nullcline_V = [] +nullcline_n = [] + +print('Searching nullclines') +for i in range(0, len(V_vec)): + index = V_matrix[:][i].index(min(V_matrix[:][i])) + if index != 0 and index != len(n_vec): + nullcline_V.append([V_vec[i], n_vec[index]]) + + index = n_matrix[:][i].index(min(n_matrix[:][i])) + if index != 0 and index != len(n_vec): + nullcline_n.append([V_vec[i], n_vec[index]]) + +print('Plotting vector field') +factor = 0.1 +for i in range(0, count, 3): + plt.plot([x[i][0], x[i][0] + factor*x[i][2]], + [x[i][1], x[i][1] + factor*x[i][3]], color=[0.6, 0.6, 0.6]) + +plt.plot(nullcline_V[:][0], nullcline_V[:][1], linewidth=2.0) +plt.plot(nullcline_n[:][0], nullcline_n[:][1], linewidth=2.0) + +plt.xlim([V_vec[0], V_vec[-1]]) +plt.ylim([n_vec[0], n_vec[-1]]) + +plt.plot(ap[:][0], ap[:][1], color='black', linewidth=1.0) + +plt.xlabel('Membrane potential V [mV]') +plt.ylabel('Inactivation variable n') +plt.title('Phase space of the Hodgkin-Huxley Neuron') + +plt.show() diff --git a/testsuite/manualtests/hh_phaseplane.m b/testsuite/manualtests/hh_phaseplane.m deleted file mode 100644 index 91e5801add..0000000000 --- a/testsuite/manualtests/hh_phaseplane.m +++ /dev/null @@ -1,78 +0,0 @@ -%% hh_phaseplane.m -%% -%% numerical phase-plane analysis of the Hodgkin-Huxley neuron. -%% needs data files phaseplane.txt and AP.txt written by -%% test_hh_phaseplane.sli -%% author Sven Schrader, Feb 2007 - -phasefile='phaseplane.txt'; -apfile='AP.txt'; - -if( (exist(phasefile) ~= 2) | (exist(apfile) ~= 2) ) - error('could not find data file(s). Make sure you have run test_hh_phaseplane.sli!'); -end - -x=load(phasefile); -t=size(x,1); - -V=unique(x(:,1)); -n=unique(x(:,2)); - -r1=abs(reshape(x(:,3),length(n),length(V))); -r2=abs(reshape(x(:,4),length(n),length(V))); - -nc_v=[]; -nc_n=[]; -count_v=0; -count_n=0; - -f=figure; a=axes; hold on; - -nullcline_V=[]; -nullcline_n=[]; -ncount=1; -vcount=1; - -disp('searching nullclines'); -for i=1:length(V) - [dummy index] = min(r1(:,i)); - if(index ~= 1 & index~=length(n)) - nullcline_V(vcount,:)= [V(i), n(index)]; - vcount=vcount+1; - end - - [dummy index] = min(r2(:,i)); - if(index ~= 1 & index~=length(n)) - nullcline_n(ncount,:)= [V(i), n(index)]; - ncount=ncount+1; - end - -end - -disp('plotting vector field') -factor=0.1; -for i=1:3:t - plot([x(i,1) x(i,1)+factor*x(i,3)], [x(i,2) x(i,2)+factor*x(i,4)],'COLOR',[0.6 0.6 0.6]); -end - -plot(nullcline_V(:,1), nullcline_V(:,2),'r','linewidth',2); -plot(nullcline_n(:,1), nullcline_n(:,2),'b','linewidth',2); - -xlim([V(1) V(end)]) -ylim([n(1) n(end)]) - -ap=load('AP.txt'); -plot(ap(:,1),ap(:,2),'k','linewidth',1 ) - -% due to a 'legend' problem, the plot-order needs to be changed -ch=get(a,'Children'); -set(a,'Children', flipud(ch)) -legend('action potential','n-nullcline','V-nullcline'); -set(a,'Children', (ch)) - -box on -set(a,'Layer','top') - -xlabel('membrane potential V (mV)') -ylabel('inactivation variable n') -title('Phase space of the Hodgkin-Huxley Neuron') diff --git a/testsuite/manualtests/test_hh_phaseplane.sli b/testsuite/manualtests/test_hh_phaseplane.sli deleted file mode 100644 index 9aa47e976c..0000000000 --- a/testsuite/manualtests/test_hh_phaseplane.sli +++ /dev/null @@ -1,121 +0,0 @@ -/* - * test_hh_phaseplane.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::test_hh_phaseplane - sli script for hh_psc_alpha model - -Synopsis: (test_hh_phaseplane) run -> 'phaseplane.txt' & 'AP.txt' - - -Description: - - test_hh_phaseplane makes a numerical phase-plane analysis of the Hodgkin-Huxley neuron - (iaf_psc_alpha). Dynamics is investigated in the V-n space (see remark below). A constant - DC can be specified and its influence on the nullclines can be studied. - Results are written into two files. 'phaseplane.txt' contains the phase-plane data as a - vector field and 'AP.txt' the trace of a single action potential as one possible - numerical solution in the vector field. The data files are used in the matlab-script hh_phaseplane.m - - REMARK - To make the two-dimensional analysis possible, the (four-dimensional) - Hodgkin-Huxley formalism needs to be artificially reduced to two dimensions, - in this case by 'clamping' the two other variables, m an h, to - constant values (m_eq and h_eq). - - Author: Schrader - -SeeAlso: iaf_psc_exp, iaf_neuron, testsuite::test_iaf_i0, testsuite::test_iaf_i0_refractory, testsuite::test_iaf_dc -*/ - - -% set externally applied current amplitude in pA -/amplitude 100. def -/dt 0.1 def % simulation step length [ms] - -% open file -(phaseplane.txt) ofstream -{ - /f Set -} -{ - /test_hh_phaseplane /CouldNotOpenFile raiseerror -} ifelse - -ResetKernel % clear all existing network elements - -M_ERROR setverbosity - -[0] -<< - /resolution dt ->> SetStatus -/hh_psc_alpha Create /neuron Set - -% numerically obtain equilibrium state -1000 Simulate - -neuron GetStatus /Act_m get /m_eq Set -neuron GetStatus /Act_h get /h_eq Set -neuron << /I_e amplitude >> SetStatus % apply external current - -% scan state space -(scanning phase space) = --100. 2. 40. { - /V Set - 0.1 0.01 0.8 { - /n Set - % set V_m and n - neuron << /V_m V /Inact_n n /Act_m m_eq /Act_h h_eq >> SetStatus - % write state into file - f neuron GetStatus /V_m get print ( ) print neuron GetStatus /Inact_n get print ( ) print ; - % simulate a short while - dt Simulate - % write new state next to old state - f neuron GetStatus /V_m get V sub print ( ) print neuron GetStatus /Inact_n get n sub print endl ; - } for -} for - -% flose first datafile -f close - -% open file -(AP.txt) ofstream -{ - /f Set -} -{ - /test_hh_phaseplane /CouldNotOpenFile raiseerror -} ifelse - -% set state for AP generation -neuron << /V_m -34. /Inact_n 0.2 /Act_m m_eq /Act_h h_eq >> SetStatus - -(AP-trajectory) = -1 1 1000 { - % write state into file and simulate a bit - f neuron GetStatus /V_m get print ( ) print neuron GetStatus /Inact_n get print endl ; - neuron << /Act_m m_eq /Act_h h_eq >> SetStatus - dt Simulate -} for - -% close second datafile -f close From 6b10cd018bbc616de5f80fe2d4b8aa0937b3a30d Mon Sep 17 00:00:00 2001 From: Stine Vennemo Date: Fri, 7 Jul 2017 12:53:58 +0200 Subject: [PATCH 10/20] Proper skip without gsl declaration --- testsuite/unittests/test_hh_cond_exp_traub.sli | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/testsuite/unittests/test_hh_cond_exp_traub.sli b/testsuite/unittests/test_hh_cond_exp_traub.sli index 41fcb8fb21..bb254c80b3 100644 --- a/testsuite/unittests/test_hh_cond_exp_traub.sli +++ b/testsuite/unittests/test_hh_cond_exp_traub.sli @@ -36,7 +36,11 @@ % The following test needs the model hh_cond_exp_traub, so % this test should only run if we have GSL -skip_if_without_gsl +statusdict/have_gsl :: not +{ + exit_test_gracefully +} +if 0.1 /h Set From 4b842ce67809d3b381094a79493cc3300bb30e78 Mon Sep 17 00:00:00 2001 From: Stine Vennemo Date: Fri, 7 Jul 2017 13:09:49 +0200 Subject: [PATCH 11/20] pep8ify --- pynest/examples/hh_phaseplane.py | 30 +++++++++++++------------- pynest/nest/tests/test_pp_psc_delta.py | 3 ++- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pynest/examples/hh_phaseplane.py b/pynest/examples/hh_phaseplane.py index 7f051e55c1..8621495798 100644 --- a/pynest/examples/hh_phaseplane.py +++ b/pynest/examples/hh_phaseplane.py @@ -35,8 +35,9 @@ import nest from matplotlib import pyplot as plt -amplitude = 100. # Set externally applied current amplitude in pA -dt = 0.1 # simulation step length [ms] + +amplitude = 100. # Set externally applied current amplitude in pA +dt = 0.1 # simulation step length [ms] nest.ResetKernel() nest.set_verbosity('M_ERROR') @@ -50,13 +51,13 @@ m_eq = nest.GetStatus(neuron)[0]['Act_m'] h_eq = nest.GetStatus(neuron)[0]['Act_h'] -nest.SetStatus(neuron, {'I_e': amplitude}) # Apply external current +nest.SetStatus(neuron, {'I_e': amplitude}) # Apply external current # Scan state space print('Scanning phase space') -V_new_vec = []; -n_new_vec = []; +V_new_vec = [] +n_new_vec = [] # x will contain the phase-plane data as a vector field x = [] count = 0 @@ -70,19 +71,19 @@ # Find state V_m = nest.GetStatus(neuron)[0]['V_m'] Inact_n = nest.GetStatus(neuron)[0]['Inact_n'] - + # Simulate a short while nest.Simulate(dt) - + # Find difference between new state and old state V_m_new = nest.GetStatus(neuron)[0]['V_m'] - V*1.0 Inact_n_new = nest.GetStatus(neuron)[0]['Inact_n'] - n/100.0 - + # Store in vector for later analysis n_V.append(abs(V_m_new)) n_n.append(abs(Inact_n_new)) x.append([V_m, Inact_n, V_m_new, Inact_n_new]) - + if count % 10 == 0: # Write updated state next to old state print('') @@ -90,13 +91,12 @@ print('new Vm:\t', V_m_new) print('Inact_n:', Inact_n) print('new Inact_n:', Inact_n_new) - + count += 1 # Store in vector for later analysis V_new_vec.append(n_V) n_new_vec.append(n_n) - # Set state for AP generation nest.SetStatus(neuron, {'V_m': -34., 'Inact_n': 0.2, 'Act_m': m_eq, 'Act_h': h_eq}) @@ -110,7 +110,7 @@ # Find state V_m = nest.GetStatus(neuron)[0]['V_m'] Inact_n = nest.GetStatus(neuron)[0]['Inact_n'] - + if i % 10 == 0: # Write new state next to old state print('Vm: \t', V_m) @@ -120,7 +120,7 @@ # Simulate again nest.SetStatus(neuron, {'Act_m': m_eq, 'Act_h': h_eq}) nest.Simulate(dt) - + # Make analysis print('') print('Plot analysis') @@ -134,11 +134,11 @@ nullcline_n = [] print('Searching nullclines') -for i in range(0, len(V_vec)): +for i in range(0, len(V_vec)): index = V_matrix[:][i].index(min(V_matrix[:][i])) if index != 0 and index != len(n_vec): nullcline_V.append([V_vec[i], n_vec[index]]) - + index = n_matrix[:][i].index(min(n_matrix[:][i])) if index != 0 and index != len(n_vec): nullcline_n.append([V_vec[i], n_vec[index]]) diff --git a/pynest/nest/tests/test_pp_psc_delta.py b/pynest/nest/tests/test_pp_psc_delta.py index f84c3f2fcd..26d8392791 100644 --- a/pynest/nest/tests/test_pp_psc_delta.py +++ b/pynest/nest/tests/test_pp_psc_delta.py @@ -28,7 +28,8 @@ class PpPscDeltaTestCase(unittest.TestCase): """Tests for pp_psc_delta""" def test_rate_and_fixed_dead_time(self): - """Check for reasonable firing rate and if fixed dead-time is respected""" + """Check for reasonable firing rate and if fixed dead-time is + respected""" # test parameters d = 25.0 From bcfa3846718d26a3b736f9cf36add49b9f941178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20M=C3=B8rk?= Date: Fri, 7 Jul 2017 15:00:13 +0200 Subject: [PATCH 12/20] Updated more tests --- pynest/examples/hh_psc_alpha.py | 74 +++++++++ pynest/nest/tests/test_pp_psc_delta.py | 4 +- pynest/nest/tests/test_pp_psc_delta_stdp.py | 93 +++++++++++ .../manualtests/parallel_conn_and_rand.sli | 138 ---------------- .../test_connect_array_fixed_outdegree_mpi.sh | 51 ------ testsuite/manualtests/test_hh_psc_alpha.sli | 122 -------------- .../manualtests/test_pp_psc_delta_stdp.py | 95 ----------- .../test_spike_poisson_ps_base2_nd.sli | 11 +- testsuite/manualtests/test_stdp_poiss.sli | 18 +-- .../manualtests/ticket-737-DScallback.sli | 69 -------- ...test_connect_array_fixed_outdegree_mpi.sli | 153 +++++++----------- .../mpitests/test_parallel_conn_and_rand.sli | 100 ++++++++++++ 12 files changed, 339 insertions(+), 589 deletions(-) create mode 100644 pynest/examples/hh_psc_alpha.py create mode 100644 pynest/nest/tests/test_pp_psc_delta_stdp.py delete mode 100644 testsuite/manualtests/parallel_conn_and_rand.sli delete mode 100755 testsuite/manualtests/test_connect_array_fixed_outdegree_mpi.sh delete mode 100644 testsuite/manualtests/test_hh_psc_alpha.sli delete mode 100644 testsuite/manualtests/test_pp_psc_delta_stdp.py delete mode 100644 testsuite/manualtests/ticket-737-DScallback.sli create mode 100644 testsuite/mpitests/test_parallel_conn_and_rand.sli diff --git a/pynest/examples/hh_psc_alpha.py b/pynest/examples/hh_psc_alpha.py new file mode 100644 index 0000000000..f994771145 --- /dev/null +++ b/pynest/examples/hh_psc_alpha.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- +# +# hh_psc_alpha.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 . + +""" +Example using hh_psc_alpha +-------------------------- + +This example produces a rate-response (FI) curve of the Hogkin-Huxley +neuron in response to a range of different current (DC) stimulations. +The result is plotted using matplotlib. + +Since a DC input affetcs only the neuron's channel dynamics, this routine +does not yet check correctness of synaptic response. +""" + +import nest +import numpy as np +import matplotlib.pyplot as plt + +nest.set_verbosity('M_WARNING') +nest.ResetKernel() + +simtime = 1000 + +# Amplitude range, in pA +dcfrom = 0 +dcstep = 20 +dcto = 2000 + +h = 0.1 # simulation step size in mS + +neuron = nest.Create('hh_psc_alpha') +sd = nest.Create('spike_detector') + +nest.SetStatus(sd, {'to_memory': False}) + +nest.Connect(neuron, sd, syn_spec={'weight': 1.0, 'delay': h}) + + +# Simulation loop +n_data = dcto / float(dcstep) +amplitudes = np.zeros(n_data) +event_freqs = np.zeros(n_data) +for i, amp in enumerate(range(dcfrom, dcto, dcstep)): + nest.SetStatus(neuron, {'I_e': float(amp)}) + print("Simulating with current I={} pA".format(amp)) + nest.Simulate(1000) # one second warm-up time for equilibrium state + nest.SetStatus(sd, {'n_events': 0}) # then reset spike counts + nest.Simulate(simtime) # another simulation call to record neuron's 'clean' firing rate + + n_events = nest.GetStatus(sd, keys={'n_events'})[0][0] + amplitudes[i] = amp + event_freqs[i] = n_events / (simtime / 1000.) + +plt.plot(amplitudes, event_freqs) +plt.show() diff --git a/pynest/nest/tests/test_pp_psc_delta.py b/pynest/nest/tests/test_pp_psc_delta.py index f84c3f2fcd..fa0f77bf0e 100644 --- a/pynest/nest/tests/test_pp_psc_delta.py +++ b/pynest/nest/tests/test_pp_psc_delta.py @@ -28,7 +28,9 @@ class PpPscDeltaTestCase(unittest.TestCase): """Tests for pp_psc_delta""" def test_rate_and_fixed_dead_time(self): - """Check for reasonable firing rate and if fixed dead-time is respected""" + """ + Check for reasonable firing rate and if fixed dead-time is respected + """ # test parameters d = 25.0 diff --git a/pynest/nest/tests/test_pp_psc_delta_stdp.py b/pynest/nest/tests/test_pp_psc_delta_stdp.py new file mode 100644 index 0000000000..99a6d14941 --- /dev/null +++ b/pynest/nest/tests/test_pp_psc_delta_stdp.py @@ -0,0 +1,93 @@ +# -*- coding: utf-8 -*- +# +# test_pp_psc_delta_stdp.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 . + +import unittest +import nest +import numpy as np + + +class PpPscDeltaSTDPTestCase(unittest.TestCase): + """ + Regressiontest to reproduce failure of pp_psc_delta to show spike + timing dependent plasticity (STDP), as opposed to iaf_psc_delta. + The problem is probably related to the setting of 'archiver_length'. + + Moritz Deger, moritz.deger@epfl.ch, Aug 14, 2015 + """ + + def test_pp_psc_delta_stdp(self): + Dt = 1. + nsteps = 100 + w_0 = 100. + + nest.ResetKernel() + + nrn_pre = nest.Create('parrot_neuron') + nrn_post1 = nest.Create('iaf_psc_delta') + nrn_post2 = nest.Create('pp_psc_delta') + + nest.Connect(nrn_pre, nrn_post1 + nrn_post2, + syn_spec={'model': 'stdp_synapse', 'weight': w_0}) + conn1 = nest.GetConnections(nrn_pre, nrn_post1) + conn2 = nest.GetConnections(nrn_pre, nrn_post2) + + sg_pre = nest.Create('spike_generator') + nest.SetStatus(sg_pre, + {'spike_times': np.arange(Dt, nsteps * Dt, 10. * Dt)}) + nest.Connect(sg_pre, nrn_pre) + + mm = nest.Create('multimeter') + nest.SetStatus(mm, {'record_from': ['V_m']}) + nest.Connect(mm, nrn_post1 + nrn_post2) + + sd = nest.Create('spike_detector') + nest.Connect(nrn_pre + nrn_post1 + nrn_post2, sd) + + t = [] + w1 = [] + w2 = [] + t.append(0.) + w1.append(nest.GetStatus(conn1, keys=['weight'])[0][0]) + w2.append(nest.GetStatus(conn2, keys=['weight'])[0][0]) + + for i in xrange(nsteps): + nest.Simulate(Dt) + t.append(i * Dt) + w1.append(nest.GetStatus(conn1, keys=['weight'])[0][0]) + w2.append(nest.GetStatus(conn2, keys=['weight'])[0][0]) + + archiver_length1 = nest.GetStatus(nrn_post1, + keys=['archiver_length'])[0] + archiver_length2 = nest.GetStatus(nrn_post2, + keys=['archiver_length'])[0] + self.assertEqual(archiver_length1, archiver_length2) + + +def suite(): + + suite = unittest.makeSuite(PpPscDeltaSTDPTestCase, 'test') + return suite + + +if __name__ == "__main__": + + runner = unittest.TextTestRunner(verbosity=2) + runner.run(suite()) diff --git a/testsuite/manualtests/parallel_conn_and_rand.sli b/testsuite/manualtests/parallel_conn_and_rand.sli deleted file mode 100644 index 3d30509095..0000000000 --- a/testsuite/manualtests/parallel_conn_and_rand.sli +++ /dev/null @@ -1,138 +0,0 @@ -/* - * parallel_conn_and_rand.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 . - * - */ - -/* - Parallel Connect and Randomize Test Script - - This script creates a neuron population to itself, randomizing - weight, delay, receptor type and one synaptic parameter. It - then dumps the complete connectivity to file pcar_NumMPIProcs_Rank.conn, - one line per connection. - - This script runs with a fixed number of virtual processes (default 16). - The script should be executed with varying numbers of MPI processes. - By merging and sorting results across ranks for each MPI process number - and comparing the resulting files, one can test whether identical - connections are created for all MPI-thread splits and thus test - for correct parallelization. - - Hans Ekkehard Plesser -*/ - -%%% PARAMETER SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -% define all relevant parameters: changes should be made here -% all data is place in the userdict dictionary - -/num_neurons 1000 def - -/connspec << /rule /fixed_indegree /indegree 100 >> def -%/connspec << /rule /fixed_outdegree /outdegree 100 >> def - -/num_vps 16 def - -/simtime 10.0 def % simulation time [ms] -/dt 0.1 def % simulation step length [ms] - -%%% HELPER SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -/padded -{ - dup 10 lt - { - cvs (0) exch join - } - { - cvs - } - ifelse -} def - -%%% CONSTRUCTION SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - -ResetKernel % clear all existing network elements -M_WARNING setverbosity - - -% set resolution and total/local number of threads -0 << - /resolution dt - /total_num_virtual_procs num_vps - /overwrite_files true ->> SetStatus - -tic % start timer on construction - -(Creating the network.) = - -% setup to allow us to randomize receptor_type -/tau_syns [0.2 1.0 0.1] Range def -/receptor_min 1 def -/receptor_max tau_syns length def -/iaf_psc_alpha_multisynapse << /tau_syn tau_syns >> SetDefaults - -/iaf_psc_alpha_multisynapse [ num_neurons ] LayoutNetwork -GetGlobalLeaves /population Set - - -(Connecting neurons.) = -population population connspec -<< /model /stdp_synapse - /delay << /distribution /uniform /low 0.5 /high 1.5 >> - /weight << /distribution /normal /mu 10.0 /sigma 5.0 >> - /receptor_type << /distribution /uniform_int /low receptor_min /high receptor_max >> - /alpha << /distribution /uniform /low 0.1 /high 2.3 >> - /tau_plus << /distribution /uniform /low 1.5 /high 5.0 >> ->> -Connect - -(Done connecting.) = - -toc /BuildCPUTime Set - -% dump connections to file -/fname (pcar_) NumProcesses padded join (_) join Rank padded join (.conn) join def - -(Dumping to file ) fname join = -/of fname (w) file def -<< /synapse_model /stdp_synapse >> GetConnections -{ - [[/source /target /weight /delay /alpha /tau_plus]] get - { of exch <- (\t) <- ; } forall - of endl ; -} forall -of close -(Done dumping) = - -%%% SIMULATION SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -(Simulating) = -simtime Simulate -(Done simulating) = - -(Number of MPI procs: ) =only NumProcesses = -(Number of VPs : ) =only num_vps = -(Number of Neurons : ) =only num_neurons = -(Number of Synapses : ) =only 0 GetStatus /num_connections get = -(Building time : ) =only BuildCPUTime =only ( s\n) = - diff --git a/testsuite/manualtests/test_connect_array_fixed_outdegree_mpi.sh b/testsuite/manualtests/test_connect_array_fixed_outdegree_mpi.sh deleted file mode 100755 index d9d12f6f31..0000000000 --- a/testsuite/manualtests/test_connect_array_fixed_outdegree_mpi.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash -# -# This file is part of NEST. -# -# Checks the output of the SLI script -# test_connect_array_fixed_outdegree_mpi.sli -# It should be run in the directory that contains the SLI script output files -# (proc_0.tmp, proc_1.tmp, ...) -# Usage: ./test_connect_array_fixed_outdegree_mpi.sh number-of-MPI-processes -# -# Author: Bruno Golosio 2016 -# -# - -re='^[0-9]+$' -if [ "$#" -ne 1 ] || ! [[ $1 =~ $re ]]; then - echo "Usage: $0 number-of-MPI-processes" - exit -fi - -NP=$1 # number of MPI processes -N=20 # number of neurons -K=5 # number of outgoing connections per source neuron - -:> conn.tmp -for neur in $(seq 1 $N); do # loop on source neurons - conn="" - for p in $(seq 0 $(expr $NP - 1)); do # loop on MPI processes - filename=proc_$p.tmp - if [ ! -f $filename ]; then - echo "Error: file $filename not found." - exit - fi - # get outgoing neuron connections created in the process p - conn1=$(cat $filename | grep "^$neur:" | sed "s/$neur://") - conn="$conn $conn1" # join all connections of neuron p - done - K1=$(echo $conn | tr ' ' '\n' | wc -l) - if [ "$K1" -ne "$K" ]; then # check the number of outgoing connections - echo Error: wrong number of connections. - exit - fi - echo $conn | tr ' ' '\n' | sort -n >> conn.tmp # sort connections -done -seq 1 $(expr $N \* $K) > conn1.tmp # file containing the sequence 1,...,N*K -conn_diff=$(diff conn.tmp conn1.tmp) # check connection elements -if [ -n "$conn_diff" ]; then - echo Error: wrong connections. - exit -fi -echo OK diff --git a/testsuite/manualtests/test_hh_psc_alpha.sli b/testsuite/manualtests/test_hh_psc_alpha.sli deleted file mode 100644 index b7b0c85adc..0000000000 --- a/testsuite/manualtests/test_hh_psc_alpha.sli +++ /dev/null @@ -1,122 +0,0 @@ -/* - * test_hh_psc_alpha.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::test_hh_psc_alpha - sli script for hh_psc_alpha model - -Synopsis: (test_hh_psc_alpha) run -> 'rates.txt' - - -Description: - - test_hh_psc_alpha produces a rate-response (FI) curve of the Hogkin-Huxley - neuron in response to a range of different current (DC) stimulations. - The result is stored in an extra file, rates.txt, and can be plotted, - e.g. in matlab using - x=load('hh_rates.txt'); plot(x(:,1),x(:,2)) - or - plot "hh_rates.txt" with lines; - in gnuplot - - Since a DC input affetcs only the neuron's channel dynamics, this routine - does not yet check correctness of synaptic response. - -Author: Schrader - -SeeAlso: iaf_psc_exp, iaf_neuron, testsuite::test_iaf_i0, testsuite::test_iaf_i0_refractory, testsuite::test_iaf_dc -*/ - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PARAMETER SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - /simtime 1000 def % simulation time in ms - the longer the smoother the curve - - % amplitude range - in pA - /dcfrom 0 def - /dcstep 20 def - /dcto 2000 def - - 0.1 /h Set % simulation step size in mS - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FUNCTION SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - /rateprint { - f % file handle - amp print (\t) print % print amplidute with tab - sd GetStatus /n_events get % get number of spikes - simtime 1000 div div % convert to Hz - print endl ; % linefeed and pop - } bind def - -%%%%%%%%%%%%%%%%%%%%%%%%%%%% SIMULATION SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - % open datafile - (hh_rates.txt) ofstream - { - /f Set - } - { - /test_hh_psc_alpha /CouldNotOpenFile raiseerror - } ifelse - - - ResetKernel % clear all existing network elements - - modeldict begin - synapsedict begin - userdict begin - - /hh_psc_alpha Create /neuron Set - /spike_detector Create /sd Set - - sd << /to_memory false >> SetStatus % spikes are not recorded but number of spikes (n_events) - - neuron sd 1.0 h Connect - - M_WARNING setverbosity % hide multiple simulation calls - - % simulation loop - dcfrom dcstep dcto { - - cvd /amp Set % dc stimulation in pA - neuron << /I_e amp >> SetStatus - - (Simulating with current I=) amp cvs join (pA) join = - - 1000 Simulate % one second warm-up time for equilibrium state - sd << /n_events 0 >> SetStatus % then reset spike counts - simtime Simulate % another simulation call to record neuron's 'clean' firing rate - - rateprint % print result to file - - } bind - for - - end - end - end - - % close datafile - f close - - (done.) = - \ No newline at end of file diff --git a/testsuite/manualtests/test_pp_psc_delta_stdp.py b/testsuite/manualtests/test_pp_psc_delta_stdp.py deleted file mode 100644 index 3670afb5bc..0000000000 --- a/testsuite/manualtests/test_pp_psc_delta_stdp.py +++ /dev/null @@ -1,95 +0,0 @@ -# -*- coding: utf-8 -*- -# -# test_pp_psc_delta_stdp.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 . - -# -# Moritz Deger, moritz.deger@epfl.ch, Aug 14, 2015 -# -# -# Python script to reproduce failure of pp_psc_delta to show spike timing -# dependent plasticity (STDP), as opposed to iaf_psc_delta. -# The problem is probably related to the setting of 'archiver_length' -# (printed at the end of the script) - - -import nest -import nest.raster_plot -import numpy as np -import pylab - -Dt = 1. -nsteps = 100 -w_0 = 100. - -nest.ResetKernel() - -nrn_pre = nest.Create('parrot_neuron') -nrn_post1 = nest.Create('iaf_psc_delta') -nrn_post2 = nest.Create('pp_psc_delta') - -nest.Connect(nrn_pre, nrn_post1 + nrn_post2, - syn_spec={'model': 'stdp_synapse', 'weight': w_0}) -conn1 = nest.GetConnections(nrn_pre, nrn_post1) -conn2 = nest.GetConnections(nrn_pre, nrn_post2) - -sg_pre = nest.Create('spike_generator') -nest.SetStatus(sg_pre, {'spike_times': np.arange(Dt, nsteps * Dt, 10. * Dt)}) -nest.Connect(sg_pre, nrn_pre) - -mm = nest.Create('multimeter') -nest.SetStatus(mm, {'record_from': ['V_m']}) -nest.Connect(mm, nrn_post1 + nrn_post2) - -sd = nest.Create('spike_detector') -nest.Connect(nrn_pre + nrn_post1 + nrn_post2, sd) - -t = [] -w1 = [] -w2 = [] -t.append(0.) -w1.append(nest.GetStatus(conn1, keys=['weight'])[0][0]) -w2.append(nest.GetStatus(conn2, keys=['weight'])[0][0]) - -for i in xrange(nsteps): - nest.Simulate(Dt) - t.append(i * Dt) - w1.append(nest.GetStatus(conn1, keys=['weight'])[0][0]) - w2.append(nest.GetStatus(conn2, keys=['weight'])[0][0]) - -pylab.figure(1) -pylab.plot(t, w1, 'g', label='iaf_psc_delta, ' + str(nrn_post1[0])) -pylab.plot(t, w2, 'r', label='pp_psc_delta, ' + str(nrn_post2[0])) -pylab.xlabel('time [ms]') -pylab.ylabel('weight [mV]') -pylab.legend(loc='best') -ylims = pylab.ylim() -pylab.ylim(ylims[0] - 5, ylims[1] + 5) -# pylab.savefig('test_pp_psc_delta_stdp_fig1.png') - -nest.raster_plot.from_device(sd) -ylims = pylab.ylim() -pylab.ylim(ylims[0] - .5, ylims[1] + .5) -pylab.show() -# pylab.savefig('test_pp_psc_delta_stdp_fig2.png') - - -print('Archiver lengths shall be equal:') -for nrn in [nrn_post1, nrn_post2]: - print(nest.GetStatus(nrn, keys=['model', 'archiver_length'])[0]) diff --git a/testsuite/manualtests/test_spike_poisson_ps_base2_nd.sli b/testsuite/manualtests/test_spike_poisson_ps_base2_nd.sli index 3bce80b574..3b2a06f85b 100644 --- a/testsuite/manualtests/test_spike_poisson_ps_base2_nd.sli +++ b/testsuite/manualtests/test_spike_poisson_ps_base2_nd.sli @@ -45,11 +45,12 @@ precision of a tic. M_ERROR setverbosity -0 /min_exponent Set +-2 /min_exponent Set /Transmission { dexp /h Set +(res = ) h cvs join = /T 4.0 def @@ -81,8 +82,10 @@ sp [/events [/times /offsets]] get cva dup == [0 min_exponent -2] Range { Transmission } Map - -% dup Rest exch First {sub} exch prepend % Map - +0 get +(########) = +pstack (OOOOOOOOO) = +dup Rest pstack (xxxxxxx) = exch First {sub} exch prepend pstack (IIIIIIII) = Map +pstack %Flatten { 0.0 neq } Select [] eq % comment these two last lines to see the %assert_or_die % minimal differences causing the failure diff --git a/testsuite/manualtests/test_stdp_poiss.sli b/testsuite/manualtests/test_stdp_poiss.sli index e7a2035545..eb51822176 100644 --- a/testsuite/manualtests/test_stdp_poiss.sli +++ b/testsuite/manualtests/test_stdp_poiss.sli @@ -85,11 +85,11 @@ pg_in << /spike_detector Create /sd Set -sd << /withtime true /withgid true /to_file true >> SetStatus +sd << /withtime true /withgid true >> SetStatus /voltmeter Create /vm Set -vm << /withtime true /withgid true /to_file true >> SetStatus +vm << /withtime true /withgid true >> SetStatus @@ -131,17 +131,9 @@ neuron1 neuron2 /stdp_synapse Connect -neuron2 GetStatus /local get -{ - (weight.gdf) (w) file /f_weight Set -} if - - - - 40000.0 /T Set -100.0 /dt Set +%100.0 /dt Set %76.0 /dt Set 50.0 /dt Set %10000.0 /dt Set @@ -155,13 +147,13 @@ neuron2 GetStatus /local get neuron2 GetStatus /local get { % we are on the machine where neuron2 resides - << /source neuron1 /synapse_model /stdp_synapse >> GetConnections + << /source [neuron1] /synapse_model /stdp_synapse >> GetConnections 0 get GetStatus /weight get /w Set %we know that there is only a single synapse w == - f_weight t <- (\t) <- w <- endl pop + %f_weight t <- (\t) <- w <- endl pop } if diff --git a/testsuite/manualtests/ticket-737-DScallback.sli b/testsuite/manualtests/ticket-737-DScallback.sli deleted file mode 100644 index a9d3302a7a..0000000000 --- a/testsuite/manualtests/ticket-737-DScallback.sli +++ /dev/null @@ -1,69 +0,0 @@ -/* - * ticket-737-DScallback.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::ticket-737 - ensure generators depending on port info detect "bad wiring" - -Synopsis: (ticket-737-DScallback) run -> NEST exits if test fails - -Description: -This tests ensures that generators relying on port information to provide target-specific -output via the DS-callback mechanism verify that all callback connections have a contiguous -port range starting from 0. - -Remarks: -This test does not work properly until #681 is fixed, because exceptions thrown in parallel -sections are not handled properly. - -Author: Hans Ekkehard Plesser, 2013-05-06 - */ - -(unittest) run -/unittest using - -M_ERROR setverbosity - -/all_fine true def - -[ /noise_generator - /ppd_sup_generator - /gamma_sup_generator - /sinusoidal_gamma_generator ] -{ - /gentype Set - - ResetKernel - - /static_synapse /A CopyModel - /static_synapse /B CopyModel - /gen1 gentype Create def - /gen2 gentype Create def - /nrns [ 6 ] { ; /iaf_neuron Create } Table def - [gen1] nrns 3 Take << /rule /all_to_all >> << /model /A >> Connect - [gen2] nrns -3 Take << /rule /all_to_all >> << /model /B >> Connect - - gentype == - { 1 Simulate } fail_or_die -} forall - -endusing diff --git a/testsuite/mpitests/test_connect_array_fixed_outdegree_mpi.sli b/testsuite/mpitests/test_connect_array_fixed_outdegree_mpi.sli index 0724635a47..bb6481ce13 100644 --- a/testsuite/mpitests/test_connect_array_fixed_outdegree_mpi.sli +++ b/testsuite/mpitests/test_connect_array_fixed_outdegree_mpi.sli @@ -40,114 +40,75 @@ (unittest) run /unittest using -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% for a more comprehensive test, uncomment the line for writing the -% results in files, and check the results using the bash script -% test_connect_array_fixed_outdegree_mpi.sh with the number of -% MPI processes as argument: -% ./test_connect_array_fixed_outdegree_mpi.sh number-of-MPI-processes -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +skip_if_not_threaded -/write_file false def -% Uncomment the following line for writing the results in files -%/write_file true def +[1 2 3] % check for 1, 2, 3 processes +{ + /N 20 def % number of neurons in each subnet + /K 5 def % number of connections per neuron -skip_if_not_threaded + ResetKernel -[2 3] % check for 2, 3 processes -{ + 0 << + /local_num_threads 2 + >> SetStatus -/N 20 def % number of neurons in each subnet -/K 5 def % number of connections per neuron + /gid1 N 1 add def % gid1 = N + 1 + /gid2 N 2 mul def % gid2 = N * 2 + /net1 [1 N] Range def % global ids of source subnet + /net2 [gid1 gid2] Range def % global ids of target subnet -ResetKernel + /iaf_neuron N 2 mul Create ; % creates source and target subnets -0 << - /local_num_threads 2 ->> SetStatus + /NC N K mul def % number of connections + /Dmax NC 1 add def % maximum delay -write_file{ - /filename (proc_) Rank cvs join (.tmp) join def - % cout filename print - /fp filename (w) file def -} if + /Warr [1 NC] Range cv_dv def % weight array Warr=[1, ..., NC] + /Darr [2 Dmax] Range cv_dv def % delay array Darr=[2, ..., NC+1] + % cv_dv converts sli-array type to double-vector type -/gid1 N 1 add def % gid1 = N + 1 -/gid2 N 2 mul def % gid2 = N * 2 -/net1 [1 N] Range def % global ids of source subnet -/net2 [gid1 gid2] Range def % global ids of target subnet + % synapses and connection dictionaries + /syn_dict << /model /static_synapse /weight Warr /delay Darr >> def + /conn_dict << /rule /fixed_outdegree /outdegree K >> def -/iaf_neuron N 2 mul Create ; % creates source and target subnets + net1 net2 conn_dict syn_dict Connect % connects source to target subnet -/NC N K mul def % number of connections -/Dmax NC 1 add def % maximum delay + /Warr_all 0 array def % creates empty weight array + net1 % loop on all neurons of source subnet + { + /neuron1 exch def -/Warr [1 NC] Range cv_dv def % weight array Warr=[1, ..., NC] -/Darr [2 Dmax] Range cv_dv def % delay array Darr=[2, ..., NC+1] -% cv_dv converts sli-array type to double-vector type + % gets all connections from the source neuron + /conn << /source [neuron1] >> GetConnections def -% synapses and connection dictionaries -/syn_dict << /model /static_synapse /weight Warr /delay Darr >> def -/conn_dict << /rule /fixed_outdegree /outdegree K >> def + /sdict_lst conn GetSynapseStatus def % gets info on synapses -net1 net2 conn_dict syn_dict Connect % connects source to target subnet + /Warr1 0 array def % creates empty weight array + + sdict_lst % loop on synapses that connect from source neuron + { + /sdict exch def + /w sdict /weight get def % gets synaptic weight + /d sdict /delay get def % gets synaptic delay + /diff d w sub def % diff = delay - weight + diff 1.0 eq assert_or_die % checks that d = w + 1 + + /Warr1 Warr1 w append def % appends w to Warr1 + } forall + + /i1 neuron1 1 sub K mul def % first index = (n1 - 1) * K + + % get row of original weight array + /Wrow Warr cva i1 K getinterval def + Warr1 { + /w exch def + % check that all elements of Warr are in Wrow + Wrow w MemberQ assert_or_die + } forall + /Warr_all Warr_all Warr1 join def + + } forall + Warr_all +} distributed_process_invariant_collect_assert_or_die -/pass true def % error control flag -net1 % loop on all neurons of source subnet -{ - /neuron1 exch def - write_file { - fp neuron1 cvs (:) join print ; - } if - - %cout (n1 ) print neuron1 = - % gets all connections from the source neuron - /conn << /source [neuron1] >> GetConnections def - - /sdict_lst conn GetSynapseStatus def % gets info on synapses - - /Warr1 0 array def % creates empty weight array - - sdict_lst % loop on synapses that connect from source neuron - { - /sdict exch def - /w sdict /weight get def % gets synaptic weight - /d sdict /delay get def % gets synaptic delay - /diff d w sub def % diff = delay - weight - diff 1.0 eq % checks that d = w + 1 - pass and /pass exch def % updates control flag - - /Warr1 Warr1 w append def % appends w to Warr1 - } forall - - %cout (Wl ) print Warr1 length = % checks the size of Warr1 - %/Warr1 Warr1 Sort def % sorts the elements of Warr1 - write_file { - Warr1 { - fp ( ) print ; - fp exch cvs print ; - } forall - fp endl ; - } if - - /i1 neuron1 1 sub K mul def % first index = (n1 - 1) * K - - % get row of original weight array - /Wrow Warr cva i1 K getinterval def - Warr1 { - /w exch def - % check that all elements of Warr are in Wrow - Wrow w MemberQ - pass and /pass exch def % updates control flag - - } forall - -} forall - -write_file { - fp close -} if - -pass -} distributed_collect_assert_or_die diff --git a/testsuite/mpitests/test_parallel_conn_and_rand.sli b/testsuite/mpitests/test_parallel_conn_and_rand.sli new file mode 100644 index 0000000000..05ac426d3e --- /dev/null +++ b/testsuite/mpitests/test_parallel_conn_and_rand.sli @@ -0,0 +1,100 @@ +/* + * test_parallel_conn_and_rand.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 . + * + */ + +/* + Parallel Connect and Randomize Test Script + + This script creates a neuron population to itself, randomizing + weight, delay, receptor type and one synaptic parameter. It runs + with a fixed number of virtual processes, and checks that connections + are invariant on executing with a varying number of MPI processes. + + Hans Ekkehard Plesser +*/ + +(unittest) run +/unittest using + +skip_if_not_threaded + +%%% PARAMETER SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% define all relevant parameters: changes should be made here +% all data is place in the userdict dictionary + +/num_neurons 10 def +%/num_neurons 1000 def + +/connspec << /rule /fixed_indegree /indegree 1 >> def +%/connspec << /rule /fixed_outdegree /outdegree 100 >> def + +/num_vps 16 def + +/simtime 10.0 def % simulation time [ms] +/dt 0.1 def % simulation step length [ms] + +%%% CONSTRUCTION SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +[1 2 4] +{ + ResetKernel % clear all existing network elements + M_WARNING setverbosity + + % set resolution, total/local number of threads, rng seed + 0 << + /resolution dt + /total_num_virtual_procs num_vps + /grng_seed 123 + >> SetStatus + + (Creating the network.) = + + % setup to allow us to randomize receptor_type + /tau_syns [0.2 1.0 0.1] Range def + /receptor_min 1 def + /receptor_max tau_syns length def + /iaf_psc_alpha_multisynapse << /tau_syn tau_syns >> SetDefaults + + /iaf_psc_alpha_multisynapse [ num_neurons ] LayoutNetwork + GetGlobalLeaves /population Set + + (Connecting neurons.) = + population population connspec + << /model /stdp_synapse + /delay << /distribution /uniform /low 0.5 /high 1.5 >> + /weight << /distribution /normal_clipped /low 0.0 /mu 10.0 /sigma 5.0 >> + /receptor_type << /distribution /uniform_int /low receptor_min /high receptor_max >> + /alpha << /distribution /uniform /low 0.1 /high 2.3 >> + /tau_plus << /distribution /uniform /low 1.5 /high 5.0 >> + >> + Connect + + (Done connecting.) = + + /conn_arr 0 array def + << /synapse_model /stdp_synapse >> GetConnections + { + [[/source /target /weight /delay /alpha /tau_plus]] get conn_arr exch append /conn_arr Set + } forall + conn_arr +} distributed_process_invariant_collect_assert_or_die + From a228d6e5d55d75e9f6521db9cb06b2add0ecbc04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20M=C3=B8rk?= Date: Mon, 10 Jul 2017 10:36:18 +0200 Subject: [PATCH 13/20] Updated test, PEP8 issue --- pynest/examples/hh_psc_alpha.py | 2 +- testsuite/manualtests/test_stdp_hom_poiss.sli | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pynest/examples/hh_psc_alpha.py b/pynest/examples/hh_psc_alpha.py index f994771145..6deeb55ad3 100644 --- a/pynest/examples/hh_psc_alpha.py +++ b/pynest/examples/hh_psc_alpha.py @@ -64,7 +64,7 @@ print("Simulating with current I={} pA".format(amp)) nest.Simulate(1000) # one second warm-up time for equilibrium state nest.SetStatus(sd, {'n_events': 0}) # then reset spike counts - nest.Simulate(simtime) # another simulation call to record neuron's 'clean' firing rate + nest.Simulate(simtime) # another simulation call to record firing rate n_events = nest.GetStatus(sd, keys={'n_events'})[0][0] amplitudes[i] = amp diff --git a/testsuite/manualtests/test_stdp_hom_poiss.sli b/testsuite/manualtests/test_stdp_hom_poiss.sli index 8830274511..50f4f111b0 100644 --- a/testsuite/manualtests/test_stdp_hom_poiss.sli +++ b/testsuite/manualtests/test_stdp_hom_poiss.sli @@ -148,7 +148,7 @@ neuron2 GetStatus /local get neuron2 GetStatus /local get { - << /source neuron1 /synapse_model /stdp_synapse_hom >> GetConnections 0 get + << /source [neuron1] /synapse_model /stdp_synapse_hom >> GetConnections 0 get GetStatus /weight get /w Set w == From 1e57e861d70aa796f016abbbdbce32cf950d8b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20M=C3=B8rk?= Date: Tue, 18 Jul 2017 09:03:21 +0200 Subject: [PATCH 14/20] Reverted 2e8d285 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 34fb0c8fcb..bf7378ddf4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,6 @@ language: generic sudo: required dist: trusty #https://blog.travis-ci.com/2017-06-19-trusty-updates-2017-Q2 -group: deprecated-2017Q2 env: matrix: From 8993de9ecd97f57bbdcf3412b2559d0366a49e0c Mon Sep 17 00:00:00 2001 From: Stine Vennemo Date: Mon, 14 Aug 2017 11:21:21 +0200 Subject: [PATCH 15/20] Started converting one of the tests to pythontest --- .../cross_check_test_mip_corrdet.py | 137 +++++++++++++++++- .../manualtests/parallel_conn_and_rand.sli | 4 +- testsuite/unittests/test_mip_corrdet.sli | 12 +- 3 files changed, 141 insertions(+), 12 deletions(-) diff --git a/testsuite/manualtests/cross_check_test_mip_corrdet.py b/testsuite/manualtests/cross_check_test_mip_corrdet.py index 6d7d9eeb53..a29611a2cd 100644 --- a/testsuite/manualtests/cross_check_test_mip_corrdet.py +++ b/testsuite/manualtests/cross_check_test_mip_corrdet.py @@ -31,8 +31,132 @@ from scipy import * from matplotlib.pylab import * # for plot - - +import nest +import unittest + + +@nest.check_stack +class mipCorrdetTestCase(unittest.TestCase): + """Testing mip_generator and correlation_detector.""" + + def test_mip_generator_correlation_detector(self): + nest.ResetKernel() + + # Cross check generated with cross_check_test_mip_corrdet.py + exptected_hist = [2453., 2528., 2507., 2439., 2459., 2451., 2441., 2523., 2494., + 2445., 4909., 2369., 2410., 2457., 2495., 2484., 2369., 2341., + 2452., 2475., 2453.] + + h = 0.1 # Computation step size in ms + T = 100000.0 # Total duration + delta_tau = 10.0 + tau_max = 100.0 + pc = 0.5 + nu = 100.0 + + # grng_seed is 0 because test data was produced for seed = 0 + nest.SetKernelStatus({'local_num_threads': 1, 'resolution': h, + 'overwrite_files': True, 'grng_seed': 0}) + + # Check, if we can set another rng + # nest.SetDefaults('mip_generator', ) + #/mip_generator << /mother_rng rngdict/MT19937 :: 101 CreateRNG >> SetDefaults + #/mip_generator << /mother_rng rngdict/knuthlfg :: 101 CreateRNG >> SetDefaults % this seed will be ignored, because explicitly set + + + mg = nest.Create('mip_generator') + nest.SetStatus(mg, {'rate': nu, 'p_copy': pc}) + + cd = nest.Create('correlation_detector') + nest.SetStatus(cd, {'tau_max': tau_max, 'delta_tau': delta_tau}) + + sd = nest.Create('spike_detector') + nest.SetStatus(sd, {'withtime': True, + 'withgid': True, 'time_in_steps': True}) + + pn1 = nest.Create('parrot_neuron') + pn2 = nest.Create('parrot_neuron') + + nest.Connect(mg, pn1) + nest.Connect(mg, pn2) + nest.Connect(pn1, sd) + nest.Connect(pn2, sd) + + nest.SetDefaults('static_synapse', {'weight': 1.0, 'receptor_type': 0}) + nest.Connect(pn1, cd) + + nest.SetDefaults('static_synapse', {'weight': 1.0, 'receptor_type': 1}) + nest.Connect(pn2, cd) + + nest.Simulate(T) + + hist = [x for x in nest.GetStatus(cd)[0]['histogram']] + n_events = nest.GetStatus(cd)[0]['n_events'] + n1 = n_events[0] + n2 = n_events[1] + + lmbd1 = ( n1 / ( T - tau_max ) ) * 1000.0 + lmbd2 = ( n2 / ( T - tau_max ) ) * 1000.0 + + print(hist) + print(lmbd1) + print(lmbd2) + + print(nest.GetStatus(sd)) + + self.assertEqual(hist, exptected_hist) + + + + h = 0.1 + tau_max = 100.0 # ms correlation window + t_bin = 10.0 # ms bin size + + spikes = nest.GetStatus(sd)[0]['events']['senders'] + print(spikes) + print(find(spikes[:] == 4)) + + sp1 = find(spikes[:] == 4) + sp2 = find(spikes[:] == 5) + + cross = self.corr_spikes_sorted(sp1, sp2, t_bin, tau_max, h) + + print(cross) + print(sum(cross)) + + def corr_spikes_sorted(self, spike1, spike2, tbin, tau_max, h): + tau_max_i = int(tau_max / h) + tbin_i = int(tbin / h) + + cross = zeros(int(2 * tau_max_i / tbin_i + 1), 'd') + + j0 = 0 + + for spki in spike1: + j = j0 + while j < len(spike2) and spike2[j] - spki < -tau_max_i - tbin_i / 2.0: + j += 1 + j0 = j + + while j < len(spike2) and spike2[j] - spki < tau_max_i + tbin_i / 2.0: + cross[int( + (spike2[j] - spki + tau_max_i + 0.5 * tbin_i) / tbin_i)] += 1.0 + j += 1 + + return cross + +def suite(): + suite = unittest.makeSuite(mipCorrdetTestCase, 'test') + return suite + + +def run(): + runner = unittest.TextTestRunner(verbosity=2) + runner.run(suite()) + +if __name__ == "__main__": + run() + # Auto- and crosscorrelation functions for spike trains. # # A time bin of size tbin is centered around the time difference it @@ -41,7 +165,6 @@ # bin are those for which tau in [-tau_max-tbin/2, tau_max+tbin/2) and # so on. - # correlate two spike trains with each other # assumes spike times to be ordered in time # tau > 0 means spike2 is later than spike1 @@ -51,6 +174,8 @@ # spike1: first spike train [tspike...] # spike2: second spike train [tspike...] # + +""" def corr_spikes_sorted(spike1, spike2, tbin, tau_max, h): tau_max_i = int(tau_max / h) tbin_i = int(tbin / h) @@ -74,13 +199,16 @@ def corr_spikes_sorted(spike1, spike2, tbin, tau_max, h): def main(): + + make_spikes() + # resolution h = 0.1 tau_max = 100.0 # ms correlation window t_bin = 10.0 # ms bin size # read input from spike detector - spikes = load('spike_detector-0-0-3.gdf') + spikes = load('spike_detector-3-0.gdf') sp1 = spikes[find(spikes[:, 0] == 4), 1] sp2 = spikes[find(spikes[:, 0] == 5), 1] @@ -92,3 +220,4 @@ def main(): main() +""" \ No newline at end of file diff --git a/testsuite/manualtests/parallel_conn_and_rand.sli b/testsuite/manualtests/parallel_conn_and_rand.sli index 3d30509095..6b23add6bf 100644 --- a/testsuite/manualtests/parallel_conn_and_rand.sli +++ b/testsuite/manualtests/parallel_conn_and_rand.sli @@ -99,7 +99,7 @@ GetGlobalLeaves /population Set population population connspec << /model /stdp_synapse /delay << /distribution /uniform /low 0.5 /high 1.5 >> - /weight << /distribution /normal /mu 10.0 /sigma 5.0 >> + /weight << /distribution /uniform /low 5.0 /high 15.0 >> /receptor_type << /distribution /uniform_int /low receptor_min /high receptor_max >> /alpha << /distribution /uniform /low 0.1 /high 2.3 >> /tau_plus << /distribution /uniform /low 1.5 /high 5.0 >> @@ -117,7 +117,7 @@ toc /BuildCPUTime Set /of fname (w) file def << /synapse_model /stdp_synapse >> GetConnections { - [[/source /target /weight /delay /alpha /tau_plus]] get + [[/source /target /weight /delay /alpha /tau_plus]] get { of exch <- (\t) <- ; } forall of endl ; } forall diff --git a/testsuite/unittests/test_mip_corrdet.sli b/testsuite/unittests/test_mip_corrdet.sli index b3d711b7ef..3c67d4f027 100644 --- a/testsuite/unittests/test_mip_corrdet.sli +++ b/testsuite/unittests/test_mip_corrdet.sli @@ -131,13 +131,13 @@ dup /histogram get cva /hist Set n1 T tau_max sub div 1000.0 mul /lmbd1 Set n2 T tau_max sub div 1000.0 mul /lmbd2 Set -%cout -%(rate 1=) <- lmbd1 <- (\n) <- -%(rate 2=) <- lmbd2 <- (\n) <- -%(background =) <- lmbd1 lmbd2 mul delta_tau 1000 div mul T tau_max sub 1000 div mul <- (\n) <- pop +cout +(rate 1=) <- lmbd1 <- (\n) <- +(rate 2=) <- lmbd2 <- (\n) <- +(background =) <- lmbd1 lmbd2 mul delta_tau 1000 div mul T tau_max sub 1000 div mul <- (\n) <- pop -%hist == -%0 hist { add } forall == +hist == +0 hist { add } forall == hist expected_hist eq From a6312860b5315ccc82695090a2d5f19ba026223c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20M=C3=B8rk?= Date: Thu, 17 Aug 2017 14:30:09 +0200 Subject: [PATCH 16/20] Removed superfluous tests --- testsuite/manualtests/stdp_check.py | 159 -------------- testsuite/manualtests/test_stdp_hom_poiss.sli | 193 ----------------- testsuite/manualtests/test_stdp_poiss.sli | 195 ------------------ 3 files changed, 547 deletions(-) delete mode 100644 testsuite/manualtests/stdp_check.py delete mode 100644 testsuite/manualtests/test_stdp_hom_poiss.sli delete mode 100644 testsuite/manualtests/test_stdp_poiss.sli diff --git a/testsuite/manualtests/stdp_check.py b/testsuite/manualtests/stdp_check.py deleted file mode 100644 index d617c69411..0000000000 --- a/testsuite/manualtests/stdp_check.py +++ /dev/null @@ -1,159 +0,0 @@ -# -*- coding: utf-8 -*- -# -# stdp_check.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 . - -from matplotlib.pylab import * - - -# Test script to reproduce changes in weight of a STDP synapse in an -# event-driven way. Pre- and post-synaptic spike trains are read in from -# spike_detector-0-0-3.gdf (output of test_stdp_poiss.sli). -# output: pre/post \t spike time \t weight -# -# Synaptic dynamics for STDP synapses according to Abigail Morrison's -# STDP model (see stdp_rec.pdf). -# -# first version: Moritz Helias, april 2006 -# adapted to python MH, SK, May 2008 - -def stdp(w_init, w_max, pre_spikes, post_spikes, alpha, mu_plus, mu_minus, - lmbd, tau_plus, tau_minus, delay): - w = w_init # initial weight - i = 0 # index of next presynaptic spike - j = 0 # index of next postsynaptic spike - - K_plus = 0. - K_minus = 0. - last_t = 0. - - advance = True - - while advance: - - advance = False - - # next spike is presynaptic - if pre_spikes[i] < post_spikes[j]: - dt = pre_spikes[i] - last_t - - # evolve exponential filters - K_plus *= exp(-dt / tau_plus) - K_minus *= exp(-dt / tau_minus) - - # depression - w = w / w_max - lmbd * alpha * (w / w_max) ** mu_minus * K_minus - if w > 0.: - w *= w_max - else: - w = 0. - - print("pre\t%.16f\t%.16f" % (pre_spikes[i], w)) - - K_plus += 1. - last_t = pre_spikes[i] # time evolved until here - if i < len(pre_spikes) - 1: - i += 1 - advance = True - - # same timing of next pre- and postsynaptic spike - elif pre_spikes[i] == post_spikes[j]: - dt = pre_spikes[i] - last_t - - # evolve exponential filters - K_plus *= exp(-dt / tau_plus) - K_minus *= exp(-dt / tau_minus) - - # facilitation - w = w / w_max + lmbd * (1. - w / w_max) ** mu_plus * K_plus - if w < 1.: - w *= w_max - else: - w = w_max - print("post\t%.16f\t%.16f" % (post_spikes[j] - delay, w)) - - # depression - w = w / w_max - lmbd * alpha * (w / w_max) ** mu_minus * K_minus - if w > 0.: - w *= w_max - else: - w = 0. - print("pre\t%.16f\t%.16f" % (pre_spikes[i], w)) - - K_plus += 1. - K_minus += 1. - last_t = pre_spikes[i] # time evolved until here - if i < len(pre_spikes) - 1: - i += 1 - advance = True - if j < len(post_spikes) - 1: - j += 1 - advance = True - - # next spike is postsynaptic - else: - dt = post_spikes[j] - last_t - - # evolve exponential filters - K_plus *= exp(-dt / tau_plus) - K_minus *= exp(-dt / tau_minus) - - # facilitation - w = w / w_max + lmbd * (1. - w / w_max) ** mu_plus * K_plus - if w < 1.: - w *= w_max - else: - w = w_max - - print("post\t%.16f\t%.16f" % (post_spikes[j] - delay, w)) - - K_minus += 1. - last_t = post_spikes[j] # time evolved until here - if j < len(post_spikes) - 1: - j += 1 - advance = True - - return w - - -# stdp parameters -w_init = 35. -w_max = 70. -alpha = .95 -mu_plus = .05 -mu_minus = .05 -lmbd = .025 -tau_plus = 20. -tau_minus = 20. - -# dendritic delay -delay = 1. - -# load spikes from simulation with test_stdp_poiss.sli -spikes = load("spike_detector-0-0-3.gdf") - -pre_spikes = spikes[find(spikes[:, 0] == 5), 1] - -# delay is purely dendritic -# postsynaptic spike arrives at sp_j + delay at the synapse -post_spikes = spikes[find(spikes[:, 0] == 6), 1] + delay - -# calculate development of stdp weight -stdp(w_init, w_max, pre_spikes, post_spikes, alpha, mu_plus, mu_minus, lmbd, - tau_plus, tau_minus, delay) diff --git a/testsuite/manualtests/test_stdp_hom_poiss.sli b/testsuite/manualtests/test_stdp_hom_poiss.sli deleted file mode 100644 index 50f4f111b0..0000000000 --- a/testsuite/manualtests/test_stdp_hom_poiss.sli +++ /dev/null @@ -1,193 +0,0 @@ -/* - * test_stdp_hom_poiss.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::test_stdp_hom_poiss - sli script to test stdp_synapse_hom model -implementing spike time dependent plasticity syanpses -according to Guetig et al. (2003), Journal of Neuroscience. It uses the version of these synapses, which uses homogeneous parameter, i.e. all STDP synapses have the same parameters. -This script performs repeated spike pairing of two neurons connected by a stdp_synapse. -The synapse strength is recorded after 60 paired spikes in a file. - - - -Synopsis: (test_stdp) run -> compare cout with comments in file - -Author: Moritz Helias, Wiebke Potjans, Abigail Morrison, Markus Diesmann -FistVersion: April 2006 -*/ - - -ResetKernel % clear all existing network elements - - - -userdict begin - - 0.1 /h Set % simulation timestep [ms] - - 0 - << - /resolution h - /total_num_virtual_procs 2 - >> SetStatus - - -/delay h def % dendritic delay [ms] - - - -10000 /K Set -0.8 /f_ex Set -f_ex K mul /K_ex Set -1.0 f_ex sub K mul /K_in Set - -10.0 /nu_ex Set -10.0 /nu_in Set - -45.0 /w_ex Set % in pA, background PSC amplitude -3.83 /g Set % -w_ex neg g mul /w_in Set - - - -% synapse constants - - - - - - -/poisson_generator Create /pg_ex Set -pg_ex << /rate K_ex nu_ex mul >> SetStatus - -/poisson_generator Create /pg_in Set -pg_in << /rate K_in nu_in mul >> SetStatus - - - -/spike_detector Create /sd Set -sd << /withtime true /withgid true /to_file true >> SetStatus - - -/voltmeter Create /vm Set -vm << /withtime true /withgid true /to_file true >> SetStatus - - - -/iaf_psc_alpha Create /neuron1 Set -/iaf_psc_alpha Create /neuron2 Set - - - -neuron1 << /tau_syn_ex 0.3 /tau_syn_in 0.3 >> SetStatus -neuron2 << /tau_syn_ex 0.3 /tau_syn_in 0.3 >> SetStatus - -pg_ex neuron1 w_ex delay Connect -pg_ex neuron2 w_ex delay Connect - -pg_in neuron1 w_in delay Connect -pg_in neuron2 w_in delay Connect - -neuron1 sd Connect -neuron2 sd Connect - -%vm neuron1 Connect -vm neuron2 Connect - -/stdp_synapse_hom << - /delay delay - /weight 35. - /Wmax 70. - /alpha 0.95 - /lambda 0.025 - /mu_plus 0.05 - /mu_minus 0.05 ->> SetDefaults - -neuron1 neuron2 /stdp_synapse_hom Connect - - - -neuron2 GetStatus /local get -{ - (weight.gdf) (w) file /f_weight Set -} if - - - - -40000.0 /T Set - -100.0 /dt Set -%76.0 /dt Set -50.0 /dt Set -%10000.0 /dt Set - -0 dt T -{ - /t Set - - neuron2 GetStatus /local get - { - << /source [neuron1] /synapse_model /stdp_synapse_hom >> GetConnections 0 get - GetStatus /weight get /w Set - - w == - - f_weight t <- (\t) <- w <- endl pop - } if - - dt Simulate -} for - - -neuron2 GetStatus /local get -{ - cout (expected weight at T=40000 ms: 33.8466 pA) <- endl pop - cout (weight at last event: ) <- w <- ( pA) <- endl pop -} if - - -end - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% Expected output of this program: -% -% The output send to std::cout is a superposition of the output of -% the voltmeter and the spike detector. Both, voltmeter and spike -% detector are connected to the same neuron. -% -% -% The expected output of the program for a simulation time of -% 40000.0ms is 33.8466pA. -% -% The result is independent of the length of the interval dt in which -% Simulate is called as long as the last pre-synaptic spike included -% in the simulation remains the same. -% - - - - - diff --git a/testsuite/manualtests/test_stdp_poiss.sli b/testsuite/manualtests/test_stdp_poiss.sli deleted file mode 100644 index eb51822176..0000000000 --- a/testsuite/manualtests/test_stdp_poiss.sli +++ /dev/null @@ -1,195 +0,0 @@ -/* - * test_stdp_poiss.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::test_stdp_sg - sli script to test stdp_synapse model -implementing spike time dependent plasticity syanpses -according to Guetig et al. (2003), Journal of Neuroscience. -This script performs repeated spike pairing of two neurons connected by a stdp_synapse. -The synapse strength is recorded after 60 paired spikes in a file. - - - -Synopsis: (test_stdp) run -> compare cout with comments in file - -author: Moritz Helias, Wiebke Potjans, Abigail Morrison, Markus Diesmann -date: Sep 2007 -*/ - - -ResetKernel % clear all existing network elements - - - -modeldict begin % open model and user dictionaries -synapsedict begin -userdict begin - - 0.1 /h Set % simulation timestep [ms] - - 0 - << - /resolution h - /total_num_virtual_procs 1 - /overwrite_files true - >> SetStatus - - -/delay 1.0 def % dendritic delay [ms] - - - -10000 /K Set -0.8 /f_ex Set -f_ex K mul /K_ex Set -1.0 f_ex sub K mul /K_in Set - -10.0 /nu_ex Set -10.0 /nu_in Set - -45.0 /w_ex Set % in pA, background PSC amplitude -3.83 /g Set % -w_ex neg g mul /w_in Set - - - -/poisson_generator Create /pg_ex Set -pg_ex << - /rate K_ex nu_ex mul - >> SetStatus - -/poisson_generator Create /pg_in Set -pg_in << - /rate K_in nu_in mul - >> SetStatus - - - -/spike_detector Create /sd Set -sd << /withtime true /withgid true >> SetStatus - - -/voltmeter Create /vm Set -vm << /withtime true /withgid true >> SetStatus - - - -/iaf_psc_alpha Create /neuron1 Set -/iaf_psc_alpha Create /neuron2 Set - - - -neuron1 << /tau_syn_ex 0.3 /tau_syn_in 0.3 /tau_minus 20.0 >> SetStatus -neuron2 << /tau_syn_ex 0.3 /tau_syn_in 0.3 /tau_minus 20.0 >> SetStatus - -pg_ex neuron1 w_ex delay Connect -pg_ex neuron2 w_ex delay Connect - -pg_in neuron1 w_in delay Connect -pg_in neuron2 w_in delay Connect - - -neuron1 sd Connect -neuron2 sd Connect - -%vm neuron1 Connect -vm neuron2 Connect - - -/stdp_synapse << - /delay delay - /weight 35. - /Wmax 70. - /alpha 0.95 - /lambda 0.025 - /mu_plus 0.05 - /mu_minus 0.05 - /tau_plus 20.0 ->> -SetDefaults - -neuron1 neuron2 /stdp_synapse Connect - - - -40000.0 /T Set - -%100.0 /dt Set -%76.0 /dt Set -50.0 /dt Set -%10000.0 /dt Set - - - -0 dt T -{ - /t Set - - neuron2 GetStatus /local get - { - % we are on the machine where neuron2 resides - << /source [neuron1] /synapse_model /stdp_synapse >> GetConnections - 0 get GetStatus /weight get - /w Set %we know that there is only a single synapse - - w == - - %f_weight t <- (\t) <- w <- endl pop - - } if - - dt Simulate -} for - -neuron2 GetStatus /local get -{ - cout (expected weight at T=40000 ms: 33.8466 pA) <- endl pop - cout (weight at last event: ) <- w <- ( pA) <- endl pop -} if - - -end -end -end - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% Expected output of this program: -% -% The output send to std::cout is a superposition of the output of -% the voltmeter and the spike detector. Both, voltmeter and spike -% detector are connected to the same neuron. -% -% -% The expected output of the program for a simulation time of -% 40000.0ms is 33.8466pA. -% -% The result is independent of the length of the interval dt in which -% Simulate is called as long as the last pre-synaptic spike included -% in the simulation remains the same. -% - - - - - From 66d0b36214eb7b82239fa66739faf0d15975b225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20M=C3=B8rk?= Date: Mon, 21 Aug 2017 15:32:10 +0200 Subject: [PATCH 17/20] Removed SLI language design study files The SLI modifications are now discussed in issue #811. --- .../test_spike_poisson_ps_base2_f.sli | 171 ------------------ .../test_spike_poisson_ps_base2_nd.sli | 91 ---------- .../test_spike_poisson_ps_base2_p.sli | 135 -------------- 3 files changed, 397 deletions(-) delete mode 100644 testsuite/manualtests/test_spike_poisson_ps_base2_f.sli delete mode 100644 testsuite/manualtests/test_spike_poisson_ps_base2_nd.sli delete mode 100644 testsuite/manualtests/test_spike_poisson_ps_base2_p.sli diff --git a/testsuite/manualtests/test_spike_poisson_ps_base2_f.sli b/testsuite/manualtests/test_spike_poisson_ps_base2_f.sli deleted file mode 100644 index 5b294c55bd..0000000000 --- a/testsuite/manualtests/test_spike_poisson_ps_base2_f.sli +++ /dev/null @@ -1,171 +0,0 @@ -/* - * test_spike_poisson_ps_base2_f.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 . - * - */ - -% THIS FILE IS A DESIGN STUDY IT WILL PROBABLY NEVER RUN - -/*BeginDocumentation -Name: testsuite::test_spike_poisson_ps_base2_f.sli - -Synopsis: (test_spike_poisson_ps_base2_f) run - -Description: -In NEST spike times are represented by an integer part in units of h -and an offset in units of milliseconds. This helps to maintain a -uniform absolute accuracy of spike times even for long simulation -times. - -The user has access to the two components of the spike if the spike -detector is set to - /time_in_steps true /precise_times true . -In thie case the spike detector returns events with the properties -/times and /offsets, where /times are the integer parts s in units of h -and offsets are the fractional parts o in milliseconds. According to -NEST's definition of a grid-constrained spike as a spike occuring -somewhere in (t-h,t], the precise spike time is - t = s*h - o - -Access to spike times with a uniform absolute accuracy is benefitial -when testing and comparing integrators for neuron models, see appendix -A.2 of [1] for details. - -This script tests whether the accuracy of spike times is maintained -independent of the choice of computation step size h. - -This assumes that also the poisson generator is capable of maintaining -the accuracy independent of computation step size. -If this test fails go back to - test_spike_poisson_ps.sli -to check whether poisson_generator_ps can emit spike times at double -precision or whether spike times are limited to the precision of a -tic. - -References: -[1] Morrison A, Straube S, Plesser H E, Diesmann M (2007) Exact -subthreshold integration with continuous spike times in discrete time -neural network simulations. Neural Computation 19: 47-79 - -Author: May 2010, adapted to NEST2, Diesmann -SeeAlso: testsuite::test_spike_poisson_ps -*/ - - -%` % <---- functional expression for immediate compilation and execution - % is enclosed by this symbol or similar - % maybe ` is the better character. - - -( -run("unittest") - - % --------- the prime indicates a literal ('x translated to /x) - % | - % v -using('unittest) - -setverbosity(M_ERROR) - -min_exponent = -20; -spike_absolute_accuracy = inv(1e15); -T = 4.0; -h_min = 2^min_exponent; - - -Transmission = Function( - { - ResetKernel() - - SetStatus(0, << 'tics_per_ms : 2^-min_exponent, 'resolution : h >>) - - sp = Create('spike_detector, - << 'withgid : false, 'to_memory : true, 'withtime : true, 'time_in_steps : true, 'precise_times : true >> - ); - - pn = Create('poisson_generator_ps, << 'rate : 16384.0 >>); - - Connect(pn,sp) - - Simulate(T) - - sp // {get(#,['events, ['times, 'offsets]])} // cva - - }, - - 'h -); - - - -Map( Range([0, min_exponent, -2]), - Function( - { - Transmission(2^e) // - { [ 2^(e-min_exponent)*First(#), Last(#)] } - }, - 'e - ) -) - - -// - Function( - { - l=Last(r); - Most(r) // {Map(#, {join(#,l)})} - }, - 'r - ) - -// -{ - Map(#, - { - Apply(#, Function( - {(s-sr)*h_min - o + or}, - 's,'o,'sr,'or - )) - } - ) -} - -// Flatten -// {Select(#,{ abs(#) > spike_absolute_accuracy})} -// { # == []} -// assert_or_die - - -) - -CompileMath exec - -% all time steps in units of smallest h - -% combine results with the one at smallest h as reference -% to 4-tuples [s o sr or] - - -% s o sr or, we compute (s*hmin-o)-(sr*hmin-or) -% trying to keep the highest possible accuracy: -% (s-sr)*hmin - o + or - -% comment these two last lines to inspect the -% differences causing the failure - diff --git a/testsuite/manualtests/test_spike_poisson_ps_base2_nd.sli b/testsuite/manualtests/test_spike_poisson_ps_base2_nd.sli deleted file mode 100644 index 3b2a06f85b..0000000000 --- a/testsuite/manualtests/test_spike_poisson_ps_base2_nd.sli +++ /dev/null @@ -1,91 +0,0 @@ -/* - * test_spike_poisson_ps_base2_nd.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 . - * - */ - -/* Testscript - -The difference in spike times is exactly 0.0 between -all resolutions. - test_spike_poisson_ps_precision.sli -already verified that spikes are produced and recorded with -double resolution. - -It is not easy to understand why this script gives identical -results if the computation time step is not representable as -a double. However, HEP seems to be able to provide a proof. - -If this test fails go back to - test_spike_poisson_ps_precision.sli -to check whether poisson_generator_ps can emit spike times at -double precision or whether spike times are limited to the -precision of a tic. - -*/ - -(unittest) run -/unittest using - -M_ERROR setverbosity - --2 /min_exponent Set - -/Transmission -{ -dexp /h Set -(res = ) h cvs join = - -/T 4.0 def - -ResetKernel - -0 << - /tics_per_ms min_exponent neg dexp - /resolution h - >> SetStatus - - /poisson_generator_ps Create /pn Set - pn << /rate 16384.0 >> SetStatus - -/spike_detector Create /sp Set -sp << /withgid false /withtime true /time_in_steps true /precise_times true >> SetStatus - - - - -pn sp Connect - - -T Simulate - -sp [/events [/times /offsets]] get cva dup == - - -} def - -[0 min_exponent -2] Range - { Transmission } Map -0 get -(########) = -pstack (OOOOOOOOO) = -dup Rest pstack (xxxxxxx) = exch First {sub} exch prepend pstack (IIIIIIII) = Map -pstack -%Flatten { 0.0 neq } Select [] eq % comment these two last lines to see the -%assert_or_die % minimal differences causing the failure diff --git a/testsuite/manualtests/test_spike_poisson_ps_base2_p.sli b/testsuite/manualtests/test_spike_poisson_ps_base2_p.sli deleted file mode 100644 index 47423662b4..0000000000 --- a/testsuite/manualtests/test_spike_poisson_ps_base2_p.sli +++ /dev/null @@ -1,135 +0,0 @@ -/* - * test_spike_poisson_ps_base2_p.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 . - * - */ - -% THIS FILE IS A DESIGN STUDY IT WILL PROBABLY NEVER RUN - -/*BeginDocumentation -Name: testsuite::test_spike_poisson_ps_base2_p.sli - -Synopsis: (test_spike_poisson_ps_base2_p) run - -Description: -In NEST spike times are represented by an integer part in units of h -and an offset in units of milliseconds. This helps to maintain a -uniform absolute accuracy of spike times even for long simulation -times. - -The user has access to the two components of the spike if the spike -detector is set to - /time_in_steps true /precise_times true . -In thie case the spike detector returns events with the properties -/times and /offsets, where /times are the integer parts s in units of h -and offsets are the fractional parts o in milliseconds. According to -NEST's definition of a grid-constrained spike as a spike occuring -somewhere in (t-h,t], the precise spike time is - t = s*h - o - -Access to spike times with a uniform absolute accuracy is benefitial -when testing and comparing integrators for neuron models, see appendix -A.2 of [1] for details. - -This script tests whether the accuracy of spike times is maintained -independent of the choice of computation step size h. - -This assumes that also the poisson generator is capable of maintaining -the accuracy independent of computation step size. -If this test fails go back to - test_spike_poisson_ps.sli -to check whether poisson_generator_ps can emit spike times at double -precision or whether spike times are limited to the precision of a -tic. - -References: -[1] Morrison A, Straube S, Plesser H E, Diesmann M (2007) Exact -subthreshold integration with continuous spike times in discrete time -neural network simulations. Neural Computation 19: 47-79 - -Author: May 2010, adapted to NEST2, Diesmann -SeeAlso: testsuite::test_spike_poisson_ps -*/ - - -` % <---- functional expression for immediate compilation and execution - % is enclosed by this symbol or similar - % maybe ` is the better character. - -run("unittest"); - - % --------- the prime indicates a literal ('x translated to /x) - % | - % v -using('unittest); - -setverbosity(M_ERROR); - -min_exponent = -20; -spike_absolute_accuracy = 1e-15; -T = 4.0; -h_min = 2^min_exponent; - - -Transmission = : 'h, - ResetKernel(); - SetStatus(0, << tics_per_ms = 2^-min_exponent, resolution = h >>); - - sp = Create('spike_detector, - { 'withgid : false, 'to_memory : true, 'withtime : true, 'time_in_steps : true, 'precise_times : true } - ); - - pn = Create('poisson_generator_ps, { 'rate : 16384.0 }); - - Connect(pn,sp); - - Simulate(T); - - sp // :get(#,['events. ['times, 'offsets]]) // cva - - - - -Map( Range([0, min_exponent, -2]), : 'e, - Transmission(2^e) // - : [ 2^(e-min_exponent)*First(#), Last(#)] - -) - - -// : 'r, - l=Last(r); - Most(r) // :Map(#, {Joint(#,l)}) - - - -// - Map(#, - Apply(#, : 's,'o,'sr,'or, - (s-sr)*h_min - o + or - ) - ) - - -// Flatten -// :Select(#,{ abs(#) > spike_absolute_accuracy}) -// :(# == []) -// assert_or_die - -` From 936b11019457d724b3c398f791664d64fc6dca9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20M=C3=B8rk?= Date: Fri, 8 Sep 2017 13:01:13 +0200 Subject: [PATCH 18/20] Removed outdated tests --- testsuite/manualtests/stdp_dopa_check.py | 307 ----------------------- testsuite/manualtests/test_stdp_dopa.py | 121 --------- 2 files changed, 428 deletions(-) delete mode 100644 testsuite/manualtests/stdp_dopa_check.py delete mode 100644 testsuite/manualtests/test_stdp_dopa.py diff --git a/testsuite/manualtests/stdp_dopa_check.py b/testsuite/manualtests/stdp_dopa_check.py deleted file mode 100644 index 577d4851ce..0000000000 --- a/testsuite/manualtests/stdp_dopa_check.py +++ /dev/null @@ -1,307 +0,0 @@ -# -*- coding: utf-8 -*- -# -# stdp_dopa_check.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 . - -from matplotlib.pylab import * -import numpy as n - -# Test script to reproduce changes in weight of a dopamine modulated STDP -# synapse in an event-driven way. -# Pre- and post-synaptic spike trains are read in from spikes-6-0.gdf -# (output of test_stdp_dopa.py). -# output: pre/post/dopa \t spike time \t weight -# -# Synaptic dynamics for dopamine modulated STDP synapses as used in [1], -# based on [2]. -# -# References: -# [1] Potjans W, Morrison A and Diesmann M (2010). -# Enabling functional neural circuit simulations with distributed -# computing of neuromodulated plasticity. -# Front. Comput. Neurosci. 4:141. doi:10.3389/fncom.2010.00141 -# [2] Izhikevich, E. M. (2007). Solving the distal reward problem through -# linkage of STDP and dopamine signaling. Cereb. Cortex 17(10), 2443-2452. -# -# author: Wiebke Potjans, October 2010 - - -def stdp_dopa(w_init, pre_spikes, post_spikes, dopa_spikes, tau_e, tau_d, - A_minus, A_plus, tau_plus, tau_minus, dendritic_delay, delay_d): - w = w_init # initial weight - w_min = 0. # minimal weight - w_max = 200. # maximal weight - i = 0 # index of presynaptic spike - j = 0 # index of postsynaptic spike - k = 0 # index of dopamine spike - - last_post_spike = dendritic_delay - Etrace = 0. - Dtrace = 0. - last_e_update = 0. - last_w_update = 0. - last_pre_spike = 0. - last_dopa_spike = 0. - - advance = True - - while advance: - - advance = False - - # next spike is presynaptic - if ((pre_spikes[i] < post_spikes[j]) and (pre_spikes[i] < - dopa_spikes[k])): - dt = pre_spikes[i] - last_post_spike - - # weight update - w += (Etrace * Dtrace / (1. / tau_e + 1. / tau_d) * - (exp((last_e_update - last_w_update) / tau_e) * - exp((last_dopa_spike - last_w_update) / tau_d) - - exp((last_e_update - pre_spikes[i]) / tau_e) * - exp((last_dopa_spike - pre_spikes[i]) / tau_d))) - - if w < w_min: - w = w_min - if w > w_max: - w = w_max - - print("pre\t%.4f\t%.4f" % (pre_spikes[i], w)) - - last_w_update = pre_spikes[i] - - Etrace = (Etrace * exp((last_e_update - pre_spikes[i]) / tau_e) - - A_minus * exp(-dt / tau_minus)) - - last_e_update = pre_spikes[i] - last_pre_spike = pre_spikes[i] - - if i < len(pre_spikes) - 1: - i += 1 - advance = True - - # next spike is postsynaptic - if ((post_spikes[j] < pre_spikes[i]) and (post_spikes[j] < - dopa_spikes[k])): - dt = post_spikes[j] - last_pre_spike - - # weight update - w -= (Etrace * Dtrace / (1. / tau_e + 1. / tau_d) * - exp((last_e_update - post_spikes[j]) / tau_e) * - exp((last_dopa_spike - post_spikes[j]) / tau_d) - - exp((last_e_update - last_w_update) / tau_e) * - exp((last_dopa_spike - last_w_update) / tau_d)) - - if w < w_min: - w = w_min - if w > w_max: - w = w_max - - print("post\t%.4f\t%.4f" % (post_spikes[j], w)) - last_w_update = post_spikes[j] - Etrace = (Etrace * exp((last_e_update - post_spikes[j]) / tau_e) + - A_plus * exp(-dt / tau_plus)) - - last_e_update = post_spikes[j] - last_post_spike = post_spikes[j] - - if j < len(post_spikes) - 1: - j += 1 - advance = True - - # next spike is dopamine spike - if ((dopa_spikes[k] < pre_spikes[i]) and (dopa_spikes[k] < - post_spikes[j])): - - # weight update - w -= (Etrace * Dtrace / (1. / tau_e + 1. / tau_d) * - (exp((last_e_update - dopa_spikes[k]) / tau_e) * - exp((last_dopa_spike - dopa_spikes[k]) / tau_d) - - exp((last_e_update - last_w_update) / tau_e) * - exp((last_dopa_spike - last_w_update) / tau_d))) - if w < w_min: - w = w_min - if w > w_max: - w = w_max - - print("dopa\t%.4f\t%.4f" % (dopa_spikes[k], w)) - last_w_update = dopa_spikes[k] - Dtrace = (Dtrace * - exp((last_dopa_spike - dopa_spikes[k]) / tau_d) + - 1 / tau_d) - - last_dopa_spike = dopa_spikes[k] - - if k < len(dopa_spikes) - 1: - k += 1 - advance = True - - if (dopa_spikes[k] == dopa_spikes[k - 1]): - advance = False - Dtrace = Dtrace + 1 / tau_d - if k < len(dopa_spikes) - 1: - k += 1 - advance = True - - # pre and postsynaptic spikes are at the same time - # Etrace is not updated for this case; therefore no weight update - # is required - if ((pre_spikes[i] == post_spikes[j]) and (pre_spikes[i] < - dopa_spikes[k])): - if i < len(pre_spikes) - 1: - i += 1 - advance = True - - if j < len(post_spikes) - 1: - j += 1 - advance = True - - # presynaptic spike and dopamine spike are at the same time - if ((pre_spikes[i] == dopa_spikes[k]) and (pre_spikes[i] < - post_spikes[j])): - dt = pre_spikes[i] - last_post_spike - - w += (Etrace * Dtrace / (1. / tau_e + 1. / tau_d) * - (exp((last_e_update - last_w_update) / tau_e) * - exp((last_dopa_spike - last_w_update) / tau_d) - - exp((last_e_update - pre_spikes[i]) / tau_e) * - exp((last_dopa_spike - pre_spikes[i]) / tau_d))) - - if w < w_min: - w = w_min - if w > w_max: - w = w_max - - print("pre\t%.4f\t%.4f" % (pre_spikes[i], w)) - last_w_update = pre_spikes[i] - Etrace = (Etrace * exp((last_e_update - pre_spikes[i]) / tau_e) - - A_minus * exp(-dt / tau_minus)) - - last_e_update = pre_spikes[i] - last_pre_spike = pre_spikes[i] - - if i < len(pre_spikes) - 1: - i += 1 - advance = True - - Dtrace = (Dtrace * - exp((last_dopa_spike - dopa_spikes[k]) / tau_d) + - 1 / tau_d) - last_dopa_spike = dopa_spikes[k] - - if k < len(dopa_spikes) - 1: - k += 1 - advance = True - - # postsynaptic spike and dopamine spike are at the same time - - if ((post_spikes[j] == dopa_spikes[k]) and (post_spikes[j] < - pre_spikes[i])): - # weight update - w -= (Etrace * Dtrace / (1. / tau_e + 1. / tau_d) * - (exp((last_e_update - post_spikes[j]) / tau_e) * - exp((last_dopa_spike - post_spikes[j]) / tau_d) - - exp((last_e_update - last_w_update) / tau_e) * - exp((last_dopa_spike - last_w_update) / tau_d))) - if w < w_min: - w = w_min - if w > w_max: - w = w_max - - print("post\t%.4f\t%.4f" % (post_spikes[j], w)) - last_w_update = post_spikes[j] - Etrace = (Etrace * exp((last_e_update - post_spikes[j]) / tau_e) + - A_plus * exp(-dt / tau_plus)) - - last_e_update = post_spikes[j] - last_post_spike = post_spikes[j] - - if j < len(post_spikes) - 1: - j += 1 - advance = True - - Dtrace = (Dtrace * - exp((last_dopa_spike - dopa_spikes[k]) / tau_d) + - 1 / tau_d) - last_dopa_spike = dopa_spikes[k] - - if k < len(dopa_spikes) - 1: - k += 1 - advance = True - - # all three spikes are at the same time - if ((post_spikes[j] == dopa_spikes[k]) and (post_spikes[j] == - pre_spikes[i])): - # weight update - w -= (Etrace * Dtrace / (1. / tau_e + 1. / tau_d) * - (exp((last_e_update - dopa_spikes[k]) / tau_e) * - exp((last_dopa_spike - dopa_spikes[k]) / tau_d) - - exp((last_e_update - last_w_update) / tau_e) * - exp((last_dopa_spike - last_w_update) / tau_d))) - if w < w_min: - w = w_min - if w > w_max: - w = w_max - - print("dopa\t%.4f\t%.4f" % (dopa_spikes[k], w)) - last_w_update = dopa_spikes[k] - Dtrace = (Dtrace * - exp((last_dopa_spike - dopa_spikes[k]) / tau_d) + - 1 / tau_d) - - last_dopa_spike = dopa_spikes[k] - - if k < len(dopa_spikes) - 1: - k += 1 - advance = True - - if (dopa_spikes[k] == dopa_spikes[k - 1]): - advance = False - Dtrace = Dtrace + 1 / tau_d - if k < len(dopa_spikes) - 1: - k += 1 - advance = True - - return w - - -# stdp dopa parameters -w_init = 35. -tau_plus = 20. -tau_minus = 15. -tau_e = 1000. -tau_d = 200. -A_minus = 1.5 -A_plus = 1.0 -dendritic_delay = 1.0 -delay_d = 1. - -# load spikes from simulation with test_stdp_dopa.py -spikes = n.loadtxt("spikes-3-0.gdf") -pre_spikes = spikes[find(spikes[:, 0] == 4), 1] -# delay is purely dendritic -# postsynaptic spike arrives at sp_j + dendritic_delay at the synapse -post_spikes = spikes[find(spikes[:, 0] == 5), 1] + dendritic_delay -# dopa spike arrives at sp_j + delay_d at the synapse -dopa_spikes = spikes[find(spikes[:, 0] == 6), 1] + delay_d - -# calculate development of stdp weight -w = stdp_dopa(w_init, pre_spikes, post_spikes, dopa_spikes, tau_e, tau_d, - A_minus, A_plus, tau_plus, tau_minus, dendritic_delay, delay_d) -print(w) diff --git a/testsuite/manualtests/test_stdp_dopa.py b/testsuite/manualtests/test_stdp_dopa.py deleted file mode 100644 index db9d37b8a7..0000000000 --- a/testsuite/manualtests/test_stdp_dopa.py +++ /dev/null @@ -1,121 +0,0 @@ -# -*- coding: utf-8 -*- -# -# test_stdp_dopa.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 . - -# Begin Documentation -# Name: testsuite::test_stdp_dopa - script to test stdp_dopamine_synapse model -# implementing dopamine-dependent spike-timing dependent plasticity as -# defined in [1], based on [2]. -# Two neurons, which fire poisson like, are connected by a -# stdp_dopamine_synapse. Dopamine is release by a third neuron, -# which also fires poisson like. -# -# author: Wiebke Potjans -# date: October 2010 - -import numpy as np -import nest - -nest.ResetKernel() -nest.SetKernelStatus( - {'overwrite_files': True}) # set to True to permit overwriting - -delay = 1. # the delay in ms - -w_ex = 45. -g = 3.83 -w_in = -w_ex * g - -K = 10000 -f_ex = 0.8 -K_ex = f_ex * K -K_in = (1.0 - f_ex) * K - -nu_ex = 10.0 # 2. -nu_in = 10.0 # 2. - -pg_ex = nest.Create("poisson_generator") -nest.SetStatus(pg_ex, {"rate": K_ex * nu_ex}) - -pg_in = nest.Create("poisson_generator") -nest.SetStatus(pg_in, {"rate": K_in * nu_in}) - -sd = nest.Create("spike_detector") -nest.SetStatus(sd, { - "label": "spikes", - "withtime": True, - "withgid": True, - "to_file": True, -}) - -neuron1 = nest.Create("iaf_psc_alpha") -neuron2 = nest.Create("iaf_psc_alpha") -dopa_neuron = nest.Create("iaf_psc_alpha") -nest.SetStatus(neuron1, - {"tau_syn_ex": 0.3, "tau_syn_in": 0.3, "tau_minus": 20.0}) -nest.SetStatus(neuron2, - {"tau_syn_ex": 0.3, "tau_syn_in": 0.3, "tau_minus": 20.0}) - -vt = nest.Create("volume_transmitter") - -nest.Connect(pg_ex, neuron1, syn_spec={'weight': w_ex, 'delay': delay}) -nest.Connect(pg_ex, neuron2, syn_spec={'weight': w_ex, 'delay': delay}) -nest.Connect(pg_ex, dopa_neuron, syn_spec={'weight': w_ex, 'delay': delay}) - -nest.Connect(pg_in, neuron1, syn_spec={'weight': w_in, 'delay': delay}) -nest.Connect(pg_in, neuron2, syn_spec={'weight': w_in, 'delay': delay}) -nest.Connect(pg_in, dopa_neuron, syn_spec={'weight': w_in, 'delay': delay}) - -nest.Connect(neuron1, sd) -nest.Connect(neuron2, sd) -nest.Connect(dopa_neuron, sd) - -nest.CopyModel("stdp_dopamine_synapse", "dopa", - {"vt": vt[0], "weight": 35., "delay": delay}) -nest.CopyModel("static_synapse", "static", {"delay": delay}) - -nest.Connect(dopa_neuron, vt, model="static") -nest.Connect(neuron1, neuron2, model="dopa") - -if nest.GetStatus(neuron2)[0]['local']: - filename = 'weight.gdf' - fname = open(filename, 'w') -else: - raise - -T = 1000.0 -dt = 10.0 - -weight = None -for t in np.arange(0, T + dt, dt): - if nest.GetStatus(neuron2)[0]['local']: - conns = nest.GetConnections(neuron1, synapse_model="dopa") - weight = nest.GetStatus(conns)[0]['weight'] - print(weight) - weightstr = str(weight) - timestr = str(t) - data = timestr + ' ' + weightstr + '\n' - fname.write(data) - nest.Simulate(dt) - -if nest.GetStatus(neuron2)[0]['local']: - print("expected weight at T=1000 ms: 28.6125 pA") - print("weight at last event: " + str(weight) + " pA") - fname.close() From ff356153d314c6ca1affcc956d3e856c87367a67 Mon Sep 17 00:00:00 2001 From: Stine Vennemo Date: Wed, 20 Sep 2017 11:52:36 +0200 Subject: [PATCH 19/20] Converted cross_check_mip_corrdet to python example. --- pynest/examples/cross_check_mip_corrdet.py | 125 ++++++++++ .../cross_check_test_mip_corrdet.py | 223 ------------------ .../manualtests/parallel_conn_and_rand.sli | 138 ----------- testsuite/unittests/test_mip_corrdet.sli | 12 +- 4 files changed, 131 insertions(+), 367 deletions(-) create mode 100644 pynest/examples/cross_check_mip_corrdet.py delete mode 100644 testsuite/manualtests/cross_check_test_mip_corrdet.py delete mode 100644 testsuite/manualtests/parallel_conn_and_rand.sli diff --git a/pynest/examples/cross_check_mip_corrdet.py b/pynest/examples/cross_check_mip_corrdet.py new file mode 100644 index 0000000000..f3f98eac55 --- /dev/null +++ b/pynest/examples/cross_check_mip_corrdet.py @@ -0,0 +1,125 @@ +# -*- coding: utf-8 -*- +# +# cross_check_mip_corrdet.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 . + +import nest +from matplotlib.pylab import * + +''' +Auto- and crosscorrelation functions for spike trains. + +A time bin of size tbin is centered around the time difference it +represents. If the correlation function is calculated for tau in +[-tau_max, tau_max], the pair events contributing to the left-most +bin are those for which tau in [-tau_max-tbin/2, tau_max+tbin/2) and +so on. + +Correlate two spike trains with each other assumes spike times to be ordered in +time. tau > 0 means spike2 is later than spike1 + +tau_max: maximum time lag in ms correlation function +tbin: bin size +spike1: first spike train [tspike...] +spike2: second spike train [tspike...] +''' +def corr_spikes_sorted(spike1, spike2, tbin, tau_max, h): + tau_max_i = int(tau_max / h) + tbin_i = int(tbin / h) + + cross = zeros(int(2 * tau_max_i / tbin_i + 1), 'd') + + j0 = 0 + + for spki in spike1: + j = j0 + while j < len(spike2) and spike2[j] - spki < -tau_max_i - tbin_i / 2.0: + j += 1 + j0 = j + + while j < len(spike2) and spike2[j] - spki < tau_max_i + tbin_i / 2.0: + cross[int( + (spike2[j] - spki + tau_max_i + 0.5 * tbin_i) / tbin_i)] += 1.0 + j += 1 + + return cross + +nest.ResetKernel() + +h = 0.1 # Computation step size in ms +T = 100000.0 # Total duration +delta_tau = 10.0 +tau_max = 100.0 +pc = 0.5 +nu = 100.0 + +# grng_seed is 0 because test data was produced for seed = 0 +nest.SetKernelStatus({'local_num_threads': 1, 'resolution': h, + 'overwrite_files': True, 'grng_seed': 0}) + +# Set up network, connect and simulate +mg = nest.Create('mip_generator') +nest.SetStatus(mg, {'rate': nu, 'p_copy': pc}) + +cd = nest.Create('correlation_detector') +nest.SetStatus(cd, {'tau_max': tau_max, 'delta_tau': delta_tau}) + +sd = nest.Create('spike_detector') +nest.SetStatus(sd, {'withtime': True, + 'withgid': True, 'time_in_steps': True}) + +pn1 = nest.Create('parrot_neuron') +pn2 = nest.Create('parrot_neuron') + +nest.Connect(mg, pn1) +nest.Connect(mg, pn2) +nest.Connect(pn1, sd) +nest.Connect(pn2, sd) + +nest.SetDefaults('static_synapse', {'weight': 1.0, 'receptor_type': 0}) +nest.Connect(pn1, cd) + +nest.SetDefaults('static_synapse', {'weight': 1.0, 'receptor_type': 1}) +nest.Connect(pn2, cd) + +nest.Simulate(T) + +n_events = nest.GetStatus(cd)[0]['n_events'] +n1 = n_events[0] +n2 = n_events[1] + +lmbd1 = ( n1 / ( T - tau_max ) ) * 1000.0 +lmbd2 = ( n2 / ( T - tau_max ) ) * 1000.0 + +h = 0.1 +tau_max = 100.0 # ms correlation window +t_bin = 10.0 # ms bin size + +spikes = nest.GetStatus(sd)[0]['events']['senders'] + +sp1 = find(spikes[:] == 4) +sp2 = find(spikes[:] == 5) + +# Find crosscorrolation +cross = corr_spikes_sorted(sp1, sp2, t_bin, tau_max, h) + +print("Crosscorrelation:") +print(cross) +print("Sum of crosscorrelation:") +print(sum(cross)) \ No newline at end of file diff --git a/testsuite/manualtests/cross_check_test_mip_corrdet.py b/testsuite/manualtests/cross_check_test_mip_corrdet.py deleted file mode 100644 index a29611a2cd..0000000000 --- a/testsuite/manualtests/cross_check_test_mip_corrdet.py +++ /dev/null @@ -1,223 +0,0 @@ -# -*- coding: utf-8 -*- -# -# cross_check_test_mip_corrdet.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 . - -# Script to check correlation_detector. - -# Calculates spike cross correlation function of both spike trains in -# spike_detector-0-0-3.gdf. The file is generated after running the -# testscript testsuite/unittests/test_mip_corrdet.sli -# -# Author: Helias -# Date: 08-04-07 -# - -from scipy import * -from matplotlib.pylab import * # for plot -import nest -import unittest - - -@nest.check_stack -class mipCorrdetTestCase(unittest.TestCase): - """Testing mip_generator and correlation_detector.""" - - def test_mip_generator_correlation_detector(self): - nest.ResetKernel() - - # Cross check generated with cross_check_test_mip_corrdet.py - exptected_hist = [2453., 2528., 2507., 2439., 2459., 2451., 2441., 2523., 2494., - 2445., 4909., 2369., 2410., 2457., 2495., 2484., 2369., 2341., - 2452., 2475., 2453.] - - h = 0.1 # Computation step size in ms - T = 100000.0 # Total duration - delta_tau = 10.0 - tau_max = 100.0 - pc = 0.5 - nu = 100.0 - - # grng_seed is 0 because test data was produced for seed = 0 - nest.SetKernelStatus({'local_num_threads': 1, 'resolution': h, - 'overwrite_files': True, 'grng_seed': 0}) - - # Check, if we can set another rng - # nest.SetDefaults('mip_generator', ) - #/mip_generator << /mother_rng rngdict/MT19937 :: 101 CreateRNG >> SetDefaults - #/mip_generator << /mother_rng rngdict/knuthlfg :: 101 CreateRNG >> SetDefaults % this seed will be ignored, because explicitly set - - - mg = nest.Create('mip_generator') - nest.SetStatus(mg, {'rate': nu, 'p_copy': pc}) - - cd = nest.Create('correlation_detector') - nest.SetStatus(cd, {'tau_max': tau_max, 'delta_tau': delta_tau}) - - sd = nest.Create('spike_detector') - nest.SetStatus(sd, {'withtime': True, - 'withgid': True, 'time_in_steps': True}) - - pn1 = nest.Create('parrot_neuron') - pn2 = nest.Create('parrot_neuron') - - nest.Connect(mg, pn1) - nest.Connect(mg, pn2) - nest.Connect(pn1, sd) - nest.Connect(pn2, sd) - - nest.SetDefaults('static_synapse', {'weight': 1.0, 'receptor_type': 0}) - nest.Connect(pn1, cd) - - nest.SetDefaults('static_synapse', {'weight': 1.0, 'receptor_type': 1}) - nest.Connect(pn2, cd) - - nest.Simulate(T) - - hist = [x for x in nest.GetStatus(cd)[0]['histogram']] - n_events = nest.GetStatus(cd)[0]['n_events'] - n1 = n_events[0] - n2 = n_events[1] - - lmbd1 = ( n1 / ( T - tau_max ) ) * 1000.0 - lmbd2 = ( n2 / ( T - tau_max ) ) * 1000.0 - - print(hist) - print(lmbd1) - print(lmbd2) - - print(nest.GetStatus(sd)) - - self.assertEqual(hist, exptected_hist) - - - - h = 0.1 - tau_max = 100.0 # ms correlation window - t_bin = 10.0 # ms bin size - - spikes = nest.GetStatus(sd)[0]['events']['senders'] - print(spikes) - print(find(spikes[:] == 4)) - - sp1 = find(spikes[:] == 4) - sp2 = find(spikes[:] == 5) - - cross = self.corr_spikes_sorted(sp1, sp2, t_bin, tau_max, h) - - print(cross) - print(sum(cross)) - - def corr_spikes_sorted(self, spike1, spike2, tbin, tau_max, h): - tau_max_i = int(tau_max / h) - tbin_i = int(tbin / h) - - cross = zeros(int(2 * tau_max_i / tbin_i + 1), 'd') - - j0 = 0 - - for spki in spike1: - j = j0 - while j < len(spike2) and spike2[j] - spki < -tau_max_i - tbin_i / 2.0: - j += 1 - j0 = j - - while j < len(spike2) and spike2[j] - spki < tau_max_i + tbin_i / 2.0: - cross[int( - (spike2[j] - spki + tau_max_i + 0.5 * tbin_i) / tbin_i)] += 1.0 - j += 1 - - return cross - -def suite(): - suite = unittest.makeSuite(mipCorrdetTestCase, 'test') - return suite - - -def run(): - runner = unittest.TextTestRunner(verbosity=2) - runner.run(suite()) - -if __name__ == "__main__": - run() - -# Auto- and crosscorrelation functions for spike trains. -# -# A time bin of size tbin is centered around the time difference it -# represents If the correlation function is calculated for tau in -# [-tau_max, tau_max], the pair events contributing to the left-most -# bin are those for which tau in [-tau_max-tbin/2, tau_max+tbin/2) and -# so on. - -# correlate two spike trains with each other -# assumes spike times to be ordered in time -# tau > 0 means spike2 is later than spike1 -# -# tau_max: maximum time lag in ms correlation function -# tbin: bin size -# spike1: first spike train [tspike...] -# spike2: second spike train [tspike...] -# - -""" -def corr_spikes_sorted(spike1, spike2, tbin, tau_max, h): - tau_max_i = int(tau_max / h) - tbin_i = int(tbin / h) - - cross = zeros(int(2 * tau_max_i / tbin_i + 1), 'd') - - j0 = 0 - - for spki in spike1: - j = j0 - while j < len(spike2) and spike2[j] - spki < -tau_max_i - tbin_i / 2.0: - j += 1 - j0 = j - - while j < len(spike2) and spike2[j] - spki < tau_max_i + tbin_i / 2.0: - cross[int( - (spike2[j] - spki + tau_max_i + 0.5 * tbin_i) / tbin_i)] += 1.0 - j += 1 - - return cross - - -def main(): - - make_spikes() - - # resolution - h = 0.1 - tau_max = 100.0 # ms correlation window - t_bin = 10.0 # ms bin size - - # read input from spike detector - spikes = load('spike_detector-3-0.gdf') - - sp1 = spikes[find(spikes[:, 0] == 4), 1] - sp2 = spikes[find(spikes[:, 0] == 5), 1] - - cross = corr_spikes_sorted(sp1, sp2, t_bin, tau_max, h) - - print(cross) - print(sum(cross)) - - -main() -""" \ No newline at end of file diff --git a/testsuite/manualtests/parallel_conn_and_rand.sli b/testsuite/manualtests/parallel_conn_and_rand.sli deleted file mode 100644 index 6b23add6bf..0000000000 --- a/testsuite/manualtests/parallel_conn_and_rand.sli +++ /dev/null @@ -1,138 +0,0 @@ -/* - * parallel_conn_and_rand.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 . - * - */ - -/* - Parallel Connect and Randomize Test Script - - This script creates a neuron population to itself, randomizing - weight, delay, receptor type and one synaptic parameter. It - then dumps the complete connectivity to file pcar_NumMPIProcs_Rank.conn, - one line per connection. - - This script runs with a fixed number of virtual processes (default 16). - The script should be executed with varying numbers of MPI processes. - By merging and sorting results across ranks for each MPI process number - and comparing the resulting files, one can test whether identical - connections are created for all MPI-thread splits and thus test - for correct parallelization. - - Hans Ekkehard Plesser -*/ - -%%% PARAMETER SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -% define all relevant parameters: changes should be made here -% all data is place in the userdict dictionary - -/num_neurons 1000 def - -/connspec << /rule /fixed_indegree /indegree 100 >> def -%/connspec << /rule /fixed_outdegree /outdegree 100 >> def - -/num_vps 16 def - -/simtime 10.0 def % simulation time [ms] -/dt 0.1 def % simulation step length [ms] - -%%% HELPER SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -/padded -{ - dup 10 lt - { - cvs (0) exch join - } - { - cvs - } - ifelse -} def - -%%% CONSTRUCTION SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - -ResetKernel % clear all existing network elements -M_WARNING setverbosity - - -% set resolution and total/local number of threads -0 << - /resolution dt - /total_num_virtual_procs num_vps - /overwrite_files true ->> SetStatus - -tic % start timer on construction - -(Creating the network.) = - -% setup to allow us to randomize receptor_type -/tau_syns [0.2 1.0 0.1] Range def -/receptor_min 1 def -/receptor_max tau_syns length def -/iaf_psc_alpha_multisynapse << /tau_syn tau_syns >> SetDefaults - -/iaf_psc_alpha_multisynapse [ num_neurons ] LayoutNetwork -GetGlobalLeaves /population Set - - -(Connecting neurons.) = -population population connspec -<< /model /stdp_synapse - /delay << /distribution /uniform /low 0.5 /high 1.5 >> - /weight << /distribution /uniform /low 5.0 /high 15.0 >> - /receptor_type << /distribution /uniform_int /low receptor_min /high receptor_max >> - /alpha << /distribution /uniform /low 0.1 /high 2.3 >> - /tau_plus << /distribution /uniform /low 1.5 /high 5.0 >> ->> -Connect - -(Done connecting.) = - -toc /BuildCPUTime Set - -% dump connections to file -/fname (pcar_) NumProcesses padded join (_) join Rank padded join (.conn) join def - -(Dumping to file ) fname join = -/of fname (w) file def -<< /synapse_model /stdp_synapse >> GetConnections -{ - [[/source /target /weight /delay /alpha /tau_plus]] get - { of exch <- (\t) <- ; } forall - of endl ; -} forall -of close -(Done dumping) = - -%%% SIMULATION SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -(Simulating) = -simtime Simulate -(Done simulating) = - -(Number of MPI procs: ) =only NumProcesses = -(Number of VPs : ) =only num_vps = -(Number of Neurons : ) =only num_neurons = -(Number of Synapses : ) =only 0 GetStatus /num_connections get = -(Building time : ) =only BuildCPUTime =only ( s\n) = - diff --git a/testsuite/unittests/test_mip_corrdet.sli b/testsuite/unittests/test_mip_corrdet.sli index 3c67d4f027..b3d711b7ef 100644 --- a/testsuite/unittests/test_mip_corrdet.sli +++ b/testsuite/unittests/test_mip_corrdet.sli @@ -131,13 +131,13 @@ dup /histogram get cva /hist Set n1 T tau_max sub div 1000.0 mul /lmbd1 Set n2 T tau_max sub div 1000.0 mul /lmbd2 Set -cout -(rate 1=) <- lmbd1 <- (\n) <- -(rate 2=) <- lmbd2 <- (\n) <- -(background =) <- lmbd1 lmbd2 mul delta_tau 1000 div mul T tau_max sub 1000 div mul <- (\n) <- pop +%cout +%(rate 1=) <- lmbd1 <- (\n) <- +%(rate 2=) <- lmbd2 <- (\n) <- +%(background =) <- lmbd1 lmbd2 mul delta_tau 1000 div mul T tau_max sub 1000 div mul <- (\n) <- pop -hist == -0 hist { add } forall == +%hist == +%0 hist { add } forall == hist expected_hist eq From 36db301c16a42c00c5e62115ddd3ba3fc246a932 Mon Sep 17 00:00:00 2001 From: Stine Vennemo Date: Wed, 20 Sep 2017 13:13:42 +0200 Subject: [PATCH 20/20] pep8ify --- pynest/examples/cross_check_mip_corrdet.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pynest/examples/cross_check_mip_corrdet.py b/pynest/examples/cross_check_mip_corrdet.py index f3f98eac55..dd0e5cde7e 100644 --- a/pynest/examples/cross_check_mip_corrdet.py +++ b/pynest/examples/cross_check_mip_corrdet.py @@ -39,6 +39,8 @@ spike1: first spike train [tspike...] spike2: second spike train [tspike...] ''' + + def corr_spikes_sorted(spike1, spike2, tbin, tau_max, h): tau_max_i = int(tau_max / h) tbin_i = int(tbin / h) @@ -62,7 +64,7 @@ def corr_spikes_sorted(spike1, spike2, tbin, tau_max, h): nest.ResetKernel() -h = 0.1 # Computation step size in ms +h = 0.1 # Computation step size in ms T = 100000.0 # Total duration delta_tau = 10.0 tau_max = 100.0 @@ -104,8 +106,8 @@ def corr_spikes_sorted(spike1, spike2, tbin, tau_max, h): n1 = n_events[0] n2 = n_events[1] -lmbd1 = ( n1 / ( T - tau_max ) ) * 1000.0 -lmbd2 = ( n2 / ( T - tau_max ) ) * 1000.0 +lmbd1 = (n1 / (T - tau_max)) * 1000.0 +lmbd2 = (n2 / (T - tau_max)) * 1000.0 h = 0.1 tau_max = 100.0 # ms correlation window @@ -122,4 +124,4 @@ def corr_spikes_sorted(spike1, spike2, tbin, tau_max, h): print("Crosscorrelation:") print(cross) print("Sum of crosscorrelation:") -print(sum(cross)) \ No newline at end of file +print(sum(cross))