qp.transforms.disentangle_cnot¶
- disentangle_cnot()¶
A peephole optimization for replacing
CNOTgates with single-qubit gates.Note
This transform requires decorating the workflow with
qjit().Example
In the circuit below, the
CNOTgate can be simplified to just aPauliXgate since the control qubit is always in the \(|1\rangle\) state.import pennylane as qp dev = qp.device("lightning.qubit", wires=2) @qp.qjit(capture=True) @qp.transforms.disentangle_cnot @qp.qnode(dev) def circuit(): # first qubit in |1> qp.X(0) # second qubit in |0> # current state : |10> qp.CNOT([0, 1]) # state after CNOT : |11> return qp.state()
When inspecting the circuit resources, only
PauliXgates are present.>>> print(qp.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/pennylane.transforms.disentangle_cnot
Download Python script
Download Notebook
View on GitHub