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] qml.QNSPSAOptimizer includes op.adjoint instead of qml.adjoint(op) in source #4420

Closed
1 task done
ikurecic opened this issue Aug 1, 2023 · 0 comments · Fixed by #4421
Closed
1 task done
Labels
bug 🐛 Something isn't working

Comments

@ikurecic
Copy link
Contributor

ikurecic commented Aug 1, 2023

Expected behavior

Circuit that includes qml.RandomLayers and uses qml.QNSPSAOptimizer executes normally.

Actual behavior

Execution raises AdjointUndefinedError. Other optimizers execute fine.

Additional information

qml.QNSPSAOptimizer includes op.adjoint in the source instead of qml.adjoint(op), as spotted by @albi3ro

Bug discovered by Lucas Tecot on the PennyLane Discussion Forum.

Source code

import pennylane as qml
from pennylane import numpy as plnp

num_qubits = 2
dev = qml.device("default.qubit", wires=num_qubits)
@qml.qnode(dev)
def cost(params):
    qml.RandomLayers(weights=params, wires=range(num_qubits), seed=42)
    return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))

params = plnp.random.normal(0, plnp.pi, (2, 4))
opt = qml.QNSPSAOptimizer(stepsize=5e-2)
for i in range(51):
    params, loss = opt.step_and_cost(cost, params)
    if i % 10 == 0:
        print(f"Step {i}: cost = {loss:.4f}")

Tracebacks

No response

System information

(Not relevant here.)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@ikurecic ikurecic added the bug 🐛 Something isn't working label Aug 1, 2023
@albi3ro albi3ro mentioned this issue Aug 1, 2023
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

Successfully merging a pull request may close this issue.

1 participant