コード例 #1
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"]))
コード例 #2
0
 def test_fixed_mask_constraint(self):
     c1 = FixedMaskConstraint(0xFF0)
     self.assertEqual(c1.mask, 4080)
     c2 = FixedMaskConstraint(0xFF0)
     c3 = FixedMaskConstraint(0xFE0)
     self.assertEqual(c1, c2)
     self.assertNotEqual(c1, c3)
     self.assertNotEqual(c3, c1)
     r = "FixedMaskConstraint(mask=4080)"
     self.assertEqual(str(c1), r)
     d = {}
     d[c1] = 1
     d[c2] = 2
     d[c3] = 3
     self.assertEqual(len(d), 2)
     self.assertEqual(d[c1], 2)
コード例 #3
0
 def get_edge_constraints(self):
     # This allocator requires each edge to have keys of the form
     # |8 bits >= 0 and <= 7|8 bits >= 0 and <= 7|5 bits >= 0 and <= 17|
     # |11 remaining bits|
     # This is because this table was designed for a 48-chip board
     fields = [
         Field(0, 7, 0xFF000000),
         Field(0, 7, 0x00FF0000),
         Field(0, 17, 0x0000F800)]
     constraints = [
         FixedMaskConstraint(0xFFFFF800),
         FixedKeyFieldConstraint(fields)]
     return constraints
コード例 #4
0
 def test_fixed_mask_constraint(self):
     c1 = FixedMaskConstraint(0xFF0)
     self.constraint_there_and_back(c1)
コード例 #5
0
    def get_outgoing_partition_constraints(self, partition):

        # Any key to the device will work, as long as it doesn't set the
        # management bit.  We also need enough for the configuration bits
        # and the management bit anyway
        return list([FixedMaskConstraint(0xFFFFF800)])