From e4e5624671bfa627be181923bb6bc44570d1e570 Mon Sep 17 00:00:00 2001 From: Julien Gacon Date: Thu, 10 Oct 2024 14:52:10 +0200 Subject: [PATCH] Document the `CommutationChecker` (#13303) * document the commutation checker * Review comments (cherry picked from commit b1d6b3591d3f3f11bbb2db5f170e4dd539aea7cb) --- qiskit/circuit/__init__.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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