reverse_parallelize#

reverse_parallelize(qc: QuantumCircuit) QuantumCircuit[source]#

This pass leverages permeability commutations to move two qubit gates to a later point in the circuit. This is especially helpful when trying to cancel out SWAP gates with other two qubit interactions.

Parameters:
qcQuantumCircuit

Input quantum circuit.

Returns:
QuantumCircuit

Circuit after reverse-order parallelization.

Examples

We demonstrate how to move a CX gate towards a SWAP.

>>> from qrisp import QuantumCircuit, PassManager
>>> from qrisp import reverse_parallelize
>>> qc = QuantumCircuit(2)
>>> qc.cx(0, 1)
>>> qc.z(0)
>>> qc.swap(0, 1)
>>> print(qc)
             ┌───┐
qb_130: ──■──┤ Z ├─X─
        ┌─┴─┐├───┤ │
qb_131: ┤ X ├┤ X ├─X─
        └───┘└───┘
>>> pm = PassManager()
>>> pm += reverse_parallelize
>>> optimized_qc = pm.run(qc)
>>> print(optimized_qc)
       ┌───┐
qb_66: ┤ Z ├──■───X─
       ├───┤┌─┴─┐ │
qb_67: ┤ X ├┤ X ├─X─
       └───┘└───┘

The CX gate can now be fused through the fuse_adjacents pass.