Skip to content

Fix nested control-flow padding state - #3076

Open
sankalpsthakur wants to merge 4 commits into
Qiskit:mainfrom
sankalpsthakur:fix-3005-block-base-padder
Open

Fix nested control-flow padding state#3076
sankalpsthakur wants to merge 4 commits into
Qiskit:mainfrom
sankalpsthakur:fix-3005-block-base-padder

Conversation

@sankalpsthakur

@sankalpsthakur sankalpsthakur commented Jul 22, 2026

Copy link
Copy Markdown

Summary

Fix nested control-flow padding so traversal state stays scoped to the block being visited and rebuilt control-flow operations retain their scheduled block index.

Details and comments

BlockBasePadder reused _idle_after and _current_block_idx while recursively visiting nested blocks. A nested visit could therefore overwrite the parent block's timing state. The control-flow rebuild path also dropped the scheduled block index, and the final fast-path barrier call passed its time and block arguments in the wrong order.

This change preserves and restores parent traversal state, carries the scheduled index through rebuilt control-flow operations, and corrects the barrier arguments. Focused regressions cover nested branch traversal and the final fast-path barrier.

Validation:

  • pytest -q test/unit/transpiler/passes/scheduling/test_scheduler.py test/unit/transpiler/passes/scheduling/test_dynamical_decoupling.py (159 passed)
  • Ruff lint and format checks
  • mypy on the changed scheduling and test modules
  • Towncrier draft rendering
  • git diff --check

Fixes #3077

This is the focused control-flow metadata subset originally catalogued in #3005; the separate idle-qubit detection bug in #3005 remains outside this PR.

Why this matters

Corrupted scheduling metadata in dynamic circuits can shift control-flow start times and attach barriers to the wrong block. That breaks downstream padding and decoupling passes silently — the kind of bug that only surfaces on nested if_test/while circuits.

Related

AI/LLM disclosure

  • I didn't use LLM tooling, or only used it privately.
  • I used OpenAI Codex and Cursor to help write this PR description.
  • I used OpenAI Codex and Cursor to generate or modify code, tests, and release-note documentation.

@TsafrirA

Copy link
Copy Markdown
Collaborator

@sankalpsthakur could you open an issue with a bug report explaining what's the issue you're encountering?

@sankalpsthakur

Copy link
Copy Markdown
Author

Opened #3077 with a runnable reproduction and scoped it to the control-flow metadata bugs fixed here. I updated this PR to close #3077, kept #3005 open for its separate idle-qubit detection bug, and renamed the release-note fragment accordingly. Thanks for flagging this.

@sankalpsthakur
sankalpsthakur force-pushed the fix-3005-block-base-padder branch 3 times, most recently from dbace93 to a4372c4 Compare July 28, 2026 10:09
Tool attribution belongs in the PR description and commit trailers, not as
inline comments in library and test code. The AI/LLM disclosure checkboxes
in the PR body are unchanged.
@sankalpsthakur
sankalpsthakur force-pushed the fix-3005-block-base-padder branch from 601a1b8 to 147b5cf Compare July 31, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BlockBasePadder corrupts scheduling metadata for rebuilt control-flow operations

2 participants