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

Allow gradient transforms applied to broadcasted tapes if the broadcasted parameter(s) are not trainable #5452

Merged
merged 16 commits into from
Apr 17, 2024

Conversation

dwierichs
Copy link
Contributor

Context:
In #4462 we discussed the differentiation of broadcasted tapes/QNodes with gradient transforms. Due to some technical debt in the code for JVPs and due to unclear desired behaviour, applying gradient transforms to such QNodes was disallowed in #4480.
However, this also disallows applying gradient transforms to broadcasted tapes for which the broadcasted parameter(s) is/are not trainable, even though the problems discussed in #4462 do not apply in this case.

Description of the Change:
This PR lifts the restriction of applying gradient transforms to broadcasted tapes for the case that no trainable parameters are broadcasted.
The problem described in this forum post can be resolved by this, for example.

Benefits:
Unlocks gradient transforms for broadcasted tapes/QNodes as long as the broadcasting is in non-trainable parameters (which is quite common for QML applications: You want to broadcast across data points rather than trainable parameters.).

Possible Drawbacks:
Usage of tape.trainable_params although we don't want to rely on this property too much in the future.

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 Apr 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.66%. Comparing base (0747c0a) to head (8a74b67).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5452      +/-   ##
==========================================
- Coverage   99.67%   99.66%   -0.01%     
==========================================
  Files         404      406       +2     
  Lines       37852    37590     -262     
==========================================
- Hits        37728    37465     -263     
- Misses        124      125       +1     

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

@albi3ro albi3ro self-requested a review April 2, 2024 15:43
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.

👍

@mudit2812 mudit2812 self-requested a review April 16, 2024 18:46
Copy link
Contributor

@vincentmr vincentmr left a comment

Choose a reason for hiding this comment

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

Hi @dwierichs , looks good to me :)

@dwierichs dwierichs removed the request for review from mudit2812 April 17, 2024 08:37
@dwierichs dwierichs enabled auto-merge (squash) April 17, 2024 08:37
@dwierichs dwierichs merged commit 9a03cce into master Apr 17, 2024
38 checks passed
@dwierichs dwierichs deleted the broadcasting-gradients branch April 17, 2024 09:05
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.

3 participants