Skip to content

Commit

Permalink
Simplify inner translation stage creation logic
Browse files Browse the repository at this point in the history
This commit changes the plugin construction logic slightly to adjust
how the embedded translation stage is created. After Qiskit#10621 merged we
only need to use the plugin interface to get the translation stage pass
manager.
  • Loading branch information
mtreinish committed Aug 22, 2023
1 parent 88e0f7e commit 52ece9d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 40 deletions.
49 changes: 16 additions & 33 deletions qiskit/transpiler/preset_passmanagers/builtin_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,31 +416,21 @@ def _opt_control(property_set):
not property_set["size_fixed_point"]
)

if translation_method not in {
"translator",
"synthesis",
"unroller",
}:
translation = plugin_manager.get_passmanager_stage(
"translation",
translation_method,
pass_manager_config,
optimization_level=1,
)
else:
translation = common.generate_translation_passmanager(
pass_manager_config.target,
pass_manager_config.basis_gates,
translation_method,
pass_manager_config.approximation_degree,
pass_manager_config.coupling_map,
pass_manager_config.backend_properties,
pass_manager_config.unitary_synthesis_method,
pass_manager_config.unitary_synthesis_plugin_config,
pass_manager_config.hls_config,
)

if optimization_level == 2:
translation = plugin_manager.get_passmanager_stage(
"translation",
translation_method,
pass_manager_config,
optimization_level=optimization_level,
)
if optimization_level == 1:
# Steps for optimization level 1
_opt = [
Optimize1qGatesDecomposition(
basis=pass_manager_config.basis_gates, target=pass_manager_config.target
),
CXCancellation(),
]
elif optimization_level == 2:
# Steps for optimization level 2
_opt = [
Optimize1qGatesDecomposition(
Expand All @@ -451,7 +441,6 @@ def _opt_control(property_set):
target=pass_manager_config.target,
),
]

elif optimization_level == 3:
# Steps for optimization level 3
_opt = [
Expand Down Expand Up @@ -480,13 +469,7 @@ def _opt_control(property_set):
return not property_set["optimization_loop_minimum_point"]

else:
# Steps for optimization level 1
_opt = [
Optimize1qGatesDecomposition(
basis=pass_manager_config.basis_gates, target=pass_manager_config.target
),
CXCancellation(),
]
raise TranspilerError(f"Invalid optimization_level: {optimization_level}")

unroll = [pass_ for x in translation.passes() for pass_ in x["passes"]]
# Build nested Flow controllers
Expand Down
2 changes: 0 additions & 2 deletions qiskit/transpiler/preset_passmanagers/level1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
Level 1 pass manager: light optimization by simple adjacent gate collapsing.
"""
from __future__ import annotations
from qiskit.transpiler.basepasses import BasePass
from qiskit.transpiler.passmanager_config import PassManagerConfig
from qiskit.transpiler.passmanager import PassManager
from qiskit.transpiler.passmanager import StagedPassManager
from qiskit.transpiler.preset_passmanagers import common
from qiskit.transpiler.preset_passmanagers.plugin import (
Expand Down
2 changes: 0 additions & 2 deletions qiskit/transpiler/preset_passmanagers/level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
gate cancellation using commutativity rules.
"""
from __future__ import annotations
from qiskit.transpiler.basepasses import BasePass
from qiskit.transpiler.passmanager_config import PassManagerConfig
from qiskit.transpiler.passmanager import PassManager
from qiskit.transpiler.passmanager import StagedPassManager
from qiskit.transpiler.preset_passmanagers import common
from qiskit.transpiler.preset_passmanagers.plugin import (
Expand Down
3 changes: 0 additions & 3 deletions qiskit/transpiler/preset_passmanagers/level3.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
gate cancellation using commutativity rules and unitary synthesis.
"""
from __future__ import annotations
from qiskit.transpiler.basepasses import BasePass
from qiskit.transpiler.passmanager_config import PassManagerConfig
from qiskit.transpiler.passmanager import PassManager
from qiskit.transpiler.passmanager import StagedPassManager
from qiskit.transpiler.passes import RemoveResetInZeroState
from qiskit.transpiler.passes import OptimizeSwapBeforeMeasure
Expand Down Expand Up @@ -63,7 +61,6 @@ def level_3_pass_manager(pass_manager_config: PassManagerConfig) -> StagedPassMa
scheduling_method = pass_manager_config.scheduling_method
optimization_method = pass_manager_config.optimization_method or "default"
scheduling_method = pass_manager_config.scheduling_method or "default"
backend_properties = pass_manager_config.backend_properties
approximation_degree = pass_manager_config.approximation_degree
unitary_synthesis_method = pass_manager_config.unitary_synthesis_method
unitary_synthesis_plugin_config = pass_manager_config.unitary_synthesis_plugin_config
Expand Down

0 comments on commit 52ece9d

Please sign in to comment.