예제 #1
0
        decodingCircuits[circuitName].h(q_register[0])
    elif pos == "Third":
        decodingCircuits[circuitName].u3(pi / 2, -pi / 2, pi / 2,
                                         q_register[0])
    decodingCircuits[circuitName].measure(q_register[0], c_register[0])

#combine encoding and decoding of q_registerACs to get a list of complete circuits
circuitNames = []
for k1 in encodingCircuits.keys():
    for k2 in decodingCircuits.keys():
        circuitNames.append(k1 + k2)
        program.add_circuit(k1 + k2,
                            encodingCircuits[k1] + decodingCircuits[k2])

print("List of circuit names:", circuitNames)  #list of circuit names
#program.get_qasms(circuitNames) #list qasms codes

results = program.execute(circuitNames, backend=backend, shots=shots)
print("Experimental Result of Encode010DecodeFirst")
plot_histogram_file(
    "Encode010DecodeFirst.svg", results.get_counts(
        "Encode010DecodeFirst"))  #We should measure "0" with probability 0.78
print("Experimental Result of Encode010DecodeSecond")
plot_histogram_file(
    "Encode010DecodeSecond.svg", results.get_counts(
        "Encode010DecodeSecond"))  #We should measure "1" with probability 0.78
print("Experimental Result of Encode010DecodeThird")
plot_histogram_file(
    "Encode010DecodeThird.svg", results.get_counts(
        "Encode010DecodeThird"))  #We should measure "0" with probability 0.78
예제 #2
0
backend = 'ibmqx2'
shots = 1024  # the number of shots in the experiment

program = QuantumProgram()
program.set_api(Qconfig.APItoken,
                Qconfig.config['url'])  # set the APIToken and API url

# Creating registers
q_register = program.create_quantum_register('q_register', 5)
c_register = program.create_classical_register('c_register', 5)

# Quantum circuit two Hadamards
qc_twohadamard = program.create_circuit('twohadamard', [q_register],
                                        [c_register])
qc_twohadamard.h(q_register)
qc_twohadamard.barrier()
qc_twohadamard.h(q_register)
qc_twohadamard.measure(q_register[0], c_register[0])

circuits = ['twohadamard']
result = program.execute(circuits,
                         backend=backend,
                         shots=shots,
                         max_credits=3,
                         wait=10,
                         timeout=240,
                         silent=False)

plot_histogram_file('twohadamard.svg', result.get_counts('twohadamard'))
예제 #3
0
backend = 'ibmqx2'  # the backend to run on
shots = 1024  # the number of shots in the experiment

Q_program = QuantumProgram()
Q_program.set_api(Qconfig.APItoken, Qconfig.config['url'])
# quantum circuit to make GHZ state
q3 = Q_program.create_quantum_register('q3', 3)
c3 = Q_program.create_classical_register('c3', 3)
ghz = Q_program.create_circuit('ghz', [q3], [c3])
ghz.h(q3[0])
ghz.cx(q3[0], q3[1])
ghz.cx(q3[0], q3[2])

# quantum circuit to measure q in standard basis
measureZZZ = Q_program.create_circuit('measureZZZ', [q3], [c3])
measureZZZ.measure(q3[0], c3[0])
measureZZZ.measure(q3[1], c3[1])
measureZZZ.measure(q3[2], c3[2])

Q_program.add_circuit('ghz_measureZZZ', ghz + measureZZZ)
circuits = ['ghz_measureZZZ']
Q_program.get_qasms(circuits)
result5 = Q_program.execute(circuits,
                            backend=backend,
                            shots=shots,
                            max_credits=5,
                            wait=10,
                            timeout=240,
                            silent=True)
plot_histogram_file('ghz_measureZZZ.svg', result5.get_counts('ghz_measureZZZ'))
예제 #4
0
        decodingCircuits[circuitName].measure(q_register[1], c_register[1])
    else: #measure 4th, 5th, 6th bit
        if pos == "Fifth": #if pos == "Fourth" we can directly measure
            decodingCircuits[circuitName].h(q_register[2])
        elif pos == "Sixth":
            decodingCircuits[circuitName].u3(pi/2, -pi/2, pi/2, q_register[2])
        decodingCircuits[circuitName].measure(q_register[2], c_register[1])

        #Quantum circuits for decoding the 7th bit
decodingCircuits["DecodeSeventh"] = program.create_circuit("DecodeSeventh", [q_register], [c_register])
decodingCircuits["DecodeSeventh"].measure(q_register[1], c_register[0])
decodingCircuits["DecodeSeventh"].measure(q_register[2], c_register[1])

#combine encoding and decoding of (7,2)-q_registerACs to get a list of complete circuits
circuitNames = []
k1 = encodingName
for k2 in decodingCircuits.keys():
    circuitNames.append(k1+k2)
    program.add_circuit(k1+k2, encodingCircuit+decodingCircuits[k2])

print("List of circuit names:", circuitNames) #list of circuit names
#program.get_qasms(circuitNames) #list qasms codes

results = program.execute(circuitNames, backend=backend, shots=shots)
for k in ["DecodeFirst", "DecodeSecond", "DecodeThird", "DecodeFourth", "DecodeFifth", "DecodeSixth"]:
    print("Experimental Result of ", encodingName+k)
    plot_histogram_file(encodingName+k+".svg", results.get_counts(encodingName+k))

print("Experimental result of ", encodingName+"DecodeSeventh")
plot_histogram_file(encodingName+"DecodeSeventh.svg", results.get_counts(encodingName+"DecodeSeventh"))
예제 #5
0
shots = 1024  # the number of shots in the experiment

program = QuantumProgram()
program.set_api(Qconfig.APItoken,
                Qconfig.config['url'])  # set the APIToken and API url

# Creating registers
q_register = program.create_quantum_register('q_register', 1)
c_register = program.create_classical_register('c_register', 1)

# Quantum circuit ground
qc_ground = program.create_circuit('ground', [q_register], [c_register])
qc_ground.measure(q_register[0], c_register[0])

# Quantum circuit superposition
qc_superposition = program.create_circuit('superposition', [q_register],
                                          [c_register])
qc_superposition.h(q_register)
qc_superposition.measure(q_register[0], c_register[0])

circuits = ['superposition']
result = program.execute(circuits,
                         backend=backend,
                         shots=shots,
                         max_credits=3,
                         wait=10,
                         timeout=240,
                         silent=False)

plot_histogram_file('superposition.svg', result.get_counts('superposition'))
예제 #6
0
from plot_histogram_file import *

program = QuantumProgram()
n = 3  # number of qubits
q_register = program.create_quantum_register('q_register', n)
c_register = program.create_classical_register('c_register', n)

ghz = program.create_circuit('ghz', [q_register], [c_register])
ghz.h(q_register[0])
ghz.cx(q_register[0], q_register[1])
ghz.cx(q_register[0], q_register[2])
ghz.s(q_register[0])
ghz.measure(q_register[0], c_register[0])
ghz.measure(q_register[1], c_register[1])
ghz.measure(q_register[2], c_register[2])

superposition = program.create_circuit('superposition', [q_register],
                                       [c_register])
superposition.h(q_register)
superposition.s(q_register[0])
superposition.measure(q_register[0], c_register[0])
superposition.measure(q_register[1], c_register[1])
superposition.measure(q_register[2], c_register[2])

circuits = ['ghz', 'superposition']

backend = 'local_qasm_simulator'
result = program.execute(circuits, backend=backend, shots=1000, silent=True)

plot_histogram_file('result1.svg', result.get_counts('ghz'))
plot_histogram_file('result2.svg', result.get_counts('superposition'), 15)
예제 #7
0
# NB: Can't have more than one measurement per circuit
for circuit in circuits:
    q_gen = Q_program.get_quantum_register("q_gen")
    c_gen = Q_program.get_classical_register('c_gen')
    IFM = Q_program.create_circuit(circuit, [q_gen], [c_gen])
    IFM.h(q_gen[0]) #Turn the qubit into |0> + |1>
    IFM.measure(q_gen[0], c_gen[0])
_ = Q_program.get_qasms(circuits) # Suppress the output

result = Q_program.execute(circuits, device, shots=1, max_credits=5, wait=10, timeout=240) # Note that we only want one shot
bombs = []
for circuit in circuits:
    for key in result.get_counts(circuit): # Hack, there should only be one key, since there was only one shot
        bombs.append(int(key))
#print(', '.join(('Live' if bomb else 'Dud' for bomb in bombs))) # Uncomment to print out "truth" of bombs
plot_histogram_file('bomb_generation_result.svg', Counter(('Live' if bomb else 'Dud' for bomb in bombs))) #Plotting bomb generation results

device = 'local_qasm_simulator' #Running on the simulator
circuits = ["IFM_meas"+str(i) for i in range(N)]
#Creating one measurement circuit for each bomb
for i in range(N):
    bomb = bombs[i]
    q = Q_program.get_quantum_register("q")
    c = Q_program.get_classical_register('c')
    IFM = Q_program.create_circuit(circuits[i], [q], [c])
    for step in range(steps):
        IFM.ry(eps, q[0]) #First we rotate the control qubit by epsilon
        if bomb: #If the bomb is live, the gate is a controlled X gate
            IFM.cx(q[0],q[1])
        #If the bomb is a dud, the gate is a controlled identity gate, which does nothing
        IFM.measure(q[1], c[step]) #Now we measure to collapse the combined state
예제 #8
0
            circ.cu1(math.pi / float(2**(j - k)), q[j], q[k])
        circ.h(q[j])


q = Q_program.create_quantum_register("q", 3)
c = Q_program.create_classical_register("c", 3)
qft3 = Q_program.create_circuit("qft3", [q], [c])

input_state(qft3, q, 3)
qft(qft3, q, 3)
for i in range(3):
    qft3.measure(q[i], c[i])
print(qft3.qasm())

simulate = Q_program.execute(["qft3"],
                             backend="local_qasm_simulator",
                             shots=1024)
simulate.get_counts("qft3")

ibmqx2_backend = Q_program.get_backend_configuration('ibmqx2')
ibmqx2_coupling = ibmqx2_backend['coupling_map']

run = Q_program.execute(["qft3"],
                        backend="ibmqx2",
                        coupling_map=ibmqx2_coupling,
                        shots=1024,
                        max_credits=3,
                        wait=10,
                        timeout=240)
plot_histogram_file('qft3.svg', run.get_counts("qft3"))
예제 #9
0
program = QuantumProgram()
#program.set_api(Qconfig.APItoken, Qconfig.config['url']) # set the APIToken and API url

# Creating registers
q_register = program.create_quantum_register('q_register', 2)
c_register = program.create_classical_register('c_register', 2)

# quantum circuit to make a mixed state
mixed1 = program.create_circuit("mixed1", [q_register], [c_register])
mixed2 = program.create_circuit("mixed2", [q_register], [c_register])
mixed2.x(q_register)
mixed1.measure(q_register[0], c_register[0])
mixed1.measure(q_register[1], c_register[1])
mixed2.measure(q_register[0], c_register[0])
mixed2.measure(q_register[1], c_register[1])
mixed_state = ["mixed1", "mixed2"]
result = program.execute(mixed_state,
                         backend=backend,
                         shots=shots,
                         max_credits=3,
                         wait=10,
                         timeout=240,
                         silent=False)
counts1 = result.get_counts(mixed_state[0])
counts2 = result.get_counts(mixed_state[1])
from collections import Counter
ground = Counter(counts1)
excited = Counter(counts2)
plot_histogram_file('entanglement2.svg', ground + excited)
예제 #10
0
#shared.x(q[0])

# For 01, apply $Z$
#shared.z(q[0])

# For 11, apply $XZ$
superdense.z(q[0])
superdense.x(q[0])
superdense.barrier()

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 = 'ibmqx2'  # the device to run on
#backend = 'local_qasm_simulator'
shots = 1024  # the number of shots in the experiment

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

plot_histogram_file('superdence.svg', result.get_counts("superdense"))
예제 #11
0
program.set_api(Qconfig.APItoken,
                Qconfig.config['url'])  # set the APIToken and API url

# Creating registers
q_register = program.create_quantum_register('q_register', 1)
c_register = program.create_classical_register('c_register', 1)

# Quantum circuit ground
qc_ground = program.create_circuit('ground', [q_register], [c_register])
qc_ground.measure(q_register[0], c_register[0])

# Quantum circuit excited
qc_excited = program.create_circuit('excited', [q_register], [c_register])
qc_excited.x(q_register)
qc_excited.measure(q_register[0], c_register[0])

circuits = ['ground', 'excited']

program.get_qasms(circuits)

result = program.execute(circuits,
                         backend=backend,
                         shots=shots,
                         max_credits=3,
                         wait=10,
                         timeout=240,
                         silent=False)

plot_histogram_file('ground.svg', result.get_counts('ground'))
plot_histogram_file('excited.svg', result.get_counts('excited'))
예제 #12
0
program.add_circuit("bell_measureXX", bell + measureXX)

circuits = [
    "bell_measureIZ", "bell_measureIX", "bell_measureZI", "bell_measureXI",
    "bell_measureZZ", "bell_measureXX"
]
program.get_qasms(circuits)

result = program.execute(circuits[0:2],
                         backend=backend,
                         shots=shots,
                         max_credits=3,
                         wait=10,
                         timeout=240,
                         silent=False)
plot_histogram_file('bell_measureIZ.svg', result.get_counts("bell_measureIZ"))

result.get_data("bell_measureIZ")
plot_histogram_file('bell_measureIX.svg', result.get_counts("bell_measureIX"))

result = program.execute(circuits[2:4],
                         backend=backend,
                         shots=shots,
                         max_credits=3,
                         wait=10,
                         timeout=240,
                         silent=False)
plot_histogram_file('bell_measureZI.svg', result.get_counts("bell_measureZI"))
plot_histogram_file('bell_measureXI.svg', result.get_counts("bell_measureXI"))

result = program.execute(circuits[4:6],