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 in Circuit.insert (simplified) #7043

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

Conversation

daxfohl
Copy link
Collaborator

@daxfohl daxfohl commented Feb 7, 2025

#6997 was a PR to fix all edge cases of #6986, but the behavior change was significant enough to be concerning. This PR replaces it with the minimum changes to fix only those edge cases that are outright bugs, without breaking any existing tests or causing possible behavior changes to 'oddities'.

Fixes #6711, and fixes #6986 edge cases that caused the bug due to order dependency: test_3 will now produce a result equal to that of test_4, and test_5 output will now equal that of test_6. Also fixes the bug test_2 where EARLIEST is not performed. The behaviors in test_1 and test_7 will remain as-is for now, and we can decide later whether we want to change those behaviors or not. (This PR description will close that issue; if we want to change those behaviors, open a new issue specific to them).

Implementation description from #6997 still applies:

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.

The diff from #6997 can be seen in commit 577f9c0

@daxfohl daxfohl requested review from vtomole and a team as code owners February 7, 2025 20:35
@daxfohl daxfohl requested a review from viathor February 7, 2025 20:35
@CirqBot CirqBot added the size: M 50< lines changed <250 label Feb 7, 2025
Copy link

codecov bot commented Feb 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.17%. Comparing base (e2de439) to head (5614fb2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7043      +/-   ##
==========================================
- Coverage   98.17%   98.17%   -0.01%     
==========================================
  Files        1087     1087              
  Lines       94722    94784      +62     
==========================================
+ Hits        92992    93052      +60     
- Misses       1730     1732       +2     

☔ 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