Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix jacobian shape in VJP for measurements with shape and batched inp…
…uts (#5986) **Context:** This PR should fix a bug related to computing the gradient of a circuit which supports: 1. batching in non-trainable data 2. Measurement with a shape (i.e. probs) 3. More than one trainable parameter in the circuit Localised example that fails, without the fix: ``` @qml.qnode(qml.device('default.qubit'), diff_method="parameter-shift") def circuit(x, data): qml.RX(x[0], 0) qml.RX(x[1], 0) qml.RY(data, 0) return qml.probs(wires=0) x = qml.numpy.array([0.5, 0.8], requires_grad=True) data = qml.numpy.array([1.2, 2.3, 3.4], requires_grad=False) circuit(x, data) qml.jacobian(circuit)(x, data) ``` Reshaping the jacobian, when computing the VJP does resolve the issue. **Description of the Change:** Jacobian is reshaped according to the shape of dy when computing the VJP for measurements with dimension. **Benefits:** One less bug :) **Possible Drawbacks:** None **Related GitHub Issues:** This PR fixes #5979 --------- Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: David Wierichs <david.wierichs@xanadu.ai> Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
- Loading branch information