def test_measure_from_threads():
    q_sim = EQSN()

    def measure_or_hadamard(_id):
        n = random.randrange(10, 20, 1)
        for _ in range(n):
            time.sleep(0.1)
            q_sim.H_gate(_id)

    nr_threads = 10
    ids = [str(x) for x in range(nr_threads)]
    for _id in ids:
        q_sim.new_qubit(_id)
    id1 = ids[0]

    for c in ids:
        if c != id1:
            q_sim.cnot_gate(id1, c)

    thread_list = []
    for _id in ids:
        t = threading.Thread(target=measure_or_hadamard, args=(_id, ))
        t.start()
        thread_list.append(t)

    for t in thread_list:
        t.join()
    q_sim.stop_all()
Esempio n. 2
0
def test_measure_from_threads():
    q_sim = EQSN()

    def measure_or_hadamard(id):
        n = random.randrange(10, 100, 1)
        for _ in range(n):
            # time.sleep(0.05)
            q_sim.H_gate(id)
        print("Finished Hadamard, measure qubit %s!" % id)
        print(q_sim.measure(id))
        print("Finished with Measure!")

    nr_threads = 10
    ids = [str(x) for x in range(nr_threads)]
    for id in ids:
        q_sim.new_qubit(id)
    id1 = ids[0]
    for c in ids:
        if c != id1:
            q_sim.cnot_gate(id1, c)
    thread_list = []
    for id in ids:
        print(id)
        t = threading.Thread(target=measure_or_hadamard, args=(id, ))
        t.start()
        thread_list.append(t)
    for t in thread_list:
        t.join()
    print("Test was successfull!")
    q_sim.stop_all()
Esempio n. 3
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()
Esempio n. 4
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))