Skip to content

[BUG] Differentiating Trotter with parameter-shift returns all 0s #6333

Open
@astralcai

Description

@astralcai

Expected behavior

Trotter can be differentiated properly:

dev = qml.device("default.qubit")

@qml.qnode(dev)
def circ(time, coeffs):
    h = qml.dot(coeffs, [qml.PauliX(0), qml.PauliZ(0)])
    qml.TrotterProduct(h, time, n=1, order=1)
    return qml.expval(qml.Hadamard(0))

time = qml.numpy.array(1.5)
coeffs = qml.numpy.array([1.23, -0.45])
>>> qml.jacobian(circ)(time, coeffs)
(array(0.9068424), array([ 1.10590537e+00, -2.27646668e-16]))

Actual behavior

When using parameter shift, the above fails:

dev = qml.device("default.qubit")

@qml.qnode(dev, diff_method="parameter-shift")
def circ(time, coeffs):
    h = qml.dot(coeffs, [qml.PauliX(0), qml.PauliZ(0)])
    qml.TrotterProduct(h, time, n=1, order=1)
    return qml.expval(qml.Hadamard(0))

time = qml.numpy.array(1.5)
coeffs = qml.numpy.array([1.23, -0.45])
>>> qml.jacobian(circ)(time, coeffs)
(array(0.90684259), array([0., 0.]))

Additional information

The issue was discovered as part of #6282, and the relevant test in test_trotter.py is xfailed, when fixed, remove the xfail from the relevant test.

Source code

No response

Tracebacks

No response

System information

Name: PennyLane
Version: 0.39.0.dev10
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/venv/lib/python3.10/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, toml, typing-extensions
Required-by: PennyLane-Catalyst, PennyLane_Lightning, PennyLane_Lightning_Kokkos

Platform info:           macOS-15.0-arm64-arm-64bit
Python version:          3.10.14
Numpy version:           1.26.4
Scipy version:           1.12.0
Installed devices:
- default.clifford (PennyLane-0.39.0.dev19)
- default.gaussian (PennyLane-0.39.0.dev19)
- default.mixed (PennyLane-0.39.0.dev19)
- default.qubit (PennyLane-0.39.0.dev19)
- default.qutrit (PennyLane-0.39.0.dev19)
- default.qutrit.mixed (PennyLane-0.39.0.dev19)
- default.tensor (PennyLane-0.39.0.dev19)
- null.qubit (PennyLane-0.39.0.dev19)
- reference.qubit (PennyLane-0.39.0.dev19)
- lightning.qubit (PennyLane_Lightning-0.39.0.dev27)
- lightning.kokkos (PennyLane_Lightning_Kokkos-0.38.0)
- nvidia.custatevec (PennyLane-Catalyst-0.9.0.dev15)
- nvidia.cutensornet (PennyLane-Catalyst-0.9.0.dev15)
- oqc.cloud (PennyLane-Catalyst-0.9.0.dev15)
- softwareq.qpp (PennyLane-Catalyst-0.9.0.dev15)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.

Metadata

Metadata

Assignees

Labels

bug 🐛Something isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions