catalyst.passes.disentangle_swap

disentangle_swap(qnode)[source]

A peephole optimization for replacing SWAP gates with simpler gates (PauliX and CNOT).

Note

This transform requires decorating the workflow with pennylane.qjit().

Parameters:

fn (QNode) – the QNode to apply the pass to.

Return type:

QNode

Example

In the circuit below, the SWAP gate can be simplified to a PauliX gate and two CNOT gates.

import pennylane as qml

dev = qml.device("lightning.qubit", wires=2)

@qml.qjit(keep_intermediate=True)
@qml.transforms.disentangle_swap
@qml.qnode(dev)
def circuit():
    # first qubit in |1>
    qml.X(0)
    # second qubit in non-basis
    qml.RX(0.2, 1)
    qml.SWAP([0, 1])
    return qml.state()

When inspecting the circuit resources, the SWAP gate is no longer present.

>>> print(qml.specs(circuit, level=1)())
Device: lightning.qubit
Device wires: 2
Shots: Shots(total=None)
Level: disentangle-swap

Wire allocations: 2
Total gates: 5
Gate counts:
- PauliX: 2
- RX: 1
- CNOT: 2
Measurements:
- state(all wires): 1
Depth: Not computed