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 nondeterminacy and a couple other issues in Circuit.insert #6997

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

Conversation

daxfohl
Copy link
Collaborator

@daxfohl daxfohl commented Jan 29, 2025

Fixes #6711, and fixes #6986 edge cases.

Instead of inserting one operation at a time, it first batches up ops by moment compatibility (see docstring for _group_into_moment_compatible). This way, the insert algorithm can first check whether any op in the batch requires a new moment to be created, and if so, preemptively create that moment before placing any of the operations from that batch. This allows it to avoid the nondeterminacy caused by the one-by-one algorithm, where one op inserted at moment[k] can inadvertently get pushed forward when a later op inserts a new moment at k.

Tests added for all documented edge cases.

@daxfohl daxfohl requested review from vtomole and a team as code owners January 29, 2025 06:11
@daxfohl daxfohl requested a review from fdmalone January 29, 2025 06:11
@CirqBot CirqBot added the size: M 50< lines changed <250 label Jan 29, 2025
Copy link

codecov bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.88%. Comparing base (116cf6e) to head (fc2acdc).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6997      +/-   ##
==========================================
- Coverage   97.89%   97.88%   -0.01%     
==========================================
  Files        1085     1085              
  Lines       95034    95107      +73     
==========================================
+ Hits        93032    93100      +68     
- Misses       2002     2007       +5     

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

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

Successfully merging this pull request may close these issues.

Circuit.insert has odd edge cases Inconsistent behavior of Default Insert Strategy
2 participants