You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
before performing rng.choice seems to solve the problem, but I guess the question is whether we're happy with this solution. Maybe we could add a check to see in the norm is "almost 1" and only re-normalize if it's sufficiently close.
**Context:** When computing the `expval` of an operator using a quantum
device with the `torch` interface and `default_dtype` set to
`torch.float32`, the probabilities do not sum to one. This error does
not occur if `default_dtype` is set to `torch.float64`.
**Description of the Change:** A renormalization of probabilities is
introduced to overcome the issue. Such renormalization of probabilities
occurs whenever the following two conditions are satisfied: 1) There is
at least one probability that does not sum precisely to one, and 2) Such
difference for all probabilities is between `0` and `1e-07`.
**Benefits:** The error is not raised anymore.
**Possible Drawbacks:** The main drawback is that renormalization can
occur in cases where it should not happen, although it is unlikely since
the cutoff `1e-07` is expected to be reasonably small to prevent such
cases (but large enough not to raise the error anymore).
**Related GitHub Issues:** #5444
[sc-59957]
Expected behavior
The following code executes regardless of whether the Torch dtype is float64 or float32.
Actual behavior
Error.
Additional information
No response
Source code
Tracebacks
ValueError: probabilities do not sum to 1
System information
Existing GitHub issues
The text was updated successfully, but these errors were encountered: