-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 order preservation in align_right #6899
Fix order preservation in align_right #6899
Conversation
Order was not preserved for non-commutable measurements and controls in the same moment. Reversing the circuit's moments did not reverse the ops within those moments. The subsequent `align_left` could split those ops into separate moments. Then reversing the moments again would have the end result of reversing the order of those operations in the final circuit. This PR makes sure to reverse the order of ops within the moment prior to the call to `align_left`.
8ed9e80
to
0ef05bc
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6899 +/- ##
=======================================
Coverage 97.87% 97.87%
=======================================
Files 1084 1084
Lines 94420 94465 +45
=======================================
+ Hits 92409 92455 +46
+ Misses 2011 2010 -1 ☔ View full report in Codecov by Sentry. |
Seems like test hit an unrelated glitch. Can someone rerun? cc @mhucka |
@daxfohl Ack, sorry I didn't see this notification sooner. I just restarted the test run. |
align_right
was implemented as e.g.reverse(align_left(reverse(circuit.moments)))
. However this did not guarantee order preservation for non-commuting operations in the same moment. Reversing the circuit's moments did not reverse the ops within those moments. The subsequentalign_left
could split those ops into separate moments. Then reversing the moments again would have the end result of swapping the order of those operations in the final circuit.This PR ensures order is preserved, by making sure to reverse the order of ops within each moment prior to the call to
align_left
and re-reversing them prior to returning.Fixes #6727