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_subedges_from_edge(self): """ test getting the subedges from a graph mapper from a edge :return: """ subvertices = list() subedges = list() subvertices.append(PartitionedVertex(None, "")) subvertices.append(PartitionedVertex(None, "")) subedges.append(MultiCastPartitionedEdge(subvertices[0], subvertices[1])) subedges.append(MultiCastPartitionedEdge(subvertices[1], subvertices[1])) sube = MultiCastPartitionedEdge(subvertices[1], subvertices[0]) subedges.append(sube) graph = GraphMapper() edge = TestPartitionableEdge(TestVertex(10, "pre"), TestVertex(5, "post")) graph.add_partitioned_edge(sube, edge) graph.add_partitioned_edge(subedges[0], edge) subedges_from_edge = \ graph.get_partitioned_edges_from_partitionable_edge(edge) self.assertIn(sube, subedges_from_edge) self.assertIn(subedges[0], subedges_from_edge) self.assertNotIn(subedges[1], subedges_from_edge)
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 test_get_edge_from_subedge(self): """ test that tests getting a edge from a graph mapper based off its subedge :return: """ subvertices = list() subvertices.append(PartitionedVertex(None, "")) subvertices.append(PartitionedVertex(None, "")) subedges = list() subedges.append(MultiCastPartitionedEdge(subvertices[0], subvertices[1])) subedges.append(MultiCastPartitionedEdge(subvertices[1], subvertices[1])) sube = MultiCastPartitionedEdge(subvertices[1], subvertices[0]) subedges.append(sube) # Create the graph mapper graph = GraphMapper() edge = TestPartitionableEdge(TestVertex(10, "pre"), TestVertex(5, "post")) graph.add_partitioned_edge(sube, edge) graph.add_partitioned_edge(subedges[0], edge) edge_from_subedge = \ graph.get_partitionable_edge_from_partitioned_edge(sube) self.assertEqual(edge_from_subedge, edge) self.assertEqual( graph.get_partitionable_edge_from_partitioned_edge(subedges[0]), edge ) self.assertRaises( PacmanNotFoundError, graph.get_partitionable_edge_from_partitioned_edge, subedges[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), "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