qiskit icon indicating copy to clipboard operation
qiskit copied to clipboard

Bring back exact probabilities for SamplerV2.

Open ziechys opened this issue 1 year ago • 2 comments

What should we add?

In the old primitives, it was possible to obtain ideal results, i.e. exact probabilities with the Sampler by setting shots to zero or None. This option is gone with the new SamplerV2 and a default shot number is always chosen. This is quite disruptive to common quantum workflows of, e.g., pre-optimizing a parametrized quantum circuit classically or testing algorithms efficiently.

ziechys avatar Jul 30 '24 08:07 ziechys

FYI: Here is the context why the change is introduced. https://github.com/Qiskit/RFCs/blob/master/0016-sampler-interface.md#motivation-

t-imamichi avatar Aug 02 '24 07:08 t-imamichi

FWIW you can always use qiskit.quantum_info.Statevector to get the exact probabilities, like

from qiskit.quantum_info import Statevector

probs = Statevector(your_circuit).probabilities_dict()  # {"0..": prob, ... }

which you could even wrap into the PrimitivesV2 interface to use a plugin replacement.

Cryoris avatar Aug 16 '24 07:08 Cryoris

We can't add new semantics to an existing option on a general interface definition, though there's nothing stopping something like Aer's implementation of the V2 primitives from having an extra entry point that does this. That said, Aer still offers direct-access backends, which is probably what the Aer team would suggest to do if this passed to them.

I'll close this now, as there's nothing we can do in the core repo about it without breaking the interface definition. Feel free to re-open or take elsewhere if there's more to discuss.

jakelishman avatar Nov 01 '24 21:11 jakelishman