Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sampler with shots=None supports neither mid-circuit measurements nor unwritten classical bits #1810

Open
garrison opened this issue May 14, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@garrison
Copy link
Member

garrison commented May 14, 2023

Informations

  • Qiskit Aer version: 0.12.0 and main
  • Python version: 3.10
  • Operating system: Linux

What is the current behavior?

Sampler with shots=None only works if each classical bit is set by a measurement at the end of the circuit.

Steps to reproduce the problem

from qiskit_aer.primitives import Sampler as AerSampler
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure(0, 0)
qc.reset(0)
qc.measure(0, 1)
AerSampler().run(qc, shots=None).result().quasi_dists

raises

QiskitError: 'Some classical bits are not used for measurements. The number of classical bits 2, the used classical bits {1}.'

What is the expected behavior?

Sampler should support calculating exact probabilities for circuits with arbitrary measurements

Suggested solutions

My understanding is that this will not be simple to fix in Aer. However, I wanted to have an open issue to refer to. In the meantime, I have created my own Sampler implementation based on Qiskit Terra's Statevector that supports mid-circuit measurements correctly: https://github.com/Qiskit-Extensions/circuit-knitting-toolbox/blob/main/circuit_knitting_toolbox/utils/simulation.py

Related Qiskit Terra issue: Qiskit/qiskit#9657

@hhorii
Copy link
Collaborator

hhorii commented May 15, 2023

As you mentioned, we need time to support quasi_dists of a dynamic circuit in Aer. Instead, I think, your ExactSample can use AerStatevector that inherits Statevector of quantum_info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants