diff --git a/spynnaker/pyNN/models/neuron/connection_holder.py b/spynnaker/pyNN/models/neuron/connection_holder.py index 1d100d374c..8d557439ff 100644 --- a/spynnaker/pyNN/models/neuron/connection_holder.py +++ b/spynnaker/pyNN/models/neuron/connection_holder.py @@ -171,15 +171,24 @@ def _get_data_items(self): # all the data if (self.__data_items_to_return is None or not self.__data_items_to_return): - self.__data_items = connections[order] + data_items = connections[order] # There is more than one item to return, so let numpy do its magic elif len(self.__data_items_to_return) > 1: - self.__data_items = \ + data_items = \ connections[order][self.__data_items_to_return] # There is 1 item to return, so make sure only one item exists else: - self.__data_items = \ + data_items = \ connections[order][self.__data_items_to_return[0]] + + # Return in a format which can be understood by a FromListConnector + self.__data_items = [] + for data_item in data_items: + data_item_list = data_item + if hasattr(data_item_list, "__len__"): + data_item_list = list(data_item) + self.__data_items.append(data_item_list) + else: if self.__data_items_to_return is None: return [] diff --git a/spynnaker_integration_tests/test_connectors/test_all_to_all_connector.py b/spynnaker_integration_tests/test_connectors/test_all_to_all_connector.py index b042c1f00e..889e3f44af 100644 --- a/spynnaker_integration_tests/test_connectors/test_all_to_all_connector.py +++ b/spynnaker_integration_tests/test_connectors/test_all_to_all_connector.py @@ -104,9 +104,9 @@ def using_population_views(self): sim.run(1) weights = conn.get(['weight', 'delay'], 'list') sim.end() - target = [(1, 2, 0.5, 2.), (1, 3, 0.5, 2.), (2, 2, 0.5, 2.), - (2, 3, 0.5, 2.)] - self.assertEqual(weights.tolist(), target) + target = [[1, 2, 0.5, 2.], [1, 3, 0.5, 2.], [2, 2, 0.5, 2.], + [2, 3, 0.5, 2.]] + self.assertCountEqual(weights, target) def test_using_population_views(self): self.runsafe(self.using_population_views) diff --git a/spynnaker_integration_tests/test_connectors/test_connectors.py b/spynnaker_integration_tests/test_connectors/test_connectors.py index 2831682b94..228390e06c 100644 --- a/spynnaker_integration_tests/test_connectors/test_connectors.py +++ b/spynnaker_integration_tests/test_connectors/test_connectors.py @@ -74,7 +74,9 @@ def check_connection(self, projection, destination, connections, repeats, counts = self.calc_spikes_received(v) expected = numpy.zeros([SOURCES, n_destinations]) - for (src, dest, _) in weights: + for weight in weights: + src = weight[0] + dest = weight[1] expected[src][dest] += 1 the_max = max(map(max, counts)) if not numpy.array_equal(expected, counts): @@ -237,8 +239,8 @@ def onetoone_population_views(self): sim.run(1) weights = conn.get(['weight', 'delay'], 'list') sim.end() - target = [(1, 2, 0.5, 2.), (2, 3, 0.5, 2.)] - self.assertEqual(weights.tolist(), target) + target = [[1, 2, 0.5, 2.], [2, 3, 0.5, 2.]] + self.assertCountEqual(weights, target) def test_onetoone_population_views(self): self.runsafe(self.onetoone_population_views) @@ -259,9 +261,9 @@ def onetoone_multicore_population_views(self): edge.label == 'machine_edge_for_test')] sim.end() # Check the connections are correct - target = [(6, 9, 0.5, 2.), (7, 10, 0.5, 2.), (8, 11, 0.5, 2.), - (9, 12, 0.5, 2.), (10, 13, 0.5, 2.), (11, 14, 0.5, 2.)] - self.assertEqual(weights.tolist(), target) + target = [[6, 9, 0.5, 2.], [7, 10, 0.5, 2.], [8, 11, 0.5, 2.], + [9, 12, 0.5, 2.], [10, 13, 0.5, 2.], [11, 14, 0.5, 2.]] + self.assertCountEqual(weights, target) # In this instance there should be three MachineEdges: one of the four # possible at the start should have been filtered out self.assertEqual(len(projection_edges), 3) @@ -278,8 +280,8 @@ def fixedprob_population_views(self): weights = conn.get(['weight', 'delay'], 'list') sim.end() # The fixed seed means this gives the same answer each time - target = [(1, 3, 0.5, 2.), (2, 2, 0.5, 2.), (2, 3, 0.5, 2)] - self.assertEqual(weights.tolist(), target) + target = [[1, 3, 0.5, 2.], [2, 2, 0.5, 2.], [2, 3, 0.5, 2]] + self.assertCountEqual(weights, target) def test_fixedprob_population_views(self): self.runsafe(self.fixedprob_population_views) @@ -296,9 +298,9 @@ def fixedpre_population_views(self): weights = conn.get(['weight', 'delay'], 'list') sim.end() # The fixed seed means this gives the same answer each time - target = [(1, 1, 0.5, 2.0), (1, 2, 0.5, 2.0), (1, 3, 0.5, 2.0), - (2, 1, 0.5, 2.0), (2, 2, 0.5, 2.0), (2, 3, 0.5, 2.0)] - self.assertEqual(weights.tolist(), target) + target = [[1, 1, 0.5, 2.0], [1, 2, 0.5, 2.0], [1, 3, 0.5, 2.0], + [2, 1, 0.5, 2.0], [2, 2, 0.5, 2.0], [2, 3, 0.5, 2.0]] + self.assertCountEqual(weights, target) def test_fixedpre_population_views(self): self.runsafe(self.fixedpre_population_views) @@ -315,9 +317,9 @@ def fixedpost_population_views(self): weights = conn.get(['weight', 'delay'], 'list') sim.end() # The fixed seed means this gives the same answer each time - target = [(0, 1, 0.5, 2.0), (0, 3, 0.5, 2.0), (1, 1, 0.5, 2.0), - (1, 3, 0.5, 2.0), (2, 1, 0.5, 2.0), (2, 2, 0.5, 2.0)] - self.assertEqual(weights.tolist(), target) + target = [[0, 1, 0.5, 2.0], [0, 3, 0.5, 2.0], [1, 1, 0.5, 2.0], + [1, 3, 0.5, 2.0], [2, 1, 0.5, 2.0], [2, 2, 0.5, 2.0]] + self.assertCountEqual(weights, target) def test_fixedpost_population_views(self): self.runsafe(self.fixedpost_population_views) @@ -341,14 +343,14 @@ def fixedtotal_population_views(self): weights2 = conn2.get(['weight', 'delay'], 'list') sim.end() # The fixed seed means this gives the same answer each time - target = [(0, 2, 0.5, 2.0), (0, 3, 0.5, 2.0), (1, 1, 0.5, 2.0), - (1, 3, 0.5, 2.0), (2, 1, 0.5, 2.0)] - target2 = [(0, 2, 0.5, 2.0), (0, 2, 0.5, 2.0), (1, 1, 0.5, 2.0), - (2, 2, 0.5, 2.0), (2, 3, 0.5, 2.0)] - self.assertEqual(weights.tolist(), target) - self.assertEqual(len(weights.tolist()), n_conns) - self.assertEqual(weights2.tolist(), target2) - self.assertEqual(len(weights2.tolist()), n_conns) + target = [[0, 2, 0.5, 2.0], [0, 3, 0.5, 2.0], [1, 1, 0.5, 2.0], + [1, 3, 0.5, 2.0], [2, 1, 0.5, 2.0]] + target2 = [[0, 2, 0.5, 2.0], [0, 2, 0.5, 2.0], [1, 1, 0.5, 2.0], + [2, 2, 0.5, 2.0], [2, 3, 0.5, 2.0]] + self.assertCountEqual(weights, target) + self.assertEqual(len(weights), n_conns) + self.assertCountEqual(weights2, target2) + self.assertEqual(len(weights2), n_conns) def test_fixedtotal_population_views(self): self.runsafe(self.fixedtotal_population_views) diff --git a/spynnaker_integration_tests/test_connectors/test_use_projection_get_in_from_list.py b/spynnaker_integration_tests/test_connectors/test_use_projection_get_in_from_list.py new file mode 100644 index 0000000000..287187536a --- /dev/null +++ b/spynnaker_integration_tests/test_connectors/test_use_projection_get_in_from_list.py @@ -0,0 +1,65 @@ +# Copyright (c) 2017-2019 The University of Manchester +# +# This program 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 3 of the License, or +# (at your option) any later version. +# +# This program 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 this program. If not, see . + +import spynnaker8 as sim +from spinnaker_testbase import BaseTestCase + + +class TestUseProjectionGetInFromList(BaseTestCase): + + def do_run(self): + sim.setup(timestep=1.0) + sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 5) + + n_neurons = 10 + weights = 0.5 + delays = 7 + n_pre = 2 + + p1 = sim.Population(n_neurons, sim.IF_curr_exp, {}, label='pop1_1') + p2 = sim.Population(n_neurons, sim.IF_curr_exp, {}, label='pop1_2') + + connector_pre = sim.FixedNumberPreConnector(n_pre) + + proj_pre = sim.Projection(p1, p2, connector_pre, + synapse_type=sim.StaticSynapse( + weight=weights, delay=delays)) + + sim.run(10) + + weights_delays_pre = proj_pre.get(["weight", "delay"], "list") + + sim.end() + + sim.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) + sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 5) + + p11 = sim.Population(n_neurons, sim.IF_curr_exp, {}, label='pop2_1') + p22 = sim.Population(n_neurons, sim.IF_curr_exp, {}, label='pop2_2') + + fromlist_conn = sim.FromListConnector(weights_delays_pre) + + proj_new = sim.Projection(p11, p22, fromlist_conn) + + sim.run(10) + + weights_delays_out = proj_new.get(["weight", "delay"], "list") + + sim.end() + + self.assertCountEqual(weights_delays_pre, weights_delays_out) + + def test_use_projection_get_in_from_list(self): + self.runsafe(self.do_run) diff --git a/spynnaker_integration_tests/test_projection_param_retrieval_from_board/test_large_pop_weight_delay_retrieval.py b/spynnaker_integration_tests/test_projection_param_retrieval_from_board/test_large_pop_weight_delay_retrieval.py index a7cc8695fd..3ea9018f31 100644 --- a/spynnaker_integration_tests/test_projection_param_retrieval_from_board/test_large_pop_weight_delay_retrieval.py +++ b/spynnaker_integration_tests/test_projection_param_retrieval_from_board/test_large_pop_weight_delay_retrieval.py @@ -89,8 +89,8 @@ def compare_before_and_after(self): assert(os.path.isfile("test_file.txt")) with open("test_file.txt") as f: file_weights = numpy.loadtxt(f) - np_weights = post_weights_list.astype( - [('source', '