def test_create_new_subedge_from_edge(self): """ test that you can use the TestPartitionableEdge.create-subedge method and not cause errors :return: """ vert1 = TestVertex(10, "New AbstractConstrainedVertex 1", 256) subv_from_vert1 = vert1.create_subvertex( Slice(0, 9), vert1.get_resources_used_by_atoms(Slice(0, 9), None)) vert2 = TestVertex(5, "New AbstractConstrainedVertex 2", 256) subv_from_vert2 = vert2.create_subvertex( Slice(0, 4), vert2.get_resources_used_by_atoms(Slice(0, 4), None)) edge1 = TestPartitionableEdge(vert1, vert2, "First edge") subedge1 = edge1.create_subedge(subv_from_vert1, subv_from_vert2, None, "First sub edge") self.assertEqual(subedge1.label, "First sub edge")
def test_new_create_subvertex_from_vertex_no_constraints(self): """ test the creating of a subedge by the AbstractPartitionableEdge create subedge method will actually create a subedge of the partitioned edge type. :return: """ vert1 = TestVertex(10, "New AbstractConstrainedVertex", 256) subv_from_vert1 = vert1.create_subvertex( Slice(0, 9), vert1.get_resources_used_by_atoms(Slice(0, 9), None)) vert2 = TestVertex(10, "New AbstractConstrainedVertex", 256) subv_from_vert2 = vert2.create_subvertex( Slice(0, 9), vert2.get_resources_used_by_atoms(Slice(0, 9), None)) edge1 = TestPartitionableEdge(vert1, vert2, "edge 1") subedge = edge1.create_subedge(subv_from_vert1, subv_from_vert2) self.assertIsInstance(subedge, AbstractPartitionedEdge)
def test_new_create_subvertex_from_vertex_check_resources(self): """ check that the creation of a subvertex means that the reosurces calcualted by the partitionable vertex is the same as what the parttiioned vertex says (given same sizes) :return: """ vert = TestVertex(10, "New AbstractConstrainedVertex", 256) resources = vert.get_resources_used_by_atoms(Slice(0, 9), None) subv_from_vert = vert.create_subvertex(Slice(0, 9), resources, "") self.assertEqual(subv_from_vert.resources_required, resources)
def test_place_subvertex_too_big_with_vertex(self): large_vertex = TestVertex(500, "Large vertex 500") large_subvertex = large_vertex.create_subvertex( 0, 499, get_resources_used_by_atoms(0, 499, []))#PartitionedVertex(0, 499, "Large subvertex") self.graph.add_vertex(large_vertex) self.graph = PartitionableGraph("Graph",[large_vertex]) self.graph_mapper = GraphMapper() self.graph_mapper.add_subvertices([large_subvertex], large_vertex) self.bp = BasicPlacer(self.machine, self.graph) self.subgraph = PartitionedGraph(subvertices=[large_subvertex]) with self.assertRaises(PacmanPlaceException): placements = self.bp.place(self.subgraph, self.graph_mapper)
def test_new_create_subvertex_from_vertex_no_constraints(self): """ test the creating of a subvertex by the AbstractPartitionableVertex create subvertex method will actually create a subvertex of the partitioned vertex type. :return: """ vert = TestVertex(10, "New AbstractConstrainedVertex", 256) subvertex = vert.create_subvertex( Slice(0, 9), vert.get_resources_used_by_atoms(Slice(0, 9), None)) self.assertIsInstance(subvertex, PartitionedVertex)
def test_create_subvertex_from_vertex_with_previous_constraints(self): """ test the create subedge command given by the TestPartitionableEdge actually works and generates a subedge with the same constraints mapped over :return: """ constraint1 = KeyAllocatorContiguousRangeContraint() vert1 = TestVertex(10, "New AbstractConstrainedVertex", 256) subv_from_vert1 = vert1.create_subvertex( Slice(0, 9), vert1.get_resources_used_by_atoms(Slice(0, 9), None)) vert2 = TestVertex(10, "New AbstractConstrainedVertex", 256) subv_from_vert2 = vert2.create_subvertex( Slice(0, 9), vert2.get_resources_used_by_atoms(Slice(0, 9), None)) edge1 = TestPartitionableEdge(vert1, vert2, "edge 1") edge1.add_constraint(constraint1) subedge = edge1.create_subedge(subv_from_vert1, subv_from_vert2) self.assertIn(constraint1, subedge.constraints)
def test_create_subvertex_from_vertex_with_previous_constraints(self): """ test the create subvertex command given by the AbstractPartitionableVertex actually works and generates a subvertex with the same constraints mapped over :return: """ constraint1 = PartitionerMaximumSizeConstraint(2) vert = TestVertex(10, "New AbstractConstrainedVertex", 256) subv_from_vert = vert.create_subvertex( Slice(0, 9), vert.get_resources_used_by_atoms(Slice(0, 9), None)) self.assertNotIn(constraint1, subv_from_vert.constraints)
def test_create_new_subvertex_from_vertex_with_additional_constraints( self): """ test that a subvertex created from a parti9onable vertex with constraints can have more constraints added to it. :return: """ constraint1 = PartitionerMaximumSizeConstraint(2) constraint2 = PartitionerMaximumSizeConstraint(3) vert = TestVertex(10, "New AbstractConstrainedVertex", 256) vert.add_constraint([constraint1]) subv_from_vert = vert.create_subvertex( Slice(0, 9), vert.get_resources_used_by_atoms(Slice(0, 9), None), "", [constraint2]) subv_from_vert.add_constraint(constraint1) self.assertEqual(len(subv_from_vert.constraints), 2) self.assertEqual(subv_from_vert.constraints[1], constraint1) self.assertEqual(subv_from_vert.constraints[0], constraint2)