Open garrison opened 1 year ago
main
Sampler with shots=None only works if each classical bit is set by a measurement at the end of the circuit.
shots=None
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}.'
Sampler should support calculating exact probabilities for circuits with arbitrary measurements
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
Statevector
Related Qiskit Terra issue: https://github.com/Qiskit/qiskit-terra/issues/9657
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.
quasi_dists
ExactSample
AerStatevector
Informations
main
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
raises
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.pyRelated Qiskit Terra issue: https://github.com/Qiskit/qiskit-terra/issues/9657