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

Upgrade and generalise basis state preparation #6021

Merged
merged 64 commits into from
Aug 21, 2024
Merged

Conversation

KetpuntoG
Copy link
Contributor

@KetpuntoG KetpuntoG commented Jul 22, 2024

This PR complete part of this story: [sc-68521]

Goal: BasisEmbedding is an alias of BasisState. This way, we don't have duplicate code that does the same thing.
In unifying this, I have had to modify some tests due to:

  • BasisEmbedding and BasisState throw errors such as "incorrect length" with different messages. Now it will always be the same. (test modified for this reason: test_default_qubit_legacy.py, test_default_qubit_tf.py
    test_default_qubit_torch.py, test_state_prep.py, test_all_singles_doubles.py and test_uccsd`)

  • In BasisEmbedding, errors were thrown in __init__ while in BasisState in state_vector. Now they are unified in __init__. For this reason, there were tests where the operator was not initialized correctly but no error was thrown since state_vector was not being called but now they are detected. To correct this, I have modified the tests: test_qscript.py, test_state_prep.py,

  • Now BasisState does not decompose BasisStatePreparation since we are going to deprecate it. This causes the number of gates after expanding to be affected. In this case I had to modify some test in test_tape.py.

This PR also solves:

Related Shortcut Stories:
[sc-69103]

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.

@isaacdevlugt
Copy link
Contributor

Just making a note here that the failed SPSA test is fixed with this PR: #6027

@KetpuntoG
Copy link
Contributor Author

[sc-68521]

Copy link

codecov bot commented Jul 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.65%. Comparing base (1f55c88) to head (e78efb4).
Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6021      +/-   ##
==========================================
- Coverage   99.67%   99.65%   -0.02%     
==========================================
  Files         432      432              
  Lines       41839    41680     -159     
==========================================
- Hits        41702    41536     -166     
- Misses        137      144       +7     

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

@KetpuntoG KetpuntoG changed the title [WIP] Clean state prep subroutines [WIP] Make BasisEmbedding an alias of BasisState Jul 23, 2024
@KetpuntoG KetpuntoG changed the title [WIP] Make BasisEmbedding an alias of BasisState [sc-68521] [WIP] Make BasisEmbedding an alias of BasisState Jul 23, 2024
@KetpuntoG KetpuntoG changed the title [sc-68521] [WIP] Make BasisEmbedding an alias of BasisState [WIP] Make BasisEmbedding an alias of BasisState Jul 24, 2024
doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
pennylane/ops/qubit/state_preparation.py Outdated Show resolved Hide resolved
pennylane/ops/qubit/state_preparation.py Outdated Show resolved Hide resolved
pennylane/ops/qubit/state_preparation.py Outdated Show resolved Hide resolved
pennylane/ops/qubit/state_preparation.py Outdated Show resolved Hide resolved
pennylane/ops/qubit/state_preparation.py Outdated Show resolved Hide resolved
pennylane/ops/qubit/state_preparation.py Outdated Show resolved Hide resolved
pennylane/ops/qubit/state_preparation.py Show resolved Hide resolved
tests/ops/qubit/test_state_prep.py Outdated Show resolved Hide resolved
@KetpuntoG KetpuntoG added this to the v0.38 milestone Aug 21, 2024
Copy link
Contributor

@soranjh soranjh left a comment

Choose a reason for hiding this comment

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

Thanks @KetpuntoG , looks good to go.

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
Copy link
Contributor

@obliviateandsurrender obliviateandsurrender left a comment

Choose a reason for hiding this comment

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

A couple of final minor comments, but looks good otherwise.

pennylane/ops/qubit/state_preparation.py Outdated Show resolved Hide resolved
pennylane/ops/qubit/state_preparation.py Outdated Show resolved Hide resolved
KetpuntoG and others added 4 commits August 21, 2024 16:08
Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com>
Co-authored-by: Utkarsh <utkarshazad98@gmail.com>
@KetpuntoG KetpuntoG merged commit f00c924 into master Aug 21, 2024
40 checks passed
@KetpuntoG KetpuntoG deleted the clean_state_prep branch August 21, 2024 23:22
maliasadi added a commit to PennyLaneAI/pennylane-lightning that referenced this pull request Aug 22, 2024
…legacy device for MPI LGPU (#864)

### Before submitting

Please complete the following checklist when submitting a PR:

- [x] All new features must include a unit test.
If you've fixed a bug or added code that should be tested, add a test to
the
      [`tests`](../tests) directory!

- [x] All new functions and code must be clearly commented and
documented.
If you do make documentation changes, make sure that the docs build and
      render correctly by running `make docs`.

- [x] Ensure that the test suite passes, by running `make test`.

- [x] Add a new entry to the `.github/CHANGELOG.md` file, summarizing
the
      change, and including a link back to the PR.

- [x] Ensure that code is properly formatted by running `make format`. 

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


------------------------------------------------------------------------------------------------------------

**Context:**

- PR PennyLaneAI/pennylane#6021 removed code
duplication for `BasisEmbedding` and `BasisState`. As the result
`BasisState` no longer decomposes to `BasisStatePreparation`. This PR
updates Python unit tests to support this generalization of basis state
preparation.

- PR PennyLaneAI/pennylane#6046 added a facade
wrapper class for "legacy" devices. This PR is a follow up to PR #839
updating Multi-GPU LGPU device and tests.

**Description of the Change:**

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**

---------

Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai>
paul0403 added a commit to PennyLaneAI/catalyst that referenced this pull request Aug 27, 2024
dime10 pushed a commit to PennyLaneAI/catalyst that referenced this pull request Aug 27, 2024
**Context:**
PL recently changed error messages for bad stateprep/basisstate use
cases (PennyLaneAI/pennylane#6021).
    We update our tests to agree with them.

**Benefits:** Frontend tests
`test_skip_initial_stateprep/TestPossibleErrors` can pass
multiphaseCFD pushed a commit to PennyLaneAI/pennylane-lightning that referenced this pull request Sep 8, 2024
…legacy device for MPI LGPU (#864)

### Before submitting

Please complete the following checklist when submitting a PR:

- [x] All new features must include a unit test.
If you've fixed a bug or added code that should be tested, add a test to
the
      [`tests`](../tests) directory!

- [x] All new functions and code must be clearly commented and
documented.
If you do make documentation changes, make sure that the docs build and
      render correctly by running `make docs`.

- [x] Ensure that the test suite passes, by running `make test`.

- [x] Add a new entry to the `.github/CHANGELOG.md` file, summarizing
the
      change, and including a link back to the PR.

- [x] Ensure that code is properly formatted by running `make format`. 

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


------------------------------------------------------------------------------------------------------------

**Context:**

- PR PennyLaneAI/pennylane#6021 removed code
duplication for `BasisEmbedding` and `BasisState`. As the result
`BasisState` no longer decomposes to `BasisStatePreparation`. This PR
updates Python unit tests to support this generalization of basis state
preparation.

- PR PennyLaneAI/pennylane#6046 added a facade
wrapper class for "legacy" devices. This PR is a follow up to PR #839
updating Multi-GPU LGPU device and tests.

**Description of the Change:**

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**

---------

Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai>
mudit2812 pushed a commit that referenced this pull request Sep 10, 2024
This PR complete part of this story:
[[sc-68521](https://app.shortcut.com/xanaduai/story/68521)]

Goal: `BasisEmbedding` is an alias of `BasisState`. This way, we don't
have duplicate code that does the same thing.
In unifying this, I have had to modify some tests due to:
- `BasisEmbedding` and `BasisState` throw errors such as "incorrect
length" with different messages. Now it will always be the same. (test
modified for this reason: `test_default_qubit_legacy.py`,
`test_default_qubit_tf.py`
`test_default_qubit_torch.py`, `test_state_prep.py`,
`test_all_singles_doubles.py` and test_uccsd`)

- In `BasisEmbedding`, errors were thrown in `__init__` while in
BasisState in `state_vector`. Now they are unified in `__init__`. For
this reason, there were tests where the operator was not initialized
correctly but no error was thrown since `state_vector` was not being
called but now they are detected. To correct this, I have modified the
tests: `test_qscript.py`, `test_state_prep.py`,

- Now `BasisState` does not decompose `BasisStatePreparation` since we
are going to deprecate it. This causes the number of gates after
expanding to be affected. In this case I had to modify some test in
`test_tape.py`.

This PR also solves:

- [issue 6008](#6008)
- [issue 6007](#6007)
- [issue 6006](#6006)

---------

Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com>
Co-authored-by: Utkarsh <utkarshazad98@gmail.com>
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.

7 participants