From 2b21bc04c21751fee5dd2d4664c663dddeba0f31 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Tue, 7 Nov 2023 13:46:15 -0500 Subject: [PATCH] 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 --- .../preset_passmanagers/builtin_plugins.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/qiskit/transpiler/preset_passmanagers/builtin_plugins.py b/qiskit/transpiler/preset_passmanagers/builtin_plugins.py index 3dc89850e37a..c54d0e0bf084 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,13 @@ 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, + SwapGate, + CYGate, +) class DefaultInitPassManager(PassManagerStagePlugin): @@ -468,7 +475,15 @@ def _opt_control(property_set): Optimize1qGatesDecomposition( basis=pass_manager_config.basis_gates, target=pass_manager_config.target ), - CXCancellation(), + InverseCancellation( + [ + CXGate(), + ECRGate(), + CZGate(), + CYGate(), + SwapGate(), + ] + ), ] elif optimization_level == 2: # Steps for optimization level 2