Skip to content

Commit

Permalink
Use InverseCancellation in opt level 1 instead of CXCancellation
Browse files Browse the repository at this point in the history
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 Qiskit#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: Qiskit#6576
Closes: Qiskit#7016
Related-to: Qiskit#7112
  • Loading branch information
mtreinish committed Nov 7, 2023
1 parent af643eb commit a534744
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 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,29 @@
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,
)


class DefaultInitPassManager(PassManagerStagePlugin):
Expand Down Expand Up @@ -468,7 +483,21 @@ 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()),
]
),
]
elif optimization_level == 2:
# Steps for optimization level 2
Expand Down

0 comments on commit a534744

Please sign in to comment.