def test_routing_info(self):
        # mock to avoid having to create a graph for this test
        graph_code = 123
        pre_vertex = SimpleMachineVertex(resources=ResourceContainer())
        partition = MulticastEdgePartition(pre_vertex, "Test")
        partition.register_graph_code(graph_code)  # This is a hack
        post_vertex = SimpleMachineVertex(resources=ResourceContainer())
        edge = MachineEdge(pre_vertex, post_vertex)
        key = 12345
        partition_info = PartitionRoutingInfo([BaseKeyAndMask(key, FULL_MASK)],
                                              partition)
        partition.add_edge(edge, graph_code)
        routing_info = RoutingInfo([partition_info])

        with self.assertRaises(PacmanAlreadyExistsException):
            routing_info.add_partition_info(partition_info)

        assert routing_info.get_first_key_from_partition(partition) == key
        assert routing_info.get_first_key_from_partition(None) is None

        assert routing_info.get_routing_info_from_partition(partition) == \
            partition_info
        assert routing_info.get_routing_info_from_partition(None) is None

        assert routing_info.get_routing_info_from_pre_vertex(
            pre_vertex, "Test") == partition_info
        assert routing_info.get_routing_info_from_pre_vertex(
            post_vertex, "Test") is None
        assert routing_info.get_routing_info_from_pre_vertex(
            pre_vertex, "None") is None

        assert routing_info.get_first_key_from_pre_vertex(pre_vertex,
                                                          "Test") == key
        assert routing_info.get_first_key_from_pre_vertex(post_vertex,
                                                          "Test") is None
        assert routing_info.get_first_key_from_pre_vertex(pre_vertex,
                                                          "None") is None

        assert routing_info.get_routing_info_for_edge(edge) == partition_info
        assert routing_info.get_routing_info_for_edge(None) is None

        assert routing_info.get_first_key_for_edge(edge) == key
        assert routing_info.get_first_key_for_edge(None) is None

        assert next(iter(routing_info)) == partition_info

        partition2 = MulticastEdgePartition(pre_vertex, "Test")
        partition2.register_graph_code(graph_code)  # This is a hack
        partition2.add_edge(MachineEdge(pre_vertex, post_vertex), graph_code)

        with self.assertRaises(PacmanAlreadyExistsException):
            routing_info.add_partition_info(
                PartitionRoutingInfo([BaseKeyAndMask(key, FULL_MASK)],
                                     partition2))
        assert partition != partition2

        partition3 = MulticastEdgePartition(pre_vertex, "Test2")
        partition3.register_graph_code(graph_code)  # This is a hack
        partition3.add_edge(MachineEdge(pre_vertex, post_vertex), graph_code)
        routing_info.add_partition_info(
            PartitionRoutingInfo([BaseKeyAndMask(key, FULL_MASK)], partition3))

        assert routing_info.get_routing_info_from_partition(partition) != \
            routing_info.get_routing_info_from_partition(partition3)
        assert partition != partition3
        assert routing_info.get_routing_info_from_partition(
            partition3).get_keys().tolist() == [key]

        partition4 = MulticastEdgePartition(pre_vertex, "Test4")
        partition4.register_graph_code(graph_code)  # This is a hack
        partition4.add_edge(MachineEdge(pre_vertex, post_vertex), graph_code)
        routing_info.add_partition_info(
            PartitionRoutingInfo([
                BaseKeyAndMask(key, FULL_MASK),
                BaseKeyAndMask(key * 2, FULL_MASK)
            ], partition4))

        assert routing_info.get_routing_info_from_partition(
            partition4).get_keys().tolist() == [key, key * 2]
    def test_routing_info(self):
        partition = MachineOutgoingEdgePartition("Test")
        pre_vertex = SimpleMachineVertex(resources=ResourceContainer())
        post_vertex = SimpleMachineVertex(resources=ResourceContainer())
        edge = MachineEdge(pre_vertex, post_vertex)
        key = 12345
        partition_info = PartitionRoutingInfo(
            [BaseKeyAndMask(key, _32_BITS)], partition)
        partition.add_edge(edge)
        routing_info = RoutingInfo([partition_info])

        with self.assertRaises(PacmanAlreadyExistsException):
            routing_info.add_partition_info(partition_info)

        assert routing_info.get_first_key_from_partition(partition) == key
        assert routing_info.get_first_key_from_partition(None) is None

        assert routing_info.get_routing_info_from_partition(partition) == \
            partition_info
        assert routing_info.get_routing_info_from_partition(None) is None

        assert routing_info.get_routing_info_from_pre_vertex(
            pre_vertex, "Test") == partition_info
        assert routing_info.get_routing_info_from_pre_vertex(
            post_vertex, "Test") is None
        assert routing_info.get_routing_info_from_pre_vertex(
            pre_vertex, "None") is None

        assert routing_info.get_first_key_from_pre_vertex(
            pre_vertex, "Test") == key
        assert routing_info.get_first_key_from_pre_vertex(
            post_vertex, "Test") is None
        assert routing_info.get_first_key_from_pre_vertex(
            pre_vertex, "None") is None

        assert routing_info.get_routing_info_for_edge(edge) == partition_info
        assert routing_info.get_routing_info_for_edge(None) is None

        assert routing_info.get_first_key_for_edge(edge) == key
        assert routing_info.get_first_key_for_edge(None) is None

        assert next(iter(routing_info)) == partition_info

        partition2 = MachineOutgoingEdgePartition("Test")
        partition2.add_edge(MachineEdge(pre_vertex, post_vertex))

        with self.assertRaises(PacmanAlreadyExistsException):
            routing_info.add_partition_info(PartitionRoutingInfo(
                [BaseKeyAndMask(key, _32_BITS)], partition2))
        assert partition != partition2

        partition3 = MachineOutgoingEdgePartition("Test2")
        partition3.add_edge(MachineEdge(pre_vertex, post_vertex))
        routing_info.add_partition_info(PartitionRoutingInfo(
            [BaseKeyAndMask(key, _32_BITS)], partition3))

        assert routing_info.get_routing_info_from_partition(partition) != \
            routing_info.get_routing_info_from_partition(partition3)
        assert partition != partition3
        assert routing_info.get_routing_info_from_partition(
            partition3).get_keys().tolist() == [key]

        partition3 = MachineOutgoingEdgePartition("Test3")
        partition3.add_edge(MachineEdge(pre_vertex, post_vertex))
        routing_info.add_partition_info(PartitionRoutingInfo(
            [BaseKeyAndMask(key, _32_BITS),
             BaseKeyAndMask(key*2, _32_BITS)], partition3))

        assert routing_info.get_routing_info_from_partition(
            partition3).get_keys().tolist() == [key, key*2]
예제 #3
0
    def test_routing_info(self):
        partition = MachineOutgoingEdgePartition("Test")
        pre_vertex = SimpleMachineVertex(resources=ResourceContainer())
        post_vertex = SimpleMachineVertex(resources=ResourceContainer())
        edge = MachineEdge(pre_vertex, post_vertex)
        key = 12345
        partition_info = PartitionRoutingInfo([BaseKeyAndMask(key, _32_BITS)],
                                              partition)
        partition.add_edge(edge)
        routing_info = RoutingInfo([partition_info])

        with self.assertRaises(PacmanAlreadyExistsException):
            routing_info.add_partition_info(partition_info)

        assert routing_info.get_first_key_from_partition(partition) == key
        assert routing_info.get_first_key_from_partition(None) is None

        assert routing_info.get_routing_info_from_partition(partition) == \
            partition_info
        assert routing_info.get_routing_info_from_partition(None) is None

        assert routing_info.get_routing_info_from_pre_vertex(
            pre_vertex, "Test") == partition_info
        assert routing_info.get_routing_info_from_pre_vertex(
            post_vertex, "Test") is None
        assert routing_info.get_routing_info_from_pre_vertex(
            pre_vertex, "None") is None

        assert routing_info.get_first_key_from_pre_vertex(pre_vertex,
                                                          "Test") == key
        assert routing_info.get_first_key_from_pre_vertex(post_vertex,
                                                          "Test") is None
        assert routing_info.get_first_key_from_pre_vertex(pre_vertex,
                                                          "None") is None

        assert routing_info.get_routing_info_for_edge(edge) == partition_info
        assert routing_info.get_routing_info_for_edge(None) is None

        assert routing_info.get_first_key_for_edge(edge) == key
        assert routing_info.get_first_key_for_edge(None) is None

        assert next(iter(routing_info)) == partition_info

        partition2 = MachineOutgoingEdgePartition("Test")
        partition2.add_edge(MachineEdge(pre_vertex, post_vertex))

        with self.assertRaises(PacmanAlreadyExistsException):
            routing_info.add_partition_info(
                PartitionRoutingInfo([BaseKeyAndMask(key, _32_BITS)],
                                     partition2))
        assert partition != partition2

        partition3 = MachineOutgoingEdgePartition("Test2")
        partition3.add_edge(MachineEdge(pre_vertex, post_vertex))
        routing_info.add_partition_info(
            PartitionRoutingInfo([BaseKeyAndMask(key, _32_BITS)], partition3))

        assert routing_info.get_routing_info_from_partition(partition) != \
            routing_info.get_routing_info_from_partition(partition3)
        assert partition != partition3
        assert routing_info.get_routing_info_from_partition(
            partition3).get_keys().tolist() == [key]

        partition3 = MachineOutgoingEdgePartition("Test3")
        partition3.add_edge(MachineEdge(pre_vertex, post_vertex))
        routing_info.add_partition_info(
            PartitionRoutingInfo([
                BaseKeyAndMask(key, _32_BITS),
                BaseKeyAndMask(key * 2, _32_BITS)
            ], partition3))

        assert routing_info.get_routing_info_from_partition(
            partition3).get_keys().tolist() == [key, key * 2]