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

Test supported gradient kwargs and raise error for shots kwarg #5748

Merged
merged 13 commits into from
Jun 4, 2024

Conversation

dwierichs
Copy link
Contributor

@dwierichs dwierichs commented May 28, 2024

Context:
Additional kwargs passed to a QNode at initialization are interpreted as gradient kwargs.
They are checked against the hardcoded collection qml.gradients.SUPPORTED_GRADIENT_KWARGS to make sure that this boilerplate interpretation of additional kwargs makes sense.

Description of the Change:
This PR adds a test that makes sure that qml.gradients.SUPPORTED_GRADIENT_KWARGS actually matches all gradient transform kwargs supported by PL.
In addition, this PR introduces an error being raised when the keyword argument shots is passed at QNode initialization, because this is not a valid gradient kwarg and even if it were, it would lead to the confusing behaviour of QNode(..., shots=100) not executing with shots=100.

Benefits:
Code quality, better user input validation.

Possible Drawbacks:

Related GitHub Issues:
#5745

[sc-64175]

Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.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 May 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.66%. Comparing base (456e474) to head (e3ed659).
Report is 256 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5748      +/-   ##
==========================================
- Coverage   99.67%   99.66%   -0.01%     
==========================================
  Files         414      414              
  Lines       39314    39023     -291     
==========================================
- Hits        39185    38893     -292     
- Misses        129      130       +1     

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

tests/test_debugging.py Outdated Show resolved Hide resolved
tests/test_debugging.py Outdated Show resolved Hide resolved
@dwierichs dwierichs added review-ready 👌 PRs which are ready for review by someone from the core team. labels May 29, 2024
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.

🎉 Looks good :)

Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni left a comment

Choose a reason for hiding this comment

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

Thanks @dwierichs ! Looks amazing. Just a couple of minor comments, but no blockers from me 👍

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
pennylane/workflow/qnode.py Outdated Show resolved Hide resolved
Co-authored-by: Pietropaolo Frisoni <pietropaolo.frisoni@xanadu.ai>
Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni left a comment

Choose a reason for hiding this comment

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

Amazing! Thanks again @dwierichs

@dwierichs dwierichs enabled auto-merge (squash) June 3, 2024 13:41
@dwierichs dwierichs added merge-ready ✔️ All tests pass and the PR is ready to be merged. and removed review-ready 👌 PRs which are ready for review by someone from the core team. labels Jun 3, 2024
@dwierichs dwierichs merged commit c14ce7b into master Jun 4, 2024
40 checks passed
@dwierichs dwierichs deleted the gradient-kwargs branch June 4, 2024 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-ready ✔️ All tests pass and the PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants