def test_custom_two_qubit_control_gate_other_qubits_not_affected():
    eqsn = EQSN()

    eqsn.new_qubit("400")
    eqsn.new_qubit("200")
    eqsn.new_qubit("300")
    eqsn.new_qubit("100")
    eqsn.new_qubit("500")

    eqsn.X_gate("100")
    eqsn.X_gate("200")
    eqsn.X_gate("500")

    # CNOT gate
    custom_gate = np.asarray(
        [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]
    )
    eqsn.custom_two_qubit_control_gate("100", "200", "500", custom_gate)

    m1 = eqsn.measure("100")
    m2 = eqsn.measure("200")
    m3 = eqsn.measure("300")
    m4 = eqsn.measure("400")
    m5 = eqsn.measure("500")

    assert m2 == 1
    assert m3 == 0
    assert m1 == 1
    assert m4 == 0
    assert m5 == 0

    eqsn.stop_all()
def test_non_destructive_measurement():
    q_sim = EQSN()
    id1 = str(1)
    q_sim.new_qubit(id1)
    q_sim.H_gate(id1)
    m = q_sim.measure(id1, non_destructive=True)
    m2 = q_sim.measure(id1)
    assert m == m2
    q_sim.stop_all()
def test_non_destructive_measurement():
    q_sim = EQSN()
    id1 = str(1)
    q_sim.new_qubit(id1)
    q_sim.H_gate(id1)
    m = q_sim.measure(id1, non_destructive=True)
    m2 = q_sim.measure(id1)
    print("Measured %d." % m)
    assert m == m2
    print("Test was successfull!")
    q_sim.stop_all()
    print("Stopped succesfully!")
    exit(0)
Пример #4
0
def test_5_qubits_gate():
    q_sim = EQSN()
    ids = [str(x) for x in range(5)]
    for i in ids:
        q_sim.new_qubit(i)
    for i in ids:
        q_sim.H_gate(i)
    q_sim.cnot_gate(ids[1], ids[0])
    q_sim.cnot_gate(ids[2], ids[1])
    q_sim.cnot_gate(ids[3], ids[2])
    q_sim.cnot_gate(ids[4], ids[3])
    for i in ids:
        q_sim.measure(i)
    q_sim.stop_all()
Пример #5
0
def test_custom_single_gate():
    eqsn = EQSN()
    gate = (1/2)**0.5 * np.array([[1, 1],[1,-1]], dtype=np.csingle)
    eqsn.new_qubit('1')
    eqsn.custom_gate('1', gate)
    eqsn.custom_gate('1', gate)
    res = eqsn.measure('1')
    eqsn.stop_all()
    assert res == 0
Пример #6
0
def test_custom_controlled_gate():
    eqsn = EQSN()
    gate = np.array([[0, 1],[1,0]], dtype=np.csingle)
    eqsn.new_qubit('1')
    eqsn.new_qubit('2')
    eqsn.H_gate('1')
    eqsn.custom_controlled_gate('2', '1', gate)
    res1 = eqsn.measure('1')
    res2 = eqsn.measure('2')
    eqsn.stop_all()
    assert res1 == res2
def test_custom_two_qubit_control_gate_control_not_applied():
    eqsn = EQSN()
    eqsn.new_qubit("100")
    eqsn.new_qubit("200")
    eqsn.new_qubit("300")
    eqsn.X_gate("200")
    # Swap gate
    custom_gate = np.asarray(
        [[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]]
    )
    eqsn.custom_two_qubit_control_gate("100", "200", "300", custom_gate)

    m1 = eqsn.measure("100")
    m2 = eqsn.measure("200")
    m3 = eqsn.measure("300")

    assert m2 == 1
    assert m3 == 0
    assert m1 == 0

    eqsn.stop_all()
def test_two_qubit_gate():
    eqsn = EQSN()
    eqsn.new_qubit("1")
    eqsn.new_qubit("2")
    eqsn.X_gate("1")
    custom_gate = np.asarray([[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0],
                              [0, 0, 0, 1]])
    eqsn.custom_two_qubit_gate("1", "2", custom_gate)
    m1 = eqsn.measure("1")
    m2 = eqsn.measure("2")
    assert m1 == 0
    assert m2 == 1
    eqsn.stop_all()
Пример #9
0
def main():
    # Activate debugging
    logging.basicConfig(level=logging.DEBUG)
    eqsn = EQSN()

    # create and measure
    id = "Qubit"
    eqsn.new_qubit(id)
    _ = eqsn.measure(id)

    # merge
    id1 = str(1)
    id2 = str(2)
    eqsn.new_qubit(id1)
    eqsn.new_qubit(id2)
    eqsn.merge_qubits(id1, id2)

    eqsn.stop_all()
Пример #10
0
def test_call_single_qubit_gate_from_threads():
    eqsn = EQSN()

    def call_X_gate_n_times(_id, n):
        for _ in range(n):
            eqsn.X_gate(_id)

    id1 = str(1)
    eqsn.new_qubit(id1)
    n = 99
    nr_threads = 5
    thread_list = []
    for _ in range(nr_threads):
        t = threading.Thread(target=call_X_gate_n_times, args=(id1, n))
        t.start()
        thread_list.append(t)
    for t in thread_list:
        t.join()
    m = eqsn.measure(id1)
    assert m == 1
    eqsn.stop_all()
def test_call_single_qubit_gate_from_threads():
    q_sim = EQSN()

    def call_X_gate_n_times(id, n):
        for c in range(n):
            # print("Apply %d time." % c)
            q_sim.X_gate(id)

    id1 = str(1)
    q_sim.new_qubit(id1)
    n = 999
    nr_threads = 5
    thread_list = []
    for _ in range(nr_threads):
        t = threading.Thread(target=call_X_gate_n_times, args=(id1, n))
        t.start()
        thread_list.append(t)
    for t in thread_list:
        t.join()
    m = q_sim.measure(id1)
    print("Measured %d." % m)
    assert m == 1
    print("Test was successfull!")
    q_sim.stop_all()
Пример #12
0
from eqsn import EQSN

if __name__ == "__main__":
    eqsn = EQSN()
    id = "Qubit"
    eqsn.new_qubit(id)
    m = eqsn.measure(id)
    print("Measured Qubit with result %d." % m)
Пример #13
0
from eqsn import EQSN

if __name__ == "__main__":
    eqsn = EQSN()
    eqsn.new_qubit('A')
    eqsn.new_qubit('B')
    eqsn.H_gate('A')
    eqsn.cnot_gate('B', 'A')
    m1 = eqsn.measure('A')
    m2 = eqsn.measure('B')
    print("Measured entangled pair with results %d and %d." % (m1, m2))