Skip to content

fix(dagcircuit): avoid copying global_phase into layer DAGs#16565

Open
92meharali wants to merge 1 commit into
Qiskit:mainfrom
92meharali:fix/basic-swap-global-phase-16271
Open

fix(dagcircuit): avoid copying global_phase into layer DAGs#16565
92meharali wants to merge 1 commit into
Qiskit:mainfrom
92meharali:fix/basic-swap-global-phase-16271

Conversation

@92meharali

Copy link
Copy Markdown

Problem

BasicSwap could inflate global_phase when rebuilding a circuit from
DAGCircuit.serial_layers(), even when no swaps were inserted (#16271).

Root Cause

layers() and serial_layers() created each layer DAG with
copy_empty_like(), which copied the parent global_phase. Composing those
layer DAGs back together accumulated the phase once per layer.

Solution

Reset global_phase to zero on layer DAGs returned by layers() and
serial_layers(), matching the existing pattern in separable_circuits().

Tests Added

  • test_serial_layers_do_not_copy_global_phase
  • test_layers_do_not_copy_global_phase
  • test_preserves_global_phase (BasicSwap, no swaps)
  • test_preserves_global_phase_when_swaps_inserted (BasicSwap, with swap)

Fixes #16271

AI/LLM disclosure

  • I used Cursor (agent) to help implement and test-plan this fix.
  • I reviewed the diff, traced the failure through serial_layers()compose(),
    and verified the fix matches the existing separable_circuits() pattern.

@92meharali
92meharali requested a review from a team as a code owner July 10, 2026 15:07
@92meharali
92meharali requested a review from jeevan0920 July 10, 2026 15:07
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jul 10, 2026
@qiskit-bot

Copy link
Copy Markdown
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:

  • @Qiskit/terra-core

@Cryoris

Cryoris commented Jul 10, 2026

Copy link
Copy Markdown
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.

@Cryoris Cryoris added the on hold Can not fix yet label Jul 10, 2026
@92meharali

Copy link
Copy Markdown
Author

Thanks @Cryoris understood. I'll hold off and wait for #16362 to land first. Happy to help review or iterate if needed once that PR is active again.

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
92meharali force-pushed the fix/basic-swap-global-phase-16271 branch from dd5ba07 to b7a265b Compare July 21, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community PR PRs from contributors that are not 'members' of the Qiskit repo on hold Can not fix yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

BasicSwap silently inflates circuit global_phase

3 participants