Closed isaacdevlugt closed 1 month ago
This works:
import pennylane as qml
from jax import numpy as jnp
import functools
n_qubits = 1
dev = qml.device("lightning.qubit", wires=n_qubits)
@qml.qjit
@functools.partial(qml.devices.preprocess.decompose, stopping_condition = lambda obj : obj in dev.operations, max_expansion=1)
@qml.qnode(dev)
def circuit(params):
qml.Rot(params[0], params[1], params[2], wires=0)
return qml.expval(qml.PauliZ(0))
params = jnp.array([0.1, 0.2, 0.3])
print(qml.draw(circuit)(params))
catalyst.grad(circuit)(params)
0: ──RZ(0.10)──RY(0.20)──RZ(0.30)─┤ <Z>
Array([ 0.00000000e+00, -1.98669331e-01, -5.55111512e-17], dtype=float64)
Without the stopping condition, we get `DifferentiableCompileError: Rot is non-differentiable on 'lightning.qubit' device.
This is not a bug, actually, as Lightning doesn't support differentiating qml.Rot
. The user must force Rot
to decompose into individual rotations with a stopping_condition
!
Issue description
A qjit'd circuit that contains
qml.Rot
cannot be differentiated.Expected behavior: It can be differentiated.
Actual behavior: It cannot be differentiated.
Reproduces how often: 100%
System information:
Platform info: macOS-14.5-arm64-arm-64bit Python version: 3.11.8 Numpy version: 1.26.4 Scipy version: 1.12.0 Installed devices:
Source code and tracebacks
Using
catalyst.grad
instead:Should this be supported then? 🤔
Additional information