diff --git a/qiskit/circuit/__init__.py b/qiskit/circuit/__init__.py index 835371443bf0..aa5c9dfdf43b 100644 --- a/qiskit/circuit/__init__.py +++ b/qiskit/circuit/__init__.py @@ -772,6 +772,30 @@ Consult :ref:`the control-flow construction documentation ` for more information on how to build circuits with control flow. +Investigating commutation relations +----------------------------------- + +If two operations in a circuit commute, we can swap the order in which they are applied. +This can allow for optimizations and simplifications, for example, if it allows to merge +or cancel gates: + +.. code-block:: text + + ┌─────────┐ ┌─────────┐ ┌─────────┐ + q_0: ┤ Rz(0.5) ├──■──┤ Rz(1.2) ├──■── q_0: ┤ Rz(1.7) ├ + └─────────┘┌─┴─┐└──┬───┬──┘┌─┴─┐ = └──┬───┬──┘ + q_1: ───────────┤ X ├───┤ X ├───┤ X ├ q_1: ───┤ X ├─── + └───┘ └───┘ └───┘ └───┘ + +Performing these optimizations are part of the transpiler, but the tools to investigate commutations +are available in the :class:`CommutationChecker`. + +.. autosummary:: + :toctree: ../stubs/ + + CommutationChecker + + .. _circuit-custom-gates: Creating custom instructions