Exemplo n.º 1
0
 def test_max_vertex_atoms_constraint(self):
     c1 = MaxVertexAtomsConstraint(5)
     self.assertEqual(c1.size, 5)
     self.assertEqual(c1, MaxVertexAtomsConstraint(5))
     self.assertEqual(str(c1), 'MaxVertexAtomsConstraint(size=5)')
     c2 = MaxVertexAtomsConstraint(7)
     self.assertNotEqual(c1, c2)
     self.assertNotEqual(c1, "1.2.3.4")
     d = {}
     d[c1] = 1
     d[c2] = 2
     self.assertEqual(len(d), 2)
Exemplo n.º 2
0
 def test_create_new_vertex_add_constraints(self):
     """
     test that creating a vertex and then adding constraints in a list
     """
     constraint1 = MaxVertexAtomsConstraint(2)
     constraint2 = MaxVertexAtomsConstraint(3)
     constr = list()
     constr.append(constraint1)
     constr.append(constraint2)
     vert = SimpleTestVertex(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)
Exemplo n.º 3
0
def constraint_from_json(json_dict, graph=None):
    if json_dict["class"] == "BoardConstraint":
        return BoardConstraint(json_dict["board_address"])
    if json_dict["class"] == "ChipAndCoreConstraint":
        if "p" in json_dict:
            p = json_dict["p"]
        else:
            p = None
        return ChipAndCoreConstraint(json_dict["x"], json_dict["y"], p)
    if json_dict["class"] == "ContiguousKeyRangeContraint":
        return ContiguousKeyRangeContraint()
    if json_dict["class"] == "FixedKeyAndMaskConstraint":
        if "key_list_function" in json_dict:
            raise NotImplementedError("key_list_function {}".format(
                json_dict["key_list_function"]))
        return FixedKeyAndMaskConstraint(
            key_masks_from_json(json_dict["keys_and_masks"]))
    if json_dict["class"] == "FixedMaskConstraint":
        return FixedMaskConstraint(json_dict["mask"])
    if json_dict["class"] == "FixedVertexAtomsConstraint":
        return FixedVertexAtomsConstraint(json_dict["size"])
    if json_dict["class"] == "MaxVertexAtomsConstraint":
        return MaxVertexAtomsConstraint(json_dict["size"])
    if json_dict["class"] == "RadialPlacementFromChipConstraint":
        return RadialPlacementFromChipConstraint(json_dict["x"],
                                                 json_dict["y"])
    if json_dict["class"] == "SameChipAsConstraint":
        return SameChipAsConstraint(vertex_lookup(json_dict["vertex"], graph))
    if json_dict["class"] == "SameAtomsAsVertexConstraint":
        return SameAtomsAsVertexConstraint(
            vertex_lookup(json_dict["vertex"], graph))
    raise NotImplementedError("constraint {}".format(json_dict["class"]))
Exemplo n.º 4
0
 def test_create_new_vertex_from_vertex_with_additional_constraints(self):
     """
     test that a vertex created from a vertex with
     constraints can have more constraints added to it.
     """
     constraint1 = MaxVertexAtomsConstraint(2)
     constraint2 = MaxVertexAtomsConstraint(3)
     vert = SimpleTestVertex(10, "New AbstractConstrainedVertex", 256)
     vert.add_constraint(constraint1)
     subv_from_vert = vert.create_machine_vertex(
         Slice(0, 9), vert.get_resources_used_by_atoms(Slice(0, 9)), "",
         [constraint2])
     subv_from_vert.add_constraint(constraint1)
     self.assertEqual(len(subv_from_vert.constraints), 2)
     self.assertIn(constraint1, subv_from_vert.constraints)
     self.assertIn(constraint2, subv_from_vert.constraints)
Exemplo n.º 5
0
    def __init__(self,
                 label=None,
                 constraints=None,
                 max_atoms_per_core=sys.maxsize,
                 splitter=None):
        """
        :param str label: The optional name of the vertex.
        :param iterable(AbstractConstraint) constraints:
            The optional initial constraints of the vertex.
        :param int max_atoms_per_core: The max number of atoms that can be
            placed on a core, used in partitioning.
        :param splitter: The splitter object needed for this vertex.
            Leave as None to delegate the choice of splitter to the selector.
        :type splitter: None or
            ~pacman.model.partitioner_interfaces.AbstractSplitterPartitioner
        :raise PacmanInvalidParameterException:
            If one of the constraints is not valid
        """
        # Need to set to None temporarily as add_constraint checks splitter
        self._splitter = None
        super(ApplicationVertex, self).__init__(label, constraints)
        self._machine_vertices = OrderedSet()

        # Use setter as there is extra work to do
        self.splitter = splitter

        # add a constraint for max partitioning
        self.add_constraint(MaxVertexAtomsConstraint(max_atoms_per_core))
Exemplo n.º 6
0
 def test_create_new_vertex_add_constraint(self):
     """
     test creating a vertex and then adding constraints individually
     """
     constraint1 = MaxVertexAtomsConstraint(2)
     constraint2 = MaxVertexAtomsConstraint(3)
     constr = list()
     constr.append(constraint1)
     constr.append(constraint2)
     vert = SimpleTestVertex(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")
Exemplo n.º 7
0
 def test_create_new_vertex_with_constraint_list(self):
     """
     test initialisation of a vertex with a max size constraint
     """
     constraint = MaxVertexAtomsConstraint(2)
     vert = SimpleTestVertex(10, "New AbstractConstrainedVertex", 256)
     vert.add_constraint(constraint)
     self.assertEqual(vert.n_atoms, 10)
     self.assertEqual(vert.label, "New AbstractConstrainedVertex")
     assert constraint in vert.constraints
Exemplo n.º 8
0
    def set_max_atoms_per_core(self, max_atoms_per_core):
        """ Supports the setting of this population's max atoms per core

        :param max_atoms_per_core: the new value for the max atoms per core.
        """
        globals_variables.get_simulator().verify_not_running()
        self._vertex.add_constraint(
            MaxVertexAtomsConstraint(max_atoms_per_core))
        # state that something has changed in the population
        self._change_requires_mapping = True
Exemplo n.º 9
0
 def test_create_vertex_from_vertex_with_previous_constraints(self):
     """
     test the create vertex command given by the
     vertex actually works and generates a vertex
     with the same constraints mapped over
     """
     constraint1 = MaxVertexAtomsConstraint(2)
     vert = SimpleTestVertex(10, "New AbstractConstrainedVertex", 256)
     subv_from_vert = vert.create_machine_vertex(
         Slice(0, 9), vert.get_resources_used_by_atoms(Slice(0, 9)))
     self.assertNotIn(constraint1, subv_from_vert.constraints)
Exemplo n.º 10
0
 def test_partition_on_target_size_vertex_than_has_to_be_split(self):
     """
     test that fixed partitioning causes correct number of vertices
     """
     self.setup()
     large_vertex = SimpleTestVertex(1000, "Large vertex")
     large_vertex.add_constraint(MaxVertexAtomsConstraint(10))
     self.graph = ApplicationGraph("Graph with large vertex")
     self.graph.add_vertex(large_vertex)
     graph, _, _ = self.bp(self.graph, self.machine)
     self.assertEqual(len(list(graph.vertices)), 100)
Exemplo n.º 11
0
 def test_partition_on_target_size_vertex_than_has_to_be_split(self):
     """
     test that fixed partitioning causes correct number of vertices
     """
     large_vertex = SimpleTestVertex(1000, "Large vertex")
     large_vertex.add_constraint(MaxVertexAtomsConstraint(10))
     large_vertex.splitter = SplitterSliceLegacy()
     self.graph = ApplicationGraph("Graph with large vertex")
     self.graph.add_vertex(large_vertex)
     graph, _ = splitter_partitioner(
         self.graph,
         self.machine,
         plan_n_time_steps=100,
         pre_allocated_resources=PreAllocatedResourceContainer())
     self.assertEqual(len(list(graph.vertices)), 100)
Exemplo n.º 12
0
    def __init__(self,
                 label=None,
                 constraints=None,
                 max_atoms_per_core=sys.maxsize):
        """
        :param label: The optional name of the vertex
        :type label: str
        :param constraints: The optional initial constraints of the vertex
        :type constraints: \
            iterable(:py:class:`pacman.model.constraints.AbstractConstraint`)
        :param max_atoms_per_core: the max number of atoms that can be\
            placed on a core, used in partitioning
        :type max_atoms_per_core: int
        :raise pacman.exceptions.PacmanInvalidParameterException:\
            * If one of the constraints is not valid
        """

        super(ApplicationVertex, self).__init__(constraints)
        self._label = label

        # add a constraint for max partitioning
        self.add_constraint(MaxVertexAtomsConstraint(max_atoms_per_core))
Exemplo n.º 13
0
 def test_max_vertex_atoms_constraint(self):
     c1 = MaxVertexAtomsConstraint(5)
     self.constraint_there_and_back(c1)