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

Register ParameterizedEvolution #4598

Merged
merged 39 commits into from
Sep 19, 2023
Merged

Register ParameterizedEvolution #4598

merged 39 commits into from
Sep 19, 2023

Conversation

lillian542
Copy link
Contributor

@lillian542 lillian542 commented Sep 14, 2023

Context:
On the old device API, a ParametrizedEvolution uses the default apply_operation behaviour if it is preferable to evolve the matrix and apply (small matrix on a large state), but has special handling for if the matrix gets bigger (specifically, if the wires for the matrix exceed half the wires for the state, it evolves the state instead). Adding this made things much faster and people were very happy.

Description of the Change:
Adds the same behaviour here, now based on the size of the state instead of the number of device wires.

Benefits:
Presumably confers the speedups observed on DQL to DQ2.

Possible Drawbacks:
I tested whether the correct function was called based on the number of calls to math.einsum, because mocker.spy can't access the devices.qubit.apply_operation module due to ambiguity between the module and the function of the same name. It's the best thing I could come up with. It does not seem very reliable if anything changes in the future.

@lillian542 lillian542 changed the base branch from master to add_prng_key September 14, 2023 21:12
@lillian542 lillian542 changed the base branch from add_prng_key to master September 14, 2023 21:12
@codecov
Copy link

codecov bot commented Sep 14, 2023

Codecov Report

Patch coverage: 94.87% and project coverage change: -0.01% ⚠️

Comparison is base (57deaea) 99.64% compared to head (0d4601b) 99.64%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4598      +/-   ##
==========================================
- Coverage   99.64%   99.64%   -0.01%     
==========================================
  Files         375      375              
  Lines       33331    33370      +39     
==========================================
+ Hits        33214    33252      +38     
- Misses        117      118       +1     
Files Changed Coverage Δ
pennylane/devices/qubit/apply_operation.py 98.43% <92.85%> (-1.57%) ⬇️
pennylane/pulse/parametrized_evolution.py 98.23% <100.00%> (+0.98%) ⬆️
pennylane/pulse/parametrized_hamiltonian.py 100.00% <100.00%> (ø)

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

@lillian542 lillian542 marked this pull request as ready for review September 15, 2023 17:22
@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.

@lillian542 lillian542 requested a review from a team September 15, 2023 17:37
@lillian542
Copy link
Contributor Author

[sc-44329]

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.

looks great! just left some comments about batching and import errors, but the rest looks nice 🕴️ also - don't forget a changelog entry!

to fix coverage issues, can you add an integration test that uses the new DQ and custom wires (eg. copy-paste one with regular wires and change them to custom ones like ['a', 'b', 'c']). if you wanna add an explicit test for ParametrizedEvolution.map_wires and double-check the ParametrizedHamiltonians on it also get mapped, it wouldn't hurt :p

pennylane/devices/qubit/apply_operation.py Outdated Show resolved Hide resolved
pennylane/devices/qubit/apply_operation.py 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.

This looks good to me. Just needs the doc string for the ParametrizedEvolution dispatcher to be updated, and there's also the question about broadcasting. Once resolved and tests are added for coverage, I'm ready to approve.

pennylane/devices/qubit/apply_operation.py Show resolved Hide resolved
pennylane/devices/qubit/apply_operation.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.

fantastic! (pls merge the pending suggestions before merging but otherwise looks ready to go :shipit: )

pennylane/devices/qubit/apply_operation.py Outdated Show resolved Hide resolved
timmysilv and others added 3 commits September 19, 2023 13:36
# Conflicts:
#	doc/releases/changelog-dev.md
Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
@timmysilv timmysilv enabled auto-merge (squash) September 19, 2023 17:44
@timmysilv timmysilv merged commit 3b082f7 into master Sep 19, 2023
38 of 39 checks passed
@timmysilv timmysilv deleted the register_PE branch September 19, 2023 18:05
mudit2812 added a commit that referenced this pull request Sep 19, 2023
**Context:**
On the old device API, a `ParametrizedEvolution` uses the default
`apply_operation` behaviour if it is preferable to evolve the matrix and
apply (small matrix on a large state), but has special handling for if
the matrix gets bigger (specifically, if the wires for the matrix exceed
half the wires for the state, it evolves the state instead). Adding this
made things much faster and people were very happy.

**Description of the Change:**
Adds the same behaviour here, now based on the size of the state instead
of the number of device wires.

**Benefits:**
Presumably confers the speedups observed on DQL to DQ2.

**Possible Drawbacks:**
I tested whether the correct function was called based on the number of
calls to `math.einsum`, because `mocker.spy` can't access the
`devices.qubit.apply_operation` module due to ambiguity between the
module and the function of the same name. It's the best thing I could
come up with. It does not seem very reliable if anything changes in the
future.

---------

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
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.

None yet

4 participants