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_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_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_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_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_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_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_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)