-
Notifications
You must be signed in to change notification settings - Fork 61
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
Fix root cause of bug reported in PR #1412 #1417
Conversation
qrange = np.arange(nqubits - 1, -1, -1, dtype=np.int32) | ||
samples = self.to_numpy(samples) | ||
return np.mod(np.right_shift(samples[:, None], qrange), 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't all the other operations in here still NumPy? Or is Torch automatically converting NumPy calls?
I expected self.np.
usage, but instead there is np.
everywhere...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried self.np
and it creates other issues because torch.arange
and torch.right_shift
work slightly differently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But is np.right_shift()
able to work on Torch tensors? (i.e. taking Torch tensors as input and returning them as output)
I see it could be vaguely possible, but it's still good to know, because I wouldn't have been confident to say it's actually able.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In [6]: import numpy as np
...: import torch
...:
...: x = torch.Tensor(torch.arange(10))
...: qrange = np.arange(10 - 1, -1, -1, dtype=np.int32)
...: type(np.right_shift(x[:, None], qrange))
Out[6]: torch.Tensor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that by now this starts being reliable
https://numpy.org/doc/stable/user/basics.interoperability.html#operating-on-foreign-objects-without-converting
https://numpy.org/neps/nep-0018-array-function-protocol.html#nep18
(ok, most likely since a while, but it is for sure framework-dependent, I should take the time of assessing which ones are fully supporting it)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1417 +/- ##
==========================================
- Coverage 99.94% 99.94% -0.01%
==========================================
Files 78 78
Lines 11225 11224 -1
==========================================
- Hits 11219 11218 -1
Misses 6 6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
The root cause of the issue raised in #1412 was a
cast
tonumpy
insideNumpyBackend.samples_to_binary
. That is what was turning the subsequentcast
into a requirement fortorch
. Without the former, the latter could be removed.Checklist: