Ejemplo n.º 1
0
    def test_scheduling_num_pairs_iterate(self):
        scheduler = WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA)

        # Compare high and low num pairs (non atomic)
        requests = [
            SchedulerRequest(timeout_cycle=None,
                             sched_cycle=None,
                             num_pairs=6,
                             create_id=0),
            SchedulerRequest(timeout_cycle=None,
                             sched_cycle=None,
                             num_pairs=3,
                             create_id=1)
        ]
        for qid, req in enumerate(requests):
            scheduler._add_to_queue(req, qid)

        sim_run(1000)

        scheduler.inc_cycle()

        for create_id in ([0, 1] * 3 + [0] * 3):
            aid, request = scheduler.select_queue()
            self.assertEqual(request.create_id, create_id)
            scheduler._post_process_success(aid)

        aid, request = scheduler.select_queue()
        self.assertIs(aid, None)
Ejemplo n.º 2
0
    def test_scheduling_atomic(self):
        scheduler = WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA)
        scheduler.mhp_cycle_period = 1
        scheduler.mhp_full_cycle = 3 * scheduler.mhp_cycle_period

        # Compare create and keep and measure direclty
        requests = [
            SchedulerRequest(timeout_cycle=None,
                             sched_cycle=None,
                             num_pairs=5,
                             create_id=0),
            SchedulerRequest(timeout_cycle=None,
                             sched_cycle=None,
                             num_pairs=3,
                             atomic=True,
                             create_id=1)
        ]
        for qid, req in enumerate(requests):
            scheduler._add_to_queue(req, qid)

        sim_run(1000)

        scheduler.inc_cycle()

        for create_id in [0, 0, 0, 1, 1, 1, 0, 0]:
            aid, request = scheduler.select_queue()
            self.assertEqual(request.create_id, create_id)
            scheduler._post_process_success(aid)

        aid, request = scheduler.select_queue()
        self.assertIs(aid, None)
Ejemplo n.º 3
0
    def test_scheduling_fidelity(self):
        scheduler = WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA)

        # Compare high and low min_fidelity
        requests = [
            SchedulerRequest(timeout_cycle=None,
                             sched_cycle=None,
                             min_fidelity=0.8,
                             create_id=0),
            SchedulerRequest(timeout_cycle=None,
                             sched_cycle=None,
                             min_fidelity=0.6,
                             create_id=1)
        ]
        for qid, req in enumerate(requests):
            scheduler._add_to_queue(req, qid)

        sim_run(1000)

        scheduler.inc_cycle()

        for create_id in [1, 0]:
            aid, request = scheduler.select_queue()
            self.assertEqual(request.create_id, create_id)
            scheduler._post_process_success(aid)

        aid, request = scheduler.select_queue()
        self.assertIs(aid, None)
Ejemplo n.º 4
0
    def test_multiple_queues(self):
        sim_reset()
        alice = QuantumNode("alice", nodeID=0)
        bob = QuantumNode("bob", nodeID=1)
        conn = ClassicalFibreConnection(alice, bob, length=.0001)
        aliceDQ = EGPDistributedQueue(alice,
                                      conn,
                                      accept_all=True,
                                      numQueues=2)
        bobDQ = EGPDistributedQueue(bob, conn, accept_all=True, numQueues=2)

        nodes = [
            (alice, [aliceDQ]),
            (bob, [bobDQ]),
        ]
        conns = [(conn, "dqp_conn", [aliceDQ, bobDQ])]

        network = EasyNetwork(name="DistQueueNetwork",
                              nodes=nodes,
                              connections=conns)
        network.start()
        alice_requests = [SchedulerRequest(), SchedulerRequest()]
        bob_requests = [SchedulerRequest(), SchedulerRequest()]
        aliceDQ.add(alice_requests[0], qid=0)
        aliceDQ.add(alice_requests[1], qid=1)
        bobDQ.add(bob_requests[0], qid=0)
        bobDQ.add(bob_requests[1], qid=1)
        sim_run(10)
        self.assertEqual(len(aliceDQ.queueList[0].queue), 2)
        self.assertEqual(len(aliceDQ.queueList[1].queue), 2)
        self.assertEqual(len(bobDQ.queueList[0].queue), 2)
        self.assertEqual(len(bobDQ.queueList[1].queue), 2)
Ejemplo n.º 5
0
    def test_scheduling_weights_same_req(self):
        weights = [0, 15, 5]
        scheduler = WFQRequestScheduler(self.distQueueA,
                                        self.qmmA,
                                        self.feuA,
                                        weights=weights)
        scheduler.mhp_cycle_period = 1
        scheduler.mhp_full_cycle = 3 * scheduler.mhp_cycle_period

        # Compare create and keep and measure direclty
        scheduler._add_to_queue(
            SchedulerRequest(timeout_cycle=None, sched_cycle=None,
                             create_id=2), 2)
        scheduler.inc_cycle()
        scheduler._add_to_queue(
            SchedulerRequest(timeout_cycle=None, sched_cycle=None,
                             create_id=1), 1)
        scheduler.inc_cycle()
        scheduler._add_to_queue(
            SchedulerRequest(timeout_cycle=None, sched_cycle=None,
                             create_id=0), 0)

        sim_run(1000)

        scheduler.inc_cycle()

        for create_id in [0, 1, 2]:
            aid, request = scheduler.select_queue()
            self.assertEqual(request.create_id, create_id)
            scheduler._post_process_success(aid)

        aid, request = scheduler.select_queue()
        self.assertIs(aid, None)
Ejemplo n.º 6
0
    def test_slave_add_while_waiting(self):
        sim_reset()
        node = QuantumNode("TestNode 1", 1)
        node2 = QuantumNode("TestNode 2", 2)
        conn = ClassicalFibreConnection(node, node2, length=25)

        dq = DistributedQueue(node,
                              conn,
                              numQueues=3,
                              throw_local_queue_events=True)
        dq2 = DistributedQueue(node2,
                               conn,
                               numQueues=3,
                               throw_local_queue_events=True)
        dq.connect_to_peer_protocol(dq2, conn)

        nodes = [
            (node, [dq]),
            (node2, [dq2]),
        ]
        conns = [(conn, "dq_conn", [dq, dq2])]

        network = EasyNetwork(name="DistQueueNetwork",
                              nodes=nodes,
                              connections=conns)
        network.start()

        # Add one request for both master and slave
        create_id = 0
        request = SchedulerRequest(0, 0, 0, 0, create_id, 0, 0, True, False,
                                   False, True)
        dq.add(request=request, qid=0)
        create_id = 1
        request = SchedulerRequest(0, 0, 0, 0, create_id, 0, 0, True, False,
                                   False, True)
        dq2.add(request=request, qid=0)

        # Wait for slaves add to arrive but not the ack
        run_time = dq.comm_delay * (3 / 4)
        sim_run(run_time)

        # Add request from master
        create_id = 2
        request = SchedulerRequest(0, 0, 0, 0, create_id, 0, 0, True, False,
                                   False, True)
        dq.add(request=request, qid=0)

        # Make sure things are added
        run_time = dq.comm_delay * 4
        sim_run(run_time)

        self.ready_items(dq.queueList[0])
        self.ready_items(dq2.queueList[0])
        self.check_local_queues(dq.queueList[0], dq2.queueList[0])
Ejemplo n.º 7
0
    def test_scheduling_weights_diff_req(self):
        scheduler = WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA)

        # First we will find the estimated times for constructing a high and low fidelity pair
        high_fid = self.feuA.achievable_fidelities[-1][1]
        low_fid = self.feuA.achievable_fidelities[-2][1]
        cycles_high = scheduler._estimate_nr_of_cycles_per_pair(
            SchedulerRequest(min_fidelity=high_fid))
        cycles_low = scheduler._estimate_nr_of_cycles_per_pair(
            SchedulerRequest(min_fidelity=low_fid))

        # Weights such that high fid should be scheduled earlier than low fid
        weight_fraction = cycles_high / cycles_low
        weight_fraction_below = weight_fraction * 9 / 10
        weight_fraction_above = weight_fraction * 11 / 10

        # Construct scheduler with the computed weights
        weights = [weight_fraction_below, 1, weight_fraction_above]
        scheduler = WFQRequestScheduler(self.distQueueA,
                                        self.qmmA,
                                        self.feuA,
                                        weights=weights)

        # Compare different weights, diff requests
        scheduler._add_to_queue(
            SchedulerRequest(timeout_cycle=None,
                             sched_cycle=None,
                             min_fidelity=high_fid,
                             create_id=0), 0)
        scheduler._add_to_queue(
            SchedulerRequest(timeout_cycle=None,
                             sched_cycle=None,
                             min_fidelity=low_fid,
                             create_id=1), 1)
        scheduler._add_to_queue(
            SchedulerRequest(timeout_cycle=None,
                             sched_cycle=None,
                             min_fidelity=high_fid,
                             create_id=2), 2)

        sim_run(1000)

        scheduler.inc_cycle()

        for create_id in [2, 1, 0]:
            aid, request = scheduler.select_queue()
            self.assertEqual(request.create_id, create_id)
            scheduler._post_process_success(aid)

        aid, request = scheduler.select_queue()
        self.assertIs(aid, None)
Ejemplo n.º 8
0
    def test_set_virtual_finish_num_pairs(self):
        scheduler = WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA)

        # Compare high and low num pairs (non atomic)
        requests = [
            SchedulerRequest(num_pairs=2),
            SchedulerRequest(num_pairs=10)
        ]
        wfq_requests = []
        for qid, req in enumerate(requests):
            wfq_requests.append(scheduler.set_virtual_finish(req, qid))
        self.assertEqual(wfq_requests[0].init_virtual_finish,
                         wfq_requests[1].init_virtual_finish)
        self.assertEqual(wfq_requests[0].est_cycles_per_pair,
                         wfq_requests[1].est_cycles_per_pair)
Ejemplo n.º 9
0
    def test_set_virtual_finish_fidelity(self):
        scheduler = WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA)

        # Compare high and low min_fidelity
        requests = [
            SchedulerRequest(min_fidelity=0.8),
            SchedulerRequest(min_fidelity=0.6)
        ]
        wfq_requests = []
        for qid, req in enumerate(requests):
            wfq_requests.append(scheduler.set_virtual_finish(req, qid))
        self.assertGreater(wfq_requests[0].init_virtual_finish,
                           wfq_requests[1].init_virtual_finish)
        self.assertGreater(wfq_requests[0].est_cycles_per_pair,
                           wfq_requests[1].est_cycles_per_pair)
Ejemplo n.º 10
0
    def test_set_virtual_finish_same_queue_same_req(self):
        scheduler = WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA)

        # Same req to same queue
        requests = [SchedulerRequest(), SchedulerRequest()]
        wfq_requests = []
        for req in requests:
            wfq_requests.append(scheduler.set_virtual_finish(req, 0))
        self.assertLess(wfq_requests[0].init_virtual_finish,
                        wfq_requests[1].init_virtual_finish)
        self.assertEqual(wfq_requests[0].est_cycles_per_pair,
                         wfq_requests[1].est_cycles_per_pair)
        self.assertEqual(
            wfq_requests[0].init_virtual_finish +
            wfq_requests[0].est_cycles_per_pair,
            wfq_requests[1].init_virtual_finish)
Ejemplo n.º 11
0
    def test_faulty_queue_ID(self):
        def add_callback(result):
            self.assertEqual(result[0], aliceDQ.DQ_REJECT)
            callback_called[0] = True

        sim_reset()

        callback_called = [False]

        alice = QuantumNode("alice", nodeID=0)
        bob = QuantumNode("bob", nodeID=1)
        conn = ClassicalFibreConnection(alice, bob, length=.0001)
        aliceDQ = EGPDistributedQueue(alice,
                                      conn,
                                      accept_all=True,
                                      numQueues=1)
        bobDQ = EGPDistributedQueue(bob, conn, accept_all=True, numQueues=1)
        aliceDQ.add_callback = add_callback

        nodes = [
            (alice, [aliceDQ]),
            (bob, [bobDQ]),
        ]
        conns = [(conn, "dqp_conn", [aliceDQ, bobDQ])]

        network = EasyNetwork(name="DistQueueNetwork",
                              nodes=nodes,
                              connections=conns)
        network.start()
        request = SchedulerRequest()
        aliceDQ.add(request, qid=1)
        sim_run(10)
        self.assertTrue(callback_called[0])
Ejemplo n.º 12
0
    def test_set_virtual_finish_measure_directly(self):
        scheduler = WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA)
        scheduler.mhp_cycle_period = 1
        scheduler.mhp_full_cycle = 3 * scheduler.mhp_cycle_period

        # Compare create and keep and measure direclty
        requests = [
            SchedulerRequest(),
            SchedulerRequest(measure_directly=True)
        ]
        wfq_requests = []
        for qid, req in enumerate(requests):
            wfq_requests.append(scheduler.set_virtual_finish(req, qid))
        self.assertGreater(wfq_requests[0].init_virtual_finish,
                           wfq_requests[1].init_virtual_finish)
        self.assertGreater(wfq_requests[0].est_cycles_per_pair,
                           wfq_requests[1].est_cycles_per_pair)
Ejemplo n.º 13
0
    def test_update_mhp_cycle_number(self):
        def callback_alice(queue_item):
            callback_called[0] = True

        def callback_bob(queue_item):
            callback_called[1] = True

        sim_reset()
        callback_called = [False, False]
        alice = QuantumNode("alice", nodeID=0)
        bob = QuantumNode("bob", nodeID=1)
        conn = ClassicalFibreConnection(alice, bob, length=.0001)
        aliceDQ = EGPDistributedQueue(alice,
                                      conn,
                                      timeout_callback=callback_alice,
                                      accept_all=True)
        bobDQ = EGPDistributedQueue(bob,
                                    conn,
                                    timeout_callback=callback_bob,
                                    accept_all=True)

        nodes = [
            (alice, [aliceDQ]),
            (bob, [bobDQ]),
        ]
        conns = [(conn, "dqp_conn", [aliceDQ, bobDQ])]

        network = EasyNetwork(name="DistQueueNetwork",
                              nodes=nodes,
                              connections=conns)
        network.start()
        request = SchedulerRequest(sched_cycle=1, timeout_cycle=2)
        aliceDQ.add(request, 0)
        sim_run(10)
        queue_item_alice = aliceDQ.local_peek(0)
        queue_item_bob = bobDQ.local_peek(0)
        self.assertFalse(queue_item_alice.ready)

        aliceDQ.update_mhp_cycle_number(1, 10)
        self.assertTrue(queue_item_alice.ready)
        self.assertFalse(queue_item_bob.ready)
        self.assertFalse(callback_called[0])
        self.assertFalse(callback_called[1])

        aliceDQ.update_mhp_cycle_number(2, 10)
        self.assertTrue(callback_called[0])
        self.assertFalse(callback_called[1])

        bobDQ.update_mhp_cycle_number(1, 10)
        self.assertTrue(queue_item_bob.ready)
        self.assertFalse(callback_called[1])

        bobDQ.update_mhp_cycle_number(2, 10)
        self.assertTrue(queue_item_bob.ready)
        self.assertTrue(callback_called[1])
Ejemplo n.º 14
0
    def test_set_virtual_finish_atomic(self):
        scheduler = WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA)
        scheduler.mhp_cycle_period = 1
        scheduler.mhp_full_cycle = 3 * scheduler.mhp_cycle_period

        # Compare compare non-atomic and atomic
        requests = [
            SchedulerRequest(num_pairs=3),
            SchedulerRequest(num_pairs=3, atomic=3)
        ]
        wfq_requests = []
        for qid, req in enumerate(requests):
            wfq_requests.append(scheduler.set_virtual_finish(req, qid))
        self.assertLess(wfq_requests[0].init_virtual_finish,
                        wfq_requests[1].init_virtual_finish)
        self.assertEqual(wfq_requests[0].est_cycles_per_pair,
                         wfq_requests[1].est_cycles_per_pair)
        self.assertAlmostEqual(
            wfq_requests[1].init_virtual_finish -
            wfq_requests[0].init_virtual_finish,
            2 * wfq_requests[0].est_cycles_per_pair)
Ejemplo n.º 15
0
    def test_set_virtual_finish_weights_same_req(self):
        weights = [0, 15, 5]
        scheduler = WFQRequestScheduler(self.distQueueA,
                                        self.qmmA,
                                        self.feuA,
                                        weights=weights)

        # Compare different weights, same requests
        requests = [SchedulerRequest(), SchedulerRequest(), SchedulerRequest()]
        wfq_requests = []
        for qid, req in enumerate(requests):
            wfq_requests.append(scheduler.set_virtual_finish(req, qid))
        self.assertIs(wfq_requests[0].init_virtual_finish, None)
        self.assertLess(wfq_requests[1].init_virtual_finish,
                        wfq_requests[2].init_virtual_finish)
        self.assertEqual(wfq_requests[1].est_cycles_per_pair,
                         wfq_requests[2].est_cycles_per_pair)
        inv_weight_diff = (weights[1] + weights[2]) * (1 / weights[2] -
                                                       1 / weights[1])
        self.assertAlmostEqual(
            wfq_requests[2].init_virtual_finish -
            wfq_requests[1].init_virtual_finish,
            inv_weight_diff * wfq_requests[1].est_cycles_per_pair)
Ejemplo n.º 16
0
    def test_set_virtual_finish_weights_diff_req(self):
        scheduler = WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA)

        # First we will find the estimated times for constructing a high and low fidelity pair
        high_fid = self.feuA.achievable_fidelities[-1][1]
        low_fid = self.feuA.achievable_fidelities[-2][1]
        cycles_high = scheduler._estimate_nr_of_cycles_per_pair(
            SchedulerRequest(min_fidelity=high_fid))
        cycles_low = scheduler._estimate_nr_of_cycles_per_pair(
            SchedulerRequest(min_fidelity=low_fid))

        # Weights such that high fid should be scheduled earlier than low fid
        weight_fraction = cycles_high / cycles_low
        weight_fraction_below = weight_fraction * 9 / 10
        weight_fraction_above = weight_fraction * 11 / 10

        # Construct scheduler with the computed weights
        weights = [weight_fraction_above, weight_fraction_below, 1]
        scheduler = WFQRequestScheduler(self.distQueueA,
                                        self.qmmA,
                                        self.feuA,
                                        weights=weights)

        # Compare different weights, diff requests
        requests = [
            SchedulerRequest(min_fidelity=high_fid),
            SchedulerRequest(min_fidelity=high_fid),
            SchedulerRequest(min_fidelity=low_fid)
        ]
        wfq_requests = []
        for qid, req in enumerate(requests):
            wfq_requests.append(scheduler.set_virtual_finish(req, qid))
        self.assertLess(wfq_requests[0].init_virtual_finish,
                        wfq_requests[2].init_virtual_finish)
        self.assertGreater(wfq_requests[1].init_virtual_finish,
                           wfq_requests[2].init_virtual_finish)
Ejemplo n.º 17
0
    def test_scheduling_same_queue_same_req(self):
        scheduler = WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA)

        # Same req to same queue
        num_req = 3
        requests = [
            SchedulerRequest(timeout_cycle=None, sched_cycle=None, create_id=i)
            for i in range(num_req)
        ]
        for req in requests:
            scheduler._add_to_queue(req, 0)

        sim_run(1000)

        scheduler.inc_cycle()

        for i in range(3):
            aid, request = scheduler.select_queue()
            self.assertEqual(request.create_id, i)
            scheduler._post_process_success(aid)

        aid, request = scheduler.select_queue()
        self.assertIs(aid, None)
Ejemplo n.º 18
0
    def test_resend_acks(self):
        sim_reset()
        node = QuantumNode("TestNode 1", 1)
        node2 = QuantumNode("TestNode 2", 2)
        conn = ClassicalFibreConnection(node, node2, length=25)

        dq = DistributedQueue(node,
                              conn,
                              numQueues=3,
                              throw_local_queue_events=True)
        dq2 = DistributedQueue(node2,
                               conn,
                               numQueues=3,
                               throw_local_queue_events=True)
        dq.connect_to_peer_protocol(dq2, conn)

        storage1 = []
        storage2 = []

        def callback1(result):
            storage1.append(result)

        def callback2(result):
            storage2.append(result)

        nodes = [
            (node, [dq]),
            (node2, [dq2]),
        ]
        conns = [(conn, "dq_conn", [dq, dq2])]

        network = EasyNetwork(name="DistQueueNetwork",
                              nodes=nodes,
                              connections=conns)
        network.start()
        dq.add_callback = callback1
        dq2.add_callback = callback2

        # Add one request
        create_id = 0
        request = SchedulerRequest(0, 0, 0, 0, create_id, 0, 0, True, False,
                                   False, True)
        dq2.add(request=request, qid=0)
        run_time = dq.comm_delay * dq.timeout_factor
        sim_run(run_time)

        # Set way to short timeout (to force resend)
        dq2.timeout_factor = 1 / 2

        # Add one request (slave)
        create_id = 1
        request = SchedulerRequest(0, 0, 0, 0, create_id, 0, 0, True, False,
                                   False, True)
        dq2.add(request=request, qid=0)
        run_time += (dq.comm_delay + 1) * 4
        sim_run(run_time)

        # Set to correct factor again
        dq2.timeout_factor = 2

        create_id = 2
        request = SchedulerRequest(0, 0, 0, 0, create_id, 0, 0, True, False,
                                   False, True)
        dq.add(request=request, qid=0)
        dq2.add(request=request, qid=0)
        run_time += dq.comm_delay * dq.timeout_factor
        sim_run(run_time)

        self.assertEqual(len(storage1), 4)
        self.assertEqual(len(storage2), 4)

        q_seqs1 = [res[2] for res in storage1]
        q_seqs2 = [res[2] for res in storage2]

        for qseq in range(4):
            for q_seqs in [q_seqs1, q_seqs2]:
                # TODO do we care about the ordering?
                self.assertIn(qseq, q_seqs)
Ejemplo n.º 19
0
    def test_unordered_subsequent_acks(self):
        sim_reset()
        node = QuantumNode("TestNode 1", 1)
        node2 = QuantumNode("TestNode 2", 2)
        conn = ClassicalFibreConnection(node, node2, length=25)

        dq = DistributedQueue(node,
                              conn,
                              numQueues=3,
                              throw_local_queue_events=True)
        dq2 = DistributedQueue(node2,
                               conn,
                               numQueues=3,
                               throw_local_queue_events=True)
        dq.connect_to_peer_protocol(dq2, conn)

        storage1 = []
        storage2 = []

        def callback1(result):
            storage1.append(result)

        def callback2(result):
            storage2.append(result)

        nodes = [
            (node, [dq]),
            (node2, [dq2]),
        ]
        conns = [(conn, "dq_conn", [dq, dq2])]

        network = EasyNetwork(name="DistQueueNetwork",
                              nodes=nodes,
                              connections=conns)
        network.start()

        # Add three requests (master)
        dq.add_callback = callback1
        dq2.add_callback = callback2
        for create_id in range(3):
            request = SchedulerRequest(0, 0, 0, 0, create_id, 0, 0, True,
                                       False, False, True)
            dq.add(request=request, qid=0)
        run_time = dq.comm_delay * dq.timeout_factor
        sim_run(run_time)
        self.assertEqual(len(storage1), 3)
        self.assertEqual(len(storage2), 3)
        q_seqs1 = [res[2] for res in storage1]
        q_seqs2 = [res[2] for res in storage2]
        self.assertEqual(q_seqs1, [0, 1, 2])
        self.assertEqual(q_seqs2, [0, 1, 2])

        # Remove one request (such that next queue seq will be 0 again)
        dq.remove_item(0, 1)
        dq2.remove_item(0, 1)
        storage1 = []
        storage2 = []

        # Add requests from master and slave
        create_id = 3
        request = SchedulerRequest(0, 0, 0, 0, create_id, 0, 0, True, False,
                                   False, True)
        dq.add(request=request, qid=0)
        request = SchedulerRequest(0, 0, 0, 0, create_id, 0, 0, True, False,
                                   False, True)
        dq2.add(request=request, qid=0)

        run_time += dq.comm_delay * dq.timeout_factor
        sim_run(run_time)

        self.assertEqual(len(storage1), 2)
        self.assertEqual(len(storage2), 2)
        q_seqs1 = [res[2] for res in storage1]
        q_seqs2 = [res[2] for res in storage2]
        self.assertIn(1, q_seqs1)
        self.assertIn(3, q_seqs1)
        self.assertIn(1, q_seqs2)
        self.assertIn(3, q_seqs2)
Ejemplo n.º 20
0
    def test_lossy_comms_wraparound(self):
        sim_reset()
        node = QuantumNode("TestNode 1", 1)
        node2 = QuantumNode("TestNode 2", 2)
        conn = ClassicalFibreConnection(node, node2, length=0.1)
        dq = DistributedQueue(node,
                              conn,
                              numQueues=3,
                              throw_local_queue_events=True)
        dq2 = DistributedQueue(node2,
                               conn,
                               numQueues=3,
                               throw_local_queue_events=True)
        dq.connect_to_peer_protocol(dq2, conn)

        self.lost_messages = 0
        self.lost_seq = dq.myWsize + 1

        def faulty_send_msg(cmd, data, clock):
            if self.lost_messages == 0 and clock[0] == self.lost_seq:
                self.lost_messages += 1
            else:
                dq.conn.put_from(dq.myID, (cmd, data, clock))

        dq.send_msg = faulty_send_msg

        nodes = [
            (node, [dq]),
            (node2, [dq2]),
        ]
        conns = [(conn, "dq_conn", [dq, dq2])]

        network = EasyNetwork(name="DistQueueNetwork",
                              nodes=nodes,
                              connections=conns)
        network.start()

        num_adds = 0
        r = 1
        curr_time = 0
        import pdb
        while num_adds < 2 * dq.maxCommsSeq:
            add_delay = 2
            for i in range(dq.myWsize):
                request = SchedulerRequest(0, 0, 0, 0, i, 0, 0, True, False,
                                           False, True)
                dq.add(request)
                sim_run(curr_time + (i + 1) * add_delay)
                curr_time += add_delay

            for j in range(dq2.myWsize):
                request = SchedulerRequest(0, 0, 0, 0, j, 0, 0, True, False,
                                           False, True)
                dq2.add(request)
                sim_run(curr_time + (j + 1) * add_delay)
                curr_time += add_delay

            num_adds += dq.myWsize
            num_adds += dq2.myWsize
            run_time = r * dq.comm_delay * 4
            sim_run(curr_time + run_time)
            curr_time += run_time
            r += 1
            self.ready_items(dq.queueList[0])
            self.ready_items(dq2.queueList[0])
            self.check_local_queues(dq.queueList[0], dq2.queueList[0])

            for i in range(dq.myWsize + dq2.myWsize):
                dq.local_pop()
                dq2.local_pop()
Ejemplo n.º 21
0
    def test_rules(self):
        sim_reset()
        alice = QuantumNode("Alice", 1)
        bob = QuantumNode("Bob", 2)

        self.result = None

        def add_callback(result):
            self.result = result

        conn = ClassicalFibreConnection(alice, bob, length=.0001)
        aliceDQ = FilteredDistributedQueue(alice, conn)
        aliceDQ.add_callback = add_callback
        bobDQ = FilteredDistributedQueue(bob, conn)
        bobDQ.add_callback = add_callback

        nodes = [
            (alice, [aliceDQ]),
            (bob, [bobDQ]),
        ]
        conns = [(conn, "dqp_conn", [aliceDQ, bobDQ])]

        network = EasyNetwork(name="DistQueueNetwork",
                              nodes=nodes,
                              connections=conns)
        network.start()

        # Test that we cannot add a request
        request = SchedulerRequest(num_pairs=1,
                                   min_fidelity=0.5,
                                   timeout_cycle=10,
                                   purpose_id=0,
                                   priority=10)

        # Test that no rule results in rejection of request
        aliceDQ.add(request)
        expected_qid = 0
        expected_qseq = 0
        sim_run(2)
        self.assertIsNotNone(self.result)
        reported_request = self.result[-1]
        self.assertEqual(reported_request, request)
        self.assertEqual(self.result[:3],
                         (aliceDQ.DQ_REJECT, expected_qid, expected_qseq))

        # Reset result
        self.result = None

        # Test that we can now add a request with the rule in place
        bobDQ.add_accept_rule(nodeID=alice.nodeID, purpose_id=0)
        aliceDQ.add(request)
        expected_qseq = 0
        sim_run(4)
        self.assertIsNotNone(self.result)
        reported_request = self.result[-1]
        self.assertEqual(reported_request, request)
        self.assertEqual(self.result[:3],
                         (aliceDQ.DQ_OK, expected_qid, expected_qseq))

        # Reset result
        self.result = None

        # Test that we can remove the acception rule and request will get rejected
        bobDQ.remove_accept_rule(nodeID=alice.nodeID, purpose_id=0)
        aliceDQ.add(request)
        expected_qseq += 1
        sim_run(6)
        self.assertIsNotNone(self.result)
        reported_request = self.result[-1]
        self.assertEqual(reported_request, request)
        self.assertEqual(self.result[:3],
                         (aliceDQ.DQ_REJECT, expected_qid, expected_qseq))
Ejemplo n.º 22
0
    def test_random_add_remove(self):
        sim_reset()
        node = QuantumNode("TestNode 1", 1)
        node2 = QuantumNode("TestNode 2", 2)
        conn = ClassicalFibreConnection(node, node2, length=25)

        dq = DistributedQueue(node,
                              conn,
                              numQueues=3,
                              throw_local_queue_events=True)
        dq2 = DistributedQueue(node2,
                               conn,
                               numQueues=3,
                               throw_local_queue_events=True)
        dq.connect_to_peer_protocol(dq2, conn)

        nodes = [
            (node, [dq]),
            (node2, [dq2]),
        ]
        conns = [(conn, "dq_conn", [dq, dq2])]

        network = EasyNetwork(name="DistQueueNetwork",
                              nodes=nodes,
                              connections=conns)
        network.start()

        create_id = 0
        for _ in range(20):
            # Add random requests to master
            num_reqs_master = randint(0, 3)
            for _ in range(num_reqs_master):
                request = SchedulerRequest(0, 0, 0, 0, create_id, 0, 0, True,
                                           False, False, True)
                try:
                    dq.add(request=request, qid=0)
                except LinkLayerException:
                    # Full queue
                    pass
                create_id += 1

            # Add random requests to slave
            num_reqs_slave = randint(0, 3)
            for _ in range(num_reqs_slave):
                request = SchedulerRequest(0, 0, 0, 0, create_id, 0, 0, True,
                                           False, False, True)
                try:
                    dq2.add(request=request, qid=0)
                except LinkLayerException:
                    # Full queue
                    pass
                create_id += 1

            # Randomly remove things for both
            num_pop = randint(0, 6)
            for _ in range(num_pop):
                dq.local_pop(qid=0)

            # Run for random fraction of timeout
            r = randint(1, 20)
            run_time = dq.comm_delay * dq.timeout_factor * (r / 10)
            sim_run(run_time)

        # Make sure things are not in flight
        sim_run()

        self.ready_items(dq.queueList[0])
        self.ready_items(dq2.queueList[0])
        self.check_local_queues(dq.queueList[0], dq2.queueList[0])

        # Add one request for both master and slave
        create_id = 0
        request = SchedulerRequest(0, 0, 0, 0, create_id, 0, 0, True, False,
                                   False, True)
        dq.add(request=request, qid=0)
        create_id = 1
        request = SchedulerRequest(0, 0, 0, 0, create_id, 0, 0, True, False,
                                   False, True)
        dq2.add(request=request, qid=0)