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

Fix expand_tape_state_prep. #4564

Merged
merged 15 commits into from
Sep 8, 2023
Merged

Fix expand_tape_state_prep. #4564

merged 15 commits into from
Sep 8, 2023

Conversation

vincentmr
Copy link
Contributor

@vincentmr vincentmr commented Aug 31, 2023

Before submitting

Please complete the following checklist when submitting a PR:

  • 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
    test directory!

  • 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.

  • Ensure that the test suite passes, by running make test.

  • Add a new entry to the doc/releases/changelog-dev.md file, summarizing the
    change, and including a link back to the PR.

  • The PennyLane source code conforms to
    PEP8 standards.
    We check all of our code against Pylint.
    To lint modified files, simply pip install pylint, and then
    run pylint pennylane/path/to/file.py.

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


Context:
43708 demands mid-circuit StatePrep support in Lightning. This PR fixes a small bug in expand_tape_state_prep.

Description of the Change:
first_op-bugfix

Benefits:

Possible Drawbacks:

Related GitHub Issues:

@codecov
Copy link

codecov bot commented Aug 31, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (df45c72) 99.64% compared to head (8d6e6ed) 99.64%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4564   +/-   ##
=======================================
  Coverage   99.64%   99.64%           
=======================================
  Files         376      376           
  Lines       33076    33076           
=======================================
  Hits        32960    32960           
  Misses        116      116           
Files Changed Coverage Δ
pennylane/tape/tape.py 98.55% <ø> (ø)

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

@vincentmr vincentmr marked this pull request as ready for review September 6, 2023 17:31
@vincentmr vincentmr requested a review from a team September 6, 2023 17:36
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.

nice find on that bug!

As for the template support - I'm worried that this helper function is getting too big for its own good with all these custom kwargs and overriden behaviours. What is the intention of this function? Should this decomposition apply to all qubit devices? I think we're only doing this because the old way of pre-processing was a little all over the place and because StatePrepBase decompositions haven't really been looked at in a while. I think this logic makes sense, but I don't think it belongs in _qubit_device.py

pennylane/_qubit_device.py Outdated Show resolved Hide resolved
pennylane/_qubit_device.py Outdated Show resolved Hide resolved
pennylane/_qubit_device.py Outdated Show resolved Hide resolved
tests/tape/test_tape.py Outdated Show resolved Hide resolved
@vincentmr
Copy link
Contributor Author

nice find on that bug!

As for the template support - I'm worried that this helper function is getting too big for its own good with all these custom kwargs and overriden behaviours. What is the intention of this function? Should this decomposition apply to all qubit devices? I think we're only doing this because the old way of pre-processing was a little all over the place and because StatePrepBase decompositions haven't really been looked at in a while. I think this logic makes sense, but I don't think it belongs in _qubit_device.py

This PR comes about because of SC-43708. I wanted to add the following test in Lightning, but I couldn't run the circuit or tape with default.qubit. I could not find a similar test in PL, so I thought I would add it and try to make it pass. If there is a better way to invoke and test mid-circuit state prep operations, would you please let me know. I agree this is hacky-washy as it is :D

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.

thanks for separating out the bug!

@vincentmr
Copy link
Contributor Author

thanks for separating out the bug!

Turns out I was misusing dev.execute and mid-circuit state prep worked off the bat in Lightning too. All good now!

@Jaybsoni
Copy link
Contributor

Jaybsoni commented Sep 8, 2023

Clean 👍🏼

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.

💯 Thanks for finding and fixing this 👍🏼

@vincentmr vincentmr enabled auto-merge (squash) September 8, 2023 18:30
@vincentmr vincentmr merged commit be67d9e into master Sep 8, 2023
38 checks passed
@vincentmr vincentmr deleted the bugfix/midcircuit_stateprep branch September 8, 2023 19:03
mudit2812 pushed a commit that referenced this pull request Sep 8, 2023
### 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
      test 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 `doc/releases/changelog-dev.md` file,
summarizing the
      change, and including a link back to the PR.

- [x] The PennyLane source code conforms to
      [PEP8 standards](https://www.python.org/dev/peps/pep-0008/).
We check all of our code against [Pylint](https://www.pylint.org/).
      To lint modified files, simply `pip install pylint`, and then
      run `pylint pennylane/path/to/file.py`.

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


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

**Context:**

[43708](https://app.shortcut.com/xanaduai/story/43708/lightning-ecosystem-devices-allow-stateprepbase-ops-to-be-used-mid-circuit)
demands mid-circuit `StatePrep` support in Lightning. This PR fixes a
small bug in `expand_tape_state_prep`.

**Description of the Change:**
`first_op`-bugfix

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**

---------

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca>
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