def do_one_run(): n_source = 2000 n_target = 16 n_neurons = 1 n_boards = math.ceil((n_source + n_target) / 16 / 48) sim.setup(timestep=1.0, n_boards_required=n_boards) try: machine = sim.get_machine() except ConfigurationException as oops: if "Failure to detect machine " in str(oops): raise SkipTest( "You Need at least {} boards to run this test".format( n_boards)) from oops raise oops target_x, target_y = find_good_chip(machine, n_target) print(machine) print(target_x, target_y) sources = [] for s in range(n_source): sources.append( sim.Population(n_neurons, sim.IF_curr_exp(), label="source_{}".format(s), additional_parameters={ "splitter": SplitterAbstractPopulationVertexSlice() })) targets = [] for t in range(n_target): pop = sim.Population(n_neurons, sim.IF_curr_exp(), label="target_{}".format(t), additional_parameters={ "splitter": SplitterAbstractPopulationVertexSlice() }) pop.add_placement_constraint(x=target_x, y=target_y) targets.append(pop) for s in range(n_source): for t in range(n_target): sim.Projection(sources[s], targets[t], sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1), receptor_type="excitatory") if t > 1 and s % t == 0: sim.Projection(sources[s], targets[t], sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1), receptor_type="inhibitory") sim.run(1) sim.end()
def test_pop_based_master_pop_table_standard(undelayed_indices_connected, delayed_indices_connected, n_pre_neurons, neurons_per_core, expect_app_keys, max_delay): unittest_setup() machine = virtual_machine(12, 12) # Build a from list connector with the delays we want connections = [] connections.extend([(i * neurons_per_core + j, j, 0, 10) for i in undelayed_indices_connected for j in range(100)]) connections.extend([(i * neurons_per_core + j, j, 0, max_delay) for i in delayed_indices_connected for j in range(100)]) # Make simple source and target, where the source has 1000 atoms # split into 10 vertices (100 each) and the target has 100 atoms in # a single vertex p.setup(1.0) post_pop = p.Population(100, p.IF_curr_exp(), label="Post", additional_parameters={ "splitter": SplitterAbstractPopulationVertexSlice() }) p.IF_curr_exp.set_model_max_atoms_per_core(neurons_per_core) pre_pop = p.Population(n_pre_neurons, p.IF_curr_exp(), label="Pre", additional_parameters={ "splitter": SplitterAbstractPopulationVertexSlice() }) p.Projection(pre_pop, post_pop, p.FromListConnector(connections), p.StaticSynapse()) app_graph = globals_variables.get_simulator().original_application_graph context = {"ApplicationGraph": app_graph} with (injection_context(context)): delay_support_adder(app_graph) machine_graph, _ = spynnaker_splitter_partitioner( app_graph, machine, 100) allocator = ZonedRoutingInfoAllocator() n_keys_map = edge_to_n_keys_mapper(machine_graph) routing_info = allocator.__call__(machine_graph, n_keys_map, flexible=False) post_mac_vertex = next(iter(post_pop._vertex.machine_vertices)) post_vertex_slice = post_mac_vertex.vertex_slice # Generate the data temp_spec = tempfile.mktemp() spec = DataSpecificationGenerator(io.FileIO(temp_spec, "wb"), None) synaptic_matrices = SynapticMatrices(post_vertex_slice, n_synapse_types=2, all_single_syn_sz=10000, synaptic_matrix_region=1, direct_matrix_region=2, poptable_region=3, connection_builder_region=4) synaptic_matrices.write_synaptic_data( spec, post_pop._vertex.incoming_projections, all_syn_block_sz=1000000, weight_scales=[32, 32], routing_info=routing_info) with io.FileIO(temp_spec, "rb") as spec_reader: executor = DataSpecificationExecutor(spec_reader, SDRAM.max_sdram_found) executor.execute() # Read the population table and check entries region = executor.get_region(3) mpop_data = numpy.frombuffer(region.region_data, dtype="uint8").view("uint32") n_entries = mpop_data[0] n_addresses = mpop_data[1] # Compute how many entries and addresses there should be expected_n_entries = 0 expected_n_addresses = 0 if expect_app_keys: # Always one for undelayed, maybe one for delayed if present n_app_entries = 1 + int(bool(delayed_indices_connected)) expected_n_entries += n_app_entries # 2 address list entries for each entry, as there is also extra_info expected_n_addresses += 2 * n_app_entries # If both delayed and undelayed, there is an entry for each incoming # machine edge elif delayed_indices_connected and undelayed_indices_connected: all_connected = set(undelayed_indices_connected) all_connected.update(delayed_indices_connected) expected_n_entries += len(all_connected) expected_n_addresses += len(all_connected) # If there are only undelayed indices, there is an entry for each elif undelayed_indices_connected: expected_n_entries += len(undelayed_indices_connected) expected_n_addresses += len(undelayed_indices_connected) # If there are only delayed indices, there are two entries for each because # the undelayed ones are still connected else: expected_n_entries += 2 * len(delayed_indices_connected) expected_n_addresses += 2 * len(delayed_indices_connected) assert (n_entries == expected_n_entries) assert (n_addresses == expected_n_addresses)
def test_write_data_spec(): unittest_setup() # UGLY but the mock transceiver NEED generate_on_machine to be False AbstractGenerateConnectorOnMachine.generate_on_machine = say_false machine = virtual_machine(2, 2) p.setup(1.0) load_config() p.set_number_of_neurons_per_core(p.IF_curr_exp, 100) pre_pop = p.Population(10, p.IF_curr_exp(), label="Pre", additional_parameters={ "splitter": SplitterAbstractPopulationVertexSlice() }) post_pop = p.Population(10, p.IF_curr_exp(), label="Post", additional_parameters={ "splitter": SplitterAbstractPopulationVertexSlice() }) proj_one_to_one_1 = p.Projection(pre_pop, post_pop, p.OneToOneConnector(), p.StaticSynapse(weight=1.5, delay=1.0)) proj_one_to_one_2 = p.Projection(pre_pop, post_pop, p.OneToOneConnector(), p.StaticSynapse(weight=2.5, delay=2.0)) proj_all_to_all = p.Projection( pre_pop, post_pop, p.AllToAllConnector(allow_self_connections=False), p.StaticSynapse(weight=4.5, delay=4.0)) from_list_list = [(i, i, i, (i * 5) + 1) for i in range(10)] proj_from_list = p.Projection(pre_pop, post_pop, p.FromListConnector(from_list_list), p.StaticSynapse()) app_graph = globals_variables.get_simulator().original_application_graph context = {"ApplicationGraph": app_graph} with (injection_context(context)): delay_support_adder(app_graph) machine_graph, _ = spynnaker_splitter_partitioner( app_graph, machine, 100) allocator = ZonedRoutingInfoAllocator() n_keys_map = edge_to_n_keys_mapper(machine_graph) routing_info = allocator.__call__(machine_graph, n_keys_map, flexible=False) post_vertex = next(iter(post_pop._vertex.machine_vertices)) post_vertex_slice = post_vertex.vertex_slice post_vertex_placement = Placement(post_vertex, 0, 0, 3) temp_spec = tempfile.mktemp() spec = DataSpecificationGenerator(io.FileIO(temp_spec, "wb"), None) synaptic_matrices = SynapticMatrices(post_vertex_slice, n_synapse_types=2, all_single_syn_sz=10000, synaptic_matrix_region=1, direct_matrix_region=2, poptable_region=3, connection_builder_region=4) synaptic_matrices.write_synaptic_data( spec, post_pop._vertex.incoming_projections, all_syn_block_sz=10000, weight_scales=[32, 32], routing_info=routing_info) spec.end_specification() with io.FileIO(temp_spec, "rb") as spec_reader: executor = DataSpecificationExecutor(spec_reader, 20000) executor.execute() all_data = bytearray() all_data.extend(bytearray(executor.get_header())) all_data.extend(bytearray(executor.get_pointer_table(0))) for r in range(MAX_MEM_REGIONS): region = executor.get_region(r) if region is not None: all_data.extend(region.region_data) transceiver = MockTransceiverRawData(all_data) report_folder = mkdtemp() try: connections_1 = numpy.concatenate( synaptic_matrices.get_connections_from_machine( transceiver, post_vertex_placement, proj_one_to_one_1._projection_edge, proj_one_to_one_1._synapse_information)) # Check that all the connections have the right weight and delay assert len(connections_1) == post_vertex_slice.n_atoms assert all([conn["weight"] == 1.5 for conn in connections_1]) assert all([conn["delay"] == 1.0 for conn in connections_1]) connections_2 = numpy.concatenate( synaptic_matrices.get_connections_from_machine( transceiver, post_vertex_placement, proj_one_to_one_2._projection_edge, proj_one_to_one_2._synapse_information)) # Check that all the connections have the right weight and delay assert len(connections_2) == post_vertex_slice.n_atoms assert all([conn["weight"] == 2.5 for conn in connections_2]) assert all([conn["delay"] == 2.0 for conn in connections_2]) connections_3 = numpy.concatenate( synaptic_matrices.get_connections_from_machine( transceiver, post_vertex_placement, proj_all_to_all._projection_edge, proj_all_to_all._synapse_information)) # Check that all the connections have the right weight and delay assert len(connections_3) == 100 assert all([conn["weight"] == 4.5 for conn in connections_3]) assert all([conn["delay"] == 4.0 for conn in connections_3]) connections_4 = numpy.concatenate( synaptic_matrices.get_connections_from_machine( transceiver, post_vertex_placement, proj_from_list._projection_edge, proj_from_list._synapse_information)) # Check that all the connections have the right weight and delay assert len(connections_4) == len(from_list_list) list_weights = [values[2] for values in from_list_list] list_delays = [values[3] for values in from_list_list] assert all(list_weights == connections_4["weight"]) assert all(list_delays == connections_4["delay"]) finally: shutil.rmtree(report_folder, ignore_errors=True)
def test_write_data_spec(): unittest_setup() # UGLY but the mock transceiver NEED generate_on_machine to be False AbstractGenerateConnectorOnMachine.generate_on_machine = say_false machine = virtual_machine(2, 2) p.setup(1.0) load_config() p.set_number_of_neurons_per_core(p.IF_curr_exp, 100) pre_pop = p.Population( 10, p.IF_curr_exp(), label="Pre", additional_parameters={ "splitter": SplitterAbstractPopulationVertexSlice()}) post_pop = p.Population( 10, p.IF_curr_exp(), label="Post", additional_parameters={ "splitter": SplitterAbstractPopulationVertexSlice()}) proj_one_to_one_1 = p.Projection( pre_pop, post_pop, p.OneToOneConnector(), p.StaticSynapse(weight=1.5, delay=1.0)) proj_one_to_one_2 = p.Projection( pre_pop, post_pop, p.OneToOneConnector(), p.StaticSynapse(weight=2.5, delay=2.0)) proj_all_to_all = p.Projection( pre_pop, post_pop, p.AllToAllConnector(allow_self_connections=False), p.StaticSynapse(weight=4.5, delay=4.0)) # spynnaker8.setup(timestep=1) # # Add an sdram so max SDRAM is high enough # SDRAM(10000) # # set_config("Simulation", "one_to_one_connection_dtcm_max_bytes", 40) # # placements = Placements() # pre_app_population = MockPopulation(10, "mock pop pre") # pre_app_vertex = SimpleTestVertex(10, label="pre") # pre_app_vertex.splitter = MockSplitter() # pre_app_vertex.splitter._called = True # pre_vertex_slice = Slice(0, 9) # # post_app_population = MockPopulation(10, "mock pop post") # pre_vertex = pre_app_vertex.create_machine_vertex( # pre_vertex_slice, None) # placements.add_placement(Placement(pre_vertex, 0, 0, 1)) # post_app_vertex = SimpleTestVertex(10, label="post") # post_app_vertex.splitter = MockSplitter() # post_app_vertex.splitter._called = True # post_vertex_slice = Slice(0, 9) # post_vertex = post_app_vertex.create_machine_vertex( # post_vertex_slice, None) # post_vertex_placement = Placement(post_vertex, 0, 0, 2) # placements.add_placement(post_vertex_placement) # delay_app_vertex = DelayExtensionVertex( # 10, 16, 51, pre_app_vertex, label="delay") # delay_app_vertex.set_new_n_delay_stages_and_delay_per_stage( # 16, 51) # delay_app_vertex.splitter = SplitterDelayVertexSlice( # pre_app_vertex.splitter) # delay_vertex = DelayExtensionMachineVertex( # resources_required=None, label="", constraints=[], # app_vertex=delay_app_vertex, vertex_slice=post_vertex_slice) # placements.add_placement(Placement(delay_vertex, 0, 0, 3)) # one_to_one_connector_1 = OneToOneConnector(None) # direct_synapse_information_1 = SynapseInformation( # one_to_one_connector_1, pre_app_population, post_app_population, # False, False, None, SynapseDynamicsStatic(), 0, True, 1.5, 1.0) # one_to_one_connector_1.set_projection_information( # direct_synapse_information_1) # one_to_one_connector_2 = OneToOneConnector(None) # direct_synapse_information_2 = SynapseInformation( # one_to_one_connector_2, pre_app_population, post_app_population, # False, False, None, SynapseDynamicsStatic(), 1, True, 2.5, 2.0) # one_to_one_connector_2.set_projection_information( # direct_synapse_information_2) # all_to_all_connector = AllToAllConnector(False) # all_to_all_synapse_information = SynapseInformation( # all_to_all_connector, pre_app_population, post_app_population, # False, False, None, SynapseDynamicsStatic(), 0, True, 4.5, 4.0) # all_to_all_connector.set_projection_information( # all_to_all_synapse_information) from_list_list = [(i, i, i, (i * 5) + 1) for i in range(10)] proj_from_list = p.Projection( pre_pop, post_pop, p.FromListConnector(from_list_list), p.StaticSynapse()) app_graph = globals_variables.get_simulator().original_application_graph context = { "ApplicationGraph": app_graph } with (injection_context(context)): delay_adder = DelaySupportAdder() delay_adder.__call__(app_graph) partitioner = SpynnakerSplitterPartitioner() machine_graph, _ = partitioner.__call__(app_graph, machine, 100) allocator = ZonedRoutingInfoAllocator() n_keys_mapper = EdgeToNKeysMapper() n_keys_map = n_keys_mapper.__call__(machine_graph) routing_info = allocator.__call__( machine_graph, n_keys_map, flexible=False) post_vertex = next(iter(post_pop._vertex.machine_vertices)) post_vertex_slice = post_vertex.vertex_slice post_vertex_placement = Placement(post_vertex, 0, 0, 3) temp_spec = tempfile.mktemp() spec = DataSpecificationGenerator(io.FileIO(temp_spec, "wb"), None) synaptic_matrices = SynapticMatrices( post_vertex_slice, n_synapse_types=2, all_single_syn_sz=10000, synaptic_matrix_region=1, direct_matrix_region=2, poptable_region=3, connection_builder_region=4) synaptic_matrices.write_synaptic_data( spec, post_pop._vertex.incoming_projections, all_syn_block_sz=10000, weight_scales=[32, 32], routing_info=routing_info) spec.end_specification() with io.FileIO(temp_spec, "rb") as spec_reader: executor = DataSpecificationExecutor(spec_reader, 20000) executor.execute() all_data = bytearray() all_data.extend(bytearray(executor.get_header())) all_data.extend(bytearray(executor.get_pointer_table(0))) for r in range(MAX_MEM_REGIONS): region = executor.get_region(r) if region is not None: all_data.extend(region.region_data) transceiver = MockTransceiverRawData(all_data) report_folder = mkdtemp() try: connections_1 = numpy.concatenate( synaptic_matrices.get_connections_from_machine( transceiver, post_vertex_placement, proj_one_to_one_1._projection_edge, proj_one_to_one_1._synapse_information)) # Check that all the connections have the right weight and delay assert len(connections_1) == post_vertex_slice.n_atoms assert all([conn["weight"] == 1.5 for conn in connections_1]) assert all([conn["delay"] == 1.0 for conn in connections_1]) connections_2 = numpy.concatenate( synaptic_matrices.get_connections_from_machine( transceiver, post_vertex_placement, proj_one_to_one_2._projection_edge, proj_one_to_one_2._synapse_information)) # Check that all the connections have the right weight and delay assert len(connections_2) == post_vertex_slice.n_atoms assert all([conn["weight"] == 2.5 for conn in connections_2]) assert all([conn["delay"] == 2.0 for conn in connections_2]) connections_3 = numpy.concatenate( synaptic_matrices.get_connections_from_machine( transceiver, post_vertex_placement, proj_all_to_all._projection_edge, proj_all_to_all._synapse_information)) # Check that all the connections have the right weight and delay assert len(connections_3) == 100 assert all([conn["weight"] == 4.5 for conn in connections_3]) assert all([conn["delay"] == 4.0 for conn in connections_3]) connections_4 = numpy.concatenate( synaptic_matrices.get_connections_from_machine( transceiver, post_vertex_placement, proj_from_list._projection_edge, proj_from_list._synapse_information)) # Check that all the connections have the right weight and delay assert len(connections_4) == len(from_list_list) list_weights = [values[2] for values in from_list_list] list_delays = [values[3] for values in from_list_list] assert all(list_weights == connections_4["weight"]) assert all(list_delays == connections_4["delay"]) finally: shutil.rmtree(report_folder, ignore_errors=True)