Пример #1
0
def test_create_constraints_to_file(tmpdir):
    # Construct the sample machine and graph
    machine = VirtualMachine(version=3, with_wrap_arounds=None)
    # TODO: define some extra monitor cores (how?)
    graph = MachineGraph("foo")
    tag1 = IPtagResource("1.2.3.4", 5, False, tag="footag")
    tag2 = ReverseIPtagResource(tag="bartag")
    v0 = SimpleMachineVertex(ResourceContainer(iptags=[tag1],
                                               reverse_iptags=[tag2]),
                             constraints=[ChipAndCoreConstraint(1, 1, 3)])
    graph.add_vertex(v0)
    v0_id = ident(v0)
    v1 = MachineSpiNNakerLinkVertex(2,
                                    constraints=[ChipAndCoreConstraint(1, 1)])
    v1.set_virtual_chip_coordinates(0, 2)
    graph.add_vertex(v1)
    v1_id = ident(v1)

    algo = CreateConstraintsToFile()
    fn = tmpdir.join("foo.json")
    filename, mapping = algo(graph, machine, str(fn))
    assert filename == str(fn)
    for vid in mapping:
        assert vid in [v0_id, v1_id]
        assert vid == ident(mapping[vid])
    obj = json.loads(fn.read())
    baseline = [{
        "type": "reserve_resource",
        "location": None,
        "reservation": [0, 1],
        "resource": "cores"
    }, {
        "type": "location",
        "location": [1, 1],
        "vertex": v0_id
    }, {
        "type": "resource",
        "resource": "cores",
        "range": [3, 4],
        "vertex": v0_id
    }, {
        "type": "resource",
        "resource": "iptag",
        "range": [0, 1],
        "vertex": v0_id
    }, {
        "type": "resource",
        "resource": "reverse_iptag",
        "range": [0, 1],
        "vertex": v0_id
    }, {
        "type": "route_endpoint",
        "direction": "south",
        "vertex": v1_id
    }, {
        "type": "location",
        "location": [1, 0],
        "vertex": v1_id
    }]
    assert obj == baseline
 def create_machine_vertex(
         self, vertex_slice, resources_required, label=None,
         constraints=None):
     machine_vertex = MachineSpiNNakerLinkVertex(
         self._spinnaker_link_id, self._board_address, label, constraints,
         self, vertex_slice)
     machine_vertex.set_virtual_chip_coordinates(
         self._virtual_chip_x, self._virtual_chip_y)
     if resources_required:
         assert (resources_required == machine_vertex.resources_required)
     return machine_vertex
def test_create_constraints_to_file(tmpdir):
    # Construct the sample machine and graph
    machine = VirtualMachine(version=3, with_wrap_arounds=None)
    # TODO: define some extra monitor cores (how?)
    graph = MachineGraph("foo")
    tag1 = IPtagResource("1.2.3.4", 5, False, tag="footag")
    tag2 = ReverseIPtagResource(tag="bartag")
    v0 = SimpleMachineVertex(ResourceContainer(
        iptags=[tag1], reverse_iptags=[tag2]), constraints=[
        ChipAndCoreConstraint(1, 1, 3)])
    graph.add_vertex(v0)
    v0_id = ident(v0)
    v1 = MachineSpiNNakerLinkVertex(0)
    v1.set_virtual_chip_coordinates(0, 2)
    graph.add_vertex(v1)
    v1_id = ident(v1)

    machine = MallocBasedChipIdAllocator()(machine, graph)
    algo = CreateConstraintsToFile()
    fn = tmpdir.join("foo.json")
    filename, mapping = algo(graph, machine, str(fn))
    assert filename == str(fn)
    for vid in mapping:
        assert vid in [v0_id, v1_id]
        assert vid == ident(mapping[vid])
    obj = json.loads(fn.read())
    baseline = [
        {
            "type": "reserve_resource",
            "location": None, "reservation": [0, 1], "resource": "cores"},
        {
            "type": "location",
            "location": [1, 1], "vertex": v0_id},
        {
            "type": "resource",
            "resource": "cores", "range": [3, 4], "vertex": v0_id},
        {
            "type": "resource",
            "resource": "iptag", "range": [0, 1], "vertex": v0_id},
        {
            "type": "resource",
            "resource": "reverse_iptag", "range": [0, 1], "vertex": v0_id},
        {
            "type": "route_endpoint",
            "direction": "west", "vertex": v1_id},
        {
            "type": "location",
            "location": [0, 0], "vertex": v1_id}]
    assert obj == baseline