From 940ccab483ecdb7053de430c08cdaab813f42d20 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Wed, 8 Nov 2023 11:10:09 -0500 Subject: [PATCH] Use InverseCancellation in opt level 1 instead of CXCancellation (#11210) * Use InverseCancellation in opt level 1 instead of CXCancellation This commit updates the default optimization stage plugin to use the InverseCancellation pass instead of CXCancellation for optimization level 1. The CXCancellation pass was hard coded to only cancel runs of CX gates on the same qubits. This was fine when CX is the target, but for other targets which aren't using CX the pass had no value. An alternative, more general, inverse cancellation pass was added in #6855 that enables defining arbitrary inverse cancellation rules and simplifying a dag based on it. This commit updates the default optimization plugin at optimization level 1 to use this with some common inverse rules for 2q gates from the standard gate library. Closes: #6576 Closes: #7016 Related-to: #7112 * Add sx sx dagger inverse pair to pass --- .../preset_passmanagers/builtin_plugins.py | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/qiskit/transpiler/preset_passmanagers/builtin_plugins.py b/qiskit/transpiler/preset_passmanagers/builtin_plugins.py index 3dc89850e37a..ca21bd2a3b57 100644 --- a/qiskit/transpiler/preset_passmanagers/builtin_plugins.py +++ b/qiskit/transpiler/preset_passmanagers/builtin_plugins.py @@ -39,7 +39,7 @@ CommutativeCancellation, Collect2qBlocks, ConsolidateBlocks, - CXCancellation, + InverseCancellation, ) from qiskit.transpiler.passes import Depth, Size, FixedPoint, MinimumPoint from qiskit.transpiler.passes.utils.gates_basis import GatesInBasis @@ -47,6 +47,23 @@ from qiskit.passmanager.flow_controllers import ConditionalController from qiskit.transpiler.timing_constraints import TimingConstraints from qiskit.transpiler.passes.layout.vf2_layout import VF2LayoutStopReason +from qiskit.circuit.library.standard_gates import ( + CXGate, + ECRGate, + CZGate, + XGate, + YGate, + ZGate, + TGate, + TdgGate, + SwapGate, + SGate, + SdgGate, + HGate, + CYGate, + SXGate, + SXdgGate, +) class DefaultInitPassManager(PassManagerStagePlugin): @@ -468,7 +485,22 @@ def _opt_control(property_set): Optimize1qGatesDecomposition( basis=pass_manager_config.basis_gates, target=pass_manager_config.target ), - CXCancellation(), + InverseCancellation( + [ + CXGate(), + ECRGate(), + CZGate(), + CYGate(), + XGate(), + YGate(), + ZGate(), + HGate(), + SwapGate(), + (TGate(), TdgGate()), + (SGate(), SdgGate()), + (SXGate(), SXdgGate()), + ] + ), ] elif optimization_level == 2: # Steps for optimization level 2