catalyst.passes.disentangle_cnot¶
- disentangle_cnot(qnode)[source]¶
A peephole optimization for replacing
CNOTgates with single-qubit gates.Note
This transform requires decorating the workflow with
pennylane.qjit().- Args:
fn (QNode): the QNode to apply the pass to
- Returns:
~.QNode:
Example
In the circuit below, the
CNOTgate can be simplified to just aPauliXgate since the control qubit is always in the :math:`|1angle` state.
import pennylane as qml dev = qml.device("lightning.qubit", wires=2) @qml.qjit(capture=True) @qml.transforms.disentangle_cnot @qml.qnode(dev) def circuit(): # first qubit in |1> qml.X(0) # second qubit in |0> # current state : |10> qml.CNOT([0, 1]) # state after CNOT : |11> return qml.state()
When inspecting the circuit resources, only
PauliXgates are present.>>> print(qml.specs(circuit, level=1)()) Device: lightning.qubit Device wires: 2 Shots: Shots(total=None) Level: disentangle-cnot Wire allocations: 2 Total gates: 2 Gate counts: - PauliX: 2 Measurements: - state(all wires): 1 Depth: Not computed
code/api/catalyst.passes.disentangle_cnot
Download Python script
Download Notebook
View on GitHub