Repository navigation
Sum VF2Layout average errors in a deterministic order - #16732
Merged
Julien Gacon (Cryoris) merged 3 commits intoAug 13, 2026
Merged
Conversation
`build_average_error_map` summed per-qubit gate errors while iterating the `HashSet` returned by `Target::operation_names_for_qargs`, whose order is randomized per call. Floating-point addition is non-associative, so the averaged error -- and therefore the `VF2Layout` score of two symmetric layouts -- varied between runs. On a target with control-flow support and a symmetric coupling map this made the selected layout, and hence the 1q-gate count and depth of the output circuit, non-deterministic. Sort the operation names before summing so the result is reproducible. Fixes Qiskit#16490. Signed-off-by: Sophia Wen <hfwen@us.ibm.com> (cherry picked from commit 8ea89ab)
Collaborator
|
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the following people are relevant to this code:
|
β¦4e6f0a1c3d57.yaml Co-authored-by: Julien Gacon <gaconju@gmail.com>
β¦4e6f0a1c3d57.yaml
Julien Gacon (Cryoris)
approved these changes
Aug 13, 2026
Julien Gacon (Cryoris)
enabled auto-merge
August 13, 2026 13:21
Contributor
|
We discussed offline to merge this w/o a dedicated test, which proved to be quite tricky. The fix is verified locally and we're tracking adding a proper test in #16760. |
1 task done
1 of 3 tasks
Ian Hincks (ihincks)
added a commit
to ihincks/qiskit-terra
that referenced
this pull request
Aug 13, 2026
Ian Hincks (ihincks)
added a commit
to ihincks/qiskit-terra
that referenced
this pull request
Aug 13, 2026
β¦Qiskit#16732)"" This reverts commit e71c5a5.
xmirya
pushed a commit
to qollabxyz/qiskit
that referenced
this pull request
Aug 13, 2026
β¦iskit#16761) * Sum VF2Layout average errors in a deterministic order `build_average_error_map` summed per-qubit gate errors while iterating the `HashSet` returned by `Target::operation_names_for_qargs`, whose order is randomized per call. Floating-point addition is non-associative, so the averaged error -- and therefore the `VF2Layout` score of two symmetric layouts -- varied between runs. On a target with control-flow support and a symmetric coupling map this made the selected layout, and hence the 1q-gate count and depth of the output circuit, non-deterministic. Sort the operation names before summing so the result is reproducible. Fixes Qiskit#16490. (cherry picked from commit 8ea89ab) * Update releasenotes/notes/fix-vf2layout-nondeterminism-error-sum-2b8d4e6f0a1c3d57.yaml * Update releasenotes/notes/fix-vf2layout-nondeterminism-error-sum-2b8d4e6f0a1c3d57.yaml --------- (cherry picked from commit b3716b5) Signed-off-by: Sophia Wen <hfwen@us.ibm.com> Co-authored-by: Sophia Wen <h_f_wen@yahoo.com> Co-authored-by: Julien Gacon <gaconju@gmail.com>
1 of 3 tasks
pull Bot
pushed a commit
to AmirulAndalib/qiskit
that referenced
this pull request
Aug 14, 2026
β¦6762) * Add a unit test for 16732 * Revert "Sum VF2Layout average errors in a deterministic order (Qiskit#16732)" This reverts commit b3716b5. * Revert "Revert "Sum VF2Layout average errors in a deterministic order (Qiskit#16732)"" This reverts commit e71c5a5.
VedantMahadik-qc
pushed a commit
to VedantMahadik-qc/qiskit
that referenced
this pull request
Oct 21, 2026
* Sum VF2Layout average errors in a deterministic order `build_average_error_map` summed per-qubit gate errors while iterating the `HashSet` returned by `Target::operation_names_for_qargs`, whose order is randomized per call. Floating-point addition is non-associative, so the averaged error -- and therefore the `VF2Layout` score of two symmetric layouts -- varied between runs. On a target with control-flow support and a symmetric coupling map this made the selected layout, and hence the 1q-gate count and depth of the output circuit, non-deterministic. Sort the operation names before summing so the result is reproducible. Fixes Qiskit#16490. Signed-off-by: Sophia Wen <hfwen@us.ibm.com> (cherry picked from commit 8ea89ab) * Update releasenotes/notes/fix-vf2layout-nondeterminism-error-sum-2b8d4e6f0a1c3d57.yaml Co-authored-by: Julien Gacon <gaconju@gmail.com> * Update releasenotes/notes/fix-vf2layout-nondeterminism-error-sum-2b8d4e6f0a1c3d57.yaml --------- Signed-off-by: Sophia Wen <hfwen@us.ibm.com> Co-authored-by: Julien Gacon <gaconju@gmail.com>
VedantMahadik-qc
pushed a commit
to VedantMahadik-qc/qiskit
that referenced
this pull request
Oct 21, 2026
β¦6762) * Add a unit test for 16732 * Revert "Sum VF2Layout average errors in a deterministic order (Qiskit#16732)" This reverts commit b3716b5. * Revert "Revert "Sum VF2Layout average errors in a deterministic order (Qiskit#16732)"" This reverts commit e71c5a5.
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.
Summary
Fixes the non-deterministic
optimization_level=2transpiler output reported in #16490: with afixed circuit, backend, and
seed_transpiler, the 1-qubit gate count and depth varied run-to-run(the 2-qubit count stayed stable) on a
Targetthat has control flow and a symmetric couplingmap.
Details and comments
Root cause (full analysis in #16490):
build_average_error_mapinVF2Layoutsummed each qubit'sper-operation gate errors while iterating the
HashSetreturned byTarget::operation_names_for_qargs, whose iteration order is randomized per call. Floating-pointaddition is not associative, so two symmetric layouts scored Ξ΅-apart in a non-deterministic
direction, and VF2's strictly-decreasing comparison then picked one of the two symmetric embeddings
~50/50 per run. The chosen layout deterministically fixes the resulting 1q-gate count and depth
(which is why the 2q count β unaffected by a symmetric relabel β stayed stable, and why both
control_flow=Trueandmake_symmetric()are required to trigger it).The fix is the short-term direct VF2 change preferred by Jake Lishman (@jakelishman) and Matthew Treinish (@mtreinish) in the issue
(commit 8ea89ab): collect the operation names into a
Vec,sort_unstable(), and sum in that stableorder. No public API change β
operation_names_for_qargsstill returns a set.Per the issue discussion, this is a candidate for backport to 2.5.2.
Fixes #16490.
AI/LLM disclosure
Code; a human authored and reviewed the change. The fix was validated locally with the Rust and
Python transpiler test suites (no regressions) when developed, and cherry-picks cleanly onto
current
mainfor this PR.