-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow '_mixture_' to return gates instead of just raw unitary matrices #7048
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7048 +/- ##
==========================================
- Coverage 98.66% 98.65% -0.01%
==========================================
Files 1106 1106
Lines 95914 95869 -45
==========================================
- Hits 94630 94581 -49
- Misses 1284 1288 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Looks great, thank you!
Please see comments before merging. (Non essential feel free to skip them)
Labeling as BREAKING since unit tests had to change. However the unit test were artificial, returning strings from the mixture implementation. I can't think of any real-world thing this would break. |
quantumlib#7048) * Allow gates to be returned from _mixture_ * Add test * lint * coverage * mypy * Make ReturnsUnitary return unitary
Fixes #1657
Updates everywhere
_mixture_
is called, to ensure gates can be handled. ChangesBitFlip
to be a mixture ofX
andI
gates as an example.Also updates
apply_mixture
to take advantage of this. Currentlyapply_mixture
callsmixture()
and passes the results toapply_unitary
one-by-one. But sincemixture()
converts the gates now returned by_mixture_
to unitaries, that prevents it from being able to use the more efficient_apply_unitary_
strategies that the gate itself may provide. This PR changesapply_mixture
to use the values returned by_mixture_
directly instead, allowing for the optimizations of those gates have them.Some of the code could be simplified if we did #7039 (plus allowing
unitary(val: <raw np unitary>) => val
), but that's purely aesthetics. (Side note: the three different protocols are each implemented with slightly different styles; it might be good to standardize on one).Note: since the mixture protocol now converts non-numpy return values to unitaries, the existing unit tests that used strings
'a'
and'b'
no longer work, and had to be changed to proper unitaries. That shouldn't be a problem in any real-world use.