# Do I need to use classical bits in measurement?

I wonder if I have to add classical bits while performing measurement for a single-qubit quantum circuit. The difference to initialize the circuit is QuantumCircuit(1) and QuantumCircuit(1,1). I noticed if I do not add the classical bit while drawing the circuit, I'm automatically assigned with a meas bit:

Is that the same as a classical bit? Will there be any difference when I run the two versions of the circuit on the simulator and quantum device? Thanks!

• Did you use the function measure_all() ? Aug 6 at 5:51
• @KAJ226 Yes, I did use that in QuantumCircuit(1):)
– ZR-
Aug 6 at 5:55

You don't need to define classical bits in your QuantumCircuit if you are going to use the function measure_all().

The two scripts below (Script 1 and Script 2) are equivalent:

# Script 1
qc1 = QuantumCircuit(1)
qc1.h(0)
qc1.measure_all()
print(qc1)

┌───┐ ░ ┌─┐
q_0: ┤ H ├─░─┤M├
└───┘ ░ └╥┘
meas: 1/═════════╩═
0

# Script 2
qc2 = QuantumCircuit(1,1)
qc2.h(0)
qc2.measure([0],[0])
print(qc2)
┌───┐┌─┐
q_0: ┤ H ├┤M├
└───┘└╥┘
c: 1/══════╩═
0


You can check the result on qasm_simulator:

execute(qc1, Aer.get_backend('qasm_simulator'), shots = 1000).result().get_counts()
>>> {'0': 486, '1': 514}

execute(qc2, Aer.get_backend('qasm_simulator'), shots = 1000).result().get_counts()
>>> {'1': 468, '0': 532}


Thus, you don't need to define classical bits (cbits) in your QuantumCircuit if you are going to use measure_all() function.

However, you want to avoid doing something like:

# Script 3
qc3 = QuantumCircuit(1,1)
qc3.h(0)
qc3.measure_all()
print(qc3)

┌───┐ ░ ┌─┐
q_0: ┤ H ├─░─┤M├
└───┘ ░ └╥┘
c: 1/═════════╬═
║
meas: 1/═════════╩═
0


You still can run the circuit, it just give you an extra cbit of '0' in your readout dictionary. That is, you would see something like:

execute(qc3, Aer.get_backend('qasm_simulator'), shots = 1000).result().get_counts()
>>>  {'0 0': 496, '1 0': 504}