Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

daxfohl
Copy link
Collaborator

@daxfohl daxfohl commented Dec 30, 2024

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 subsequent align_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

@daxfohl daxfohl requested review from vtomole and a team as code owners December 30, 2024 12:50
@daxfohl daxfohl requested a review from viathor December 30, 2024 12:50
@CirqBot CirqBot added the size: S 10< lines changed <50 label Dec 30, 2024
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`.
@daxfohl daxfohl force-pushed the fix-align-right-order-preservation branch from 8ed9e80 to 0ef05bc Compare December 30, 2024 12:51
Copy link

codecov bot commented Dec 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.86%. Comparing base (06f12b9) to head (51f4870).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6899      +/-   ##
==========================================
- Coverage   97.86%   97.86%   -0.01%     
==========================================
  Files        1084     1084              
  Lines       94225    94301      +76     
==========================================
+ Hits        92215    92287      +72     
- Misses       2010     2014       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@daxfohl
Copy link
Collaborator Author

daxfohl commented Jan 1, 2025

Seems like test hit an unrelated glitch. Can someone rerun? cc @mhucka

@mhucka
Copy link
Contributor

mhucka commented Jan 2, 2025

@daxfohl Ack, sorry I didn't see this notification sooner. I just restarted the test run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: S 10< lines changed <50
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect behaviour when inserting classical control circuit element, causing ValueError
3 participants