-
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
Add sparse_encoder
to models.encodings
#1591
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1591 +/- ##
=======================================
Coverage 99.11% 99.11%
=======================================
Files 77 77
Lines 11475 11571 +96
=======================================
+ Hits 11373 11469 +96
Misses 102 102
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Can I merge that one into this one and make it just one PR then? |
Making functions in `models.encodings` backend-aware
@BrunoLiegiBastonLiegi @AlejandroSopena all tests in |
I lied. It's fixed now. |
Run on QPU
|
_data_test = data[0][1] | ||
_data_test = ( | ||
_data_test.dtype if "array" in str(type(_data_test)) else type(_data_test) | ||
) |
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.
_data_test = data[0][1] | |
_data_test = ( | |
_data_test.dtype if "array" in str(type(_data_test)) else type(_data_test) | |
) | |
_data_test = ( | |
_data_test.dtype if "array" in str(type(data[0][1])) else type(data[0][1]) | |
) |
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 didn't want to do that to not call data[0][1]
three times in the same line
# TODO: Fix this mess with qibo native dtypes | ||
try: | ||
type_test = bool("int" in str(data[0][0].dtype)) | ||
except AttributeError: | ||
type_test = bool("int" in str(type(data[0][0]))) |
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.
yeah indeed I think it's time we address this because it's extremely tedious.
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.
Maybe this is a good issue for the unitaryHACK
@alecandido @AlejandroSopena
thetas = _generate_rbs_angles( | ||
_data_sorted, architecture="diagonal", backend=backend | ||
) | ||
phis = backend.np.zeros(len(thetas) + 1) |
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.
This may be failing with CupyBackend
as backend.np
is numpy
and not cupy
. Or better, it may not fail but it most likely won't use cupy
arrays, and thus GPU.
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.
This fix, in my opinion, is to be done outside of this PR. I have been thinking of refactoring this part of the backends as something like backend.engine
or backend.platform
(or even backend.math
) and drop backend.np
entirely from every backend.
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.
Yeah yeah I agree, just pointing out here, if you want to simply patch it here you could just do a backend.cast
even though it's not the cleanest solution...
for qubit, bit in enumerate(bitstrings_sorted[0]): | ||
if bit == 1: | ||
touched_qubits.append(qubit) | ||
touched_qubits.append(int(qubit)) |
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.
Do you actually need the explicit cast to int, enumerate should produce an int in any case I believe. In any case, if bitstring_sorted
is a int8
np array you could probably just do
touched_qubits = (bitstrings_sorted[0] == 1).nonzero()[0]
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.
Yes, the cast to int needs to be explicit because of the GPU backends.
list(backend.np.argsort(b_0)[-hw_0:]), | ||
list(backend.np.argsort(b_1)[-hw_1:]), | ||
) | ||
ones, new_ones = {int(elem) for elem in ones}, {int(elem) for elem in new_ones} |
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.
Can't you just do
ones, new_ones = {int(elem) for elem in ones}, {int(elem) for elem in new_ones} | |
ones, new_ones = set(ones), set(new_ones) |
?
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.
This doesn't work again because of GPU backends. The elements are unhashable without the explicit casting to int
.
if qubit not in touched_qubits: | ||
touched_qubits.append(qubit) | ||
touched_qubits.append(int(qubit)) |
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.
touched_qubits.append(int(qubit)) | |
touched_qubits.append(qubit) |
qubit should already be an int, as you just casted it
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.
They need to be actual int
s instead of cp.int8
otherwise some other errors are raised down the line.
Co-authored-by: BrunoLiegiBastonLiegi <[email protected]>
Run on QPU
|
This is based on Section IV of https://arxiv.org/abs/2405.20408
Depends on qiboteam/qibojit#220
Checklist: