Qiskit/qiskit-ibm-runtime

Precision and shots are not consistent for EstimatorV2

hJaffaliColibritd opened this issue · 1 comments

In the new version of the EstimatorV2, we can't anymore give the shots for the experiment, but rather the required precision. I think first that this is a mistake, you may need to let the choice to the user if he needs to perform an experiment with a very specific number of shots for specific reasons. Moreover, the required precision and the final precision may not be the same, while if we use shots, we are sure that the right number of shots will be performed.

Anyway, if we try to manually set the precision to have a corresponding number of shots, this will also not work. If we use the relation given in this line

shots = int(np.ceil(1.0 / pub.precision**2))
, by setting the precision to precision = 1/np.sqrt(required_shots), if we do the math we will exactly retrieve that shots=required_shots.

However, for some reasons, when we run some jobs online with the EstimatorV2, and we check the number of shots in the metadata, it is not exactly the same. For instance, for a number of shots required of 1234, we find out that 1280 were performed. This is maybe due to the fact that the reached precision is not the same as the required precision, or due to some truncation or rounding in the decimal part of precision.

I suggest that you put back the possibility to precise directly the number of shots, and let alo the precision option.

  • qiskit-ibm-runtime version: 0.23.0
  • Python version: 3.9.5
  • Operating system: Windows 10 Professionnel

Please see the option called default_shots here, it may be what you are looking for.

However, it also may not be exactly what you are looking for, and something that we could do a better job at documenting: if you are using twirling, either or both of gates/measurements, then it splits the provided shots, either via precision or default_shots, up into num_randomizations random circuits, and performs num_shots_per_randomization shots on each. If the number of shots is not divisible by the number of randomizations, then it will overshoot the total number of shots by the smallest amount possible. This is likely for a number like 1234. If you want exact control, then you can specify num_randomizations and num_shots_per_randomization exactly in the twirling options, or you can turn off twirling.