Skip to content

dagcircuit: transfer DAG-level variables in substitute_node_with_dag - #15542

Merged
Raynel Sanchez (raynelfss) merged 16 commits into
Qiskit:mainfrom
arnavk23:fix-15509-substitute-node-variables
Aug 11, 2026
Merged

Raynel Sanchez (raynelfss) merged 16 commits into
Qiskit:mainfrom
arnavk23:fix-15509-substitute-node-variables

Conversation

@arnavk23

@arnavk23 Arnav Kapoor (arnavk23) commented Jan 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes missing variable/stretches when the replacement DAG carries declarations (e.g., for control-flow conditions/targets).
Adds tests for input-vars and captured/declared-vars transfer.
Includes a release note.
Closes #15509.

AI/LLM disclosure

  • I didn't use LLM tooling, or only used it privately.
  • I used the following tool to help write this PR description:
  • I used the following tool to generate or modify code:

…ixes Qiskit#15509)\n\n- Add input/captured/declared vars and stretches from replacement DAG\n- Add tests verifying input vars and captured/declared vars transfer\n- Add release note entry
@arnavk23
Arnav Kapoor (arnavk23) requested a review from a team as a code owner January 9, 2026 22:29
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jan 9, 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

@arnavk23 Arnav Kapoor (arnavk23) changed the title dagcircuit: transfer DAG-level variables in substitute_node_with_dag (fixes #15509) dagcircuit: transfer DAG-level variables in substitute_node_with_dag Jan 9, 2026
@arnavk23 Arnav Kapoor (arnavk23) changed the title dagcircuit: transfer DAG-level variables in substitute_node_with_dag dagcircuit: transfer DAG-level variables in substitute_node_with_dag Jan 9, 2026
Previously, substitute_node_with_dag() would try to add all variables
from the replacement DAG, including those already present in the target
DAG. This violated the constraint that a DAG cannot have both input and
captured variables simultaneously when the same variable object appears
in both contexts.

Now check if each variable is already present before adding it, matching
the behavior of compose() with inline_captures=False.
@coveralls

Coveralls (coveralls) commented Jan 9, 2026 •

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 21313279594

Details

  • 15 of 25 (60.0%) changed or added relevant lines in 1 file are covered.
  • 19 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.02%) to 87.972%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/circuit/src/dag_circuit.rs 15 25 60.0%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 3 92.8%
crates/qasm2/src/parse.rs 6 97.63%
crates/circuit/src/parameter/symbol_expr.rs 10 72.99%
Totals Coverage Status
Change from base Build 21278844666: -0.02%
Covered Lines: 100065
Relevant Lines: 113746

πŸ’› - Coveralls

@arnavk23

Copy link
Copy Markdown
Contributor Author

Alexander Ivrii (@alexanderivrii) can you also look through this and if this is okay add this to the 2.4.0 list for reviewers to review this pr. Thank you for all your help and feedback.

@alexanderivrii Alexander Ivrii (alexanderivrii) added this to the 2.4.0 milestone Feb 8, 2026
@github-project-automation github-project-automation Bot moved this to Ready in Qiskit 2.4 Feb 8, 2026
@alexanderivrii Alexander Ivrii (alexanderivrii) added the Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. label Feb 8, 2026
@raynelfss

Raynel Sanchez (raynelfss) commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Hello Arnav Kapoor (@arnavk23), please add this snippet to your PR description as it is now required by anyone contributing to Qiskit to disclose any usage of Generative AI in your code (even if you don't use it, you must declare it).

### AI/LLM disclosure

- [ ] I didn't use LLM tooling, or only used it privately.
- [ ] I used the following tool to help write this PR description:
- [ ] I used the following tool to generate or modify code:

<!-- Any code generated by LLM or modified from LLM suggestions must commented inline too. -->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be about ready to merge. I just really have one more test suggestion.

Comment thread crates/circuit/src/dag_circuit.rs Resolved
…e check was failing because the node variable substitution was not being applied correctly in the dagcircuit code. This commit fixes that issue by ensuring that the node variable substitution is applied correctly when checking for node variables in the dagcircuit code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more comments!

@raynelfss Raynel Sanchez (raynelfss) added the stable backport potential Make Mergify open a backport PR to the most recent stable branch on merge. label Aug 11, 2026
@raynelfss
Raynel Sanchez (raynelfss) added this pull request to the merge queue Aug 11, 2026
Merged via the queue into Qiskit:main with commit f671c03 Aug 11, 2026
32 checks passed
@arnavk23
Arnav Kapoor (arnavk23) deleted the fix-15509-substitute-node-variables branch August 11, 2026 20:44
Mohamedma96 pushed a commit to Mohamedma96/qiskit that referenced this pull request Aug 13, 2026
Qiskit#15542)

* dagcircuit: transfer DAG-level variables in substitute_node_with_dag (fixes Qiskit#15509)\n\n- Add input/captured/declared vars and stretches from replacement DAG\n- Add tests verifying input vars and captured/declared vars transfer\n- Add release note entry

* Apply Black formatting to test file

* Update test_dagcircuit.py

* Fix variable transfer to skip already-present variables

Previously, substitute_node_with_dag() would try to add all variables
from the replacement DAG, including those already present in the target
DAG. This violated the constraint that a DAG cannot have both input and
captured variables simultaneously when the same variable object appears
in both contexts.

Now check if each variable is already present before adding it, matching
the behavior of compose() with inline_captures=False.

* addressing review comments

* fixing failing check for node variable substitution in dagcircuit. The check was failing because the node variable substitution was not being applied correctly in the dagcircuit code. This commit fixes that issue by ensuring that the node variable substitution is applied correctly when checking for node variables in the dagcircuit code.

* adressing review comments

* reno
xmirya pushed a commit to qollabxyz/qiskit that referenced this pull request Aug 13, 2026
Qiskit#15542) (Qiskit#16744)

* dagcircuit: transfer DAG-level variables in substitute_node_with_dag (fixes Qiskit#15509)\n\n- Add input/captured/declared vars and stretches from replacement DAG\n- Add tests verifying input vars and captured/declared vars transfer\n- Add release note entry

* Apply Black formatting to test file

* Update test_dagcircuit.py

* Fix variable transfer to skip already-present variables

Previously, substitute_node_with_dag() would try to add all variables
from the replacement DAG, including those already present in the target
DAG. This violated the constraint that a DAG cannot have both input and
captured variables simultaneously when the same variable object appears
in both contexts.

Now check if each variable is already present before adding it, matching
the behavior of compose() with inline_captures=False.

* addressing review comments

* fixing failing check for node variable substitution in dagcircuit. The check was failing because the node variable substitution was not being applied correctly in the dagcircuit code. This commit fixes that issue by ensuring that the node variable substitution is applied correctly when checking for node variables in the dagcircuit code.

* adressing review comments

* reno

(cherry picked from commit f671c03)

Co-authored-by: Arnav Kapoor <kapoorarnav43@gmail.com>
VedantMahadik-qc pushed a commit to VedantMahadik-qc/qiskit that referenced this pull request Oct 21, 2026
Qiskit#15542)

* dagcircuit: transfer DAG-level variables in substitute_node_with_dag (fixes Qiskit#15509)\n\n- Add input/captured/declared vars and stretches from replacement DAG\n- Add tests verifying input vars and captured/declared vars transfer\n- Add release note entry

* Apply Black formatting to test file

* Update test_dagcircuit.py

* Fix variable transfer to skip already-present variables

Previously, substitute_node_with_dag() would try to add all variables
from the replacement DAG, including those already present in the target
DAG. This violated the constraint that a DAG cannot have both input and
captured variables simultaneously when the same variable object appears
in both contexts.

Now check if each variable is already present before adding it, matching
the behavior of compose() with inline_captures=False.

* addressing review comments

* fixing failing check for node variable substitution in dagcircuit. The check was failing because the node variable substitution was not being applied correctly in the dagcircuit code. This commit fixes that issue by ensuring that the node variable substitution is applied correctly when checking for node variables in the dagcircuit code.

* adressing review comments

* reno
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. Community PR PRs from contributors that are not 'members' of the Qiskit repo stable backport potential Make Mergify open a backport PR to the most recent stable branch on merge.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

DAGCircuit.substitute_node_with_dag() does not handle DAG-level variable declarations

7 participants