Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] default.qubit.legacy returns wrong jacobian with qml.QubitUnitary+requires_grad=False #4821

Closed
1 task done
vincentmr opened this issue Nov 10, 2023 · 2 comments
Closed
1 task done
Labels
bug 🐛 Something isn't working

Comments

@vincentmr
Copy link
Contributor

Expected behavior

I expect adjoint to return the same results as parameter-shift for the Jacobian of the circuit below.

[-0.13893233 -0.31571638 -0.62490128]

Actual behavior

It returns a different Jacobian

[ 0.         -0.13893233 -0.31571638]

Additional information

No response

Source code

import pennylane as qml
import pennylane.numpy as np
n_wires = 3
n_targets = 2

dev = qml.device("default.qubit.legacy", wires=n_wires, )

par = np.arange(1, n_wires+1) / 3

def circuit(x):
    for i in range(n_wires):
        qml.RY(x[i], wires=i)
    qml.QubitUnitary(np.eye(4, requires_grad=False), wires=range(n_targets))
    return qml.expval(qml.PauliZ(0)@qml.PauliZ(1)@qml.PauliZ(2))

circ = qml.QNode(circuit, dev, diff_method="adjoint")
print(qml.jacobian(circ)(par))
circ = qml.QNode(circuit, dev, diff_method="parameter-shift")
print(qml.jacobian(circ)(par))

Tracebacks

No response

System information

Name: PennyLane
Version: 0.34.0.dev0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /global/u2/v/vincentm/repos/pennylane-lightning/venv/lib/python3.11/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-Lightning

Platform info:           Linux-5.14.21-150400.24.81_12.0.86-cray_shasta_c-x86_64-with-glibc2.31
Python version:          3.11.4
Numpy version:           1.26.1
Scipy version:           1.11.3
Installed devices:
- lightning.qubit (PennyLane-Lightning-0.34.0.dev5)
- default.gaussian (PennyLane-0.34.0.dev0)
- default.mixed (PennyLane-0.34.0.dev0)
- default.qubit (PennyLane-0.34.0.dev0)
- default.qubit.autograd (PennyLane-0.34.0.dev0)
- default.qubit.jax (PennyLane-0.34.0.dev0)
- default.qubit.legacy (PennyLane-0.34.0.dev0)
- default.qubit.tf (PennyLane-0.34.0.dev0)
- default.qubit.torch (PennyLane-0.34.0.dev0)
- default.qutrit (PennyLane-0.34.0.dev0)
- null.qubit (PennyLane-0.34.0.dev0)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@vincentmr vincentmr added the bug 🐛 Something isn't working label Nov 10, 2023
@vincentmr
Copy link
Contributor Author

#4820

@Alex-Preciado
Copy link
Contributor

This issue is now closed by PR #4820

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants