Skip to content

Commit

Permalink
Use InverseCancellation in opt level 1 instead of CXCancellation (#11210
Browse files Browse the repository at this point in the history
)

* 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
  • Loading branch information
mtreinish committed Nov 8, 2023
1 parent 25c46dc commit 940ccab
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions qiskit/transpiler/preset_passmanagers/builtin_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,31 @@
CommutativeCancellation,
Collect2qBlocks,
ConsolidateBlocks,
CXCancellation,
InverseCancellation,
)
from qiskit.transpiler.passes import Depth, Size, FixedPoint, MinimumPoint
from qiskit.transpiler.passes.utils.gates_basis import GatesInBasis
from qiskit.transpiler.passes.synthesis.unitary_synthesis import UnitarySynthesis
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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 940ccab

Please sign in to comment.