def test_create_new_vertex_with_constraint_list(self): """ test initisation of a vertex with a max size constraint :return: """ constraint = PartitionerMaximumSizeConstraint(2) vert = TestVertex(10, "New AbstractConstrainedVertex", 256) vert.add_constraint(constraint) self.assertEqual(vert.n_atoms, 10) self.assertEqual(vert.label, "New AbstractConstrainedVertex") self.assertEqual(vert.constraints[1], constraint)
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_partition_on_target_size_vertex_than_has_to_be_split(self): """ test that fixed partitioning causes correct number of subvertices :return: """ self.setup() large_vertex = TestVertex(1000, "Large vertex") large_vertex.add_constraint(PartitionerMaximumSizeConstraint(10)) self.graph = PartitionableGraph( "Graph with large vertex", [large_vertex], []) subgraph, mapper = self.bp.partition(self.graph, self.machine) self.assertEqual(len(subgraph.subvertices), 100)
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 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_operation_with_same_size_as_vertex_constraint_exception(self): """ test that a partition same as constraint with differetn size atoms causes errors :return: """ self.setup() constrained_vertex = TestVertex(100, "Constrained") constrained_vertex.add_constraint( PartitionerSameSizeAsVertexConstraint(self.vert2)) self.graph.add_vertex(constrained_vertex) partitioner = PartitionAndPlacePartitioner() self.assertRaises(PacmanPartitionException, partitioner.partition, self.graph, self.machine)
def test_partition_with_unsupported_constraints(self): """ test that when a vertex has a constraint that is unrecognised, it raises an error :return: """ self.setup() constrained_vertex = TestVertex(13, "Constrained") constrained_vertex.add_constraint( NewPartitionerConstraint("Mock constraint")) graph = PartitionableGraph("Graph", [constrained_vertex], None) partitioner = BasicPartitioner() self.assertRaises(PacmanInvalidParameterException, partitioner.partition, graph, self.machine)
def test_operation_with_same_size_as_vertex_constraint(self): """ test that the partition and place partitioner can handle same size as constraints ona vertex that is split into one core :return: """ self.setup() constrained_vertex = TestVertex(5, "Constrained") constrained_vertex.add_constraint( PartitionerSameSizeAsVertexConstraint(self.vert2)) self.graph.add_vertex(constrained_vertex) partitioner = PartitionAndPlacePartitioner() subgraph, graph_to_sub_graph_mapper = \ partitioner.partition(self.graph, self.machine) self.assertEqual(len(subgraph.subvertices), 5)
def test_create_new_vertex_add_constraints(self): """ test that creating a vertex and then adding constraints in a list :return: """ constraint1 = PartitionerMaximumSizeConstraint(2) constraint2 = PartitionerMaximumSizeConstraint(3) constr = list() constr.append(constraint1) constr.append(constraint2) vert = TestVertex(10, "New AbstractConstrainedVertex", 256) vert.add_constraints(constr) self.assertEqual(vert.n_atoms, 10) self.assertEqual(vert.label, "New AbstractConstrainedVertex") self.assertEqual(len(vert.constraints), 3) for constraint in constr: self.assertIn(constraint, vert.constraints)
def test_operation_with_same_size_as_vertex_constraint_large_vertices(self): """ test that the partition and place partitioner can handle same size as constraints on a vertex which has to be split over many cores :return: """ self.setup() constrained_vertex = TestVertex(300, "Constrained") new_large_vertex = TestVertex(300, "Non constrained") constrained_vertex.add_constraint( PartitionerSameSizeAsVertexConstraint(new_large_vertex)) self.graph = PartitionableGraph( "New graph", [new_large_vertex, constrained_vertex]) partitioner = PartitionAndPlacePartitioner() subgraph, graph_to_sub_graph_mapper = \ partitioner.partition(self.graph, self.machine) self.assertEqual(len(subgraph.subvertices), 6)
def test_operation_same_size_as_vertex_constraint_different_order(self): """ test that the partition and place partitioner can handle same size as constraints on a vertex which has to be split over many cores where the order of the vetices being added is different. :return: """ self.setup() constrained_vertex = TestVertex(300, "Constrained") new_large_vertex = TestVertex(300, "Non constrained") constrained_vertex.add_constraint( PartitionerSameSizeAsVertexConstraint(new_large_vertex)) self.graph = PartitionableGraph("New graph", [constrained_vertex, new_large_vertex]) partitioner = PartitionAndPlacePartitioner() subgraph, graph_to_sub_graph_mapper = \ partitioner.partition(self.graph, self.machine) # split in 256 each, so 4 partitioned vertices self.assertEqual(len(subgraph.subvertices), 4)
def test_create_new_vertex_add_constraint(self): """ test creating a vertex and then adding constraints indivusally :return: """ constraint1 = PartitionerMaximumSizeConstraint(2) constraint2 = PartitionerMaximumSizeConstraint(3) constr = list() constr.append(constraint1) constr.append(constraint2) vert = TestVertex(10, "New AbstractConstrainedVertex", 256) vert.add_constraint(constraint2) vert.add_constraint(constraint1) self.assertEqual(vert.n_atoms, 10) self.assertEqual(len(vert.constraints), 3) self.assertEqual(vert.label, "New AbstractConstrainedVertex") for constraint in constr: if constraint not in vert.constraints: raise Exception("dont exist where should")
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)
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_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 setUp(self): ######################################################################## # Setting up vertices, edges and graph # ######################################################################## self.vert1 = TestVertex(100, "New AbstractConstrainedTestVertex 1") self.vert2 = TestVertex(5, "New AbstractConstrainedTestVertex 2") self.vert3 = TestVertex(3, "New AbstractConstrainedTestVertex 3") self.edge1 = MultiCastPartitionableEdge(self.vert1, self.vert2, "First edge") self.edge2 = MultiCastPartitionableEdge(self.vert2, self.vert1, "Second edge") self.edge3 = MultiCastPartitionableEdge(self.vert1, self.vert3, "Third edge") self.verts = [self.vert1, self.vert2, self.vert3] self.edges = [self.edge1, self.edge2, self.edge3] self.graph = PartitionableGraph("Graph", self.verts, self.edges) ######################################################################## # Setting up machine # ######################################################################## flops = 1000 (e, ne, n, w, sw, s) = range(6) processors = list() for i in range(18): processors.append(Processor(i, flops)) _sdram = SDRAM(128 * (2**20)) ip = "192.168.240.253" chips = list() for x in range(10): for y in range(10): links = list() links.append(Link(x, y, 0, (x + 1) % 10, y, n, n)) links.append(Link(x, y, 1, (x + 1) % 10, (y + 1) % 10, s, s)) links.append(Link(x, y, 2, x, (y + 1) % 10, n, n)) links.append(Link(x, y, 3, (x - 1) % 10, y, s, s)) links.append(Link(x, y, 4, (x - 1) % 10, (y - 1) % 10, n, n)) links.append(Link(x, y, 5, x, (y - 1) % 10, s, s)) r = Router(links, False, 100, 1024) chips.append(Chip(x, y, processors, r, _sdram, 0, 0, ip)) self.machine = Machine(chips) ######################################################################## # Setting up subgraph and graph_mapper # ######################################################################## self.subvertices = list() self.subvertex1 = PartitionedVertex( 0, 1, self.vert1.get_resources_used_by_atoms(0, 1, []), "First subvertex") self.subvertex2 = PartitionedVertex( 1, 5, get_resources_used_by_atoms(1, 5, []), "Second subvertex") self.subvertex3 = PartitionedVertex( 5, 10, get_resources_used_by_atoms(5, 10, []), "Third subvertex") self.subvertex4 = PartitionedVertex( 10, 100, get_resources_used_by_atoms(10, 100, []), "Fourth subvertex") self.subvertices.append(self.subvertex1) self.subvertices.append(self.subvertex2) self.subvertices.append(self.subvertex3) self.subvertices.append(self.subvertex4) self.subedges = list() self.subgraph = PartitionedGraph("Subgraph", self.subvertices, self.subedges) self.graph_mapper = GraphMapper() self.graph_mapper.add_subvertices(self.subvertices)
class TestBasicPlacer(unittest.TestCase): """ test for basic placement algorithum """ def setUp(self): ######################################################################## # Setting up vertices, edges and graph # ######################################################################## self.vert1 = TestVertex(100, "New AbstractConstrainedTestVertex 1") self.vert2 = TestVertex(5, "New AbstractConstrainedTestVertex 2") self.vert3 = TestVertex(3, "New AbstractConstrainedTestVertex 3") self.edge1 = MultiCastPartitionableEdge(self.vert1, self.vert2, "First edge") self.edge2 = MultiCastPartitionableEdge(self.vert2, self.vert1, "Second edge") self.edge3 = MultiCastPartitionableEdge(self.vert1, self.vert3, "Third edge") self.verts = [self.vert1, self.vert2, self.vert3] self.edges = [self.edge1, self.edge2, self.edge3] self.graph = PartitionableGraph("Graph", self.verts, self.edges) ######################################################################## # Setting up machine # ######################################################################## flops = 1000 (e, ne, n, w, sw, s) = range(6) processors = list() for i in range(18): processors.append(Processor(i, flops)) _sdram = SDRAM(128 * (2**20)) ip = "192.168.240.253" chips = list() for x in range(10): for y in range(10): links = list() links.append(Link(x, y, 0, (x + 1) % 10, y, n, n)) links.append(Link(x, y, 1, (x + 1) % 10, (y + 1) % 10, s, s)) links.append(Link(x, y, 2, x, (y + 1) % 10, n, n)) links.append(Link(x, y, 3, (x - 1) % 10, y, s, s)) links.append(Link(x, y, 4, (x - 1) % 10, (y - 1) % 10, n, n)) links.append(Link(x, y, 5, x, (y - 1) % 10, s, s)) r = Router(links, False, 100, 1024) chips.append(Chip(x, y, processors, r, _sdram, 0, 0, ip)) self.machine = Machine(chips) ######################################################################## # Setting up subgraph and graph_mapper # ######################################################################## self.subvertices = list() self.subvertex1 = PartitionedVertex( 0, 1, self.vert1.get_resources_used_by_atoms(0, 1, []), "First subvertex") self.subvertex2 = PartitionedVertex( 1, 5, get_resources_used_by_atoms(1, 5, []), "Second subvertex") self.subvertex3 = PartitionedVertex( 5, 10, get_resources_used_by_atoms(5, 10, []), "Third subvertex") self.subvertex4 = PartitionedVertex( 10, 100, get_resources_used_by_atoms(10, 100, []), "Fourth subvertex") self.subvertices.append(self.subvertex1) self.subvertices.append(self.subvertex2) self.subvertices.append(self.subvertex3) self.subvertices.append(self.subvertex4) self.subedges = list() self.subgraph = PartitionedGraph("Subgraph", self.subvertices, self.subedges) self.graph_mapper = GraphMapper() self.graph_mapper.add_subvertices(self.subvertices) @unittest.skip("demonstrating skipping") def test_new_basic_placer(self): self.bp = BasicPlacer(self.machine, self.graph) self.assertEqual(self.bp._machine, self.machine) self.assertEqual(self.bp._graph, self.graph) @unittest.skip("demonstrating skipping") def test_place_where_subvertices_dont_have_vertex(self): self.bp = BasicPlacer(self.machine, self.graph) placements = self.bp.place(self.subgraph, self.graph_mapper) for placement in placements.placements: print placement.subvertex.label, placement.subvertex.n_atoms, \ 'x:', placement.x, 'y:', placement.y, 'p:', placement.p @unittest.skip("demonstrating skipping") def test_place_where_subvertices_have_vertices(self): self.bp = BasicPlacer(self.machine, self.graph) self.graph_mapper = GraphMapper() self.graph_mapper.add_subvertices(self.subvertices, self.vert1) placements = self.bp.place(self.subgraph, self.graph_mapper) for placement in placements.placements: print placement.subvertex.label, placement.subvertex.n_atoms, \ 'x:', placement.x, 'y:', placement.y, 'p:', placement.p @unittest.skip("demonstrating skipping") 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) @unittest.skip("demonstrating skipping") def test_try_to_place(self): self.assertEqual(True, False, "Test not implemented yet") @unittest.skip("demonstrating skipping") def test_deal_with_constraint_placement_subvertices_dont_have_vertex(self): self.bp = BasicPlacer(self.machine, self.graph) self.subvertex1.add_constraint(PlacerChipAndCoreConstraint(8, 3, 2)) self.assertIsInstance(self.subvertex1.constraints[0], PlacerChipAndCoreConstraint) self.subvertex2.add_constraint(PlacerChipAndCoreConstraint(3, 5, 7)) self.subvertex3.add_constraint(PlacerChipAndCoreConstraint(2, 4, 6)) self.subvertex4.add_constraint(PlacerChipAndCoreConstraint(6, 4, 16)) self.subvertices = list() self.subvertices.append(self.subvertex1) self.subvertices.append(self.subvertex2) self.subvertices.append(self.subvertex3) self.subvertices.append(self.subvertex4) self.subedges = list() self.subgraph = PartitionedGraph("Subgraph", self.subvertices, self.subedges) self.graph_mapper = GraphMapper() self.graph_mapper.add_subvertices(self.subvertices) placements = self.bp.place(self.subgraph, self.graph_mapper) for placement in placements.placements: print placement.subvertex.label, placement.subvertex.n_atoms, \ 'x:', placement.x, 'y:', placement.y, 'p:', placement.p @unittest.skip("demonstrating skipping") def test_deal_with_constraint_placement_subvertices_have_vertices(self): self.bp = BasicPlacer(self.machine, self.graph) self.subvertex1.add_constraint(PlacerChipAndCoreConstraint(1, 5, 2)) self.assertIsInstance(self.subvertex1.constraints[0], PlacerChipAndCoreConstraint) self.subvertex2.add_constraint(PlacerChipAndCoreConstraint(3, 5, 7)) self.subvertex3.add_constraint(PlacerChipAndCoreConstraint(2, 4, 6)) self.subvertex4.add_constraint(PlacerChipAndCoreConstraint(6, 7, 16)) self.subvertices = list() self.subvertices.append(self.subvertex1) self.subvertices.append(self.subvertex2) self.subvertices.append(self.subvertex3) self.subvertices.append(self.subvertex4) self.subedges = list() self.subgraph = PartitionedGraph("Subgraph", self.subvertices, self.subedges) self.graph_mapper = GraphMapper() self.graph_mapper.add_subvertices(self.subvertices, self.vert1) placements = self.bp.place(self.subgraph, self.graph_mapper) for placement in placements.placements: print placement.subvertex.label, placement.subvertex.n_atoms, \ 'x:', placement.x, 'y:', placement.y, 'p:', placement.p @unittest.skip("demonstrating skipping") def test_unsupported_non_placer_constraint(self): self.assertEqual(True, False, "Test not implemented yet") @unittest.skip("demonstrating skipping") def test_unsupported_placer_constraint(self): self.assertEqual(True, False, "Test not implemented yet") @unittest.skip("demonstrating skipping") def test_unsupported_placer_constraints(self): self.assertEqual(True, False, "Test not implemented yet") @unittest.skip("demonstrating skipping") def test_many_subvertices(self): subvertices = list() for i in range(20 * 17): #50 atoms per each processor on 20 chips subvertices.append(PartitionedTestVertex( 0, 50, get_resources_used_by_atoms(0, 50, []), "PartitionedVertex " + str(i))) self.graph = PartitionableGraph("Graph",subvertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_subvertices(subvertices) self.bp = BasicPlacer(self.machine, self.graph) self.subgraph = PartitionedGraph(subvertices=subvertices) placements = self.bp.place(self.subgraph, self.graph_mapper) for placement in placements.placements: print placement.subvertex.label, placement.subvertex.n_atoms, \ 'x:', placement.x, 'y:', placement.y, 'p:', placement.p @unittest.skip("demonstrating skipping") def test_too_many_subvertices(self): subvertices = list() for i in range(100 * 17): #50 atoms per each processor on 20 chips subvertices.append(PartitionedTestVertex( 0, 50, get_resources_used_by_atoms(0, 50, []), "PartitionedVertex " + str(i))) self.graph = PartitionableGraph("Graph",subvertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_subvertices(subvertices) self.bp = BasicPlacer(self.machine, self.graph) self.subgraph = PartitionedGraph(subvertices=subvertices) with self.assertRaises(PacmanPlaceException): placements = self.bp.place(self.subgraph, self.graph_mapper) @unittest.skip("demonstrating skipping") def test_fill_machine(self): subvertices = list() for i in range(99 * 17): #50 atoms per each processor on 20 chips subvertices.append(PartitionedTestVertex( 0, 50, get_resources_used_by_atoms(0, 50, []), "PartitionedVertex " + str(i))) self.graph = PartitionableGraph("Graph",subvertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_subvertices(subvertices) self.bp = BasicPlacer(self.machine, self.graph) self.subgraph = PartitionedGraph(subvertices=subvertices) placements = self.bp.place(self.subgraph, self.graph_mapper)