Skip to content

Fix VF2PostLayout with uncoupled qubits in strict_direction=True#14998

Merged
mtreinish merged 1 commit intoQiskit:mainfrom
jakelishman:fix-vf2post-uncoupled
Sep 8, 2025
Merged

Fix VF2PostLayout with uncoupled qubits in strict_direction=True#14998
mtreinish merged 1 commit intoQiskit:mainfrom
jakelishman:fix-vf2post-uncoupled

Conversation

@jakelishman
Copy link
Copy Markdown
Member

@jakelishman jakelishman commented Sep 8, 2025

When VF2PostLayout is set in strict mode, we have to include even active but uncoupled qubits in the interaction graph, because of the semantic constraints. We need to limit the number of these uncoupled qubits we'll consider, though, because there's a factorial overhead to handling them.

A previous commit1 added this skip to strict_direction=False, but didn't correctly handle the continuation case where we're within the limit. This commit ups the limit to 3 uncoupled qubits (a potential 6x overhead) and correctly clears out the uncoupled-qubit metadata that was causing problems in later layout reconstruction.

Summary

Details and comments

No release note because the bug isn't released.

Fix #14997

Footnotes

  1. b4094dd: Fix calls to VF2PostLayout after optimization loop at O3

@jakelishman jakelishman added this to the 2.2.0 milestone Sep 8, 2025
@jakelishman jakelishman requested a review from a team as a code owner September 8, 2025 10:57
@jakelishman jakelishman added Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. mod: transpiler Issues and PRs related to Transpiler labels Sep 8, 2025
@qiskit-bot
Copy link
Copy Markdown
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

When `VF2PostLayout` is set in strict mode, we have to include even
active but uncoupled qubits in the interaction graph, because of the
semantic constraints.  We need to limit the number of these uncoupled
qubits we'll consider, though, because there's a factorial overhead to
handling them.

A previous commit[^1] added this skip to `strict_direction=False`, but
didn't correctly handle the continuation case where we're within the
limit.  This commit correctly clears out the uncoupled-qubit metadata
that was causing problems in later layout reconstruction.

[^1]: b4094dd: Fix calls to `VF2PostLayout` after optimization loop at O3
@jakelishman jakelishman force-pushed the fix-vf2post-uncoupled branch from 632525f to 90b2665 Compare September 8, 2025 10:59
@jakelishman jakelishman added the stable backport potential Make Mergify open a backport PR to the most recent stable branch on merge. label Sep 8, 2025
@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 17548526532

Details

  • 5 of 5 (100.0%) changed or added relevant lines in 1 file are covered.
  • 25 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.004%) to 88.37%

Files with Coverage Reduction New Missed Lines %
qiskit/transpiler/passes/layout/vf2_utils.py 1 93.71%
crates/qasm2/src/lex.rs 3 91.49%
crates/circuit/src/parameter/symbol_expr.rs 9 72.82%
crates/qasm2/src/parse.rs 12 97.09%
Totals Coverage Status
Change from base Build 17500557721: -0.004%
Covered Lines: 92201
Relevant Lines: 104335

💛 - Coveralls

Copy link
Copy Markdown
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for catching this and the quick fix.

Comment on lines +163 to +168
if len(free_nodes) > 1:
self.property_set["VF2PostLayout_stop_reason"] = (
VF2PostLayoutStopReason.NO_BETTER_SOLUTION_FOUND
)
return
free_nodes.clear()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It took me a sec to remember that I had an if not strict_direction for the free node removal in the vf2_utils code that generated the free_nodes. With that this does the correct thing as described in the comment. But I was initially worried that the case of a single free node would be missing from the interaction graph.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That logic in build_interaction_graph is why it took me ~30 minutes to actually produce this patch too haha.

I wasn't too worried about changing the code much because it all disappears in #14863 and becomes Rust.

@mtreinish mtreinish added this pull request to the merge queue Sep 8, 2025
Merged via the queue into Qiskit:main with commit 2d73e5d Sep 8, 2025
27 checks passed
mergify Bot pushed a commit that referenced this pull request Sep 8, 2025
…14998)

When `VF2PostLayout` is set in strict mode, we have to include even
active but uncoupled qubits in the interaction graph, because of the
semantic constraints.  We need to limit the number of these uncoupled
qubits we'll consider, though, because there's a factorial overhead to
handling them.

A previous commit[^1] added this skip to `strict_direction=False`, but
didn't correctly handle the continuation case where we're within the
limit.  This commit correctly clears out the uncoupled-qubit metadata
that was causing problems in later layout reconstruction.

[^1]: b4094dd: Fix calls to `VF2PostLayout` after optimization loop at O3

(cherry picked from commit 2d73e5d)
@jakelishman jakelishman deleted the fix-vf2post-uncoupled branch September 8, 2025 13:47
github-merge-queue Bot pushed a commit that referenced this pull request Sep 8, 2025
…14998) (#15001)

When `VF2PostLayout` is set in strict mode, we have to include even
active but uncoupled qubits in the interaction graph, because of the
semantic constraints.  We need to limit the number of these uncoupled
qubits we'll consider, though, because there's a factorial overhead to
handling them.

A previous commit[^1] added this skip to `strict_direction=False`, but
didn't correctly handle the continuation case where we're within the
limit.  This commit correctly clears out the uncoupled-qubit metadata
that was causing problems in later layout reconstruction.

[^1]: b4094dd: Fix calls to `VF2PostLayout` after optimization loop at O3

(cherry picked from commit 2d73e5d)

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
aaryav-3 pushed a commit to aaryav-3/qiskit that referenced this pull request Sep 28, 2025
…iskit#14998)

When `VF2PostLayout` is set in strict mode, we have to include even
active but uncoupled qubits in the interaction graph, because of the
semantic constraints.  We need to limit the number of these uncoupled
qubits we'll consider, though, because there's a factorial overhead to
handling them.

A previous commit[^1] added this skip to `strict_direction=False`, but
didn't correctly handle the continuation case where we're within the
limit.  This commit correctly clears out the uncoupled-qubit metadata
that was causing problems in later layout reconstruction.

[^1]: b4094dd: Fix calls to `VF2PostLayout` after optimization loop at O3
aaryav-3 pushed a commit to aaryav-3/qiskit that referenced this pull request Oct 21, 2025
…iskit#14998)

When `VF2PostLayout` is set in strict mode, we have to include even
active but uncoupled qubits in the interaction graph, because of the
semantic constraints.  We need to limit the number of these uncoupled
qubits we'll consider, though, because there's a factorial overhead to
handling them.

A previous commit[^1] added this skip to `strict_direction=False`, but
didn't correctly handle the continuation case where we're within the
limit.  This commit correctly clears out the uncoupled-qubit metadata
that was causing problems in later layout reconstruction.

[^1]: b4094dd: Fix calls to `VF2PostLayout` after optimization loop at O3
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. mod: transpiler Issues and PRs related to Transpiler stable backport potential Make Mergify open a backport PR to the most recent stable branch on merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VF2PostLayout fails during layout finalisation with 1q wires

5 participants