def run(self, subgraph, graph_mapper): new_sub_graph = PartitionedGraph(label=subgraph.label) new_graph_mapper = GraphMapper(graph_mapper.first_graph_label, subgraph.label) # create progress bar progress_bar = ProgressBar( len(subgraph.subvertices) + len(subgraph.subedges), "Filtering edges") # add the subverts directly, as they wont be pruned. for subvert in subgraph.subvertices: new_sub_graph.add_subvertex(subvert) associated_vertex = graph_mapper.get_vertex_from_subvertex(subvert) vertex_slice = graph_mapper.get_subvertex_slice(subvert) new_graph_mapper.add_subvertex( subvertex=subvert, vertex_slice=vertex_slice, vertex=associated_vertex) progress_bar.update() # start checking subedges to decide which ones need pruning.... for subedge in subgraph.subedges: if not self._is_filterable(subedge, graph_mapper): logger.debug("this subedge was not pruned {}".format(subedge)) new_sub_graph.add_subedge(subedge) associated_edge = graph_mapper.\ get_partitionable_edge_from_partitioned_edge(subedge) new_graph_mapper.add_partitioned_edge(subedge, associated_edge) else: logger.debug("this subedge was pruned {}".format(subedge)) progress_bar.update() progress_bar.end() # returned the pruned partitioned_graph and graph_mapper return new_sub_graph, new_graph_mapper
def __call__(self, subgraph, graph_mapper): """ :param subgraph: the subgraph whose edges are to be filtered :param graph_mapper: the graph mapper between partitionable and \ partitioned graphs. :return: a new graph mapper and partitioned graph """ new_sub_graph = PartitionedGraph(label=subgraph.label) new_graph_mapper = GraphMapper(graph_mapper.first_graph_label, subgraph.label) # create progress bar progress_bar = ProgressBar( len(subgraph.subvertices) + len(subgraph.subedges), "Filtering edges") # add the subverts directly, as they wont be pruned. for subvert in subgraph.subvertices: new_sub_graph.add_subvertex(subvert) associated_vertex = graph_mapper.get_vertex_from_subvertex(subvert) vertex_slice = graph_mapper.get_subvertex_slice(subvert) new_graph_mapper.add_subvertex( subvertex=subvert, vertex_slice=vertex_slice, vertex=associated_vertex) progress_bar.update() # start checking subedges to decide which ones need pruning.... for subvert in subgraph.subvertices: out_going_partitions = \ subgraph.outgoing_edges_partitions_from_vertex(subvert) for partitioner_identifier in out_going_partitions: for subedge in \ out_going_partitions[partitioner_identifier].edges: if not self._is_filterable(subedge, graph_mapper): logger.debug("this subedge was not pruned {}" .format(subedge)) new_sub_graph.add_subedge(subedge, partitioner_identifier) associated_edge = graph_mapper.\ get_partitionable_edge_from_partitioned_edge( subedge) new_graph_mapper.add_partitioned_edge( subedge, associated_edge) else: logger.debug("this subedge was pruned {}" .format(subedge)) progress_bar.update() progress_bar.end() # returned the pruned partitioned_graph and graph_mapper return {'new_sub_graph': new_sub_graph, 'new_graph_mapper': new_graph_mapper}
def test_new_subgraph(self): """ tests that after building a partitioned graph, all partitined vertices and partitioend edges are in existance :return: """ subvertices = list() subedges = list() for i in range(10): subvertices.append(PartitionedVertex(None, "")) for i in range(5): subedges.append(MultiCastPartitionedEdge(subvertices[0], subvertices[(i + 1)])) for i in range(5, 10): subedges.append(MultiCastPartitionedEdge( subvertices[5], subvertices[(i + 1) % 10])) subgraph = PartitionedGraph(subvertices=subvertices, subedges=subedges) outgoing = subgraph.outgoing_subedges_from_subvertex(subvertices[0]) for i in range(5): if subedges[i] not in outgoing: raise AssertionError( "subedges[" + str(i) + "] is not in outgoing and should be") for i in range(5, 10): if subedges[i] in outgoing: raise AssertionError( "subedges[" + str(i) + "] is in outgoing and shouldn't be") incoming = subgraph.incoming_subedges_from_subvertex(subvertices[0]) if subedges[9] not in incoming: raise AssertionError( "subedges[9] is not in incoming and should be") for i in range(9): if subedges[i] in incoming: raise AssertionError( "subedges[" + str(i) + "] is in incoming and shouldn't be") subvertices_from_subgraph = list(subgraph.subvertices) for subvert in subvertices_from_subgraph: self.assertIn(subvert, subvertices) subvedges_from_subgraph = list(subgraph.subedges) for subedge in subvedges_from_subgraph: self.assertIn(subedge, subedges)
def setUp(self): # sort out graph self.vert1 = Vertex(10, "New AbstractConstrainedVertex 1") self.vert2 = Vertex(5, "New AbstractConstrainedVertex 2") self.edge1 = AbstractPartitionableEdge(self.vert1, self.vert2, "First edge") self.verts = [self.vert1, self.vert2] self.edges = [self.edge1] self.graph = PartitionableGraph("Graph", self.verts, self.edges) # sort out subgraph self.subgraph = PartitionedGraph() self.subvert1 = PartitionedVertex( 0, 10, get_resources_used_by_atoms(0, 10, [])) self.subvert2 = PartitionedVertex( 0, 5, get_resources_used_by_atoms(0, 10, [])) self.subedge = AbstractPartitionedEdge(self.subvert1, self.subvert2) self.subgraph.add_subvertex(self.subvert1) self.subgraph.add_subvertex(self.subvert2) self.subgraph.add_subedge(self.subedge) # sort out placements self.placements = Placements() self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1) self.placement2 = Placement(x=1, y=1, p=2, subvertex=self.subvert2) self.placements.add_placement(self.placement1) self.placements.add_placement(self.placement2) # sort out routing infos self.routing_info = RoutingInfo() self.subedge_routing_info1 = \ SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK, subedge=self.subedge) self.routing_info.add_subedge_info(self.subedge_routing_info1) # create machine flops = 1000 (e, ne, n, w, sw, s) = range(6) processors = list() for i in range(18): processors.append(Processor(i, flops)) _sdram = SDRAM(128 * (2 ** 20)) ip = "192.162.240.253" chips = list() for x in range(10): for y in range(10): links = list() links.append(Link(x, y, 0, (x + 1) % 10, y, n, n)) links.append(Link(x, y, 1, (x + 1) % 10, (y + 1) % 10, s, s)) links.append(Link(x, y, 2, x, (y + 1) % 10, n, n)) links.append(Link(x, y, 3, (x - 1) % 10, y, s, s)) links.append(Link(x, y, 4, (x - 1) % 10, (y - 1) % 10, n, n)) links.append(Link(x, y, 5, x, (y - 1) % 10, s, s)) r = Router(links, False, 100, 1024) chips.append(Chip(x, y, processors, r, _sdram, ip)) self.machine = Machine(chips)
def __call__(self, subgraph, graph_mapper): """ :param subgraph: the subgraph whose edges are to be filtered :param graph_mapper: the graph mapper between partitionable and \ partitioned graphs. :return: a new graph mapper and partitioned graph """ new_sub_graph = PartitionedGraph(label=subgraph.label) new_graph_mapper = GraphMapper(graph_mapper.first_graph_label, subgraph.label) # create progress bar progress_bar = ProgressBar( len(subgraph.subvertices) + len(subgraph.subedges), "Filtering edges") # add the subverts directly, as they wont be pruned. for subvert in subgraph.subvertices: new_sub_graph.add_subvertex(subvert) associated_vertex = graph_mapper.get_vertex_from_subvertex(subvert) vertex_slice = graph_mapper.get_subvertex_slice(subvert) new_graph_mapper.add_subvertex(subvertex=subvert, vertex_slice=vertex_slice, vertex=associated_vertex) progress_bar.update() # start checking subedges to decide which ones need pruning.... for subvert in subgraph.subvertices: out_going_partitions = \ subgraph.outgoing_edges_partitions_from_vertex(subvert) for partitioner_identifier in out_going_partitions: for subedge in \ out_going_partitions[partitioner_identifier].edges: if not self._is_filterable(subedge, graph_mapper): logger.debug( "this subedge was not pruned {}".format(subedge)) new_sub_graph.add_subedge(subedge, partitioner_identifier) associated_edge = graph_mapper.\ get_partitionable_edge_from_partitioned_edge( subedge) new_graph_mapper.add_partitioned_edge( subedge, associated_edge) else: logger.debug( "this subedge was pruned {}".format(subedge)) progress_bar.update() progress_bar.end() # returned the pruned partitioned_graph and graph_mapper return { 'new_sub_graph': new_sub_graph, 'new_graph_mapper': new_graph_mapper }
def setUp(self): #sort out graph self.vert1 = Vertex(10, "New AbstractConstrainedVertex 1") self.vert2 = Vertex(5, "New AbstractConstrainedVertex 2") self.edge1 = AbstractPartitionableEdge(self.vert1, self.vert2, "First edge") self.verts = [self.vert1, self.vert2] self.edges = [self.edge1] self.graph = PartitionableGraph("Graph", self.verts, self.edges) #sort out subgraph self.subgraph = PartitionedGraph() self.subvert1 = PartitionedVertex( 0, 10, self.vert1.get_resources_used_by_atoms(0, 10, [])) self.subvert2 = PartitionedVertex( 0, 5, self.vert2.get_resources_used_by_atoms(0, 10, [])) self.subedge = AbstractPartitionedEdge(self.subvert1, self.subvert2) self.subgraph.add_subvertex(self.subvert1) self.subgraph.add_subvertex(self.subvert2) self.subgraph.add_subedge(self.subedge)
def run(self, subgraph, graph_mapper): new_sub_graph = PartitionedGraph(label=subgraph.label) new_graph_mapper = GraphMapper(graph_mapper.first_graph_label, subgraph.label) # create progress bar progress_bar = \ ProgressBar(len(subgraph.subvertices) + len(subgraph.subedges), "on checking which subedges are filterable given " "heuristics") # add the subverts directly, as they wont be pruned. for subvert in subgraph.subvertices: new_sub_graph.add_subvertex(subvert) associated_vertex = graph_mapper.get_vertex_from_subvertex(subvert) vertex_slice = graph_mapper.get_subvertex_slice(subvert) new_graph_mapper.add_subvertex(subvertex=subvert, vertex_slice=vertex_slice, vertex=associated_vertex) progress_bar.update() # start checking subedges to decide which ones need pruning.... for subedge in subgraph.subedges: if not self._is_filterable(subedge, graph_mapper): logger.debug("this subedge was not pruned {}".format(subedge)) new_sub_graph.add_subedge(subedge) associated_edge = graph_mapper.\ get_partitionable_edge_from_partitioned_edge(subedge) new_graph_mapper.add_partitioned_edge(subedge, associated_edge) else: logger.debug("this subedge was pruned {}".format(subedge)) progress_bar.update() progress_bar.end() # returned the pruned partitioned_graph and graph_mapper return new_sub_graph, new_graph_mapper
class MyTestCase(unittest.TestCase): def setUp(self): # sort out graph self.vert1 = Vertex(10, "New AbstractConstrainedVertex 1") self.vert2 = Vertex(5, "New AbstractConstrainedVertex 2") self.edge1 = AbstractPartitionableEdge(self.vert1, self.vert2, "First edge") self.verts = [self.vert1, self.vert2] self.edges = [self.edge1] self.graph = PartitionableGraph("Graph", self.verts, self.edges) # sort out subgraph self.subgraph = PartitionedGraph() self.subvert1 = PartitionedVertex( 0, 10, get_resources_used_by_atoms(0, 10, [])) self.subvert2 = PartitionedVertex( 0, 5, get_resources_used_by_atoms(0, 10, [])) self.subedge = AbstractPartitionedEdge(self.subvert1, self.subvert2) self.subgraph.add_subvertex(self.subvert1) self.subgraph.add_subvertex(self.subvert2) self.subgraph.add_subedge(self.subedge) # sort out placements self.placements = Placements() self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1) self.placement2 = Placement(x=1, y=1, p=2, subvertex=self.subvert2) self.placements.add_placement(self.placement1) self.placements.add_placement(self.placement2) # sort out routing infos self.routing_info = RoutingInfo() self.subedge_routing_info1 = \ SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK, subedge=self.subedge) self.routing_info.add_subedge_info(self.subedge_routing_info1) # create machine flops = 1000 (e, ne, n, w, sw, s) = range(6) processors = list() for i in range(18): processors.append(Processor(i, flops)) _sdram = SDRAM(128 * (2 ** 20)) ip = "192.162.240.253" chips = list() for x in range(10): for y in range(10): links = list() links.append(Link(x, y, 0, (x + 1) % 10, y, n, n)) links.append(Link(x, y, 1, (x + 1) % 10, (y + 1) % 10, s, s)) links.append(Link(x, y, 2, x, (y + 1) % 10, n, n)) links.append(Link(x, y, 3, (x - 1) % 10, y, s, s)) links.append(Link(x, y, 4, (x - 1) % 10, (y - 1) % 10, n, n)) links.append(Link(x, y, 5, x, (y - 1) % 10, s, s)) r = Router(links, False, 100, 1024) chips.append(Chip(x, y, processors, r, _sdram, ip)) self.machine = Machine(chips) @unittest.skip("demonstrating skipping") def set_up_4_node_board(self): flops = 1000 (e, ne, n, w, sw, s) = range(6) processors = list() for i in range(18): processors.append(Processor(i, flops)) _sdram = SDRAM(128 * (2 ** 20)) ip = "192.162.240.253" chips = list() for x in range(2): for y in range(2): links = list() links.append(Link(x, y, 0, (x + 1) % 2, y, n, n)) links.append(Link(x, y, 1, (x + 1) % 2, (y + 1) % 2, s, s)) links.append(Link(x, y, 2, x, (y + 1) % 2, n, n)) links.append(Link(x, y, 3, (x - 1) % 2, y, s, s)) links.append(Link(x, y, 4, (x - 1) % 2, (y - 1) % 2, n, n)) links.append(Link(x, y, 5, x, (y - 1) % 2, s, s)) r = Router(links, False, 100, 1024) chips.append(Chip(x, y, processors, r, _sdram, ip)) self.machine = Machine(chips) @unittest.skip("demonstrating skipping") def test_new_basic_router(self): dijkstra_router = BasicDijkstraRouting() self.assertEqual(dijkstra_router._k, 1) self.assertEqual(dijkstra_router._l, 0) self.assertEqual(dijkstra_router._m, 0) self.assertEqual(dijkstra_router._bw_per_route_entry, dijkstra_router.BW_PER_ROUTE_ENTRY) self.assertEqual(dijkstra_router._max_bw, dijkstra_router.MAX_BW) @unittest.skip("demonstrating skipping") def test_run_basic_routing_off_chip_custom_100_node_machine(self): dijkstra_router = BasicDijkstraRouting() routing_tables = dijkstra_router.route( machine=self.machine, placements=self.placements, partitioned_graph=self.subgraph, routing_info_allocation=self.routing_info) for entry in routing_tables.routing_tables: print entry.x, entry.y for routing_entry in entry.multicast_routing_entries: print "\t\tProcessor_ids:{}, Link_ids:{}".format( routing_entry.processor_ids, routing_entry.link_ids) @unittest.skip("demonstrating skipping") def test_run_basic_routing_off_chip_custom_4_node_machine(self): self.set_up_4_node_board() dijkstra_router = BasicDijkstraRouting() routing_tables = dijkstra_router.route( machine=self.machine, placements=self.placements, partitioned_graph=self.subgraph, routing_info_allocation=self.routing_info) for entry in routing_tables.routing_tables: print entry.x, entry.y for routing_entry in entry.multicast_routing_entries: print "\t\tProcessor_ids:{}, Link_ids:{}".format( routing_entry.processor_ids, routing_entry.link_ids) @unittest.skip("demonstrating skipping") def test_bad_machine_setup(self): # create machine flops = 1000 (e, ne, n, w, sw, s) = range(6) processors = list() for i in range(18): processors.append(Processor(i, flops)) links = list() links.append(Link(0, 0, 0, 0, 1, s, s)) _sdram = SDRAM(128 * (2 ** 20)) links = list() links.append(Link(0, 0, 0, 1, 1, n, n)) links.append(Link(0, 1, 1, 1, 0, s, s)) links.append(Link(1, 1, 2, 0, 0, e, e)) links.append(Link(1, 0, 3, 0, 1, w, w)) r = Router(links, False, 100, 1024) ip = "192.162.240.253" chips = list() for x in range(5): for y in range(5): chips.append(Chip(x, y, processors, r, _sdram, ip)) self.machine = Machine(chips) dijkstra_router = BasicDijkstraRouting() with self.assertRaises(PacmanRoutingException): dijkstra_router.route( machine=self.machine, placements=self.placements, partitioned_graph=self.subgraph, routing_info_allocation=self.routing_info) @unittest.skip("demonstrating skipping") def test_routing_on_chip_custom_4_node_machine(self): self.placements = Placements() self.placement1 = Placement(x=1, y=0, p=2, subvertex=self.subvert1) self.placement2 = Placement(x=1, y=0, p=3, subvertex=self.subvert2) self.placements.add_placement(self.placement1) self.placements.add_placement(self.placement2) # sort out routing infos self.routing_info = RoutingInfo() self.subedge_routing_info1 = \ SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK, subedge=self.subedge) self.routing_info.add_subedge_info(self.subedge_routing_info1) self.set_up_4_node_board() dijkstra_router = BasicDijkstraRouting() routing_tables = dijkstra_router.route( machine=self.machine, placements=self.placements, partitioned_graph=self.subgraph, routing_info_allocation=self.routing_info) for entry in routing_tables.routing_tables: print entry.x, entry.y for routing_entry in entry.multicast_routing_entries: print "\t\tProcessor_ids:{}, Link_ids:{}".format( routing_entry.processor_ids, routing_entry.link_ids) @unittest.skip("demonstrating skipping") def test_full_machine_routing(self): placements = Placements() self.placement1 = Placement(x=1, y=0, p=2, subvertex=self.subvert1) self.placement2 = Placement(x=1, y=0, p=3, subvertex=self.subvert2) subvertices = list() for i in range(4 * 17): #51 atoms per each processor on 20 chips subvertices.append(PartitionedVertex( 0, 50, get_resources_used_by_atoms(0, 50, []), "Subvertex " + str(i))) subedges = list() for i in range(len(subvertices)): subedges.append(AbstractPartitionedEdge( subvertices[i], subvertices[(i + 1)%len(subvertices)])) subgraph = PartitionedGraph("Subgraph", subvertices, subedges) p = 1 x = 0 y = 0 for subvert in subvertices: placements.add_placement(Placement(subvert, x, y, p)) p = (p + 1) % 18 if p == 0: p += 1 y += 1 if y == 2: y = 0 x += 1 routing_info = RoutingInfo() subedge_routing_info = list() for i in range(len(subedges)): subedge_routing_info.append(SubedgeRoutingInfo( subedges[i], i<<11, constants.DEFAULT_MASK)) for subedge_info in subedge_routing_info: routing_info.add_subedge_info(subedge_info) self.set_up_4_node_board() dijkstra_router = BasicDijkstraRouting() routing_tables = dijkstra_router.route( machine=self.machine, placements=placements, partitioned_graph=subgraph, routing_info_allocation=routing_info) for entry in routing_tables.routing_tables: print entry.x, entry.y for routing_entry in entry.multicast_routing_entries: print "\t\tProcessor_ids:{}, Link_ids:{}".format( routing_entry.processor_ids, routing_entry.link_ids) @unittest.skip("demonstrating skipping") def test_routing_to_other_machine(self): self.assertEqual(True, False, "Test not implemented yet")
def __call__(self, graph, machine): utility_calls.check_algorithm_can_support_constraints( constrained_vertices=graph.vertices, supported_constraints=[PartitionerMaximumSizeConstraint], abstract_constraint_type=AbstractPartitionerConstraint) # start progress bar progress_bar = ProgressBar(len(graph.vertices), "Partitioning graph vertices") vertices = graph.vertices subgraph = PartitionedGraph(label="partitioned_graph for partitionable" "_graph {}".format(graph.label)) graph_to_subgraph_mapper = GraphMapper(graph.label, subgraph.label) resource_tracker = ResourceTracker(machine) # Partition one vertex at a time for vertex in vertices: # Get the usage of the first atom, then assume that this # will be the usage of all the atoms requirements = vertex.get_resources_used_by_atoms(Slice(0, 1), graph) # Locate the maximum resources available max_resources_available = \ resource_tracker.get_maximum_constrained_resources_available( vertex.constraints) # Find the ratio of each of the resources - if 0 is required, # assume the ratio is the max available atoms_per_sdram = self._get_ratio( max_resources_available.sdram.get_value(), requirements.sdram.get_value()) atoms_per_dtcm = self._get_ratio( max_resources_available.dtcm.get_value(), requirements.dtcm.get_value()) atoms_per_cpu = self._get_ratio( max_resources_available.cpu.get_value(), requirements.cpu.get_value()) max_atom_values = [atoms_per_sdram, atoms_per_dtcm, atoms_per_cpu] max_atoms_constraints = utility_calls.locate_constraints_of_type( vertex.constraints, PartitionerMaximumSizeConstraint) for max_atom_constraint in max_atoms_constraints: max_atom_values.append(max_atom_constraint.size) atoms_per_core = min(max_atom_values) # Partition into subvertices counted = 0 while counted < vertex.n_atoms: # Determine subvertex size remaining = vertex.n_atoms - counted if remaining > atoms_per_core: alloc = atoms_per_core else: alloc = remaining # Create and store new subvertex, and increment elements # counted if counted < 0 or counted + alloc - 1 < 0: raise PacmanPartitionException("Not enough resources" " available to create" " subvertex") vertex_slice = Slice(counted, counted + (alloc - 1)) subvertex_usage = vertex.get_resources_used_by_atoms( vertex_slice, graph) subvert = vertex.create_subvertex( vertex_slice, subvertex_usage, "{}:{}:{}".format(vertex.label, counted, (counted + (alloc - 1))), partition_algorithm_utilities. get_remaining_constraints(vertex)) subgraph.add_subvertex(subvert) graph_to_subgraph_mapper.add_subvertex( subvert, vertex_slice, vertex) counted = counted + alloc # update allocated resources resource_tracker.allocate_constrained_resources( subvertex_usage, vertex.constraints) # update and end progress bars as needed progress_bar.update() progress_bar.end() partition_algorithm_utilities.generate_sub_edges( subgraph, graph_to_subgraph_mapper, graph) return {'Partitioned_graph': subgraph, 'Graph_mapper': graph_to_subgraph_mapper}
class TestRouter(unittest.TestCase): def setUp(self): #sort out graph self.vert1 = Vertex(10, "New AbstractConstrainedVertex 1") self.vert2 = Vertex(5, "New AbstractConstrainedVertex 2") self.edge1 = AbstractPartitionableEdge(self.vert1, self.vert2, "First edge") self.verts = [self.vert1, self.vert2] self.edges = [self.edge1] self.graph = PartitionableGraph("Graph", self.verts, self.edges) #sort out subgraph self.subgraph = PartitionedGraph() self.subvert1 = PartitionedVertex( 0, 10, self.vert1.get_resources_used_by_atoms(0, 10, [])) self.subvert2 = PartitionedVertex( 0, 5, self.vert2.get_resources_used_by_atoms(0, 10, [])) self.subedge = AbstractPartitionedEdge(self.subvert1, self.subvert2) self.subgraph.add_subvertex(self.subvert1) self.subgraph.add_subvertex(self.subvert2) self.subgraph.add_subedge(self.subedge) @unittest.skip("demonstrating skipping") def test_router_with_same_chip_route(self): #sort out placements self.placements = Placements() self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1) self.placement2 = Placement(x=0, y=0, p=3, subvertex=self.subvert2) self.placements.add_placement(self.placement1) self.placements.add_placement(self.placement2) #sort out routing infos self.routing_info = RoutingInfo() self.subedge_routing_info1 = \ SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK, subedge=self.subedge) self.routing_info.add_subedge_info(self.subedge_routing_info1) #create machine self.machine = VirtualMachine(10, 10, False) self.routing = BasicDijkstraRouting() self.routing.route( machine=self.machine, placements=self.placements, partitioned_graph=self.subgraph, routing_info_allocation=self.routing_info) @unittest.skip("demonstrating skipping") def test_router_with_neighbour_chip(self): #sort out placements self.placements = Placements() self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1) self.placement2 = Placement(x=1, y=1, p=2, subvertex=self.subvert2) self.placements.add_placement(self.placement1) self.placements.add_placement(self.placement2) #sort out routing infos self.routing_info = RoutingInfo() self.subedge_routing_info1 = \ SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK, subedge=self.subedge) self.routing_info.add_subedge_info(self.subedge_routing_info1) #create machine self.machine = VirtualMachine(10, 10, False) self.routing = BasicDijkstraRouting() self.routing.route( machine=self.machine, placements=self.placements, partitioned_graph=self.subgraph, routing_info_allocation=self.routing_info) @unittest.skip("demonstrating skipping") def test_router_with_one_hop_route_all_default_link_0(self): #sort out placements self.placements = Placements() self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1) self.placement2 = Placement(x=2, y=0, p=2, subvertex=self.subvert2) self.placements.add_placement(self.placement1) self.placements.add_placement(self.placement2) #sort out routing infos self.routing_info = RoutingInfo() self.subedge_routing_info1 = \ SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK, subedge=self.subedge) self.routing_info.add_subedge_info(self.subedge_routing_info1) #create machine self.machine = VirtualMachine(10, 10, False) self.routing = BasicDijkstraRouting() self.routing.route( machine=self.machine, placements=self.placements, partitioned_graph=self.subgraph, routing_info_allocation=self.routing_info) @unittest.skip("demonstrating skipping") def test_router_with_one_hop_route_all_default_link_1(self): self.placements = Placements() self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1) self.placement2 = Placement(x=2, y=2, p=2, subvertex=self.subvert2) self.placements.add_placement(self.placement1) self.placements.add_placement(self.placement2) #sort out routing infos self.routing_info = RoutingInfo() self.subedge_routing_info1 = \ SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK, subedge=self.subedge) self.routing_info.add_subedge_info(self.subedge_routing_info1) #create machine self.machine = VirtualMachine(10, 10, False) self.routing = BasicDijkstraRouting() self.routing.route( machine=self.machine, placements=self.placements, partitioned_graph=self.subgraph, routing_info_allocation=self.routing_info) @unittest.skip("demonstrating skipping") def test_router_with_one_hop_route_all_default_link_2(self): self.placements = Placements() self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1) self.placement2 = Placement(x=0, y=2, p=2, subvertex=self.subvert2) self.placements.add_placement(self.placement1) self.placements.add_placement(self.placement2) #sort out routing infos self.routing_info = RoutingInfo() self.subedge_routing_info1 = \ SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK, subedge=self.subedge) self.routing_info.add_subedge_info(self.subedge_routing_info1) #create machine self.machine = VirtualMachine(10, 10, False) self.routing = BasicDijkstraRouting() self.routing.route( machine=self.machine, placements=self.placements, partitioned_graph=self.subgraph, routing_info_allocation=self.routing_info) @unittest.skip("demonstrating skipping") def test_router_with_one_hop_route_all_default_link_3(self): self.placements = Placements() self.placement1 = Placement(x=2, y=0, p=2, subvertex=self.subvert1) self.placement2 = Placement(x=0, y=0, p=2, subvertex=self.subvert2) self.placements.add_placement(self.placement1) self.placements.add_placement(self.placement2) #sort out routing infos self.routing_info = RoutingInfo() self.subedge_routing_info1 = \ SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK, subedge=self.subedge) self.routing_info.add_subedge_info(self.subedge_routing_info1) #create machine self.machine = VirtualMachine(10, 10, False) self.routing = BasicDijkstraRouting() self.routing.route( machine=self.machine, placements=self.placements, partitioned_graph=self.subgraph, routing_info_allocation=self.routing_info) @unittest.skip("demonstrating skipping") def test_router_with_one_hop_route_all_default_link_4(self): self.placements = Placements() self.placement1 = Placement(x=2, y=2, p=2, subvertex=self.subvert1) self.placement2 = Placement(x=0, y=0, p=2, subvertex=self.subvert2) self.placements.add_placement(self.placement1) self.placements.add_placement(self.placement2) #sort out routing infos self.routing_info = RoutingInfo() self.subedge_routing_info1 = \ SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK, subedge=self.subedge) self.routing_info.add_subedge_info(self.subedge_routing_info1) #create machine self.machine = VirtualMachine(10, 10, False) self.routing = BasicDijkstraRouting() self.routing.route( machine=self.machine, placements=self.placements, partitioned_graph=self.subgraph, routing_info_allocation=self.routing_info) @unittest.skip("demonstrating skipping") def test_router_with_one_hop_route_all_default_link_5(self): self.placements = Placements() self.placement1 = Placement(x=0, y=2, p=2, subvertex=self.subvert1) self.placement2 = Placement(x=0, y=0, p=2, subvertex=self.subvert2) self.placements.add_placement(self.placement1) self.placements.add_placement(self.placement2) #sort out routing infos self.routing_info = RoutingInfo() self.subedge_routing_info1 = \ SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK, subedge=self.subedge) self.routing_info.add_subedge_info(self.subedge_routing_info1) #create machine self.machine = VirtualMachine(10, 10, False) self.routing = BasicDijkstraRouting() self.routing.route( machine=self.machine, placements=self.placements, partitioned_graph=self.subgraph, routing_info_allocation=self.routing_info) @unittest.skip("demonstrating skipping") def test_router_with_one_hop_route_not_default(self): #sort out placements self.placements = Placements() self.placement1 = Placement(x=2, y=1, p=2, subvertex=self.subvert1) self.placement2 = Placement(x=0, y=0, p=2, subvertex=self.subvert2) self.placements.add_placement(self.placement1) self.placements.add_placement(self.placement2) #sort out routing infos self.routing_info = RoutingInfo() self.subedge_routing_info1 = \ SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK, subedge=self.subedge) self.routing_info.add_subedge_info(self.subedge_routing_info1) #create machine self.machine = VirtualMachine(10, 10, False) self.routing = BasicDijkstraRouting() self.routing.route( machine=self.machine, placements=self.placements, partitioned_graph=self.subgraph, routing_info_allocation=self.routing_info) @unittest.skip("demonstrating skipping") def test_router_with_multi_hop_route_across_board(self): #sort out placements self.placements = Placements() self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1) self.placement2 = Placement(x=8, y=7, p=2, subvertex=self.subvert2) self.placements.add_placement(self.placement1) self.placements.add_placement(self.placement2) #sort out routing infos self.routing_info = RoutingInfo() self.subedge_routing_info1 = \ SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK, subedge=self.subedge) self.routing_info.add_subedge_info(self.subedge_routing_info1) #create machine self.machine = VirtualMachine(10, 10, False) self.routing = BasicDijkstraRouting() self.routing.route( machine=self.machine, placements=self.placements, partitioned_graph=self.subgraph, routing_info_allocation=self.routing_info) @unittest.skip("demonstrating skipping") def test_new_router(self): report_folder = "..\reports" self.routing = BasicDijkstraRouting() self.assertEqual(self.routing._report_folder, report_folder) self.assertEqual(self.routing._graph, None) self.assertEqual(self.routing.report_states, None) self.assertEqual(self.routing._hostname, None) self.assertIsInstance(self.routing._router_algorithm, BasicDijkstraRouting) self.assertEqual(self.routing._graph_to_subgraph_mappings, None) @unittest.skip("demonstrating skipping") def test_new_router_set_non_default_routing_algorithm(self): report_folder = "..\reports" self.routing = BasicDijkstraRouting() self.assertEqual(self.routing._report_folder, report_folder) self.assertEqual(self.routing._graph, None) self.assertEqual(self.routing.report_states, None) self.assertEqual(self.routing._hostname, None) self.assertEqual(self.routing._graph_to_subgraph_mappings, None) @unittest.skip("demonstrating skipping") def test_run_router(self): #sort out placements self.placements = Placements() self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1) self.placement2 = Placement(x=1, y=1, p=2, subvertex=self.subvert2) self.placements.add_placement(self.placement1) self.placements.add_placement(self.placement2) #sort out routing infos self.routing_info = RoutingInfo() self.subedge_routing_info1 = \ SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK, subedge=self.subedge) self.routing_info.add_subedge_info(self.subedge_routing_info1) #create machine self.machine = VirtualMachine(10, 10, False) self.routing = BasicDijkstraRouting() self.routing.route( machine=self.machine, placements=self.placements, partitioned_graph=self.subgraph, routing_info_allocation=self.routing_info)
def __call__(self, graph, machine): """ Partition a partitionable_graph so that each subvertex will fit\ on a processor within the machine :param graph: The partitionable_graph to partition :type graph:\ :py:class:`pacman.model.graph.partitionable_graph.PartitionableGraph` :param machine: The machine with respect to which to partition the\ partitionable_graph :type machine: :py:class:`spinn_machine.machine.Machine` :return: A partitioned_graph of partitioned vertices and partitioned\ edges :rtype:\ :py:class:`pacman.model.partitioned_graph.partitioned_graph.PartitionedGraph` :raise pacman.exceptions.PacmanPartitionException: If something\ goes wrong with the partitioning """ utility_calls.check_algorithm_can_support_constraints( constrained_vertices=graph.vertices, abstract_constraint_type=AbstractPartitionerConstraint, supported_constraints=[PartitionerMaximumSizeConstraint, PartitionerSameSizeAsVertexConstraint]) # Load the vertices and create the subgraph to fill vertices = graph.vertices subgraph = PartitionedGraph( label="partitioned graph for {}".format(graph.label)) graph_mapper = GraphMapper(graph.label, subgraph.label) # sort out vertex's by constraints vertices = utility_calls.sort_objects_by_constraint_authority(vertices) # Set up the progress n_atoms = 0 for vertex in vertices: n_atoms += vertex.n_atoms progress_bar = ProgressBar(n_atoms, "Partitioning graph vertices") resource_tracker = ResourceTracker(machine) # Partition one vertex at a time for vertex in vertices: # check that the vertex hasn't already been partitioned subverts_from_vertex = \ graph_mapper.get_subvertices_from_vertex(vertex) # if not, partition if subverts_from_vertex is None: self._partition_vertex( vertex, subgraph, graph_mapper, resource_tracker, graph) progress_bar.update(vertex.n_atoms) progress_bar.end() partition_algorithm_utilities.generate_sub_edges( subgraph, graph_mapper, graph) results = dict() results['partitioned_graph'] = subgraph results['graph_mapper'] = graph_mapper results['nChips'] = len(resource_tracker.keys) return results