Skip to content

VF2PostLayout runs at optimization_level=3 even with a set initial_layout #14867

@jakelishman

Description

@jakelishman

Environment

  • Qiskit version: 2.1.1
  • Python version: 3.13
  • Operating system: macOS

What is happening?

Currently, the end of the optimisation loop at O3 runs VF2PostLayout to attempt to find a better layout, after the circuit has been entirely lowered to hardware. However, this is currently running if initial_layout is set, and consequently the result would be thrown out.

How can we reproduce the issue?

from qiskit import transpile, QuantumCircuit
from qiskit.circuit import library as lib
from qiskit.transpiler import Target, InstructionProperties

target = Target()
target.add_instruction(lib.CXGate(), {
    (0, 1): InstructionProperties(error=1e-2),
    (1, 2): InstructionProperties(error=1e-5),
})
qc = QuantumCircuit(2)
qc.cx(0, 1)

def callback(pass_, **_):
    assert not pass_.name().startswith("VF2")

transpile(qc, target=target, optimization_level=3, initial_layout=[0, 1], callback=callback)

This triggers the assertion at optimization_level=3, but correctly not at lower optimisation levels. The selected layout is the given initial one, even though this Target has a better layout available.

What should happen?

No layout-selection passes should run if initial_layout is set.

Any suggestions?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions