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

Use SampleMPs in dynamic_one_shot #5486

Merged
merged 33 commits into from
Apr 22, 2024
Merged

Use SampleMPs in dynamic_one_shot #5486

merged 33 commits into from
Apr 22, 2024

Conversation

vincentmr
Copy link
Contributor

@vincentmr vincentmr commented Apr 9, 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
    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:
The native MCM workflow breaks the device API where a sequence of MeasurementProcess objects is expected in the output.

Description of the Change:
Introduce SampleMPs in the auxiliary tape. Pass the mid_measurements dictionary around simulate and sampling to return the correct sample measurements. Modify the dynamic_one_shot transform post-processing function accordingly.

Benefits:
Conform to current API.
Road to jax.jit support.

Possible Drawbacks:
Ad hoc post-processing required in measure_with_samples.

Related GitHub Issues:
[sc-60945]

Copy link

codecov bot commented Apr 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.68%. Comparing base (d03216e) to head (7125646).
Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5486      +/-   ##
==========================================
+ Coverage   99.67%   99.68%   +0.01%     
==========================================
  Files         407      409       +2     
  Lines       38019    37907     -112     
==========================================
- Hits        37895    37789     -106     
+ Misses        124      118       -6     

☔ 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 April 11, 2024 13:39
pennylane/transforms/dynamic_one_shot.py Outdated Show resolved Hide resolved
pennylane/transforms/dynamic_one_shot.py Outdated Show resolved Hide resolved
vincentmr and others added 2 commits April 12, 2024 08:33
@vincentmr vincentmr requested a review from albi3ro April 12, 2024 12:51
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

All the source code looks good to me.

I'm surprised no tests failed with this change. Could we perhaps add some more unit tests to tests/transforms/test_dynamic_one_shot.py to assert the output batch when applied to a tape looks correct?

@vincentmr vincentmr requested a review from albi3ro April 19, 2024 13:57
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.

Looks good to me. Approving since the only thing I can see that needs to be changed is the additional tests Christina suggested.

@vincentmr
Copy link
Contributor Author

Looks good to me. Approving since the only thing I can see that needs to be changed is the additional tests Christina suggested.

Thanks @mudit2812 . I added some tests in tests/transforms/test_dynamic_one_shot.py as suggested by @albi3ro . Do you think there is enough there?

@mudit2812
Copy link
Contributor

The added tests seem sound to me. Could you also add a test to check the correctness for broadcasted tapes? The number of tapes in that case should be batch_size * n_shots

Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

Thanks 🚀 !

@vincentmr vincentmr enabled auto-merge (squash) April 22, 2024 19:49
@vincentmr vincentmr merged commit 44018e9 into master Apr 22, 2024
38 checks passed
@vincentmr vincentmr deleted the feature/dynamic_samples branch April 22, 2024 20:33
rmoyard added a commit to PennyLaneAI/catalyst that referenced this pull request Apr 26, 2024
**Context:**
`_validate_computational_basis_sampling` takes tape as input since
PennyLaneAI/pennylane#5486

**Description of the Change:**

The argument is now the tape instead of the list of measurements
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