-
Notifications
You must be signed in to change notification settings - Fork 586
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
Micro-optimize basis state conversion #1088
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1088 +/- ##
=======================================
Coverage 97.73% 97.73%
=======================================
Files 154 154
Lines 11679 11681 +2
=======================================
+ Hits 11414 11416 +2
Misses 265 265 ☔ View full report in Codecov by Sentry. |
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.
Let me grab a before/after benchmark from asv
unraveled_indices = [2] * len(device_wires) | ||
indices = np.ravel_multi_index(samples.T, unraveled_indices) | ||
powers_of_two = 2 ** np.arange(len(device_wires))[::-1] | ||
indices = samples @ powers_of_two |
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 is very clever!
Co-authored-by: Chase Roberts <chase@xanadu.ai>
Context:
Description of the Change:
QubitDevice
, replacing the current conversion logic with one that works for > 32 qubits.Benefits:
Samples can now be processed if the devices has more than 32 qubits
The new logic is easier to read and understand than
np.ravel_multi_index
The new logic is ever so slightly faster:
Possible Drawbacks:
There are two other places where
np.ravel_multi_index
is used:default.qubit
, when applying a statevector to a subset of wiresdefault.mixed
, same as above.It might be worth exploring if a better implementation can be used here as well.
Related GitHub Issues: n/a