Skip to content

Commit

Permalink
qiskit-toqm performs layout changes always.
Browse files Browse the repository at this point in the history
...when configured using one of its optimization strategies. This is because
non-optimal configurations (i.e. anything using GreedyMapper under the
hood) aren't compatible with the layout search parameter, and in fact
break when it is provided. These configurations happen to always perform
layout (without the explicit search) through a different means. To make
everything consistent, it should be assumed that no matter which optimization
strategy is used, layout changes will be made via routing.

qiskit-toqm users can still create a custom strategy if they wish to use
an optimal configuration that does not make layout changes, and then
use their own pass manager.
  • Loading branch information
kevinhartman committed Apr 22, 2022
1 parent df76825 commit 66b0695
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 28 deletions.
3 changes: 1 addition & 2 deletions qiskit/compiler/transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ def transpile(
[qr[0], None, None, qr[1], None, qr[2]]
layout_method: Name of layout selection pass
('trivial', 'dense', 'noise_adaptive', 'sabre', 'toqm')
layout_method: Name of layout selection pass ('trivial', 'dense', 'noise_adaptive', 'sabre')
routing_method: Name of routing pass
('basic', 'lookahead', 'stochastic', 'sabre', 'toqm', 'none')
translation_method: Name of translation pass ('unroller', 'translator', 'synthesis')
Expand Down
13 changes: 5 additions & 8 deletions qiskit/transpiler/preset_passmanagers/level0.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@ def _choose_layout_condition(property_set):
_choose_layout = NoiseAdaptiveLayout(backend_properties)
elif layout_method == "sabre":
_choose_layout = SabreLayout(coupling_map, max_iterations=1, seed=seed_transpiler)
elif layout_method == "toqm":
HAS_TOQM.require_now("TOQM-based layout")
if routing_method != "toqm":
raise TranspilerError("Layout method 'toqm' requires routing method 'toqm'.")
_choose_layout = TrivialLayout(coupling_map)
else:
raise TranspilerError("Invalid layout method %s." % layout_method)

Expand All @@ -157,16 +152,18 @@ def _swap_needs_basis(property_set):
_swap += [SabreSwap(coupling_map, heuristic="basic", seed=seed_transpiler)]
elif routing_method == "toqm":
HAS_TOQM.require_now("TOQM-based routing")
from qiskit_toqm import ToqmSwap, ToqmStrategyO1
from qiskit_toqm import ToqmSwap, ToqmStrategyO0

if initial_layout:
raise TranspilerError("Initial layouts are not supported with TOQM-based routing.")

# Note: BarrierBeforeFinalMeasurements is skipped intentionally since ToqmSwap
# does not yet support barriers.
_swap = [
ToqmSwap(
coupling_map,
instruction_durations,
perform_layout=(layout_method == "toqm"),
strategy=ToqmStrategyO1(),
strategy=ToqmStrategyO0(),
basis_gates=basis_gates,
backend_properties=backend_properties,
)
Expand Down
9 changes: 3 additions & 6 deletions qiskit/transpiler/preset_passmanagers/level1.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,6 @@ def _vf2_match_not_found(property_set):
_improve_layout = NoiseAdaptiveLayout(backend_properties)
elif layout_method == "sabre":
_improve_layout = SabreLayout(coupling_map, max_iterations=2, seed=seed_transpiler)
elif layout_method == "toqm":
HAS_TOQM.require_now("TOQM-based layout")
if routing_method != "toqm":
raise TranspilerError("Layout method 'toqm' requires routing method 'toqm'.")
_improve_layout = TrivialLayout(coupling_map)
else:
raise TranspilerError("Invalid layout method %s." % layout_method)

Expand Down Expand Up @@ -216,13 +211,15 @@ def _swap_needs_basis(property_set):
HAS_TOQM.require_now("TOQM-based routing")
from qiskit_toqm import ToqmSwap, ToqmStrategyO1

if initial_layout:
raise TranspilerError("Initial layouts are not supported with TOQM-based routing.")

# Note: BarrierBeforeFinalMeasurements is skipped intentionally since ToqmSwap
# does not yet support barriers.
_swap = [
ToqmSwap(
coupling_map,
instruction_durations,
perform_layout=(layout_method == "toqm"),
strategy=ToqmStrategyO1(),
basis_gates=basis_gates,
backend_properties=backend_properties,
Expand Down
9 changes: 3 additions & 6 deletions qiskit/transpiler/preset_passmanagers/level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ def _vf2_match_not_found(property_set):
_choose_layout_1 = NoiseAdaptiveLayout(backend_properties)
elif layout_method == "sabre":
_choose_layout_1 = SabreLayout(coupling_map, max_iterations=2, seed=seed_transpiler)
elif layout_method == "toqm":
HAS_TOQM.require_now("TOQM-based layout")
if routing_method != "toqm":
raise TranspilerError("Layout method 'toqm' requires routing method 'toqm'.")
_choose_layout_1 = TrivialLayout(coupling_map)
else:
raise TranspilerError("Invalid layout method %s." % layout_method)

Expand Down Expand Up @@ -200,13 +195,15 @@ def _swap_needs_basis(property_set):
HAS_TOQM.require_now("TOQM-based routing")
from qiskit_toqm import ToqmSwap, ToqmStrategyO2

if initial_layout:
raise TranspilerError("Initial layouts are not supported with TOQM-based routing.")

# Note: BarrierBeforeFinalMeasurements is skipped intentionally since ToqmSwap
# does not yet support barriers.
_swap = [
ToqmSwap(
coupling_map,
instruction_durations,
perform_layout=(layout_method == "toqm"),
strategy=ToqmStrategyO2(),
basis_gates=basis_gates,
backend_properties=backend_properties,
Expand Down
9 changes: 3 additions & 6 deletions qiskit/transpiler/preset_passmanagers/level3.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ def _vf2_match_not_found(property_set):
_choose_layout_1 = NoiseAdaptiveLayout(backend_properties)
elif layout_method == "sabre":
_choose_layout_1 = SabreLayout(coupling_map, max_iterations=4, seed=seed_transpiler)
elif layout_method == "toqm":
HAS_TOQM.require_now("TOQM-based layout")
if routing_method != "toqm":
raise TranspilerError("Layout method 'toqm' requires routing method 'toqm'.")
_choose_layout_1 = TrivialLayout(coupling_map)
else:
raise TranspilerError("Invalid layout method %s." % layout_method)

Expand Down Expand Up @@ -202,13 +197,15 @@ def _swap_needs_basis(property_set):
HAS_TOQM.require_now("TOQM-based routing")
from qiskit_toqm import ToqmSwap, ToqmStrategyO3

if initial_layout:
raise TranspilerError("Initial layouts are not supported with TOQM-based routing.")

# Note: BarrierBeforeFinalMeasurements is skipped intentionally since ToqmSwap
# does not yet support barriers.
_swap = [
ToqmSwap(
coupling_map,
instruction_durations,
perform_layout=(layout_method == "toqm"),
strategy=ToqmStrategyO3(),
basis_gates=basis_gates,
backend_properties=backend_properties,
Expand Down

0 comments on commit 66b0695

Please sign in to comment.