Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.13k stars 2.35k forks source link

Bring back exact probabilities for SamplerV2. #12849

Open ziechys opened 2 months ago

ziechys commented 2 months ago

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.

t-imamichi commented 2 months ago

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

Cryoris commented 1 month ago

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.