def test_get_vertex_from_subvertex(self): """ test that the graph mapper can retribve a vertex froma given subvertex :return: """ subvertices = list() subvertices.append(PartitionedVertex(None, "")) subvertices.append(PartitionedVertex(None, "")) subvert1 = PartitionedVertex(None, "") subvert2 = PartitionedVertex(None, "") graph_mapper = GraphMapper() vert = TestVertex(10, "Some testing vertex") vertex_slice = Slice(0, 1) graph_mapper.add_subvertex(subvert1, vertex_slice, vert) vertex_slice = Slice(2, 3) graph_mapper.add_subvertex(subvert2, vertex_slice, vert) self.assertEqual( vert, graph_mapper.get_vertex_from_subvertex(subvert1)) self.assertEqual( vert, graph_mapper.get_vertex_from_subvertex(subvert2)) self.assertEqual( None, graph_mapper.get_vertex_from_subvertex(subvertices[0])) self.assertEqual( None, graph_mapper.get_vertex_from_subvertex(subvertices[1]))
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 test_get_subvertices_from_vertex(self): """ test getting the subvertex from a graph mappert via the vertex :return: """ subvertices = list() subvertices.append(PartitionedVertex(None, "")) subvertices.append(PartitionedVertex(None, "")) subvert1 = PartitionedVertex(None, "") subvert2 = PartitionedVertex(None, "") subedges = list() subedges.append(MultiCastPartitionedEdge(subvertices[0], subvertices[1])) subedges.append(MultiCastPartitionedEdge(subvertices[1], subvertices[1])) graph_mapper = GraphMapper() vert = TestVertex(4, "Some testing vertex") vertex_slice = Slice(0, 1) graph_mapper.add_subvertex(subvert1, vertex_slice, vert) vertex_slice = Slice(2, 3) graph_mapper.add_subvertex(subvert2, vertex_slice, vert) returned_subverts = graph_mapper.get_subvertices_from_vertex(vert) self.assertIn(subvert1, returned_subverts) self.assertIn(subvert2, returned_subverts) for sub in subvertices: self.assertNotIn(sub, returned_subverts)
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 __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 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
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}