-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend
CommutativeInverseCancellation
to cancel pairs of gates up-t…
…o-phase (#11248) * pass, tests, reno * using assertAlmostEqual for checking floating-point calculations * renaming * improving description * simplifying code based on review * renaming; changing order of arguments; propagating max_qubits to commutativity checker; docs improvements * doc-string improvements
- Loading branch information
1 parent
1c20b84
commit 8c29cee
Showing
4 changed files
with
314 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
releasenotes/notes/commutative-inv-cancellation-uptophase-028525d21b199cef.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
features: | ||
- | | ||
Added two new arguments ``matrix_based`` and ``max_qubits`` to the | ||
constructor of :class:`.CommutativeInverseCancellation` transpiler pass. | ||
When ``matrix_based`` is ``True`` the pass uses matrix representations to | ||
check whether two operations are inverse of each other. This makes the | ||
checks more powerful, and in addition allows canceling pairs of operations | ||
that are inverse up to a phase, while updating the global phase of the circuit | ||
accordingly. Generally this leads to more reductions at the expense of increased | ||
runtime. The argument ``max_qubits`` limits the number of qubits in matrix-based | ||
commutativity and inverse checks. For example:: | ||
import numpy as np | ||
from qiskit.circuit import QuantumCircuit | ||
from qiskit.transpiler import PassManager | ||
from qiskit.transpiler.passes import CommutativeInverseCancellation | ||
circuit = QuantumCircuit(1) | ||
circuit.rz(np.pi / 4, 0) | ||
circuit.p(-np.pi / 4, 0) | ||
passmanager = PassManager(CommutativeInverseCancellation(matrix_based=True)) | ||
new_circuit = passmanager.run(circuit) | ||
The pass is able to cancel the ``RZ`` and ``P`` gates, while adjusting the circuit's global | ||
phase to :math:`\frac{15 \pi}{8}`. |
Oops, something went wrong.