def create_app_less():
    app_graph = ApplicationGraph("Test")

    mac_graph = MachineGraph("Test", app_graph)
    n_keys_map = DictBasedMachinePartitionNKeysMap()

    # An output vertex to aim things at (to make keys required)
    out_mac_vertex = SimpleMacVertex()
    mac_graph.add_vertex(out_mac_vertex)

    # Create 5 application vertices (3 bits)
    for app_index in range(5):

        # For each, create up to (5 x 4) + 1 = 21 machine vertices (5 bits)
        for mac_index in range((app_index * 4) + 1):
            mac_vertex = SimpleMacVertex()
            mac_graph.add_vertex(mac_vertex)

            # For each machine vertex create up to
            # (20 x 2) + 1 = 81(!) partitions (6 bits)
            for mac_edge_index in range((mac_index * 2) + 1):
                mac_edge = MachineEdge(mac_vertex, out_mac_vertex)
                part_name = "Part{}".format(mac_edge_index)
                mac_graph.add_edge(mac_edge, part_name)

                # Give the partition up to (40 x 4) + 1 = 161 keys (8 bits)
                p = mac_graph.get_outgoing_edge_partition_starting_at_vertex(
                    mac_vertex, part_name)
                n_keys_map.set_n_keys_for_partition(
                    p, (mac_edge_index * 4) + 1)

    return app_graph, mac_graph, n_keys_map
def create_graphs_only_fixed():
    app_graph = ApplicationGraph("Test")
    # An output vertex to aim things at (to make keys required)
    out_app_vertex = SimpleAppVertex()
    app_graph.add_vertex(out_app_vertex)
    # Create 5 application vertices (3 bits)
    app_vertex = SimpleAppVertex()
    app_graph.add_vertex(app_vertex)

    mac_graph = MachineGraph("Test", app_graph)
    n_keys_map = DictBasedMachinePartitionNKeysMap()

    # An output vertex to aim things at (to make keys required)
    out_mac_vertex = SimpleMacVertex(app_vertex=out_app_vertex)
    mac_graph.add_vertex(out_mac_vertex)

    mac_vertex = SimpleMacVertex(app_vertex=app_vertex)
    mac_graph.add_vertex(mac_vertex)
    for mac_edge_index in range(2):
        mac_edge = MachineEdge(mac_vertex, out_mac_vertex)
        part_name = "Part{}".format(mac_edge_index)
        mac_graph.add_edge(mac_edge, part_name)
        p = mac_graph.get_outgoing_edge_partition_starting_at_vertex(
            mac_vertex, part_name)
        if (mac_edge_index == 0):
            p.add_constraint(FixedKeyAndMaskConstraint(
                [BaseKeyAndMask(0x4c00000, 0xFFFFFFFE)]))
        if (mac_edge_index == 1):
            p.add_constraint(FixedKeyAndMaskConstraint(
                [BaseKeyAndMask(0x4c00000, 0xFFFFFFFF)]))
        n_keys_map.set_n_keys_for_partition(
                p, (mac_edge_index * 4) + 1)

    return app_graph, mac_graph, n_keys_map
def create_big(with_fixed):
    # This test shows how easy it is to trip up the allocator with a retina
    app_graph = ApplicationGraph("Test")
    # Create a single "big" vertex
    big_app_vertex = SimpleTestVertex(1, label="Retina")
    app_graph.add_vertex(big_app_vertex)
    # Create a single output vertex (which won't send)
    out_app_vertex = SimpleTestVertex(1, label="Destination")
    app_graph.add_vertex(out_app_vertex)
    # Create a load of middle vertex
    mid_app_vertex = SimpleTestVertex(1, "Population")
    app_graph.add_vertex(mid_app_vertex)

    mac_graph = MachineGraph("Test", app_graph)
    n_keys_map = DictBasedMachinePartitionNKeysMap()

    # Create a single big machine vertex
    big_mac_vertex = big_app_vertex.create_machine_vertex(None,
                                                          None,
                                                          label="RETINA")
    mac_graph.add_vertex(big_mac_vertex)

    # Create a single output vertex (which won't send)
    out_mac_vertex = out_app_vertex.create_machine_vertex(None, None)
    mac_graph.add_vertex(out_mac_vertex)

    # Create a load of middle vertices and connect them up
    for _ in range(2000):  # 2000 needs 11 bits
        mid_mac_vertex = mid_app_vertex.create_machine_vertex(None, None)
        mac_graph.add_vertex(mid_mac_vertex)
        edge = MachineEdge(big_mac_vertex, mid_mac_vertex)
        mac_graph.add_edge(edge, "Test")
        edge_2 = MachineEdge(mid_mac_vertex, out_mac_vertex)
        mac_graph.add_edge(edge_2, "Test")
        mid_part = mac_graph.get_outgoing_edge_partition_starting_at_vertex(
            mid_mac_vertex, "Test")
        n_keys_map.set_n_keys_for_partition(mid_part, 100)

    big_mac_part = mac_graph.get_outgoing_edge_partition_starting_at_vertex(
        big_mac_vertex, "Test")
    if with_fixed:
        big_mac_part.add_constraint(
            FixedKeyAndMaskConstraint([BaseKeyAndMask(0x0, 0x180000)]))
    # Make the "retina" need 21 bits, so total is now 21 + 11 = 32 bits,
    # but the application vertices need some bits too
    n_keys_map.set_n_keys_for_partition(big_mac_part, 1024 * 768 * 2)
    return app_graph, mac_graph, n_keys_map
def create_graphs_no_edge():
    app_graph = ApplicationGraph("Test")
    # An output vertex to aim things at (to make keys required)
    out_app_vertex = SimpleAppVertex()
    app_graph.add_vertex(out_app_vertex)
    # Create 5 application vertices (3 bits)
    app_vertex = SimpleAppVertex()
    app_graph.add_vertex(app_vertex)

    mac_graph = MachineGraph("Test", app_graph)
    n_keys_map = DictBasedMachinePartitionNKeysMap()

    # An output vertex to aim things at (to make keys required)
    out_mac_vertex = SimpleMacVertex(app_vertex=out_app_vertex)
    mac_graph.add_vertex(out_mac_vertex)

    mac_vertex = SimpleMacVertex(app_vertex=app_vertex)
    mac_graph.add_vertex(mac_vertex)

    return app_graph, mac_graph, n_keys_map
def create_graphs1(with_fixed):
    app_graph = ApplicationGraph("Test")
    # An output vertex to aim things at (to make keys required)
    out_app_vertex = SimpleAppVertex()
    app_graph.add_vertex(out_app_vertex)
    # Create 5 application vertices (3 bits)
    app_vertices = list()
    for app_index in range(5):
        app_vertices.append(SimpleAppVertex())
    app_graph.add_vertices(app_vertices)

    mac_graph = MachineGraph("Test", app_graph)
    n_keys_map = DictBasedMachinePartitionNKeysMap()

    # An output vertex to aim things at (to make keys required)
    out_mac_vertex = SimpleMacVertex(app_vertex=out_app_vertex)
    mac_graph.add_vertex(out_mac_vertex)

    # Create 5 application vertices (3 bits)
    for app_index, app_vertex in enumerate(app_vertices):

        # For each, create up to (5 x 4) + 1 = 21 machine vertices (5 bits)
        for mac_index in range((app_index * 4) + 1):
            mac_vertex = SimpleMacVertex(app_vertex=app_vertex)
            mac_graph.add_vertex(mac_vertex)

            # For each machine vertex create up to
            # (20 x 2) + 1 = 81(!) partitions (6 bits)
            for mac_edge_index in range((mac_index * 2) + 1):
                mac_edge = MachineEdge(mac_vertex, out_mac_vertex)
                part_name = "Part{}".format(mac_edge_index)
                mac_graph.add_edge(mac_edge, part_name)

                # Give the partition up to (40 x 4) + 1 = 161 keys (8 bits)
                p = mac_graph.get_outgoing_edge_partition_starting_at_vertex(
                    mac_vertex, part_name)
                if with_fixed:
                    if (app_index == 2 and mac_index == 4 and
                            part_name == "Part7"):
                        p.add_constraint(FixedKeyAndMaskConstraint(
                            [BaseKeyAndMask(0xFE00000, 0xFFFFFFC0)]))
                    if (app_index == 2 and mac_index == 0 and
                            part_name == "Part1"):
                        p.add_constraint(FixedKeyAndMaskConstraint(
                            [BaseKeyAndMask(0x4c00000, 0xFFFFFFFE)]))
                    if (app_index == 2 and mac_index == 0 and
                            part_name == "Part1"):
                        p.add_constraint(FixedKeyAndMaskConstraint(
                            [BaseKeyAndMask(0x4c00000, 0xFFFFFFFF)]))
                    if (app_index == 3 and mac_index == 0 and
                            part_name == "Part1"):
                        p.add_constraint(FixedKeyAndMaskConstraint(
                            [BaseKeyAndMask(0x3300000, 0xFFFFFFFF)]))
                    if (app_index == 3 and mac_index == 0 and
                            part_name == "Part1"):
                        p.add_constraint(FixedKeyAndMaskConstraint(
                            [BaseKeyAndMask(0x3300001, 0)]))
                n_keys_map.set_n_keys_for_partition(
                    p, (mac_edge_index * 4) + 1)

    return app_graph, mac_graph, n_keys_map