Closed astralcai closed 2 weeks ago
import pennylane as qml import numpy as np import pennylane.numpy as pnp dev = qml.device("default.qubit", wires=2, shots=50000) @qml.qnode(dev) def circuit(coeff1, coeff2): qml.RX(np.pi / 4, wires=0) qml.RY(np.pi / 4, wires=1) return qml.expval( qml.Hamiltonian([coeff1, coeff2], [qml.Y(0) @ qml.Z(1), qml.X(1)]) ) def cost(theta, phi): return circuit(theta, phi) params = pnp.array(pnp.pi / 4), pnp.array(3 * pnp.pi / 4)
>>> qml.jacobian(cost)(*params) (array(-0.49796), array(0.7084))
If we apply split_non_commuting:
split_non_commuting
>>> circuit = qml.transforms.split_non_commuting(circuit) >>> qml.jacobian(cost)(*params) (array(0.), array(0.))
This is caused by this line: https://github.com/PennyLaneAI/pennylane/blob/d70f61aed57497712f3c5c86033aa9747c7fb029/pennylane/transforms/split_non_commuting.py#L696
No response
Name: PennyLane Version: 0.37.0.dev0 Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network. Home-page: https://github.com/PennyLaneAI/pennylane Author: Author-email: License: Apache License 2.0 Location: /Users/astral.cai/Workspace/pennylane Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing_extensions Required-by: PennyLane_Lightning Platform info: macOS-14.5-arm64-arm-64bit Python version: 3.9.19 Numpy version: 1.26.4 Scipy version: 1.12.0 Installed devices: - default.clifford (PennyLane-0.37.0.dev0) - default.gaussian (PennyLane-0.37.0.dev0) - default.mixed (PennyLane-0.37.0.dev0) - default.qubit (PennyLane-0.37.0.dev0) - default.qubit.autograd (PennyLane-0.37.0.dev0) - default.qubit.jax (PennyLane-0.37.0.dev0) - default.qubit.legacy (PennyLane-0.37.0.dev0) - default.qubit.tf (PennyLane-0.37.0.dev0) - default.qubit.torch (PennyLane-0.37.0.dev0) - default.qutrit (PennyLane-0.37.0.dev0) - default.qutrit.mixed (PennyLane-0.37.0.dev0) - null.qubit (PennyLane-0.37.0.dev0) - lightning.qubit (PennyLane-Lightning-0.36.0)
Expected behavior
Actual behavior
If we apply
split_non_commuting
:Additional information
This is caused by this line: https://github.com/PennyLaneAI/pennylane/blob/d70f61aed57497712f3c5c86033aa9747c7fb029/pennylane/transforms/split_non_commuting.py#L696
Source code
No response
Tracebacks
No response
System information
Existing GitHub issues