You are noticing that measurement behavior is different in different versions of Qiskit. In qiskit==0.33.1
, we have the following behavior:
import qiskit
print(qiskit.__qiskit_version__)
{'qiskit-terra': '0.19.1', 'qiskit-aer': '0.9.1', 'qiskit-ignis': '0.7.0', 'qiskit-ibmq-provider': '0.18.2', 'qiskit-aqua': '0.9.5', 'qiskit': '0.33.1', 'qiskit-nature': None, 'qiskit-finance': None, 'qiskit-optimization': None, 'qiskit-machine-learning': None}
from qiskit import Aer
from qiskit import execute
from qiskit import QuantumCircuit
circ = QuantumCircuit(3,3)
circ.h(0)
circ.cx(0,1)
circ.cx(0,2)
backend = Aer.get_backend("qasm_simulator")
job = execute(circ, backend, shots = 100000)
result = job.result()
counts = result.get_counts(circ)
print(counts)
{'000': 100000}
But in the next update qiskit==0.34.0
there is an error:
import qiskit
print(qiskit.__qiskit_version__)
{'qiskit-terra': '0.19.1', 'qiskit-aer': '0.10.1', 'qiskit-ignis': '0.7.0', 'qiskit-ibmq-provider': '0.18.3', 'qiskit-aqua': '0.9.5', 'qiskit': '0.34.0', 'qiskit-nature': None, 'qiskit-finance': None, 'qiskit-optimization': None, 'qiskit-machine-learning': None}
from qiskit import Aer
from qiskit import execute
from qiskit import QuantumCircuit
circ = QuantumCircuit(3,3)
circ.h(0)
circ.cx(0,1)
circ.cx(0,2)
backend = Aer.get_backend("qasm_simulator")
job = execute(circ, backend, shots = 100000)
result = job.result()
counts = result.get_counts(circ)
print(counts)
QiskitError: 'No counts for experiment "<qiskit.circuit.quantumcircuit.QuantumCircuit object at 0x1550e7790>"'
So your issue is not with the measure_all()
concept per say, but rather you just need to keep notes of the versions in which these changes take place.
Clarification: It should also be noted that in the qiskit==0.33.1
case, the output {'000': 100000}
is reflecting the fact that no measurements have been loaded in to the classical bits (so the values all remain zero). If a measurement statement is included, then this circuit will have GHZ state measurement statistics:
from qiskit import Aer
from qiskit import execute
from qiskit import QuantumCircuit
circ = QuantumCircuit(3,3)
circ.h(0)
circ.cx(0,1)
circ.cx(0,2)
circ.measure(range(3), range(3)) # actually measure the circuit
backend = Aer.get_backend("qasm_simulator")
job = execute(circ, backend, shots = 100000)
result = job.result()
counts = result.get_counts(circ)
print(counts)
{'000': 50094, '111': 49906}
qiksit version 0.32.1
,python version 3.8.18
. It gives me result{'000': 100000}
$\endgroup$