def test_get_vertices_from_vertex(self): """ test getting the vertex from a graph mapper via the vertex """ vertices = list() vertices.append(SimpleMachineVertex(None, "")) vertices.append(SimpleMachineVertex(None, "")) vertex1 = SimpleMachineVertex(None, "") vertex2 = SimpleMachineVertex(None, "") edges = list() edges.append(MachineEdge(vertices[0], vertices[1])) edges.append(MachineEdge(vertices[1], vertices[1])) graph_mapper = GraphMapper() vert = SimpleTestVertex(4, "Some testing vertex") vertex_slice = Slice(0, 1) graph_mapper.add_vertex_mapping(vertex1, vertex_slice, vert) vertex_slice = Slice(2, 3) graph_mapper.add_vertex_mapping(vertex2, vertex_slice, vert) returned_vertices = graph_mapper.get_machine_vertices(vert) self.assertIn(vertex1, returned_vertices) self.assertIn(vertex2, returned_vertices) for v in vertices: self.assertNotIn(v, returned_vertices)
def test_get_vertices_from_vertex(self): """ test getting the vertex from a graph mapper via the vertex """ vertices = list() vertices.append(SimpleMachineVertex(None, "")) vertices.append(SimpleMachineVertex(None, "")) vertex1 = SimpleMachineVertex(None, "") vertex2 = SimpleMachineVertex(None, "") edges = list() edges.append(MachineEdge(vertices[0], vertices[1])) edges.append(MachineEdge(vertices[1], vertices[1])) graph_mapper = GraphMapper() vert = SimpleTestVertex(4, "Some testing vertex") vertex_slice = Slice(0, 1) graph_mapper.add_vertex_mapping(vertex1, vertex_slice, vert) vertex_slice = Slice(2, 3) graph_mapper.add_vertex_mapping(vertex2, vertex_slice, vert) returned_vertices = graph_mapper.get_machine_vertices(vert) self.assertIn(vertex1, returned_vertices) self.assertIn(vertex2, returned_vertices) for v in vertices: self.assertNotIn(v, returned_vertices)
def __call__(self, graph, machine, preallocated_resources=None): """ :param graph: The application_graph to partition :type graph:\ :py:class:`pacman.model.graph.application.ApplicationGraph` :param machine: The machine with respect to which to partition the\ application_graph :type machine: :py:class:`spinn_machine.Machine` :return: \ A machine_graph of partitioned vertices and partitioned edges :rtype:\ :py:class:`pacman.model.graph.machine.MachineGraph` :raise pacman.exceptions.PacmanPartitionException: \ If something goes wrong with the partitioning """ ResourceTracker.check_constraints(graph.vertices) utils.check_algorithm_can_support_constraints( constrained_vertices=graph.vertices, abstract_constraint_type=AbstractPartitionerConstraint, supported_constraints=[MaxVertexAtomsConstraint, SameAtomsAsVertexConstraint, FixedVertexAtomsConstraint]) # Load the vertices and create the machine_graph to fill machine_graph = MachineGraph( label="partitioned graph for {}".format(graph.label)) graph_mapper = GraphMapper() # sort out vertex's by placement constraints vertices = placer_utils.sort_vertices_by_known_constraints( graph.vertices) # Set up the progress n_atoms = 0 for vertex in vertices: n_atoms += vertex.n_atoms progress = ProgressBar(n_atoms, "Partitioning graph vertices") resource_tracker = ResourceTracker( machine, preallocated_resources=preallocated_resources) # Group vertices that are supposed to be the same size vertex_groups = partition_utils.get_same_size_vertex_groups(vertices) # Partition one vertex at a time for vertex in vertices: # check that the vertex hasn't already been partitioned machine_vertices = graph_mapper.get_machine_vertices(vertex) # if not, partition if machine_vertices is None: self._partition_vertex( vertex, machine_graph, graph_mapper, resource_tracker, progress, vertex_groups) progress.end() partition_utils.generate_machine_edges( machine_graph, graph_mapper, graph) return machine_graph, graph_mapper, resource_tracker.chips_used
def __call__( self, graph, machine, plan_n_timesteps, preallocated_resources=None): """ :param graph: The application_graph to partition :type graph:\ :py:class:`pacman.model.graph.application.ApplicationGraph` :param machine: The machine with respect to which to partition the\ application_graph :type machine: :py:class:`spinn_machine.Machine` :param plan_n_timesteps: number of timesteps to plan for :type plan_n_timesteps: int :return: \ A machine_graph of partitioned vertices and partitioned edges :rtype:\ :py:class:`pacman.model.graph.machine.MachineGraph` :raise pacman.exceptions.PacmanPartitionException: \ If something goes wrong with the partitioning """ ResourceTracker.check_constraints(graph.vertices) utils.check_algorithm_can_support_constraints( constrained_vertices=graph.vertices, abstract_constraint_type=AbstractPartitionerConstraint, supported_constraints=[MaxVertexAtomsConstraint, SameAtomsAsVertexConstraint, FixedVertexAtomsConstraint]) # Load the vertices and create the machine_graph to fill machine_graph = MachineGraph( label="partitioned graph for {}".format(graph.label)) graph_mapper = GraphMapper() # sort out vertex's by placement constraints vertices = sort_vertices_by_known_constraints(graph.vertices) # Set up the progress n_atoms = 0 for vertex in vertices: n_atoms += vertex.n_atoms progress = ProgressBar(n_atoms, "Partitioning graph vertices") resource_tracker = ResourceTracker( machine, plan_n_timesteps, preallocated_resources=preallocated_resources) # Group vertices that are supposed to be the same size vertex_groups = get_same_size_vertex_groups(vertices) # Partition one vertex at a time for vertex in vertices: # check that the vertex hasn't already been partitioned machine_vertices = graph_mapper.get_machine_vertices(vertex) # if not, partition if machine_vertices is None: self._partition_vertex( vertex, plan_n_timesteps, machine_graph, graph_mapper, resource_tracker, progress, vertex_groups) progress.end() generate_machine_edges(machine_graph, graph_mapper, graph) return machine_graph, graph_mapper, resource_tracker.chips_used