def test_new_graph(self): """ tests that after building a machine graph, all partitined vertices and partitioned edges are in existence """ vertices = list() edges = list() for i in range(10): vertices.append( SimpleMachineVertex(ResourceContainer(), "V{}".format(i))) with self.assertRaises(NotImplementedError): vertices[1].add_constraint(SameAtomsAsVertexConstraint( vertices[4])) vertices[4].add_constraint(SameAtomsAsVertexConstraint( vertices[1])) for i in range(5): edges.append(MachineEdge(vertices[0], vertices[(i + 1)])) for i in range(5, 10): edges.append(MachineEdge(vertices[5], vertices[(i + 1) % 10])) graph = MachineGraph("foo") graph.add_vertices(vertices) graph.add_outgoing_edge_partition( MulticastEdgePartition(identifier="bar", pre_vertex=vertices[0])) graph.add_outgoing_edge_partition( MulticastEdgePartition(identifier="bar", pre_vertex=vertices[5])) graph.add_edges(edges, "bar") self.graph_there_and_back(graph)
def test_add_duplicate_edge(self): """ test that adding the same machine edge will cause an error """ vertices = list() edges = list() vertices.append(SimpleMachineVertex(None, "")) vertices.append(SimpleMachineVertex(None, "")) edge = MachineEdge(vertices[0], vertices[1]) edges.append(edge) edges.append(edge) graph = MachineGraph("foo") graph.add_vertices(vertices) graph.add_edges(edges, "bar")
def test_add_edge_with_no_existing_pre_vertex_in_graph(self): """ test that adding a edge where the pre vertex has not been added to the machine graph causes an error """ vertices = list() edges = list() vertices.append(SimpleMachineVertex(None, "")) vertices.append(SimpleMachineVertex(None, "")) edges.append(MachineEdge(vertices[0], vertices[1])) edges.append(MachineEdge(SimpleMachineVertex(None, ""), vertices[0])) with self.assertRaises(PacmanInvalidParameterException): graph = MachineGraph("foo") graph.add_vertices(vertices) graph.add_edges(edges, "bar")
def test_add_duplicate_vertex(self): """ testing that adding the same machine vertex twice will cause an error """ vertices = list() edges = list() subv = SimpleMachineVertex(None, "") vertices.append(subv) vertices.append(SimpleMachineVertex(None, "")) vertices.append(subv) edges.append(MachineEdge(vertices[0], vertices[1])) edges.append(MachineEdge(vertices[1], vertices[0])) graph = MachineGraph("foo") graph.add_vertices(vertices) graph.add_edges(edges, "bar")
def test_add_edge_with_no_existing_pre_vertex_in_graph(self): """ test that adding a edge where the pre vertex has not been added to the machine graph causes an error """ vertices = list() edges = list() vertices.append(SimpleMachineVertex(None, "")) vertices.append(SimpleMachineVertex(None, "")) edges.append(MachineEdge(vertices[0], vertices[1])) edges.append(MachineEdge( SimpleMachineVertex(None, ""), vertices[0])) with self.assertRaises(PacmanInvalidParameterException): graph = MachineGraph("foo") graph.add_vertices(vertices) graph.add_edges(edges, "bar")
def test_add_duplicate_edge(self): """ test that adding the same machine edge will cause an error """ vertices = list() edges = list() vertices.append(SimpleMachineVertex(None, "")) vertices.append(SimpleMachineVertex(None, "")) edge = MachineEdge(vertices[0], vertices[1]) edges.append(edge) edges.append(edge) graph = MachineGraph("foo") graph.add_vertices(vertices) graph.add_outgoing_edge_partition( MulticastEdgePartition(vertices[0], "bar")) with self.assertRaises(PacmanAlreadyExistsException): graph.add_edges(edges, "bar")
def test_new_graph(self): """ tests that after building a machine graph, all partitined vertices and partitioned edges are in existence """ vertices = list() edges = list() for i in range(10): vertices.append(SimpleMachineVertex(None, "")) for i in range(5): edges.append(MachineEdge(vertices[0], vertices[(i + 1)])) for i in range(5, 10): edges.append(MachineEdge( vertices[5], vertices[(i + 1) % 10])) graph = MachineGraph("foo") graph.add_vertices(vertices) graph.add_edges(edges, "bar") outgoing = set(graph.get_edges_starting_at_vertex(vertices[0])) for i in range(5): assert edges[i] in outgoing, \ "edges[" + str(i) + "] is not in outgoing and should be" for i in range(5, 10): assert edges[i] not in outgoing, \ "edges[" + str(i) + "] is in outgoing and shouldn't be" incoming = set(graph.get_edges_ending_at_vertex(vertices[0])) assert edges[9] in incoming, \ "edges[9] is not in incoming and should be" for i in range(9): assert edges[i] not in incoming, \ "edges[" + str(i) + "] is in incoming and shouldn't be" vertices_from_graph = list(graph.vertices) for vert in vertices_from_graph: self.assertIn(vert, vertices) edges_from_graph = list(graph.edges) for edge in edges_from_graph: self.assertIn(edge, edges)
def test_new_graph(self): """ tests that after building a machine graph, all partitined vertices and partitioned edges are in existence """ vertices = list() edges = list() for i in range(10): vertices.append(SimpleMachineVertex(None, "")) for i in range(5): edges.append(MachineEdge(vertices[0], vertices[(i + 1)])) for i in range(5, 10): edges.append(MachineEdge(vertices[5], vertices[(i + 1) % 10])) graph = MachineGraph("foo") graph.add_vertices(vertices) graph.add_edges(edges, "bar") outgoing = set(graph.get_edges_starting_at_vertex(vertices[0])) for i in range(5): assert edges[i] in outgoing, \ "edges[" + str(i) + "] is not in outgoing and should be" for i in range(5, 10): assert edges[i] not in outgoing, \ "edges[" + str(i) + "] is in outgoing and shouldn't be" incoming = set(graph.get_edges_ending_at_vertex(vertices[0])) assert edges[9] in incoming, \ "edges[9] is not in incoming and should be" for i in range(9): assert edges[i] not in incoming, \ "edges[" + str(i) + "] is in incoming and shouldn't be" vertices_from_graph = list(graph.vertices) for vert in vertices_from_graph: self.assertIn(vert, vertices) edges_from_graph = list(graph.edges) for edge in edges_from_graph: self.assertIn(edge, edges)
def check_new_graph(self, app_graph, app_vertex): """ tests that after building a machine graph, all partitined vertices and partitioned edges are in existence """ vertices = list() edges = list() for i in range(10): vertices.append( SimpleMachineVertex(None, "", app_vertex=app_vertex)) for i in range(5): edges.append(MachineEdge(vertices[0], vertices[(i + 1)])) for i in range(5, 10): edges.append(MachineEdge(vertices[5], vertices[(i + 1) % 10])) graph = MachineGraph("foo", application_graph=app_graph) graph.add_vertices(vertices) graph.add_outgoing_edge_partition( MulticastEdgePartition(vertices[0], "bar")) graph.add_outgoing_edge_partition( MulticastEdgePartition(vertices[5], "bar")) graph.add_edges(edges, "bar") outgoing = set(graph.get_edges_starting_at_vertex(vertices[0])) for i in range(5): assert edges[i] in outgoing, \ "edges[" + str(i) + "] is not in outgoing and should be" for i in range(5, 10): assert edges[i] not in outgoing, \ "edges[" + str(i) + "] is in outgoing and shouldn't be" incoming = set(graph.get_edges_ending_at_vertex(vertices[0])) assert edges[9] in incoming, \ "edges[9] is not in incoming and should be" for i in range(9): assert edges[i] not in incoming, \ "edges[" + str(i) + "] is in incoming and shouldn't be" vertices_from_graph = list(graph.vertices) for vert in vertices_from_graph: self.assertIn(vert, vertices) for vert in vertices: self.assertEqual(vert, graph.vertex_by_label(vert.label)) edges_from_graph = list(graph.edges) for edge in edges_from_graph: self.assertIn(edge, edges) if app_graph: with self.assertRaises(PacmanInvalidParameterException): graph.clone() else: second = graph.clone() self.assertEqual(graph.n_vertices, second.n_vertices) vertices_from_graph = list(second.vertices) for vert in vertices_from_graph: self.assertIn(vert, vertices) for vert in vertices: self.assertEqual(vert, graph.vertex_by_label(vert.label)) self.assertEqual(graph.n_outgoing_edge_partitions, second.n_outgoing_edge_partitions) edges_from_graph = list(second.edges) for edge in edges_from_graph: self.assertIn(edge, edges) self.assertEqual(len(edges_from_graph), len(edges)) third = MachineGraphView(graph) self.assertEqual(graph.n_vertices, third.n_vertices) vertices_from_graph = list(third.vertices) for vert in vertices_from_graph: self.assertIn(vert, vertices) for vert in vertices: self.assertEqual(vert, graph.vertex_by_label(vert.label)) self.assertEqual(graph.n_outgoing_edge_partitions, third.n_outgoing_edge_partitions) edges_from_graph = list(third.edges) for edge in edges_from_graph: self.assertIn(edge, edges) self.assertEqual(len(edges_from_graph), len(edges)) with self.assertRaises(PacmanConfigurationException): third.add_edge("mock", "mock") with self.assertRaises(PacmanConfigurationException): third.add_vertex("mock") with self.assertRaises(PacmanConfigurationException): third.add_outgoing_edge_partition("mock")