Fix preservation of order in align_right in cirq-core/cirq/transformers/align.py#6899
Merged
dstrain115 merged 9 commits intoquantumlib:mainfrom Jan 15, 2025
Merged
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. |
Collaborator
Author
|
Seems like test hit an unrelated glitch. Can someone rerun? cc @mhucka |
Contributor
|
@daxfohl Ack, sorry I didn't see this notification sooner. I just restarted the test run. |
dstrain115
approved these changes
Jan 14, 2025
BichengYing
pushed a commit
to BichengYing/Cirq
that referenced
this pull request
Jun 20, 2025
* Fix order preservation in align_right 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`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
align_rightwas 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_leftcould 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_leftand re-reversing them prior to returning.Fixes #6727