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

Do not decompose non-trainable operations in adjoint #5233

Merged
merged 8 commits into from Feb 21, 2024
Merged

Conversation

astralcai
Copy link
Contributor

Context:
The following code throws an error trying to decompose non-trainable QubitUnitary.

import pennylane as qml
from pennylane import numpy as pnp

@qml.qnode(qml.device("default.qubit", wires=3), diff_method="adjoint")
def circuit(x):
    qml.RX(x, 0)
    qml.QubitUnitary(np.eye(8), [0, 1, 2])
    return qml.expval(qml.PauliZ(2))

x = pnp.array(1.1, requires_grad=True)
qml.jacobian(circuit)(x)

Description of the Change:
Add qml.operation.is_trainable check to the stopping condition for adjoint ops.

Benefits:
Bug Fix

Related GitHub Issues:
#5217

Related Shortcut Stories
[sc-56905]

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
@astralcai astralcai marked this pull request as ready for review February 20, 2024 16:01
Copy link

codecov bot commented Feb 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a8be574) 99.68% compared to head (a2296f7) 99.68%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5233      +/-   ##
==========================================
- Coverage   99.68%   99.68%   -0.01%     
==========================================
  Files         399      399              
  Lines       36793    36515     -278     
==========================================
- Hits        36678    36399     -279     
- Misses        115      116       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this 🎉

@astralcai astralcai enabled auto-merge (squash) February 21, 2024 20:38
@astralcai astralcai merged commit e254301 into master Feb 21, 2024
39 checks passed
@astralcai astralcai deleted the adjoint branch February 21, 2024 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants