-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Probabilities do not sum to 1 #517
Comments
The problem involves all kind of measurements, with a very strange behavior:
If Is anyone able to reproduce this error? Note that you need to plot probabilities directly or revert #460, otherwise no error is raised for standard measurements (but it still appears with collapse gates). |
I prepared a code snippet to isolate the problem. It doesn't even need qibo, only numpy.
It looks like that summing over the first 25 or more axis in one step gives unexpected results. |
Thank you very much for identifying this and the very detailed investigation. The numpy script is a bit crazy but I can reproduce it. It seems like a precision issue to me. For example, try the following: import numpy as np
n = 26
t = 1
x = (np.random.random(2 ** n) ** 2 / 2 ** (n / 2)).astype(np.float32)
x = np.reshape(x, (2 ** (n - t), 2 ** t))
print(np.sum(x))
print(np.sum(np.sum(x, axis=0)))
print(np.sum(np.sum(x, axis=1))) This is just calculating the sum of a random |
@mlazzarin could you please open an issue in numpy with this short example? |
Done, see numpy/numpy#20458 . |
It looks like it's a precision issue indeed. The fact that the different sum order gives different results is actually documented in Numpy's doc.
When I have some spare time, I'll try to figure out how to cope with this problem in Qibo. |
Ok, then one possibility is to avoid the axis and write explicitly the sum of each array column. |
I have a very interesting bug to report. If I run the following circuit with
NQUBITS>=26
andTARGET>=25
:I obtain the following error:
Additional details:
TARGET >= 25
. IfTARGET < 25
, the problem disappears.The main issue appears here:
qibo/src/qibo/core/states.py
Lines 78 to 83 in fe91300
In line 82, state is normalized, but then after the call to
K.sum
, we obtain a probability distribution which is not normalized.I will investigate this issue further, in particular I'm curious to see if there is the same problem with non-collapse measurements.
The text was updated successfully, but these errors were encountered: