fix(dagcircuit): avoid copying global_phase into layer DAGs#16565
Open
92meharali wants to merge 1 commit into
Open
fix(dagcircuit): avoid copying global_phase into layer DAGs#1656592meharali wants to merge 1 commit into
92meharali wants to merge 1 commit into
Conversation
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:
|
Contributor
|
#16362 is an existing and more complete fix, I would give the author a chance to finish that work first. If that doesn't work out we can consider this one instead. |
Author
Zero the global phase on DAGs returned by layers() and serial_layers() so composing them does not accumulate the parent phase multiple times. Add regression tests for BasicSwap and the layer methods. Fixes Qiskit#16271
92meharali
force-pushed
the
fix/basic-swap-global-phase-16271
branch
from
July 21, 2026 21:43
dd5ba07 to
b7a265b
Compare
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.
Problem
BasicSwapcould inflateglobal_phasewhen rebuilding a circuit fromDAGCircuit.serial_layers(), even when no swaps were inserted (#16271).Root Cause
layers()andserial_layers()created each layer DAG withcopy_empty_like(), which copied the parentglobal_phase. Composing thoselayer DAGs back together accumulated the phase once per layer.
Solution
Reset
global_phaseto zero on layer DAGs returned bylayers()andserial_layers(), matching the existing pattern inseparable_circuits().Tests Added
test_serial_layers_do_not_copy_global_phasetest_layers_do_not_copy_global_phasetest_preserves_global_phase(BasicSwap, no swaps)test_preserves_global_phase_when_swaps_inserted(BasicSwap, with swap)Fixes #16271
AI/LLM disclosure
serial_layers()→compose(),and verified the fix matches the existing
separable_circuits()pattern.