0

Error 'No counts for experiment "0"' in line answer = job_result.get_counts() here's my code

shots = 1000
backend_type = 'qasm_simulator'
backend = Aer.get_backend(backend_type)

provider = IBMQ.load_account()
#backend = provider.get_backend(backend_type)
job = execute(qc, backend = backend, shots = shots)
job_result = job.result()
answer = job_result.get_counts()
print(answer)

plot_histogram(answer, title = 'Measurement Qubit')
  • First try updating qiskit-terra and qiskit-aer; for me this code works (it will be better to supply the full code, including the include section and the generation of qc itself) – Gadi A May 02 '23 at 06:48
  • I'm using IBM quantum lab. How do I update qiskit? – user20451489 May 02 '23 at 07:15
  • In that case, try creating a new notebook. Qiskit is moving away from using IBMQ and tends to use qiskit runtime along with the Sampler primitive in order to get counts (when creating a new notebook I believe it comes with the relevant sample code) – Gadi A May 02 '23 at 07:19

1 Answers1

0

This error message usually comes up if you don’t have a measurement in your circuit