コード例 #1
0
def test_BBPSSW_success_rate():
    tl = Timeline()
    a1 = FakeNode("a1", tl)
    a2 = FakeNode("a2", tl)
    cc0 = ClassicalChannel("cc0", tl, 0, 1e5)
    cc1 = ClassicalChannel("cc1", tl, 0, 1e5)
    cc0.delay = ONE_MILLISECOND
    cc1.delay = ONE_MILLISECOND
    cc0.set_ends(a1, a2)
    cc1.set_ends(a2, a1)

    tl.init()
    counter1 = counter2 = 0
    fidelity = 0.8

    for i in range(1000):
        kept_memo1 = Memory("a1.kept", tl, fidelity=fidelity, frequency=0, efficiency=1, coherence_time=1,
                            wavelength=HALF_MICRON)
        kept_memo2 = Memory("a2.kept", tl, fidelity, 0, 1, 1, HALF_MICRON)
        meas_memo1 = Memory("a1.meas", tl, fidelity, 0, 1, 1, HALF_MICRON)
        meas_memo2 = Memory("a2.meas", tl, fidelity, 0, 1, 1, HALF_MICRON)

        kept_memo1.entangled_memory["node_id"] = "a2"
        kept_memo1.entangled_memory["memo_id"] = "a2.kept"
        kept_memo1.fidelity = fidelity
        kept_memo2.entangled_memory["node_id"] = "a1"
        kept_memo2.entangled_memory["memo_id"] = "a1.kept"
        kept_memo2.fidelity = fidelity
        meas_memo1.entangled_memory["node_id"] = "a2"
        meas_memo1.entangled_memory["memo_id"] = "a2.meas"
        meas_memo1.fidelity = fidelity
        meas_memo2.entangled_memory["node_id"] = "a1"
        meas_memo2.entangled_memory["memo_id"] = "a1.meas"
        meas_memo2.fidelity = fidelity

        pair1 = np.random.choice(range(4), 1,
                                 p=[fidelity, (1 - fidelity) / 3, (1 - fidelity) / 3, (1 - fidelity) / 3])
        pair2 = np.random.choice(range(4), 1,
                                 p=[fidelity, (1 - fidelity) / 3, (1 - fidelity) / 3, (1 - fidelity) / 3])
        tl.quantum_manager.set([kept_memo1.qstate_key, kept_memo2.qstate_key], BELL_STATES[pair1[0]])
        tl.quantum_manager.set([meas_memo1.qstate_key, meas_memo2.qstate_key], BELL_STATES[pair2[0]])

        ep1 = BBPSSW(a1, "a1.ep1.%d" % i, kept_memo1, meas_memo1)
        ep2 = BBPSSW(a2, "a2.ep2.%d" % i, kept_memo2, meas_memo2)
        a1.protocols.append(ep1)
        a2.protocols.append(ep2)
        ep1.set_others(ep2)
        ep2.set_others(ep1)

        ep1.start()
        ep2.start()

        if ep1.meas_res == ep2.meas_res:
            counter1 += 1
        else:
            counter2 += 1

        tl.run()

    assert abs(counter1 / (counter1 + counter2) - BBPSSW.success_probability(fidelity)) < 0.1
コード例 #2
0
def test_BBPSSW2():
    tl = Timeline()
    a1 = FakeNode("a1", tl)
    a2 = FakeNode("a2", tl)
    cc = ClassicalChannel("cc", tl, 0, 1e5)
    cc.delay = 1e9
    cc.set_ends(a1, a2)

    tl.init()
    counter1 = counter2 = 0
    fidelity = 0.8

    for i in range(1000):
        kept_memo1 = Memory("a1.kept",
                            tl,
                            fidelity=fidelity,
                            frequency=0,
                            efficiency=1,
                            coherence_time=1,
                            wavelength=500)
        kept_memo2 = Memory("a2.kept", tl, fidelity, 0, 1, 1, 500)
        meas_memo1 = Memory("a1.meas", tl, fidelity, 0, 1, 1, 500)
        meas_memo2 = Memory("a2.meas", tl, fidelity, 0, 1, 1, 500)

        kept_memo1.entangled_memory["node_id"] = "a2"
        kept_memo1.entangled_memory["memo_id"] = "a2.kept"
        kept_memo1.fidelity = fidelity
        kept_memo2.entangled_memory["node_id"] = "a1"
        kept_memo2.entangled_memory["memo_id"] = "a1.kept"
        kept_memo2.fidelity = fidelity
        meas_memo1.entangled_memory["node_id"] = "a2"
        meas_memo1.entangled_memory["memo_id"] = "a2.meas"
        meas_memo1.fidelity = fidelity
        meas_memo2.entangled_memory["node_id"] = "a1"
        meas_memo2.entangled_memory["memo_id"] = "a1.meas"
        meas_memo2.fidelity = fidelity

        ep1 = BBPSSW(a1, "a1.ep1.%d" % i, kept_memo1, meas_memo1)
        ep2 = BBPSSW(a2, "a2.ep2.%d" % i, kept_memo2, meas_memo2)
        a1.protocols.append(ep1)
        a2.protocols.append(ep2)
        ep1.set_others(ep2)
        ep2.set_others(ep1)

        ep1.start()
        ep2.start()

        assert ep1.is_success == ep2.is_success
        if ep1.is_success:
            counter1 += 1
        else:
            counter2 += 1

        tl.run()

    assert abs(counter1 / (counter1 + counter2) -
               BBPSSW.success_probability(fidelity)) < 0.1
コード例 #3
0
def test_BBPSSW1():
    tl = Timeline()
    a1 = FakeNode("a1", tl)
    a2 = FakeNode("a2", tl)
    cc = ClassicalChannel("cc", tl, 0, 1e5)
    cc.delay = 1e9
    cc.set_ends(a1, a2)

    tl.init()
    for i in range(1000):
        fidelity = numpy.random.uniform(0.5, 1)
        kept_memo1 = Memory("a1.kept",
                            tl,
                            fidelity=fidelity,
                            frequency=0,
                            efficiency=1,
                            coherence_time=1,
                            wavelength=500)
        kept_memo2 = Memory("a2.kept", tl, fidelity, 0, 1, 1, 500)
        meas_memo1 = Memory("a1.meas", tl, fidelity, 0, 1, 1, 500)
        meas_memo2 = Memory("a2.meas", tl, fidelity, 0, 1, 1, 500)

        kept_memo1.entangled_memory["node_id"] = "a2"
        kept_memo1.entangled_memory["memo_id"] = "a2.kept"
        kept_memo1.fidelity = fidelity
        kept_memo2.entangled_memory["node_id"] = "a1"
        kept_memo2.entangled_memory["memo_id"] = "a1.kept"
        kept_memo2.fidelity = fidelity
        meas_memo1.entangled_memory["node_id"] = "a2"
        meas_memo1.entangled_memory["memo_id"] = "a2.meas"
        meas_memo1.fidelity = fidelity
        meas_memo2.entangled_memory["node_id"] = "a1"
        meas_memo2.entangled_memory["memo_id"] = "a1.meas"
        meas_memo2.fidelity = fidelity

        ep1 = BBPSSW(a1, "a1.ep1.%d" % i, kept_memo1, meas_memo1)
        ep2 = BBPSSW(a2, "a2.ep2.%d" % i, kept_memo2, meas_memo2)
        a1.protocols.append(ep1)
        a2.protocols.append(ep2)
        ep1.set_others(ep2)
        ep2.set_others(ep1)

        ep1.start()
        ep2.start()

        assert ep1.is_success == ep2.is_success

        tl.run()

        assert a1.resource_manager.log[-2] == (meas_memo1, "RAW")
        assert a2.resource_manager.log[-2] == (meas_memo2, "RAW")
        assert meas_memo1.fidelity == meas_memo2.fidelity == 0

        if ep1.is_success:
            assert kept_memo1.fidelity == kept_memo2.fidelity == BBPSSW.improved_fidelity(
                fidelity)
            assert kept_memo1.entangled_memory[
                "node_id"] == "a2" and kept_memo2.entangled_memory[
                    "node_id"] == "a1"
            assert a1.resource_manager.log[-1] == (kept_memo1, "ENTANGLED")
            assert a2.resource_manager.log[-1] == (kept_memo2, "ENTANGLED")
        else:
            assert kept_memo1.fidelity == kept_memo2.fidelity == 0
            assert kept_memo1.entangled_memory[
                "node_id"] == kept_memo2.entangled_memory["node_id"] == None
            assert a1.resource_manager.log[-1] == (kept_memo1, "RAW")
            assert a2.resource_manager.log[-1] == (kept_memo2, "RAW")
コード例 #4
0
def test_BBPSSW_fidelity():
    tl = Timeline()
    a1 = FakeNode("a1", tl)
    a2 = FakeNode("a2", tl)
    cc0 = ClassicalChannel("cc0", tl, 0, 1e5)
    cc1 = ClassicalChannel("cc1", tl, 0, 1e5)
    cc0.delay = ONE_MILLISECOND
    cc1.delay = ONE_MILLISECOND
    cc0.set_ends(a1, a2)
    cc1.set_ends(a2, a1)

    tl.init()

    for i in range(1000):
        fidelity = np.random.uniform(0.5, 1)
        kept_memo1 = Memory("a1.kept", tl, fidelity=fidelity, frequency=0, efficiency=1, coherence_time=1,
                            wavelength=HALF_MICRON)
        kept_memo2 = Memory("a2.kept", tl, fidelity, 0, 1, 1, HALF_MICRON)
        meas_memo1 = Memory("a1.meas", tl, fidelity, 0, 1, 1, HALF_MICRON)
        meas_memo2 = Memory("a2.meas", tl, fidelity, 0, 1, 1, HALF_MICRON)

        kept_memo1.entangled_memory["node_id"] = "a2"
        kept_memo1.entangled_memory["memo_id"] = "a2.kept"
        kept_memo1.fidelity = fidelity
        kept_memo2.entangled_memory["node_id"] = "a1"
        kept_memo2.entangled_memory["memo_id"] = "a1.kept"
        kept_memo2.fidelity = fidelity
        meas_memo1.entangled_memory["node_id"] = "a2"
        meas_memo1.entangled_memory["memo_id"] = "a2.meas"
        meas_memo1.fidelity = fidelity
        meas_memo2.entangled_memory["node_id"] = "a1"
        meas_memo2.entangled_memory["memo_id"] = "a1.meas"
        meas_memo2.fidelity = fidelity

        pair1 = np.random.choice(range(4), 1,
                                 p=[fidelity, (1 - fidelity) / 3, (1 - fidelity) / 3, (1 - fidelity) / 3])
        pair2 = np.random.choice(range(4), 1,
                                 p=[fidelity, (1 - fidelity) / 3, (1 - fidelity) / 3, (1 - fidelity) / 3])
        tl.quantum_manager.set([kept_memo1.qstate_key, kept_memo2.qstate_key], BELL_STATES[pair1[0]])
        tl.quantum_manager.set([meas_memo1.qstate_key, meas_memo2.qstate_key], BELL_STATES[pair2[0]])

        ep1 = BBPSSW(a1, "a1.ep1.%d" % i, kept_memo1, meas_memo1)
        ep2 = BBPSSW(a2, "a2.ep2.%d" % i, kept_memo2, meas_memo2)
        a1.protocols.append(ep1)
        a2.protocols.append(ep2)
        ep1.set_others(ep2)
        ep2.set_others(ep1)

        ep1.start()
        ep2.start()

        tl.run()

        assert a1.resource_manager.log[-2] == (meas_memo1, RAW)
        assert a2.resource_manager.log[-2] == (meas_memo2, RAW)
        assert meas_memo1.fidelity == meas_memo2.fidelity == 0

        if ep1.meas_res == ep2.meas_res:
            assert kept_memo1.fidelity == kept_memo2.fidelity == BBPSSW.improved_fidelity(fidelity)
            assert kept_memo1.entangled_memory["node_id"] == "a2" and kept_memo2.entangled_memory["node_id"] == "a1"
            assert a1.resource_manager.log[-1] == (kept_memo1, ENTANGLED)
            assert a2.resource_manager.log[-1] == (kept_memo2, ENTANGLED)
        else:
            assert kept_memo1.fidelity == kept_memo2.fidelity == 0
            assert kept_memo1.entangled_memory["node_id"] == kept_memo2.entangled_memory["node_id"] == None
            assert a1.resource_manager.log[-1] == (kept_memo1, RAW)
            assert a2.resource_manager.log[-1] == (kept_memo2, RAW)
コード例 #5
0
def test_EntanglementSwapping():
    tl = Timeline()
    a1 = FakeNode("a1", tl)
    a2 = FakeNode("a2", tl)
    a3 = FakeNode("a3", tl)
    cc0 = ClassicalChannel("a2-a1", tl, 0, 1e5)
    cc1 = ClassicalChannel("a2-a3", tl, 0, 1e5)
    cc0.set_ends(a2, a1)
    cc1.set_ends(a2, a3)
    tl.init()
    counter1 = counter2 = 0

    for i in range(1000):
        memo1 = Memory("a1.%d" % i, timeline=tl, fidelity=0.9, frequency=0, efficiency=1, coherence_time=1,
                       wavelength=500)
        memo2 = Memory("a2.%d" % i, tl, 0.9, 0, 1, 1, 500)
        memo3 = Memory("a2.%d" % i, tl, 0.9, 0, 1, 1, 500)
        memo4 = Memory("a3.%d" % i, tl, 0.9, 0, 1, 1, 500)

        memo1.entangled_memory["node_id"] = "a2"
        memo1.entangled_memory["memo_id"] = memo2.name
        memo1.fidelity = 0.9
        memo2.entangled_memory["node_id"] = "a1"
        memo2.entangled_memory["memo_id"] = memo1.name
        memo2.fidelity = 0.9
        memo3.entangled_memory["node_id"] = "a3"
        memo3.entangled_memory["memo_id"] = memo4.name
        memo3.fidelity = 0.9
        memo4.entangled_memory["node_id"] = "a2"
        memo4.entangled_memory["memo_id"] = memo3.name
        memo4.fidelity = 0.9

        es1 = EntanglementSwappingB(a1, "a1.ESb%d" % i, memo1)
        a1.protocols.append(es1)
        es2 = EntanglementSwappingA(a2, "a2.ESa%d" % i, memo2, memo3, success_prob=0.2)
        a2.protocols.append(es2)
        es3 = EntanglementSwappingB(a3, "a3.ESb%d" % i, memo4)
        a3.protocols.append(es3)

        es1.set_others(es2)
        es3.set_others(es2)
        es2.set_others(es1)
        es2.set_others(es3)

        es2.start()

        assert memo2.fidelity == memo3.fidelity == 0
        assert memo1.entangled_memory["node_id"] == memo4.entangled_memory["node_id"] == "a2"
        assert memo2.entangled_memory["node_id"] == memo3.entangled_memory["node_id"] == None
        assert memo2.entangled_memory["memo_id"] == memo3.entangled_memory["memo_id"] == None
        assert a2.resource_manager.log[-2] == (memo2, "RAW")
        assert a2.resource_manager.log[-1] == (memo3, "RAW")

        tl.run()

        if es2.is_success:
            counter1 += 1
            assert memo1.entangled_memory["node_id"] == "a3" and memo4.entangled_memory["node_id"] == "a1"
            assert memo1.fidelity == memo4.fidelity <= memo1.raw_fidelity
            assert a1.resource_manager.log[-1] == (memo1, "ENTANGLED")
            assert a3.resource_manager.log[-1] == (memo4, "ENTANGLED")
        else:
            counter2 += 1
            assert memo1.entangled_memory["node_id"] == memo4.entangled_memory["node_id"] == None
            assert memo1.fidelity == memo4.fidelity == 0
            assert a1.resource_manager.log[-1] == (memo1, "RAW")
            assert a3.resource_manager.log[-1] == (memo4, "RAW")

    assert abs((counter1 / (counter1 + counter2)) - 0.2) < 0.1