Skip to content

Commit 11b290e

Browse files
committed
Increase heuristic effort for optimization level 2
This commit tweaks the heuristic effort in optimization level 2 to be more of a middle ground between level 1 and 3; with a better balance between output quality and runtime. This places it to be a better default for a pass manager we use if one isn't specified. The tradeoff here is that the vf2layout and vf2postlayout search space is reduced to be the same as level 1. There are diminishing margins of return on the vf2 layout search especially for cases when there are a large number of qubit permutations for the mapping found. Then the number of sabre trials is brought up to the same level as optimization level 3. As this can have a significant impact on output and the extra runtime cost is minimal. The larger change is that the optimization passes from level 3. This ends up mainly being 2q peephole optimization. With the performance improvements from Qiskit#12010 and Qiskit#11946 and all the follow-on PRs this is now fast enough to rely on in optimization level 2.
1 parent 97788f0 commit 11b290e

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

qiskit/transpiler/preset_passmanagers/builtin_plugins.py

+11-24
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def pass_manager(self, pass_manager_config, optimization_level=None) -> PassMana
8787
pass_manager_config.unitary_synthesis_plugin_config,
8888
pass_manager_config.hls_config,
8989
)
90-
elif optimization_level in {1, 2}:
90+
elif optimization_level == 1:
9191
init = PassManager()
9292
if (
9393
pass_manager_config.initial_layout
@@ -123,10 +123,8 @@ def pass_manager(self, pass_manager_config, optimization_level=None) -> PassMana
123123
]
124124
)
125125
)
126-
if optimization_level == 2:
127-
init.append(CommutativeCancellation())
128126

129-
elif optimization_level == 3:
127+
elif optimization_level in {2, 3}:
130128
init = common.generate_unroll_3q(
131129
pass_manager_config.target,
132130
pass_manager_config.basis_gates,
@@ -543,18 +541,7 @@ def _opt_control(property_set):
543541
]
544542
),
545543
]
546-
elif optimization_level == 2:
547-
# Steps for optimization level 2
548-
_opt = [
549-
Optimize1qGatesDecomposition(
550-
basis=pass_manager_config.basis_gates, target=pass_manager_config.target
551-
),
552-
CommutativeCancellation(
553-
basis_gates=pass_manager_config.basis_gates,
554-
target=pass_manager_config.target,
555-
),
556-
]
557-
elif optimization_level == 3:
544+
elif optimization_level in {2, 3}:
558545
# Steps for optimization level 3
559546
_opt = [
560547
Collect2qBlocks(),
@@ -596,13 +583,13 @@ def _unroll_condition(property_set):
596583
ConditionalController(unroll, condition=_unroll_condition),
597584
]
598585

599-
if optimization_level == 3:
586+
if optimization_level in {2, 3}:
600587
optimization.append(_minimum_point_check)
601588
else:
602589
optimization.append(_depth_check + _size_check)
603590
opt_loop = (
604591
_opt + _unroll_if_out_of_basis + _minimum_point_check
605-
if optimization_level == 3
592+
if optimization_level in {2, 3}
606593
else _opt + _unroll_if_out_of_basis + _depth_check + _size_check
607594
)
608595
optimization.append(DoWhileController(opt_loop, do_while=_opt_control))
@@ -746,10 +733,10 @@ def _swap_mapped(property_set):
746733
choose_layout_0 = VF2Layout(
747734
coupling_map=pass_manager_config.coupling_map,
748735
seed=pass_manager_config.seed_transpiler,
749-
call_limit=int(5e6), # Set call limit to ~10s with rustworkx 0.10.2
736+
call_limit=int(5e4), # Set call limit to ~10s with rustworkx 0.10.2
750737
properties=pass_manager_config.backend_properties,
751738
target=pass_manager_config.target,
752-
max_trials=25000, # Limits layout scoring to < 10s on ~400 qubit devices
739+
max_trials=2500, # Limits layout scoring to < 10s on ~400 qubit devices
753740
)
754741
layout.append(
755742
ConditionalController(choose_layout_0, condition=_choose_layout_condition)
@@ -758,8 +745,8 @@ def _swap_mapped(property_set):
758745
coupling_map,
759746
max_iterations=2,
760747
seed=pass_manager_config.seed_transpiler,
761-
swap_trials=10,
762-
layout_trials=10,
748+
swap_trials=20,
749+
layout_trials=20,
763750
skip_routing=pass_manager_config.routing_method is not None
764751
and pass_manager_config.routing_method != "sabre",
765752
)
@@ -911,8 +898,8 @@ def _swap_mapped(property_set):
911898
coupling_map,
912899
max_iterations=2,
913900
seed=pass_manager_config.seed_transpiler,
914-
swap_trials=10,
915-
layout_trials=10,
901+
swap_trials=20,
902+
layout_trials=20,
916903
skip_routing=pass_manager_config.routing_method is not None
917904
and pass_manager_config.routing_method != "sabre",
918905
)

qiskit/transpiler/preset_passmanagers/common.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -627,16 +627,11 @@ def get_vf2_limits(
627627
"""
628628
limits = VF2Limits(None, None)
629629
if layout_method is None and initial_layout is None:
630-
if optimization_level == 1:
630+
if optimization_level in {1, 2}:
631631
limits = VF2Limits(
632632
int(5e4), # Set call limit to ~100ms with rustworkx 0.10.2
633633
2500, # Limits layout scoring to < 600ms on ~400 qubit devices
634634
)
635-
elif optimization_level == 2:
636-
limits = VF2Limits(
637-
int(5e6), # Set call limit to ~10 sec with rustworkx 0.10.2
638-
25000, # Limits layout scoring to < 6 sec on ~400 qubit devices
639-
)
640635
elif optimization_level == 3:
641636
limits = VF2Limits(
642637
int(3e7), # Set call limit to ~60 sec with rustworkx 0.10.2

0 commit comments

Comments
 (0)