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

Update interfaces module to use bind_new_parameters #4345

Merged
merged 16 commits into from
Jul 14, 2023

Conversation

eddddddy
Copy link
Contributor

Context:
Part of the effort towards QuantumScript immutability. In the end we want to deprecate QuantumScript.set_parameters altogether.

Description of the Change:
Define a new function bind_new_parameters_tape that takes a tape and the new parameters, and returns a new tape. The original tape is unmodified.

Update the jax, jax-jit, tensorflow, and tensorflow-autograph interfaces to call this new bind_new_parameters_tape function instead of QuantumScript.set_parameters.

@github-actions
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.

@eddddddy eddddddy marked this pull request as draft July 10, 2023 18:55
@eddddddy eddddddy marked this pull request as ready for review July 10, 2023 21:08
@eddddddy eddddddy requested a review from a team July 11, 2023 14:00
@codecov
Copy link

codecov bot commented Jul 11, 2023

Codecov Report

Merging #4345 (9d4b047) into master (327b672) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #4345      +/-   ##
==========================================
- Coverage   99.79%   99.77%   -0.02%     
==========================================
  Files         351      351              
  Lines       32120    32139      +19     
==========================================
+ Hits        32053    32066      +13     
- Misses         67       73       +6     
Impacted Files Coverage Δ
pennylane/interfaces/tensorflow_autograph.py 100.00% <ø> (ø)
pennylane/math/utils.py 99.11% <ø> (ø)
pennylane/interfaces/jax.py 99.51% <100.00%> (-0.01%) ⬇️
pennylane/interfaces/jax_jit.py 100.00% <100.00%> (ø)
pennylane/interfaces/jax_jit_tuple.py 100.00% <100.00%> (ø)
pennylane/interfaces/tensorflow.py 99.32% <100.00%> (-0.01%) ⬇️
pennylane/pulse/parametrized_evolution.py 96.55% <100.00%> (+0.21%) ⬆️
pennylane/qchem/integrals.py 100.00% <100.00%> (ø)
pennylane/tape/qscript.py 99.03% <100.00%> (+0.06%) ⬆️

... and 3 files with indirect coverage changes

pennylane/tape/qscript.py Outdated Show resolved Hide resolved
Copy link
Contributor

@mudit2812 mudit2812 left a comment

Choose a reason for hiding this comment

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

Some redundant-code related suggestions, but overall looks good! Happy to approve once comments are addressed.

pennylane/pulse/parametrized_evolution.py Show resolved Hide resolved
pennylane/tape/qscript.py Outdated Show resolved Hide resolved
pennylane/tape/qscript.py Outdated Show resolved Hide resolved
pennylane/tape/qscript.py Outdated Show resolved Hide resolved
pennylane/interfaces/jax_jit.py Outdated Show resolved Hide resolved
pennylane/tape/qscript.py Outdated Show resolved Hide resolved
pennylane/tape/qscript.py Outdated Show resolved Hide resolved
Copy link
Contributor

@mudit2812 mudit2812 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! I don't think that the discussion about bind_new_parameters_tape vs tape.bind_new_parameters affects approval.

tests/tape/test_qscript.py Outdated Show resolved Hide resolved
@mudit2812
Copy link
Contributor

I also just realized once this PR is merged, we should probably go back to the gradients module to update the changes from #4220 to use QuantumScript.bind_new_parameters instead. It virtually does the same thing.

@eddddddy
Copy link
Contributor Author

Yep, and also with the broadcasting transforms. That's the intention.

Copy link
Contributor

@mudit2812 mudit2812 left a comment

Choose a reason for hiding this comment

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

See comment.

pennylane/tape/qscript.py Outdated Show resolved Hide resolved
@mudit2812 mudit2812 self-requested a review July 13, 2023 20:59
Copy link
Contributor

@mudit2812 mudit2812 left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks Edward :)

pennylane/tape/qscript.py Outdated Show resolved Hide resolved
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.

a few little concerns left, but otherwise lgtm!

pennylane/tape/qscript.py Outdated Show resolved Hide resolved
pennylane/tape/qscript.py Show resolved Hide resolved
tests/tape/test_tape.py Outdated Show resolved Hide resolved
Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
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.

the update upon re-construction is disappointing but I see that it must be done. looks good to me!

@eddddddy eddddddy merged commit 3f7bbd6 into master Jul 14, 2023
42 checks passed
@eddddddy eddddddy deleted the interfaces_set_parameters branch July 14, 2023 19:59
@eddddddy
Copy link
Contributor Author

[sc-41633]

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