catalyst.passes.disentangle_swap¶
- disentangle_swap()¶
A peephole optimization for replacing
SWAPgates with simpler gates (PauliXandCNOT).Note
This transform requires decorating the workflow with
qjit().- Parameters:
fn (QNode) – the QNode to apply the pass to
- Returns:
Example
In the circuit below, the
SWAPgate can be simplified to aPauliXgate and twoCNOTgates.import pennylane as qp dev = qp.device("lightning.qubit", wires=2) @qp.qjit(keep_intermediate=True) @qp.transforms.disentangle_swap @qp.qnode(dev) def circuit(): # first qubit in |1> qp.X(0) # second qubit in non-basis qp.RX(0.2, 1) qp.SWAP([0, 1]) return qp.state()
When inspecting the circuit resources, the
SWAPgate is no longer present.>>> print(qp.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