Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting some manualtests to tests used by installcheck #774

Merged
merged 30 commits into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1bbf42c
Updated and moved some of the tests from "manualtests" folder
hakonsbm May 8, 2017
db52266
Fixed PEP 8 errors
hakonsbm Jun 30, 2017
ffe5b41
Made requested changes.
hakonsbm Jun 30, 2017
96d3941
Small cleanup
hakonsbm Jul 3, 2017
46ee0e0
Minor changes to comments and formatting
jougs Jul 6, 2017
accd1d5
Merge pull request #16 from jougs/hakonsbm-manualtests
hakonsbm Jul 6, 2017
568fd4a
pep8ify
jougs Jul 6, 2017
720bad8
Merge pull request #17 from jougs/hakonsbm-manualtests
hakonsbm Jul 6, 2017
df6feae
Deleted manualtests that could not be fixed
hakonsbm Jul 6, 2017
2e8d285
Switched back to old Ubuntu image
hakonsbm Jul 7, 2017
18c874d
Merge remote-tracking branch 'origin/master' into manualtests
hakonsbm Jul 7, 2017
5e9fc81
Converted hh_phaseplane.m and test_hh_phaseplane.sli to PyNEST
stinebuu Jul 7, 2017
6b10cd0
Proper skip without gsl declaration
stinebuu Jul 7, 2017
4b842ce
pep8ify
stinebuu Jul 7, 2017
af99960
Merge pull request #18 from stinebuu/manualtests
hakonsbm Jul 7, 2017
bcfa384
Updated more tests
hakonsbm Jul 7, 2017
9f8a4c5
Merge branch 'manualtests' of
hakonsbm Jul 7, 2017
a228d6e
Updated test, PEP8 issue
hakonsbm Jul 10, 2017
1e57e86
Reverted 2e8d285
hakonsbm Jul 18, 2017
d02e279
Merge branch 'master' into manualtests
hakonsbm Jul 18, 2017
8993de9
Started converting one of the tests to pythontest
stinebuu Aug 14, 2017
a631286
Removed superfluous tests
hakonsbm Aug 17, 2017
66d0b36
Removed SLI language design study files
hakonsbm Aug 21, 2017
936b110
Removed outdated tests
hakonsbm Sep 8, 2017
ff35615
Converted cross_check_mip_corrdet to python example.
stinebuu Sep 20, 2017
c915b3c
Merge pull request #19 from stinebuu/manualtests
hakonsbm Sep 20, 2017
caf9806
Merge branch 'manualtests' of https://github.com/hakonsbm/nest-simula…
hakonsbm Sep 20, 2017
36db301
pep8ify
stinebuu Sep 20, 2017
745758d
Removed manualtests from testsuite cmakelist, made a test python 3
stinebuu Sep 20, 2017
cc22ee1
Merge pull request #20 from stinebuu/manualtests
hakonsbm Sep 20, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions pynest/nest/tests/test_current_recording_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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,
Expand All @@ -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)), \
Expand All @@ -197,5 +198,6 @@ def run():
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite())


if __name__ == "__main__":
run()
167 changes: 167 additions & 0 deletions pynest/nest/tests/test_facetshw_stdp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# -*- 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 <http://www.gnu.org/licenses/>.

# 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 #
# 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]
tau = 20.0

timeBetweenPairs = 100.0
# 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,
'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')
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.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)

# just before theoretical updates
weightTraceMod36pre = weightTrace[35::36]

# just after theoretical updates
weightTraceMod36 = weightTrace[::36]

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()
Loading