Skip to content

Conversation

mtreinish
Copy link
Member

Summary

This commit fixes a bug in the construction of the preset pass manager for optimization level 3. In Qiskit 2.1.0 we started running the VF2PostLayout pass in strict mode at the end of the optimization stage. However when that was added it neglected to have a check that the user didn't specify an explicit layout with the initial_layout argument or a specific layout method be used with the layout_method argument. This meant even though the user requested a specific layout or layout technique the preset pass managers would ignore that setting and VF2PostLayout would potentially pick a different layout. This commit fixes this by only running the VF2PostLayout pass if these settings are not used.

Details and comments

Fixes #14867

@mtreinish mtreinish added this to the 2.1.2 milestone Aug 11, 2025
@mtreinish mtreinish requested a review from a team as a code owner August 11, 2025 15:07
@mtreinish mtreinish added stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: Bugfix Include in the "Fixed" section of the changelog labels Aug 11, 2025
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

This commit fixes a bug in the construction of the preset pass manager
for optimization level 3. In Qiskit 2.1.0 we started running the
VF2PostLayout pass in strict mode at the end of the optimization stage.
However when that was added it neglected to have a check that the user
didn't specify an explicit layout with the `initial_layout` argument
or a specific layout method be used with the `layout_method` argument.
This meant even though the user requested a specific layout or layout
technique the preset pass managers would ignore that setting and
VF2PostLayout would potentially pick a different layout. This commit
fixes this by only running the VF2PostLayout pass if these settings are
not used.

Fixes Qiskit#14867
Comment on lines 737 to 762
def test_level3_does_not_run_vf2post_layout_when_layout_method_set(self):
"""Test that level 3 does not run VF2PostLayout when layout_method is set."""
target = GenericBackendV2(
num_qubits=7,
basis_gates=["cx", "id", "rz", "sx", "x"],
coupling_map=LAGOS_CMAP,
seed=42,
)
_target = target.target
target._target.add_instruction(ForLoopOp, name="for_loop")
qc = QuantumCircuit(4)
qc.h(0)
qc.cx(0, 1)
qc.cx(0, 2)
qc.cx(0, 3)
with qc.for_loop((1,)):
qc.cx(0, 1)
qc.measure_all()
_ = transpile(
qc, target, optimization_level=1, callback=self.callback, layout_method="dense"
)
self.assertIn("SetLayout", self.passes)
self.assertNotIn("VF2Layout", self.passes)
self.assertNotIn("SabreLayout", self.passes)
self.assertNotIn("VF2PostLayout", self.passes)
self.assertIn("DenseLayout", self.passes)
Copy link
Member

Choose a reason for hiding this comment

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

This one is slightly more questionable to me. I guess it's consistent with what we already have, though gating the layout-improvement logic in the optimisation stage as being dependent on the layout stage being default feels weird.

I think we should leave it as written, it just makes me question our current configuration methods a bit.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the logic that the pass manager exhibits today. The idea is more if you request an explicit layout method the transpiler should run that method and nothing else. For example, if you said sabre the idea is that it only runs sabre and never vf2 layout. I guess it's more questionable for vf2 post layout case because it runs after the layout stage and the layout_method argument is nominally for which plugin to use. But I think this behavior predates the staged pass manager and the plugin interface.

@coveralls
Copy link

coveralls commented Aug 11, 2025

Pull Request Test Coverage Report for Build 16910437198

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 5 of 5 (100.0%) changed or added relevant lines in 1 file are covered.
  • 20 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.01%) to 87.668%

Files with Coverage Reduction New Missed Lines %
crates/circuit/src/parameter/parameter_expression.rs 1 83.39%
crates/qasm2/src/lex.rs 7 90.98%
crates/qasm2/src/parse.rs 12 97.09%
Totals Coverage Status
Change from base Build 16882978136: -0.01%
Covered Lines: 82375
Relevant Lines: 93962

💛 - Coveralls

mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Aug 14, 2025
…l 3 (Qiskit#14120)"

This temporarily reverts commit a8d2366
due to multiple bugs found around the implementation see Qiskit#14867
and Qiskit#14869. Sincefixing the bugs will have a large impact on the
transpilation results it is better to just disable it and save the runtime
overhead which has been reported in a few places (see Qiskit#14855 and the end
of the discussion in Qiskit#14653). This functionality will be fixed in 2.2.0
and re-enabled there, but for the rest of the 2.1.x release series we
should just leave it disabled.
github-merge-queue bot pushed a commit that referenced this pull request Aug 14, 2025
…l 3 (#14120)" (#14905)

* Revert "Added VF2PostLayout at the end of optimization stage for level 3 (#14120)"

This temporarily reverts commit a8d2366
due to multiple bugs found around the implementation see #14867
and #14869. Sincefixing the bugs will have a large impact on the
transpilation results it is better to just disable it and save the runtime
overhead which has been reported in a few places (see #14855 and the end
of the discussion in #14653). This functionality will be fixed in 2.2.0
and re-enabled there, but for the rest of the 2.1.x release series we
should just leave it disabled.

* Apply suggestions from code review

Co-authored-by: Jake Lishman <jake@binhbar.com>

---------

Co-authored-by: Jake Lishman <jake@binhbar.com>
@jakelishman jakelishman modified the milestones: 2.1.2, 2.2.0 Aug 14, 2025
@jakelishman jakelishman removed the stable backport potential The bug might be minimal and/or import enough to be port to stable label Aug 14, 2025
@jakelishman jakelishman self-assigned this Aug 14, 2025
@mtreinish mtreinish requested a review from jakelishman August 18, 2025 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VF2PostLayout runs at optimization_level=3 even with a set initial_layout
4 participants