If I want to run a circuit on a real quantum computer, I have to measure it before running it. For example:


To run on a quantum computer:

#Import IBMQ
from qiskit import IBMQ #different companies(IBM ic)'s quantum provider
from qiskit.providers.ibmq import least_busy

#ask for the least busy quantum computer
provider = IBMQ.get_provider(hub='ibm-q')
backend = least_busy(provider.backends(filters=lambda x: x.configuration().n_qubits >= 2 
                                       and not x.configuration().simulator #dont want a simulator, want a actual machine
                                       and x.status().operational==True)) #want an operational machine
#tell us what the least busy one is
print("least busy backend: ", backend)

# send the job to a quantum computer
job = execute(qc, backend=backend, shots=100)
result = job.result()

#then we plot our histogram as usual
counts = result.get_counts(qc)

I am wondering why do we have to measure the circuit before sending it to the real quantum computer? I know that we shouldn't measure the circuit if we send it to a statevector simulator.


3 Answers 3


The simple answer is that you can't get the statevector information out of a real quantum computer; or, more generally, a quantum system. For the real computer to extract information from the qubits, they have to collapse to some basis state $\left(|0\rangle \; \text{or} \; |1\rangle \right)$. And this collapse is performed by measuring the qubits.


Note that you do not measure anything before sending to QC. What you actually send to QC is a sequence of instructions telling QC what to do. The measurement is the last instruction necessary for obtaining results as pointed out in the other answer.


I am guessing the confusion is because x(), cx(), and measure_all() all appear to be executing a function because of the ()'s.

What is actually happening is that those are methods on the QuantumCircuit class that tell it to add the specified gate to its internal list of gates.

So when you enter your code:


You are just setting up the description of what your circuit should look like and do. How many qubits does it have? Which gates? etc...

So, adding the measure_all() to qc does not immediately measure the circuit. It just adds measurement gates (and silently creates the classical bits to record those measurements) to the definition of your circuit stored in qc.

Once you setup the backend and tell it to execute qc, your definition for the circuit gets forwarded off to the backend and everything is setup and executed in the order you specified, but on the quantum hardware.

The measurement actually happens there (multiple measurements really because you execute the circuit the number of times specified in shots).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.