Skip to content

Commit

Permalink
* Added flexibilty to the pass manager creator (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
eggerdj authored Nov 5, 2024
1 parent d2257c0 commit 8f9d945
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions qopt_best_practices/transpilation/preset_qaoa_passmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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)

0 comments on commit 8f9d945

Please sign in to comment.