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

AmplitudeEmbedding inherits from StatePrep #4583

Merged
merged 8 commits into from
Sep 13, 2023

Conversation

timmysilv
Copy link
Contributor

@timmysilv timmysilv commented Sep 8, 2023

Context:
While porting DQ2, the merge_amplitude_embedding tests were failing because AmplitudeEmbedding was being decomposed. I figured that since it behaves like a StatePrep op, we should make it inherit from it and gain the benefit!

Description of the Change:
AmplitudeEmbedding inherits from StatePrep, gaining its state_vector implementation and various properties.

The only real change now that it inherits from StatePrep is that it will return True for isinstance(op, StatePrep) checks but I think this is not a problem.

Benefits:
AmplitudeEmbedding will behave the same on DQ2 as it did on DQL (it would decompose once to StatePrep, then be "supported" by DQL, and then it would have the custom apply function - on DQ2, it was decomposing all the way, and then I hit a bug where it thought it could support batching but the full decomposition disagreed). I confirmed locally that all changed tests, test_amplitude.py, and test_merge_amplitude_embeddings.py all passed with DQ2 as well.

Possible Drawbacks:
If someone somehow calls expand_tape_state_prep with AmplitudeEmbedding and skip_first=False, it will decompose once to a StatePrep and call it a day. This is reflected in tests, but I figured it shouldn't be too much of a concern... users don't even have a way to set skip_first to False (...yet?)

@timmysilv timmysilv requested review from Jaybsoni and a team September 8, 2023 03:22
@codecov
Copy link

codecov bot commented Sep 8, 2023

Codecov Report

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

Comparison is base (2d1f6a3) 99.64% compared to head (06c8ed7) 99.64%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4583      +/-   ##
==========================================
- Coverage   99.64%   99.64%   -0.01%     
==========================================
  Files         376      376              
  Lines       33247    33238       -9     
==========================================
- Hits        33128    33119       -9     
  Misses        119      119              
Files Changed Coverage Δ
pennylane/templates/embeddings/amplitude.py 97.91% <100.00%> (-0.33%) ⬇️

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

@timmysilv
Copy link
Contributor Author

[sc-44390]

# Conflicts:
#	tests/tape/test_tape.py
Copy link
Contributor

@Jaybsoni Jaybsoni 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, just a few small comments then happy to approve. Also for the tests, the doc-strings and test names should be changed to reflect the new thing we are testing/

tests/tape/test_tape.py Show resolved Hide resolved
tests/devices/qubit/test_initialize_state.py Show resolved Hide resolved
@timmysilv timmysilv changed the title AmplitudeEmbedding inherits from StatePrepBase AmplitudeEmbedding inherits from StatePrep Sep 12, 2023
Copy link
Contributor

@Jaybsoni Jaybsoni left a comment

Choose a reason for hiding this comment

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

Nice, thanks for putting up with my comments! Happy to merge for now and we can revisit and deprecate this pipeline once we swap the devices

@timmysilv timmysilv enabled auto-merge (squash) September 13, 2023 16:13
@timmysilv timmysilv merged commit edf6c12 into master Sep 13, 2023
38 checks passed
@timmysilv timmysilv deleted the amplitude-embedding-stateprep branch September 13, 2023 16:42
mudit2812 pushed a commit that referenced this pull request Sep 15, 2023
**Context:**
While porting DQ2, the merge_amplitude_embedding tests were failing
because `AmplitudeEmbedding` was being decomposed. I figured that since
it behaves like a `StatePrep` op, we should make it inherit from it and
gain the benefit!

**Description of the Change:**
`AmplitudeEmbedding` inherits from `StatePrep`, gaining its
`state_vector` implementation and various properties.

The only real change now that it inherits from `StatePrep` is that it
will return True for `isinstance(op, StatePrep)` checks but I think this
is not a problem.

**Benefits:**
`AmplitudeEmbedding` will behave the same on DQ2 as it did on DQL (it
would decompose once to `StatePrep`, then be "supported" by DQL, and
then it would have the custom apply function - on DQ2, it was
decomposing all the way, and then I hit a bug where it thought it could
support batching but the full decomposition disagreed). I confirmed
locally that all changed tests, `test_amplitude.py`, and
`test_merge_amplitude_embeddings.py` all passed with DQ2 as well.

**Possible Drawbacks:**
If someone somehow calls `expand_tape_state_prep` with
`AmplitudeEmbedding` and `skip_first=False`, it will decompose once to a
`StatePrep` and call it a day. This is reflected in tests, but I figured
it shouldn't be too much of a concern... users don't even have a way to
set `skip_first` to False (...yet?)
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