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

Add MidMeasureMP C++ implementation #621

Closed
wants to merge 71 commits into from
Closed

Conversation

tomlqc
Copy link
Contributor

@tomlqc tomlqc commented Feb 28, 2024

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
    tests 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 .github/CHANGELOG.md file, summarizing the
    change, and including a link back to the PR.

  • 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:
Native-execution of circuits with mid-measurements is enabled via the dynamic-one-shot transform. To support the transform, a device must implement methods to apply MidMeasureMP.

MidMeasureMP is a special kind of operation where a sample is drawn from the state vector probability distribution and a projector is applied to the state vector accordingly. It may also support options like reset and post-selection.

The most straightforward way to deal with the requirements is to enhance the state vector class StateVectorLQubit.

Description of the Change:

  • Add method to obtain the probability in the z-basis on a given wire.
  • Add RNG attribute.
  • Add method to init the RNG attribute with a given seed.
  • Add method to sample from a binomial distribution.
  • Add method to collapse the state vector onto a given branch.
  • Add method which implements the MidMeasureMP workflow.
  • Add bindings to the MidMeasureMP method.

Benefits:

Possible Drawbacks:

Related GitHub Issues:

Related Shortcut Story:
[sc-57704]

@tomlqc tomlqc requested a review from vincentmr February 28, 2024 14:02
@tomlqc tomlqc force-pushed the feature/mid-measure-cpp branch from 3bfb1b7 to 567f83a Compare February 28, 2024 17:20
@tomlqc tomlqc force-pushed the feature/mid-measure-cpp branch from 567f83a to 8dae8e9 Compare February 28, 2024 17:22
Copy link

codecov bot commented Mar 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.71%. Comparing base (6c758e4) to head (9e76d5d).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #621   +/-   ##
=======================================
  Coverage   98.70%   98.71%           
=======================================
  Files         172      172           
  Lines       24318    24382   +64     
=======================================
+ Hits        24004    24068   +64     
  Misses        314      314           

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

Copy link
Contributor

@AmintorDusko AmintorDusko left a comment

Choose a reason for hiding this comment

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

Beautiful! You have my approval already, but please check my suggestions.

tomlqc and others added 5 commits March 14, 2024 16:17
Co-authored-by: Amintor Dusko <87949283+AmintorDusko@users.noreply.github.com>
Co-authored-by: Amintor Dusko <87949283+AmintorDusko@users.noreply.github.com>
Copy link
Contributor

@dime10 dime10 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 from my side 💯 So on the Catalyst side we move to just calling the sample and collapse function ourselves here (similar to what lightningqubit.py is doing) ?

*
* @param seed Seed
*/
void setSeed(const size_t seed) { rng.seed(seed); }
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! So the seed has to be set on each measurement object right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the current way in LQubit or GPU implementations (set randomly).

@tomlqc tomlqc mentioned this pull request Mar 21, 2024
12 tasks
@vincentmr vincentmr closed this Mar 22, 2024
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.

5 participants