-
Notifications
You must be signed in to change notification settings - Fork 3
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
I()
for cupy matrices
#207
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #207 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 12 12
Lines 1121 1121
=========================================
Hits 1121 1121
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Run on QPU
|
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 was having a look at Qibo to understand why this is needed for cupy.
It appears that the identity is the only matrix in Qibo alongside Unitary
that we don't cast using _cast
.
https://github.com/qiboteam/qibo/blob/415d98a350af864ca5e02ef52b8ed295138a3b26/src/qibo/backends/npmatrices.py#L66-L67
At this point shouldn't it be better to just cast the identity in Qibo to avoid to redefine it here?
Eventually by casting also Unitary
I believe that we can remove also Unitary
from CupyMatrices
.
Yeah, that might be a solution as well. The only counterargument that I would see is that you are introducing a cast that often is not needed, and in some cases it does not matter much because there's not much to do anyway, but for pytorch for instance: |
I agree we should try to make better use of the standardized array API, and avoiding casting as much as possible. However, here almost all the matrices are being cast, and only one 2x2 is left plain. I'd say that @andrea-pasquale's proposal is pretty practical... We're always in time to prevent casting truly leveraging the analogous calls (i.e. what you were doing with CuPy was exactly the same code of the NumPy one), but this is something to properly face in a separate effort. |
Now that you mention it I remember that when I looked at the Jax backend casting everything was one of the main bottlenecks... From one side as @alecandido said casting everything is more practical but it comes at the cost of worst performances. Therefore either we accept these "worst performances" or if we want better performances we should duplicate the For the time being we can merge this PR as it is. |
Actually, what I was mentioning before was a win-win alternative: As you can see: cp.eye(n, dtype=self.dtype) is practically the same of np.eye(n, dtype=self.dtype) This is often the case for these functions, and not by chance. The project mention above is a joint agreement to standardize this API. I believe NumPy mostly completed his share with NumPy 2. But, as said, this would take more time, because we also need to check at which point the other projects are in the adoption, and "cast the difference". Let's postpone this. |
This is an add on for #199, which makes
I
acupy
array as well. Should also fix the tests of qiboteam/qibo#1548.