From 664e153146c806628daa5e47212bf74718466719 Mon Sep 17 00:00:00 2001 From: Andrew Rowley Date: Fri, 1 May 2020 10:07:29 +0100 Subject: [PATCH 1/9] Testing of weight_scales From 6a1c2dd1ce508ce45ae74b75b9f486181193c3c4 Mon Sep 17 00:00:00 2001 From: Andrew Rowley Date: Fri, 1 May 2020 11:37:18 +0100 Subject: [PATCH 2/9] Fix pylint --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fb07d621f..81191f926 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,7 +51,7 @@ before_install: install: - pip install -r requirements-test.txt - - pip install pylint python-coveralls 'coverage>=4.4,<5.0' + - pip install 'pylint<2.5' python-coveralls 'coverage>=4.4,<5.0' - python ./setup.py install before_script: From a2afd8105984d6a51cae31e60b470c3c6aebd15a Mon Sep 17 00:00:00 2001 From: Andrew Rowley Date: Wed, 20 May 2020 08:56:12 +0100 Subject: [PATCH 3/9] Update to account for changes in weight representation --- .../quick_test/test_various/test_synaptic_expander.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p8_integration_tests/quick_test/test_various/test_synaptic_expander.py b/p8_integration_tests/quick_test/test_various/test_synaptic_expander.py index 66d65c2f1..5f2b555cf 100644 --- a/p8_integration_tests/quick_test/test_various/test_synaptic_expander.py +++ b/p8_integration_tests/quick_test/test_various/test_synaptic_expander.py @@ -96,7 +96,7 @@ def run_script(): def check_params(param, result): if not isinstance(param, RandomDistribution): - assert(all(param == value for value in result)) + assert numpy.allclose(result, param, atol=0.01) else: # Check the values are "random" (yes I know they might be the same, # but the chances are quite small!) From c09fe49297101cf973247a6077b6af4e278543ba Mon Sep 17 00:00:00 2001 From: Andrew Rowley Date: Wed, 20 May 2020 10:19:39 +0100 Subject: [PATCH 4/9] Fix tests as weights might not be as precise --- .../test_using_virtual_board/test_from_file_connector.py | 4 ++-- .../test_using_virtual_board/test_from_list_connector.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/unittests/test_using_virtual_board/test_from_file_connector.py b/unittests/test_using_virtual_board/test_from_file_connector.py index d42c861ae..b5e934684 100644 --- a/unittests/test_using_virtual_board/test_from_file_connector.py +++ b/unittests/test_using_virtual_board/test_from_file_connector.py @@ -41,11 +41,11 @@ def check_weights( self.assertEqual(from_as[0], source) self.assertEqual(from_as[1], dest) if w_index: - self.assertAlmostEqual(from_as[w_index], weight, 4) + self.assertAlmostEqual(from_as[w_index], weight, 3) else: self.assertEqual(WEIGHT, weight) if d_index: - self.assertAlmostEqual(from_as[d_index], delay, 4) + self.assertAlmostEqual(from_as[d_index], delay, 3) else: self.assertEqual(DELAY, delay) as_index += 1 diff --git a/unittests/test_using_virtual_board/test_from_list_connector.py b/unittests/test_using_virtual_board/test_from_list_connector.py index e0a36993e..2684eb140 100644 --- a/unittests/test_using_virtual_board/test_from_list_connector.py +++ b/unittests/test_using_virtual_board/test_from_list_connector.py @@ -38,11 +38,11 @@ def check_weights( self.assertEqual(from_as[0], source) self.assertEqual(from_as[1], dest) if w_index: - self.assertAlmostEqual(from_as[w_index], weight, 4) + self.assertAlmostEqual(from_as[w_index], weight, 3) else: self.assertEqual(WEIGHT, weight) if d_index: - self.assertAlmostEqual(from_as[d_index], delay, 4) + self.assertAlmostEqual(from_as[d_index], delay, 3) else: self.assertEqual(DELAY, delay) as_index += 1 From f99f842e20961ca7282ce33d5626b222b71a270b Mon Sep 17 00:00:00 2001 From: Andrew Rowley Date: Wed, 20 May 2020 10:35:13 +0100 Subject: [PATCH 5/9] More precision fixes --- .../test_using_virtual_board/test_from_file_connector.py | 4 ++-- .../test_using_virtual_board/test_from_list_connector.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/unittests/test_using_virtual_board/test_from_file_connector.py b/unittests/test_using_virtual_board/test_from_file_connector.py index b5e934684..02022bb3c 100644 --- a/unittests/test_using_virtual_board/test_from_file_connector.py +++ b/unittests/test_using_virtual_board/test_from_file_connector.py @@ -43,11 +43,11 @@ def check_weights( if w_index: self.assertAlmostEqual(from_as[w_index], weight, 3) else: - self.assertEqual(WEIGHT, weight) + self.assertAlmostEqual(WEIGHT, weight, 3) if d_index: self.assertAlmostEqual(from_as[d_index], delay, 3) else: - self.assertEqual(DELAY, delay) + self.assertAlmostEqual(DELAY, delay, 3) as_index += 1 while as_index < len(aslist): from_as = aslist[as_index] diff --git a/unittests/test_using_virtual_board/test_from_list_connector.py b/unittests/test_using_virtual_board/test_from_list_connector.py index 2684eb140..61439fd64 100644 --- a/unittests/test_using_virtual_board/test_from_list_connector.py +++ b/unittests/test_using_virtual_board/test_from_list_connector.py @@ -40,11 +40,11 @@ def check_weights( if w_index: self.assertAlmostEqual(from_as[w_index], weight, 3) else: - self.assertEqual(WEIGHT, weight) + self.assertAlmostEqual(WEIGHT, weight, 3) if d_index: self.assertAlmostEqual(from_as[d_index], delay, 3) else: - self.assertEqual(DELAY, delay) + self.assertAlmostEqual(DELAY, delay, 3) as_index += 1 while as_index < len(aslist): from_as = aslist[as_index] From 957ec9df95bdb59f91b89093ad7a0b2919720999 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Thu, 30 Jul 2020 16:00:07 +0100 Subject: [PATCH 6/9] Update integration tests that now use closest representable values - also updated test_structural_shared to not do the same thing twice --- .../test_connectors/test_kernel_connector.py | 24 ++++++--- .../test_struct_pl/test_structural_shared.py | 54 ++++++++++++++----- .../test_alltoone_with_large_weight.py | 5 +- 3 files changed, 61 insertions(+), 22 deletions(-) diff --git a/p8_integration_tests/quick_test/test_connectors/test_kernel_connector.py b/p8_integration_tests/quick_test/test_connectors/test_kernel_connector.py index 941c8c736..34d119d48 100644 --- a/p8_integration_tests/quick_test/test_connectors/test_kernel_connector.py +++ b/p8_integration_tests/quick_test/test_connectors/test_kernel_connector.py @@ -77,8 +77,10 @@ def test_oddsquarek_run(self): self.assertEqual(25, len(weightsdelays)) list10 = (1, 0, 5.0, 20.0) list11 = (1, 1, 7.0, 10.0) - [self.assertEqual(list10[i], weightsdelays[1][i]) for i in range(4)] - [self.assertEqual(list11[i], weightsdelays[5][i]) for i in range(4)] + [self.assertAlmostEqual( + list10[i], weightsdelays[1][i], places=3) for i in range(4)] + [self.assertAlmostEqual( + list11[i], weightsdelays[5][i], places=3) for i in range(4)] # NOTE: you can probably replace the above in later versions of python3 # with the following, but in 3.5 it generates a FutureWarning # self.assertSequenceEqual(list10, weightsdelays[1]) @@ -91,8 +93,10 @@ def test_evensquarek_run(self): self.assertEqual(9, len(weightsdelays)) list01 = (0, 1, 5.0, 20.0) list03 = (0, 3, 7.0, 10.0) - [self.assertEqual(list01[i], weightsdelays[1][i]) for i in range(4)] - [self.assertEqual(list03[i], weightsdelays[5][i]) for i in range(4)] + [self.assertAlmostEqual( + list01[i], weightsdelays[1][i], places=3) for i in range(4)] + [self.assertAlmostEqual( + list03[i], weightsdelays[5][i], places=3) for i in range(4)] def test_nonsquarek_run(self): (psh, psw, ksh, ksw) = (4, 4, 1, 3) @@ -101,8 +105,10 @@ def test_nonsquarek_run(self): self.assertEqual(10, len(weightsdelays)) list10 = (1, 0, 7.0, 10.0) list42 = (4, 2, 5.0, 20.0) - [self.assertEqual(list10[i], weightsdelays[1][i]) for i in range(4)] - [self.assertEqual(list42[i], weightsdelays[5][i]) for i in range(4)] + [self.assertAlmostEqual( + list10[i], weightsdelays[1][i], places=3) for i in range(4)] + [self.assertAlmostEqual( + list42[i], weightsdelays[5][i], places=3) for i in range(4)] def test_bigger_nonsquarep_run(self): (psh, psw, ksh, ksw) = (32, 16, 3, 3) @@ -111,5 +117,7 @@ def test_bigger_nonsquarep_run(self): self.assertEqual(1081, len(weightsdelays)) list10 = (1, 0, 5.0, 20.0) list11 = (1, 1, 7.0, 10.0) - [self.assertEqual(list10[i], weightsdelays[1][i]) for i in range(4)] - [self.assertEqual(list11[i], weightsdelays[5][i]) for i in range(4)] + [self.assertAlmostEqual( + list10[i], weightsdelays[1][i], places=3) for i in range(4)] + [self.assertAlmostEqual( + list11[i], weightsdelays[5][i], places=3) for i in range(4)] diff --git a/p8_integration_tests/quick_test/test_struct_pl/test_structural_shared.py b/p8_integration_tests/quick_test/test_struct_pl/test_structural_shared.py index 62aaea6f1..37cd381f3 100644 --- a/p8_integration_tests/quick_test/test_struct_pl/test_structural_shared.py +++ b/p8_integration_tests/quick_test/test_struct_pl/test_structural_shared.py @@ -12,7 +12,8 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from p8_integration_tests.base_test_case import BaseTestCase +from p8_integration_tests.base_test_case import ( + BaseTestCase, calculate_spike_pair_additive_stdp_weight) import spynnaker8 as p import numpy @@ -27,37 +28,56 @@ def structural_shared(): w_min = 0.0 w_max = 5.0 w_init = 5.0 + w_init_stdp = 2.0 delay_init = 2.0 + delay_init_stdp = 5.0 stim = p.Population(1, p.SpikeSourceArray(pre_spikes), label="stim") pop = p.Population(1, p.IF_curr_exp(), label="pop") pop_2 = p.Population(1, p.IF_curr_exp(), label="pop_2") pop_3 = p.Population(1, p.IF_curr_exp(), label="pop_3") pop_4 = p.Population(1, p.IF_curr_exp(), label="pop_4") pop.record("spikes") - pop_2.record("spikes") - struct_pl_static = p.StructuralMechanismStatic( + pop_3.record("spikes") + struct_pl_static_form = p.StructuralMechanismStatic( partner_selection=p.LastNeuronSelection(), formation=p.DistanceDependentFormation([1, 1], 1.0), elimination=p.RandomByWeightElimination(2.0, 0, 0), f_rew=1000, initial_weight=w_init, initial_delay=delay_init, s_max=1, seed=0, weight=0.0, delay=1.0) - struct_pl_stdp = p.StructuralMechanismSTDP( + struct_pl_static_elim = p.StructuralMechanismStatic( + partner_selection=p.LastNeuronSelection(), + formation=p.DistanceDependentFormation([1, 1], 0.0), + elimination=p.RandomByWeightElimination(4.0, 1.0, 1.0), + f_rew=1000, initial_weight=w_init, initial_delay=delay_init, + s_max=1, seed=0, weight=0.0, delay=1.0) + struct_pl_stdp_form = p.StructuralMechanismSTDP( + partner_selection=p.LastNeuronSelection(), + formation=p.DistanceDependentFormation([1, 1], 1.0), + elimination=p.RandomByWeightElimination(2.0, 0, 0), + timing_dependence=p.SpikePairRule( + tau_plus, tau_minus, A_plus, A_minus), + weight_dependence=p.AdditiveWeightDependence(w_min, w_max), + f_rew=1000, initial_weight=w_init_stdp, + initial_delay=delay_init_stdp, + s_max=1, seed=0, weight=0.0, delay=1.0) + struct_pl_stdp_elim = p.StructuralMechanismSTDP( partner_selection=p.LastNeuronSelection(), formation=p.DistanceDependentFormation([1, 1], 0.0), elimination=p.RandomByWeightElimination(4.0, 1.0, 1.0), timing_dependence=p.SpikePairRule( tau_plus, tau_minus, A_plus, A_minus), weight_dependence=p.AdditiveWeightDependence(w_min, w_max), - f_rew=1000, initial_weight=2.0, initial_delay=5.0, + f_rew=1000, initial_weight=w_init_stdp, + initial_delay=delay_init_stdp, s_max=1, seed=0, weight=0.0, delay=1.0) proj = p.Projection( - stim, pop, p.FromListConnector([]), struct_pl_static) + stim, pop, p.FromListConnector([]), struct_pl_static_form) proj_2 = p.Projection( - stim, pop_2, p.FromListConnector([]), struct_pl_static) + stim, pop_2, p.FromListConnector([(0, 0)]), struct_pl_static_elim) proj_3 = p.Projection( - stim, pop_3, p.FromListConnector([(0, 0)]), struct_pl_stdp) + stim, pop_3, p.FromListConnector([]), struct_pl_stdp_form) proj_4 = p.Projection( - stim, pop_4, p.FromListConnector([(0, 0)]), struct_pl_stdp) + stim, pop_4, p.FromListConnector([(0, 0)]), struct_pl_stdp_elim) p.Projection(pop_3, pop_4, p.AllToAllConnector(), p.StaticSynapse(weight=1, delay=3)) p.run(10) @@ -67,6 +87,8 @@ def structural_shared(): conns_3 = list(proj_3.get(["weight", "delay"], "list")) conns_4 = list(proj_4.get(["weight", "delay"], "list")) + spikes_3 = [s.magnitude + for s in pop_3.get_data("spikes").segments[0].spiketrains] p.end() print(conns) @@ -74,11 +96,17 @@ def structural_shared(): print(conns_3) print(conns_4) + w_final_1 = calculate_spike_pair_additive_stdp_weight( + pre_spikes, spikes_3[0], w_init_stdp, delay_init_stdp, w_max, + A_plus, A_minus, tau_plus, tau_minus) + assert(len(conns) == 1) - assert(tuple(conns[0]) == (0, 0, w_init, delay_init)) - assert(len(conns_2) == 1) - assert(tuple(conns_2[0]) == (0, 0, w_init, delay_init)) - assert(len(conns_3) == 0) + assert(conns[0][2] >= w_init - 0.01 and + conns[0][2] <= w_init + 0.01) + assert(len(conns_2) == 0) + assert(len(conns_3) == 1) + assert(conns_3[0][2] >= w_final_1 - 0.01 and + conns_3[0][2] <= w_final_1 + 0.01) assert(len(conns_4) == 0) diff --git a/p8_integration_tests/quick_test/test_various/test_alltoone_with_large_weight.py b/p8_integration_tests/quick_test/test_various/test_alltoone_with_large_weight.py index 8d9d42a5b..0c160383f 100644 --- a/p8_integration_tests/quick_test/test_various/test_alltoone_with_large_weight.py +++ b/p8_integration_tests/quick_test/test_various/test_alltoone_with_large_weight.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from data_specification.enums import DataType from p8_integration_tests.base_test_case import BaseTestCase import spynnaker8 as sim @@ -40,7 +41,9 @@ def do_run(self): sim.end() weight_sum = sum(weight[2] for weight in weight_list) - self.assertEqual(weight_sum, sources * weights) + weight_used = 1 / ( + DataType.S1615.closest_representable_value_above(1 / weights)) + self.assertAlmostEqual(weight_sum, sources * weight_used) def test_run(self): self.runsafe(self.do_run) From d302a193444c622362d44c26452ed0bd79763b4b Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Fri, 31 Jul 2020 09:44:29 +0100 Subject: [PATCH 7/9] logger doesn't need to be sent inside warning(...) --- spynnaker8/models/populations/population.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spynnaker8/models/populations/population.py b/spynnaker8/models/populations/population.py index 401866822..7e8422583 100644 --- a/spynnaker8/models/populations/population.py +++ b/spynnaker8/models/populations/population.py @@ -252,7 +252,7 @@ def write_data(self, io, variables='all', gather=True, clear=False, # pylint: disable=too-many-arguments if not gather: logger.warning( - logger, "sPyNNaker only supports gather=True. We will run " + "sPyNNaker only supports gather=True. We will run " "as if gather was set to True.") if isinstance(io, string_types): @@ -330,7 +330,7 @@ def get_data( """ if not gather: logger.warning( - logger, "sPyNNaker only supports gather=True. We will run " + "sPyNNaker only supports gather=True. We will run " "as if gather was set to True.") if annotations is not None: warn_once( From 90a80e485548ec38b7e98b1c2fcb193c1d3017c0 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Tue, 6 Oct 2020 10:38:22 +0100 Subject: [PATCH 8/9] Update test tolerance --- .../quick_test/test_connectors/test_one_to_one_connector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p8_integration_tests/quick_test/test_connectors/test_one_to_one_connector.py b/p8_integration_tests/quick_test/test_connectors/test_one_to_one_connector.py index f910e4b1a..7676d52c9 100644 --- a/p8_integration_tests/quick_test/test_connectors/test_one_to_one_connector.py +++ b/p8_integration_tests/quick_test/test_connectors/test_one_to_one_connector.py @@ -36,7 +36,7 @@ def do_one_to_one_test( sim.end() for pre, post, w, d in conns: assert pre == post - assert w == weight + assert numpy.allclose(w, weight, rtol=0.0001) assert d == delay def do_one_to_one_conductance_test( From 70e5bf6cbe80a8f31c278c8e923f980163f69db6 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Tue, 19 Jan 2021 16:26:02 +0000 Subject: [PATCH 9/9] minor tidying up of tests --- .../test_stdp/test_STDP_nearest_pair_multiplicative.py | 5 +++-- .../quick_test/test_stdp/test_STDP_pair_multiplicative.py | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/p8_integration_tests/quick_test/test_stdp/test_STDP_nearest_pair_multiplicative.py b/p8_integration_tests/quick_test/test_stdp/test_STDP_nearest_pair_multiplicative.py index 5608cb7ba..d53945bad 100644 --- a/p8_integration_tests/quick_test/test_stdp/test_STDP_nearest_pair_multiplicative.py +++ b/p8_integration_tests/quick_test/test_stdp/test_STDP_nearest_pair_multiplicative.py @@ -127,8 +127,6 @@ def potentiation_and_depression(self): # print("Pre neuron spikes at: {}".format(pre_spikes)) # print("Post-neuron spikes at: {}".format(post_spikes)) - target_spikes = [1014, 1032, 1053] - self.assertListEqual(list(post_spikes), target_spikes) # print("Potentiation time differences: {}".format(potentiation_times)) # print("Depression time differences: {}".format(depression_times)) # print("Potentiation: {}".format(potentiations)) @@ -136,6 +134,9 @@ def potentiation_and_depression(self): # print("New weight exact: {}".format(new_weight_exact)) # print("New weight SpiNNaker: {}".format(weights)) + target_spikes = [1014, 1032, 1053] + self.assertListEqual(list(post_spikes), target_spikes) + self.assertTrue(numpy.allclose( weights[0], new_weight_exact, atol=0.001)) diff --git a/p8_integration_tests/quick_test/test_stdp/test_STDP_pair_multiplicative.py b/p8_integration_tests/quick_test/test_stdp/test_STDP_pair_multiplicative.py index 6ae225cff..45ad3f8f3 100644 --- a/p8_integration_tests/quick_test/test_stdp/test_STDP_pair_multiplicative.py +++ b/p8_integration_tests/quick_test/test_stdp/test_STDP_pair_multiplicative.py @@ -69,9 +69,9 @@ def post_spike_same_time(): pre_spikes, post_spikes, initial_weight, plastic_delay, min_weight, max_weight, a_plus, a_minus, tau_plus, tau_minus) - print(weights_1) - print(weights_2) - print(new_weight_exact) + # print(weights_1) + # print(weights_2) + # print(new_weight_exact) assert(len(weights_1) == 1) assert(len(weights_2) == 1) @@ -161,7 +161,7 @@ def potentiation_and_depression(): print("Pre neuron spikes at: {}".format(pre_spikes)) print("Post-neuron spikes at: {}".format(post_spikes)) - target_spikes = [1014, 1032, 1053] + target_spikes = [1014, 1032, 1053] assert(all(s1 == s2 for s1, s2 in zip(list(post_spikes), target_spikes))) print("New weight exact: {}".format(new_weight_exact))