catalyst.passes.merge_rotations¶
- merge_rotations(qnode)[source]¶
Specify that the
-merge-rotationsMLIR compiler pass for merging roations (peephole) will be applied.The full list of supported gates are as follows:
qml.RX,qml.CRX,qml.RY,qml.CRY,qml.RZ,qml.CRZ,qml.PhaseShift,qml.ControlledPhaseShift,qml.Rot,qml.CRot,qml.MultiRZ.Note
Unlike PennyLane circuit transformations, the QNode itself will not be changed or transformed by applying these decorators.
As a result, circuit inspection tools such as
draw()will continue to display the circuit as written in Python.To instead view the optimized circuit, the MLIR must be viewed after the
"QuantumCompilationPass"stage via theget_compilation_stage()function.- Parameters:
fn (QNode) – the QNode to apply the cancel inverses compiler pass to
- Return type:
QNode
Example
In this example the three
qml.RXwill be merged in a single one with the sum of angles as parameter.from catalyst.debug import get_compilation_stage from catalyst.passes import merge_rotations dev = qml.device("lightning.qubit", wires=1) @qjit(keep_intermediate=True) @merge_rotations @qml.qnode(dev) def circuit(x: float): qml.RX(x, wires=0) qml.RX(0.1, wires=0) qml.RX(x**2, wires=0) return qml.expval(qml.PauliZ(0))
>>> circuit(0.54) Array(0.5965506257017892, dtype=float64)