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

[Return-types #5.3] Param-shift shot vector case #3099

Merged
merged 115 commits into from
Oct 24, 2022

Conversation

antalszava
Copy link
Contributor

@antalszava antalszava commented Sep 21, 2022

Context:
Follows the previous PRs on Return-types to allow the param_shift gradient transform to process results when the gradient tapes are executed on a device that has a shot vector defined.

Description of the Change:

  • Introduced the shots parameter to the param_shift, expval_param_shift and var_param_shift functions including the new return type versions of these functions and auxiliary functions that may require information about shots;
  • Updated the logic of param_shift to handle executing gradient tapes on a device with a shot vector;
  • Ported over the majority of tests from tests/returntypes/test_parameter_shift_new.py (Hamiltonian tests being left as TODO).

Benefits:
Most cases work for execution using shot vectors.

Possible Drawbacks:
The logic that attempts to determine if the user didn't pass the shots argument, but execution happened with a shot vector device. To do this, ValueErrors raised are being caught - the user sees a message related to setting the shots argument along the original error message.

Related GitHub Issues:

[sc-27498]

@antalszava antalszava marked this pull request as ready for review October 14, 2022 19:10
@antalszava antalszava requested a review from timmysilv October 17, 2022 15:34
Copy link
Contributor

@rmoyard rmoyard left a comment

Choose a reason for hiding this comment

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

Great job @antalszava, it is looking good 💯 I have some comments and questions. It might be worth to create a smalll separate test class with all the cases we know where you parametrize the number of parameters, number of measurements and different shot vectors like we did for backprop previously.

pennylane/gradients/parameter_shift.py Show resolved Hide resolved
pennylane/gradients/parameter_shift.py Show resolved Hide resolved
pennylane/gradients/parameter_shift.py Show resolved Hide resolved
pennylane/gradients/parameter_shift.py Show resolved Hide resolved
pennylane/gradients/parameter_shift.py Show resolved Hide resolved
pennylane/gradients/parameter_shift.py Show resolved Hide resolved
pennylane/gradients/parameter_shift.py Show resolved Hide resolved
pennylane/gradients/parameter_shift.py Show resolved Hide resolved
pennylane/gradients/parameter_shift.py Outdated Show resolved Hide resolved
pennylane/gradients/parameter_shift.py Outdated Show resolved Hide resolved
pennylane/gradients/parameter_shift.py Outdated Show resolved Hide resolved
pennylane/gradients/parameter_shift.py Show resolved Hide resolved
@timmysilv
Copy link
Contributor

my above comments are all pretty small, this PR looks great! updating that test file was a true feat 😸

@antalszava
Copy link
Contributor Author

@timmysilv @rmoyard thanks for the great comments! 🎉

I think I've addressed them all, some with questions - keen to get further thoughts. 👍 Let me know what should definitely change still in this PR.

Copy link
Contributor

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

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

🥳

Copy link
Contributor

@rmoyard rmoyard left a comment

Choose a reason for hiding this comment

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

Great job @antalszava 🥇 We might be missing one test case. If it is not the case I will be happy to approve the PR!

@rmoyard rmoyard self-requested a review October 24, 2022 17:07
Copy link
Contributor

@rmoyard rmoyard left a comment

Choose a reason for hiding this comment

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

Thanks it looks great 💯

@antalszava antalszava merged commit 43cb8bf into master Oct 24, 2022
@antalszava antalszava deleted the param_shift_shot_vec_new_ret branch October 24, 2022 17:31
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.

4 participants