Skip to content

Fix non-determinism in CommutativeCancellation #14763

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jakelishman
Copy link
Member

The use of HashMap and HashSet for internal tracking structures in the pass, which were subsequently iterated over, caused node removals to happen in a non-deterministic order, which in turn could cause the edge structure of the DAGCircuit to be non-deterministic. This did not affect a topological iteration over the nodes when canonicalised by the qargs and cargs, but passes (such as Rust-space Sabre) that iterate over the edge structure themselves can observe the non-determinism.

Sabre wants to iterate over the edges itself because, as a routing algorithm, it is implementing its own coroutine variant of topological ordering on a related graph.

Summary

Details and comments

No test currently, because how I write it depends on whether we take #14762 or not. I manually verified that this PR fixes the current determinism issue in the ASV benchmark QUEKOTranspilerBench.track_depth_bss_optimal_depth_100.

The use of `HashMap` and `HashSet` for internal tracking structures in
the pass, which were subsequently iterated over, caused node removals
to happen in a non-deterministic order, which in turn could cause the
edge structure of the `DAGCircuit` to be non-deterministic.  This did
not affect a topological iteration over the nodes when canonicalised by
the `qargs` and `cargs`, but passes (such as Rust-space Sabre) that
iterate over the edge structure themselves can observe the
non-determinism.

Sabre wants to iterate over the edges itself because, as a routing
algorithm, it is implementing its own coroutine variant of topological
ordering on a related graph.
@jakelishman jakelishman added Changelog: Bugfix Include in the "Fixed" section of the changelog mod: transpiler Issues and PRs related to Transpiler labels Jul 19, 2025
@coveralls
Copy link

Pull Request Test Coverage Report for Build 16383505829

Details

  • 6 of 6 (100.0%) changed or added relevant lines in 3 files are covered.
  • 17 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.003%) to 87.763%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 93.63%
crates/circuit/src/symbol_expr.rs 3 73.9%
crates/qasm2/src/parse.rs 6 97.09%
crates/qasm2/src/lex.rs 7 91.24%
Totals Coverage Status
Change from base Build 16327707788: -0.003%
Covered Lines: 81471
Relevant Lines: 92831

💛 - Coveralls

@jakelishman jakelishman added this to the 2.2.0 milestone Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog mod: transpiler Issues and PRs related to Transpiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants