catalyst.passes.disentangle_swap¶
- disentangle_swap(qnode)[source]¶
A peephole optimization for replacing
SWAPgates with simpler gates (PauliXandCNOT).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
SWAPgate can be simplified to aPauliXgate and twoCNOTgates.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
SWAPgate 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
code/api/catalyst.passes.disentangle_swap
Download Python script
Download Notebook
View on GitHub