From b6838a45c490bef8c260d71569d0aeae6b439fe8 Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Fri, 1 Nov 2024 13:52:23 +0100 Subject: [PATCH] * Added flexibilty to the pass manager creator --- .../transpilation/preset_qaoa_passmanager.py | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/qopt_best_practices/transpilation/preset_qaoa_passmanager.py b/qopt_best_practices/transpilation/preset_qaoa_passmanager.py index 279e198..3cd0d04 100644 --- a/qopt_best_practices/transpilation/preset_qaoa_passmanager.py +++ b/qopt_best_practices/transpilation/preset_qaoa_passmanager.py @@ -24,6 +24,7 @@ def qaoa_swap_strategy_pm(config: Dict[str, Any]): swap_strategy = config.get("swap_strategy", None) edge_coloring = config.get("edge_coloring", None) basis_gates = config.get("basis_gates", ["sx", "x", "rz", "cx", "id"]) + construct_qaoa = config.get("construct_qaoa", True) if swap_strategy is None: raise ValueError("No swap_strategy provided in config.") @@ -32,19 +33,19 @@ def qaoa_swap_strategy_pm(config: Dict[str, Any]): raise ValueError("No edge_coloring provided in config.") # 2. define pass manager for cost layer - qaoa_pm = PassManager( - [ - HighLevelSynthesis(basis_gates=["PauliEvolution"]), - FindCommutingPauliEvolutions(), - Commuting2qGateRouter( - swap_strategy, - edge_coloring, - ), - SwapToFinalMapping(), - HighLevelSynthesis(basis_gates=basis_gates), - InverseCancellation(gates_to_cancel=[CXGate()]), - QAOAConstructionPass(num_layers), - ] - ) - - return qaoa_pm + qaoa_passes = [ + HighLevelSynthesis(basis_gates=["PauliEvolution"]), + FindCommutingPauliEvolutions(), + Commuting2qGateRouter( + swap_strategy, + edge_coloring, + ), + SwapToFinalMapping(), + HighLevelSynthesis(basis_gates=basis_gates), + InverseCancellation(gates_to_cancel=[CXGate()]), + ] + + if construct_qaoa: + qaoa_passes.append(QAOAConstructionPass(num_layers)) + + return PassManager(qaoa_passes)