0

I'm trying to run X gates on 2 qubits and then return the chance of the qubit in either state as a decimal. I've searched for answers but I haven't gotten anywhere.

##THE CODE##
import math
import numpy as np
from qiskit import *
from qiskit.providers.aer.extensions.snapshot_probabilities import *


#call for qubits
q = QuantumRegister(2)
c = ClassicalRegister(2)

#creates qubits and classical bits
qc = QuantumCircuit(q, c)

#applys a half not ad 
for i in range(2):
    qc.u3(0.5 * math.pi,0,0, q[i])

# Map the quantum measurement to the classical bits
for i in range(2):
    qc.measure(q[i], c[i])

# Execute the circuit on the qasm simulator
simulator = Aer.get_backend('qasm_simulator')
job = execute(qc, simulator, shots=1000)

result = job.result()
counts = result.get_counts(qc)
## END OF CODE##

1 Answers1

0

Alright, so the result.get_counts() returns a list of the possible dictionary named after possible answers. So loop through the possible answers

##THE CODE##
counts = result.get_counts(qc)
ls = []
for i, key in enumerate(counts.keys()):
    v = counts.get(key)
    ls.append(v)
    
print(ls) 
##END OF CODE##

Example

If I run the code from before an apply half x gates to two qubits

for i in range(2):
    qc.u3(0.5 * math.pi,0,0, q[i]) 

My the output will be the chance of a qubits in state 1, out of 1000.

OUTPUT

[241, 238, 262, 259]
Community
  • 1
  • 1