mirror of https://github.com/Qiskit/qiskit.git
52 lines
2.2 KiB
YAML
52 lines
2.2 KiB
YAML
---
|
|
features:
|
|
- |
|
|
Refactored gate commutativity analysis into a class :class:`~qiskit.circuit.CommutationChecker`.
|
|
This class allows you to check (based on matrix multiplication) whether two gates commute or do not commute,
|
|
and to cache the results (so that a similar check in the future will no longer require matrix
|
|
multiplication).
|
|
|
|
For example we can now do::
|
|
|
|
from qiskit.circuit import QuantumRegister, CommutationChecker
|
|
|
|
comm_checker = CommutationChecker()
|
|
qr = QuantumRegister(4)
|
|
|
|
res = comm_checker.commute(CXGate(), [qr[1], qr[0]], [], CXGate(), [qr[1], qr[2]], [])
|
|
|
|
As the two CX gates commute (the first CX gate is over qubits ``qr[1]`` and ``qr[0]``, and the
|
|
second CX gate is over qubits ``qr[1]`` and ``qr[2]``), we will have that ``res`` is ``True``.
|
|
|
|
This commutativity checking is over-conservative for conditional and parameterized gates,
|
|
and may return ``False`` even when such gates commute.
|
|
|
|
- |
|
|
Added a new transpiler pass :class:`.CommutativeInverseCancellation` that cancels pairs of
|
|
inverse gates exploiting commutation relations between gates. This pass is a generalization
|
|
of the transpiler pass :class:`.InverseCancellation` as it detects a larger set of inverse
|
|
gates, and as it takes commutativity into account. The pass also avoids some problems
|
|
associated with the transpiler pass :class:`.CommutativeCancellation`.
|
|
|
|
For example::
|
|
|
|
from qiskit.circuit import QuantumCircuit
|
|
from qiskit.transpiler import PassManager
|
|
from qiskit.transpiler.passes import CommutativeInverseCancellation
|
|
|
|
circuit = QuantumCircuit(2)
|
|
circuit.z(0)
|
|
circuit.x(1)
|
|
circuit.cx(0, 1)
|
|
circuit.z(0)
|
|
circuit.x(1)
|
|
|
|
passmanager = PassManager(CommutativeInverseCancellation())
|
|
new_circuit = passmanager.run(circuit)
|
|
|
|
cancels the pair of self-inverse `Z`-gates, and the pair of self-inverse `X`-gates (as the
|
|
relevant gates commute with the `CX`-gate), producing a circuit consisting of a single `CX`-gate.
|
|
|
|
The inverse checking is over-conservative for conditional and parameterized gates,
|
|
and may not cancel some of such gates.
|