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

Fix the issue with adjoint-jacobian of adjoint ops #996

Merged
merged 12 commits into from
Nov 18, 2024

Conversation

maliasadi
Copy link
Member

@maliasadi maliasadi commented Nov 14, 2024

Before submitting

Please complete the following checklist when submitting a PR:

  • All new features must include a unit test.
    If you've fixed a bug or added code that should be tested, add a test to the
    tests directory!

  • All new functions and code must be clearly commented and documented.
    If you do make documentation changes, make sure that the docs build and
    render correctly by running make docs.

  • Ensure that the test suite passes, by running make test.

  • Add a new entry to the .github/CHANGELOG.md file, summarizing the
    change, and including a link back to the PR.

  • Ensure that code is properly formatted by running make format.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


Context:
The Adjoint-Jacobian of adjoint operations in Lightning is incorrectly returning 0 if we don't decompose them. This issue stems from the ops serialization logic in Python, which mistakenly assumes inverse = False for all operations. This PR fixes the issue so that we can add Adjoint(op) for all supported op to the frozenset of devices operations that will also fix the blocker for merging PR #988.

import pennylane as qml

dev = qml.device("lightning.qubit", wires=2)

@qml.qnode(dev, diff_method="adjoint")
def circuit(params):
    qml.adjoint(qml.RX(params[0], wires=[0]))
    qml.adjoint(qml.RY(params[0], wires=[0]))
    qml.adjoint(qml.RZ(params[0], wires=[0]))
    qml.adjoint(qml.SingleExcitation(params[0], wires=[0, 1]))
    return qml.expval(qml.Z(0))

params = qml.numpy.array([0.123])
qml.jacobian(circuit)(params)

Description of the Change:

Benefits:

Possible Drawbacks:

Related GitHub Issues:
[sc-78336]

Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit .github/CHANGELOG.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.85%. Comparing base (d473c61) to head (83401e2).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #996      +/-   ##
==========================================
- Coverage   97.76%   95.85%   -1.92%     
==========================================
  Files         231      231              
  Lines       36707    36190     -517     
==========================================
- Hits        35886    34689    -1197     
- Misses        821     1501     +680     

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


🚨 Try these New Features:

@josephleekl josephleekl added ci:build_wheels Activate wheel building. urgent Mark a pull request as high priority ci:use-gpu-runner Enable usage of GPU runner for this Pull Request labels Nov 14, 2024
@josephleekl josephleekl requested review from LuisAlfredoNu, multiphaseCFD and AmintorDusko and removed request for LuisAlfredoNu November 14, 2024 21:05
Copy link
Member Author

@maliasadi maliasadi left a comment

Choose a reason for hiding this comment

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

LGTM! @astralcai could you check your PR against the latest changes?

@maliasadi maliasadi requested a review from astralcai November 14, 2024 21:42
Copy link
Contributor

@AmintorDusko AmintorDusko left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks!

Copy link
Contributor

@astralcai astralcai left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you for fixing this!

pennylane_lightning/core/_serialize.py Show resolved Hide resolved
@maliasadi
Copy link
Member Author

LGTM! Thanks @josephleekl for completing the PR 🙌

@maliasadi maliasadi merged commit 3abd17d into master Nov 18, 2024
114 checks passed
@maliasadi maliasadi deleted the fix_adjops_jacobian branch November 18, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:build_wheels Activate wheel building. ci:use-gpu-runner Enable usage of GPU runner for this Pull Request urgent Mark a pull request as high priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants