Ejemplo n.º 1
0
def main():
    Q_program = QuantumProgram()
    Q_program.register(Qconfig.APItoken, Qconfig.config["url"])
    #Creating registers
    q = Q_program.create_quantum_register("q", 2)
    c = Q_program.create_classical_register("c", 2)
    #Quantum circuit to make shared entangled state
    superdense = Q_program.create_circuit("superdense", [q], [c])
    #Party A : Alice
    superdense.h(q[0])
    superdense.cx(q[0], q[1])
    #00:do nothing, 10:apply x, 01:apply z
    superdense.x(q[0])
    superdense.z(q[0])
    #11:apply zx
    superdense.z(q[0])
    superdense.x(q[0])
    superdense.barrier()

    #Party B : Bob
    superdense.cx(q[0], q[1])
    superdense.h(q[0])
    superdense.measure(q[0], c[0])
    superdense.measure(q[1], c[1])

    circuits = ["superdense"]
    print(Q_program.get_qasms(circuits)[0])

    backend = "ibmq_qasm_simulator"
    shots = 1024

    result = Q_program.execute(circuits, backend=backend, shots=shots, max_credits=3, timeout=240)

    print("Counts:" + str(result.get_counts("superdense")))
    plot_histogram(result.get_counts("superdense"))
def main():
    Q_program = QuantumProgram()
    Q_program.register(Qconfig.APItoken, Qconfig.config["url"])

    #Create registers
    q = Q_program.create_quantum_register('q', 3)
    c0 = Q_program.create_classical_register('c0', 1)
    c1 = Q_program.create_classical_register('c1', 1)
    c0 = Q_program.create_classical_register('c2', 1)

    #Quantum circuit to make Bell Pair
    teleport = Q_program.create_circuit('teleport', [q], [c0, c1, c2])
    teleport.h(q[1])
    teleport.cx(q[1], q[2])

    #A prepares quantum state to be teleported
    teleport.ry(np.pi / 4, q[0])
    #A applies CNOT to her two quantum states followed by H to entangle them
    teleport.cx(q[0], q[1])
    teleport.h(q[0])
    teleport.barrier()
    #A measures her two quantum states
    teleport.measure(q[0], c0[0])
    teleport.measure(q[1], c1[0])

    circuits = ['teleport']
    print(Q_program.get_qasms(circuits)[0])

    #B depending on the result applies x or z or both
    teleport.z(q[2]).c_if(c0, 1)
    teleport.x(q[2]).c_if(c1, 1)

    teleport.measure(q[2], c2[0])

    #dump asm
    circuits = ['teleport']
    print(Q_program.get_qasms(circuits)[0])

    backend = "ibmq_qasm_simulator"
    shots = 1024
    result = Q_program.execute(circuits,
                               backend=backend,
                               shots=shots,
                               max_credits=3,
                               timeout=240)

    print("Counts:" + str(result.get_counts("teleport")))

    #RESULTS
    #Alice's measurements
    data = result.get_counts("teleport")
    alice = {}
    alice['00'] = data['0 0 0'] + data['1 0 0']
    alice['10'] = data['0 1 0'] + data['1 1 0']
    alice['01'] = data['0 0 1'] + data['1 0 1']
    alice['11'] = data['0 1 1'] + data['1 1 1']
    plot_histogram(alice)

    bob = {}
    bob['0'] = data['0 0 0'] + data['0 1 0'] + data['0 0 1'] + data['0 1 1']
    bob['1'] = data['1 0 0'] + data['1 1 0'] + data['1 0 1'] + data['1 1 1']
    plot_histogram(bob)