Skip to content

Commit 2f08762

Browse files
mergify[bot]ToroDatajakelishman
authored
docs(transpiler-plugins): fix layout plugin example for v2.1.2 (Qiskit#14985) (Qiskit#14991) (Qiskit#15103)
* docs(transpiler-plugins): fix layout plugin example for v2.1.2 (Qiskit#14985) Fixes Qiskit#14985 issue. Updates the example under `qiskit.transpiler.preset_passmanagers.plugin` so it runs on Qiskit SDK v2.1.2. - Replace `PassManager.append(..., condition=...)` with `ConditionalController`. - Remove usage of `backend_properties` from `PassManagerConfig`. - Pass `target=pass_manager_config.target` to `VF2Layout`. - Add the missing comma in `max_trials=...`. - Guard property_set lookups with `.get(...)` and check against `VF2LayoutStopReason.SOLUTION_FOUND`. Tested with `generate_preset_pass_manager(..., layout_method="vf2lite")` at `optimization_level=1..3` on SDK v2.1.2. * Fix lint error in plugin.py docstring (line too long) * Fix spacing --------- (cherry picked from commit cbe1f20) Co-authored-by: Ricard Santiago Raigada García <[email protected]> Co-authored-by: Jake Lishman <[email protected]>
1 parent ff43eaa commit 2f08762

File tree

1 file changed

+13
-12
lines changed
  • qiskit/transpiler/preset_passmanagers

1 file changed

+13
-12
lines changed

qiskit/transpiler/preset_passmanagers/plugin.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,32 @@
103103
from qiskit.transpiler import PassManager
104104
from qiskit.transpiler.passes import VF2Layout, TrivialLayout
105105
from qiskit.transpiler.passes.layout.vf2_layout import VF2LayoutStopReason
106+
from qiskit.passmanager import ConditionalController
106107
107108
108109
def _vf2_match_not_found(property_set):
109-
return property_set["layout"] is None or (
110-
property_set["VF2Layout_stop_reason"] is not None
111-
and property_set["VF2Layout_stop_reason"] is not VF2LayoutStopReason.SOLUTION_FOUND
110+
return property_set.get("layout") is None or (
111+
property_set.get("VF2Layout_stop_reason") is not None
112+
and property_set.get("VF2Layout_stop_reason")
113+
is not VF2LayoutStopReason.SOLUTION_FOUND
114+
)
112115
113116
114117
class VF2LayoutPlugin(PassManagerStagePlugin):
115-
116118
def pass_manager(self, pass_manager_config, optimization_level):
117119
layout_pm = PassManager(
118120
[
119121
VF2Layout(
120122
coupling_map=pass_manager_config.coupling_map,
121-
properties=pass_manager_config.backend_properties,
122-
max_trials=optimization_level * 10 + 1
123-
target=pass_manager_config.target
124-
)
123+
max_trials=optimization_level * 10 + 1,
124+
target=pass_manager_config.target,
125+
),
126+
ConditionalController(
127+
TrivialLayout(pass_manager_config.coupling_map),
128+
condition=_vf2_match_not_found,
129+
),
125130
]
126131
)
127-
layout_pm.append(
128-
TrivialLayout(pass_manager_config.coupling_map),
129-
condition=_vf2_match_not_found,
130-
)
131132
layout_pm += common.generate_embed_passmanager(pass_manager_config.coupling_map)
132133
return layout_pm
133134

0 commit comments

Comments
 (0)