def test_call(self):
        """ Test calling the binary gatherer normally
        """

        vertex_1 = _TestVertexWithBinary("test.aplx", ExecutableType.RUNNING)
        vertex_2 = _TestVertexWithBinary("test2.aplx", ExecutableType.RUNNING)
        vertex_3 = _TestVertexWithBinary("test2.aplx", ExecutableType.RUNNING)
        vertex_4 = _TestVertexWithoutBinary()

        graph = MachineGraph("Test")
        graph.add_vertices([vertex_1, vertex_2, vertex_3])

        placements = Placements(placements=[
            Placement(vertex_1, 0, 0, 0),
            Placement(vertex_2, 0, 0, 1),
            Placement(vertex_3, 0, 0, 2),
            Placement(vertex_4, 0, 0, 3)
        ])

        gatherer = GraphBinaryGatherer()
        targets = gatherer.__call__(placements, graph, _TestExecutableFinder())
        gatherer = LocateExecutableStartType()
        start_type = gatherer.__call__(graph, placements)
        self.assertEqual(next(iter(start_type)), ExecutableType.RUNNING)
        self.assertEqual(targets.total_processors, 3)

        test_cores = targets.get_cores_for_binary("test.aplx")
        test_2_cores = targets.get_cores_for_binary("test2.aplx")
        self.assertEqual(len(test_cores), 1)
        self.assertEqual(len(test_2_cores), 2)
        self.assertIn((0, 0, 0), test_cores)
        self.assertIn((0, 0, 1), test_2_cores)
        self.assertIn((0, 0, 2), test_2_cores)
Ejemplo n.º 2
0
 def test_new_graph(self):
     """
     tests that after building a machine graph, all partitined vertices
     and partitioned edges are in existence
     """
     vertices = list()
     edges = list()
     for i in range(10):
         vertices.append(
             SimpleMachineVertex(ResourceContainer(), "V{}".format(i)))
     with self.assertRaises(NotImplementedError):
         vertices[1].add_constraint(SameAtomsAsVertexConstraint(
             vertices[4]))
         vertices[4].add_constraint(SameAtomsAsVertexConstraint(
             vertices[1]))
     for i in range(5):
         edges.append(MachineEdge(vertices[0], vertices[(i + 1)]))
     for i in range(5, 10):
         edges.append(MachineEdge(vertices[5], vertices[(i + 1) % 10]))
     graph = MachineGraph("foo")
     graph.add_vertices(vertices)
     graph.add_outgoing_edge_partition(
         MulticastEdgePartition(identifier="bar", pre_vertex=vertices[0]))
     graph.add_outgoing_edge_partition(
         MulticastEdgePartition(identifier="bar", pre_vertex=vertices[5]))
     graph.add_edges(edges, "bar")
     self.graph_there_and_back(graph)
Ejemplo n.º 3
0
 def test_none_have_app_vertex(self):
     app_graph = ApplicationGraph("Test")
     graph = MachineGraph("foo", app_graph)
     app1 = SimpleTestVertex(12, "app1")
     mach1 = SimpleMachineVertex("mach1", app_vertex=None)
     mach2 = SimpleMachineVertex("mach2", app_vertex=None)
     mach3 = SimpleMachineVertex("mach3", app_vertex=app1)
     graph.add_vertices([mach1, mach2])
     with self.assertRaises(PacmanInvalidParameterException):
         graph.add_vertex(mach3)
Ejemplo n.º 4
0
 def test_add_duplicate_edge(self):
     """
     test that adding the same machine edge will cause an error
     """
     vertices = list()
     edges = list()
     vertices.append(SimpleMachineVertex(None, ""))
     vertices.append(SimpleMachineVertex(None, ""))
     edge = MachineEdge(vertices[0], vertices[1])
     edges.append(edge)
     edges.append(edge)
     graph = MachineGraph("foo")
     graph.add_vertices(vertices)
     graph.add_edges(edges, "bar")
 def test_add_duplicate_edge(self):
     """
     test that adding the same machine edge will cause an error
     """
     vertices = list()
     edges = list()
     vertices.append(SimpleMachineVertex(None, ""))
     vertices.append(SimpleMachineVertex(None, ""))
     edge = MachineEdge(vertices[0], vertices[1])
     edges.append(edge)
     edges.append(edge)
     graph = MachineGraph("foo")
     graph.add_vertices(vertices)
     graph.add_edges(edges, "bar")
Ejemplo n.º 6
0
 def test_add_edge_with_no_existing_pre_vertex_in_graph(self):
     """
     test that adding a edge where the pre vertex has not been added
     to the machine graph causes an error
     """
     vertices = list()
     edges = list()
     vertices.append(SimpleMachineVertex(None, ""))
     vertices.append(SimpleMachineVertex(None, ""))
     edges.append(MachineEdge(vertices[0], vertices[1]))
     edges.append(MachineEdge(SimpleMachineVertex(None, ""), vertices[0]))
     with self.assertRaises(PacmanInvalidParameterException):
         graph = MachineGraph("foo")
         graph.add_vertices(vertices)
         graph.add_edges(edges, "bar")
Ejemplo n.º 7
0
    def test_mixed_binaries(self):
        """ Test calling the binary gatherer with mixed executable types
        """

        vertex_1 = _TestVertexWithBinary("test.aplx",
                                         ExecutableStartType.RUNNING)
        vertex_2 = _TestVertexWithBinary("test2.aplx",
                                         ExecutableStartType.SYNC)

        graph = MachineGraph("Test")
        graph.add_vertices([vertex_1, vertex_2])

        gatherer = LocateExecutableStartType()
        with self.assertRaises(ConfigurationException):
            gatherer.__call__(graph)
Ejemplo n.º 8
0
 def test_add_duplicate_vertex(self):
     """
     testing that adding the same machine vertex twice will cause an
     error
     """
     vertices = list()
     edges = list()
     subv = SimpleMachineVertex(None, "")
     vertices.append(subv)
     vertices.append(SimpleMachineVertex(None, ""))
     vertices.append(subv)
     edges.append(MachineEdge(vertices[0], vertices[1]))
     edges.append(MachineEdge(vertices[1], vertices[0]))
     graph = MachineGraph("foo")
     graph.add_vertices(vertices)
     graph.add_edges(edges, "bar")
 def test_add_duplicate_vertex(self):
     """
     testing that adding the same machine vertex twice will cause an
     error
     """
     vertices = list()
     edges = list()
     subv = SimpleMachineVertex(None, "")
     vertices.append(subv)
     vertices.append(SimpleMachineVertex(None, ""))
     vertices.append(subv)
     edges.append(MachineEdge(vertices[0], vertices[1]))
     edges.append(MachineEdge(vertices[1], vertices[0]))
     graph = MachineGraph("foo")
     graph.add_vertices(vertices)
     graph.add_edges(edges, "bar")
 def test_add_edge_with_no_existing_pre_vertex_in_graph(self):
     """
     test that adding a edge where the pre vertex has not been added
     to the machine graph causes an error
     """
     vertices = list()
     edges = list()
     vertices.append(SimpleMachineVertex(None, ""))
     vertices.append(SimpleMachineVertex(None, ""))
     edges.append(MachineEdge(vertices[0], vertices[1]))
     edges.append(MachineEdge(
         SimpleMachineVertex(None, ""), vertices[0]))
     with self.assertRaises(PacmanInvalidParameterException):
         graph = MachineGraph("foo")
         graph.add_vertices(vertices)
         graph.add_edges(edges, "bar")
Ejemplo n.º 11
0
 def test_add_duplicate_edge(self):
     """
     test that adding the same machine edge will cause an error
     """
     vertices = list()
     edges = list()
     vertices.append(SimpleMachineVertex(None, ""))
     vertices.append(SimpleMachineVertex(None, ""))
     edge = MachineEdge(vertices[0], vertices[1])
     edges.append(edge)
     edges.append(edge)
     graph = MachineGraph("foo")
     graph.add_vertices(vertices)
     graph.add_outgoing_edge_partition(
         MulticastEdgePartition(vertices[0], "bar"))
     with self.assertRaises(PacmanAlreadyExistsException):
         graph.add_edges(edges, "bar")
Ejemplo n.º 12
0
 def test_remember_machine_vertex(self):
     app_graph = ApplicationGraph("Test")
     graph = MachineGraph("foo", app_graph)
     app1 = SimpleTestVertex(12, "app1")
     app2 = SimpleTestVertex(12, "app2")
     mach1 = SimpleMachineVertex("mach1", app_vertex=app1)
     mach2 = SimpleMachineVertex("mach2", app_vertex=app1)
     mach3 = SimpleMachineVertex("mach3", app_vertex=app1)
     mach4 = SimpleMachineVertex("mach4", app_vertex=app2)
     self.assertEquals(0, len(app1.machine_vertices))
     self.assertEquals(0, len(app2.machine_vertices))
     graph.add_vertices([mach1, mach2])
     graph.add_vertex(mach3)
     graph.add_vertex(mach4)
     self.assertEquals(3, len(app1.machine_vertices))
     self.assertEquals(1, len(app2.machine_vertices))
     self.assertIn(mach1, app1.machine_vertices)
     self.assertIn(mach2, app1.machine_vertices)
     self.assertIn(mach3, app1.machine_vertices)
     self.assertIn(mach4, app2.machine_vertices)
    def test_mixed_binaries(self):
        """ Test calling the binary gatherer with mixed executable types
        """

        vertex_1 = _TestVertexWithBinary("test.aplx", ExecutableType.RUNNING)
        vertex_2 = _TestVertexWithBinary("test2.aplx", ExecutableType.SYNC)

        placements = Placements(placements=[
            Placement(vertex_1, 0, 0, 0),
            Placement(vertex_2, 0, 0, 1)
        ])

        graph = MachineGraph("Test")
        graph.add_vertices([vertex_1, vertex_2])

        gatherer = LocateExecutableStartType()
        results = gatherer.__call__(graph, placements=placements)
        self.assertIn(ExecutableType.RUNNING, results)
        self.assertIn(ExecutableType.SYNC, results)
        self.assertNotIn(ExecutableType.USES_SIMULATION_INTERFACE, results)
        self.assertNotIn(ExecutableType.NO_APPLICATION, results)
    def test_mixed_binaries(self):
        """ Test calling the binary gatherer with mixed executable types
        """

        vertex_1 = _TestVertexWithBinary(
            "test.aplx", ExecutableType.RUNNING)
        vertex_2 = _TestVertexWithBinary(
            "test2.aplx", ExecutableType.SYNC)

        placements = Placements(placements=[
            Placement(vertex_1, 0, 0, 0),
            Placement(vertex_2, 0, 0, 1)])

        graph = MachineGraph("Test")
        graph.add_vertices([vertex_1, vertex_2])

        gatherer = LocateExecutableStartType()
        results = gatherer.__call__(graph, placements=placements)
        self.assertIn(ExecutableType.RUNNING, results)
        self.assertIn(ExecutableType.SYNC, results)
        self.assertNotIn(ExecutableType.USES_SIMULATION_INTERFACE, results)
        self.assertNotIn(ExecutableType.NO_APPLICATION, results)
    def test_new_graph(self):
        """
        tests that after building a machine graph, all partitined vertices
        and partitioned edges are in existence
        """
        vertices = list()
        edges = list()
        for i in range(10):
            vertices.append(SimpleMachineVertex(None, ""))
        for i in range(5):
            edges.append(MachineEdge(vertices[0], vertices[(i + 1)]))
        for i in range(5, 10):
            edges.append(MachineEdge(
                vertices[5], vertices[(i + 1) % 10]))
        graph = MachineGraph("foo")
        graph.add_vertices(vertices)
        graph.add_edges(edges, "bar")
        outgoing = set(graph.get_edges_starting_at_vertex(vertices[0]))
        for i in range(5):
            assert edges[i] in outgoing, \
                "edges[" + str(i) + "] is not in outgoing and should be"
        for i in range(5, 10):
            assert edges[i] not in outgoing, \
                "edges[" + str(i) + "] is in outgoing and shouldn't be"

        incoming = set(graph.get_edges_ending_at_vertex(vertices[0]))

        assert edges[9] in incoming, \
            "edges[9] is not in incoming and should be"
        for i in range(9):
            assert edges[i] not in incoming, \
                "edges[" + str(i) + "] is in incoming and shouldn't be"

        vertices_from_graph = list(graph.vertices)
        for vert in vertices_from_graph:
            self.assertIn(vert, vertices)
        edges_from_graph = list(graph.edges)
        for edge in edges_from_graph:
            self.assertIn(edge, edges)
Ejemplo n.º 16
0
    def test_new_graph(self):
        """
        tests that after building a machine graph, all partitined vertices
        and partitioned edges are in existence
        """
        vertices = list()
        edges = list()
        for i in range(10):
            vertices.append(SimpleMachineVertex(None, ""))
        for i in range(5):
            edges.append(MachineEdge(vertices[0], vertices[(i + 1)]))
        for i in range(5, 10):
            edges.append(MachineEdge(vertices[5], vertices[(i + 1) % 10]))
        graph = MachineGraph("foo")
        graph.add_vertices(vertices)
        graph.add_edges(edges, "bar")
        outgoing = set(graph.get_edges_starting_at_vertex(vertices[0]))
        for i in range(5):
            assert edges[i] in outgoing, \
                "edges[" + str(i) + "] is not in outgoing and should be"
        for i in range(5, 10):
            assert edges[i] not in outgoing, \
                "edges[" + str(i) + "] is in outgoing and shouldn't be"

        incoming = set(graph.get_edges_ending_at_vertex(vertices[0]))

        assert edges[9] in incoming, \
            "edges[9] is not in incoming and should be"
        for i in range(9):
            assert edges[i] not in incoming, \
                "edges[" + str(i) + "] is in incoming and shouldn't be"

        vertices_from_graph = list(graph.vertices)
        for vert in vertices_from_graph:
            self.assertIn(vert, vertices)
        edges_from_graph = list(graph.edges)
        for edge in edges_from_graph:
            self.assertIn(edge, edges)
    def test_call(self):
        """ Test calling the binary gatherer normally
        """

        vertex_1 = _TestVertexWithBinary(
            "test.aplx", ExecutableType.RUNNING)
        vertex_2 = _TestVertexWithBinary(
            "test2.aplx", ExecutableType.RUNNING)
        vertex_3 = _TestVertexWithBinary(
            "test2.aplx", ExecutableType.RUNNING)
        vertex_4 = _TestVertexWithoutBinary()

        graph = MachineGraph("Test")
        graph.add_vertices([vertex_1, vertex_2, vertex_3])

        placements = Placements(placements=[
            Placement(vertex_1, 0, 0, 0),
            Placement(vertex_2, 0, 0, 1),
            Placement(vertex_3, 0, 0, 2),
            Placement(vertex_4, 0, 0, 3)])

        gatherer = GraphBinaryGatherer()
        targets = gatherer.__call__(
            placements, graph, _TestExecutableFinder())
        gatherer = LocateExecutableStartType()
        start_type = gatherer.__call__(graph, placements)
        self.assertEqual(next(iter(start_type)), ExecutableType.RUNNING)
        self.assertEqual(targets.total_processors, 3)

        test_cores = targets.get_cores_for_binary("test.aplx")
        test_2_cores = targets.get_cores_for_binary("test2.aplx")
        self.assertEqual(len(test_cores), 1)
        self.assertEqual(len(test_2_cores), 2)
        self.assertIn((0, 0, 0), test_cores)
        self.assertIn((0, 0, 1), test_2_cores)
        self.assertIn((0, 0, 2), test_2_cores)
Ejemplo n.º 18
0
    def check_new_graph(self, app_graph, app_vertex):
        """
        tests that after building a machine graph, all partitined vertices
        and partitioned edges are in existence
        """
        vertices = list()
        edges = list()
        for i in range(10):
            vertices.append(
                SimpleMachineVertex(None, "", app_vertex=app_vertex))
        for i in range(5):
            edges.append(MachineEdge(vertices[0], vertices[(i + 1)]))
        for i in range(5, 10):
            edges.append(MachineEdge(vertices[5], vertices[(i + 1) % 10]))
        graph = MachineGraph("foo", application_graph=app_graph)
        graph.add_vertices(vertices)
        graph.add_outgoing_edge_partition(
            MulticastEdgePartition(vertices[0], "bar"))
        graph.add_outgoing_edge_partition(
            MulticastEdgePartition(vertices[5], "bar"))
        graph.add_edges(edges, "bar")
        outgoing = set(graph.get_edges_starting_at_vertex(vertices[0]))
        for i in range(5):
            assert edges[i] in outgoing, \
                "edges[" + str(i) + "] is not in outgoing and should be"
        for i in range(5, 10):
            assert edges[i] not in outgoing, \
                "edges[" + str(i) + "] is in outgoing and shouldn't be"

        incoming = set(graph.get_edges_ending_at_vertex(vertices[0]))

        assert edges[9] in incoming, \
            "edges[9] is not in incoming and should be"
        for i in range(9):
            assert edges[i] not in incoming, \
                "edges[" + str(i) + "] is in incoming and shouldn't be"

        vertices_from_graph = list(graph.vertices)
        for vert in vertices_from_graph:
            self.assertIn(vert, vertices)
        for vert in vertices:
            self.assertEqual(vert, graph.vertex_by_label(vert.label))
        edges_from_graph = list(graph.edges)
        for edge in edges_from_graph:
            self.assertIn(edge, edges)

        if app_graph:
            with self.assertRaises(PacmanInvalidParameterException):
                graph.clone()
        else:
            second = graph.clone()
            self.assertEqual(graph.n_vertices, second.n_vertices)
            vertices_from_graph = list(second.vertices)
            for vert in vertices_from_graph:
                self.assertIn(vert, vertices)
            for vert in vertices:
                self.assertEqual(vert, graph.vertex_by_label(vert.label))
            self.assertEqual(graph.n_outgoing_edge_partitions,
                             second.n_outgoing_edge_partitions)
            edges_from_graph = list(second.edges)
            for edge in edges_from_graph:
                self.assertIn(edge, edges)
            self.assertEqual(len(edges_from_graph), len(edges))

        third = MachineGraphView(graph)
        self.assertEqual(graph.n_vertices, third.n_vertices)
        vertices_from_graph = list(third.vertices)
        for vert in vertices_from_graph:
            self.assertIn(vert, vertices)
        for vert in vertices:
            self.assertEqual(vert, graph.vertex_by_label(vert.label))
        self.assertEqual(graph.n_outgoing_edge_partitions,
                         third.n_outgoing_edge_partitions)
        edges_from_graph = list(third.edges)
        for edge in edges_from_graph:
            self.assertIn(edge, edges)
        self.assertEqual(len(edges_from_graph), len(edges))
        with self.assertRaises(PacmanConfigurationException):
            third.add_edge("mock", "mock")
        with self.assertRaises(PacmanConfigurationException):
            third.add_vertex("mock")
        with self.assertRaises(PacmanConfigurationException):
            third.add_outgoing_edge_partition("mock")
Ejemplo n.º 19
0
    def test_at_vertex_methods(self):
        graph = MachineGraph("foo")
        mach1 = MockMachineVertex("mach1", sdram_requirement=0)
        mach2 = MockMachineVertex("mach2", sdram_requirement=0)
        mach3 = MockMachineVertex("mach3", sdram_requirement=0)
        mach4 = SimpleMachineVertex("mach4")
        graph.add_vertices([mach1, mach2, mach3, mach4])

        # Add partition then edge
        part_m_1 = MulticastEdgePartition(mach1, "spikes")
        graph.add_outgoing_edge_partition(part_m_1)
        edge_m_11 = MachineEdge(mach1,
                                mach2,
                                traffic_type=EdgeTrafficType.MULTICAST)
        graph.add_edge(edge_m_11, "spikes")
        # check clear error it you add the edge again
        with self.assertRaises(PacmanAlreadyExistsException):
            graph.add_edge(edge_m_11, "spikes")
        self.assertIn(edge_m_11, part_m_1.edges)
        edge_m_12 = MachineEdge(mach1,
                                mach3,
                                traffic_type=EdgeTrafficType.MULTICAST)
        graph.add_edge(edge_m_12, "spikes")
        edge_m_21 = MachineEdge(mach3,
                                mach4,
                                traffic_type=EdgeTrafficType.MULTICAST)
        graph.add_edge(edge_m_21, "spikes")
        part_m_2 = graph.get_outgoing_partition_for_edge(edge_m_21)

        edge_f_1 = MachineEdge(mach1,
                               mach3,
                               traffic_type=EdgeTrafficType.FIXED_ROUTE)
        graph.add_edge(edge_f_1, "Control")
        part_f = graph.get_outgoing_partition_for_edge(edge_f_1)

        part_s_1 = ConstantSDRAMMachinePartition("ram", mach1, "ram1")
        graph.add_outgoing_edge_partition(part_s_1)
        edge_s_11 = SDRAMMachineEdge(mach1, mach2, "s1")
        graph.add_edge(edge_s_11, "ram")
        edge_s_12 = SDRAMMachineEdge(mach1, mach3, "s2")
        graph.add_edge(edge_s_12, "ram")

        starting_at_mach1 = list(
            graph.get_outgoing_edge_partitions_starting_at_vertex(mach1))
        self.assertIn(part_m_1, starting_at_mach1)
        self.assertIn(part_f, starting_at_mach1)
        self.assertIn(part_s_1, starting_at_mach1)
        self.assertEqual(3, len(starting_at_mach1))

        starting_at_mach3 = list(
            graph.get_outgoing_edge_partitions_starting_at_vertex(mach3))
        self.assertIn(part_m_2, starting_at_mach3)
        self.assertEqual(1, len(starting_at_mach3))

        starting_at_mach4 = list(
            graph.get_outgoing_edge_partitions_starting_at_vertex(mach4))
        self.assertEqual(0, len(starting_at_mach4))

        ending_at_mach2 = list(
            graph.get_edge_partitions_ending_at_vertex(mach2))
        self.assertIn(part_m_1, ending_at_mach2)
        self.assertIn(part_s_1, ending_at_mach2)
        self.assertEqual(2, len(ending_at_mach2))

        ending_at_mach3 = list(
            graph.get_edge_partitions_ending_at_vertex(mach3))
        self.assertIn(part_m_1, ending_at_mach3)
        self.assertIn(part_f, ending_at_mach3)
        self.assertIn(part_s_1, ending_at_mach3)
        self.assertEqual(3, len(ending_at_mach3))

        ending_at_mach1 = list(
            graph.get_edge_partitions_ending_at_vertex(mach1))
        self.assertEqual(0, len(ending_at_mach1))