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

Patch Measurements.probs(wires) to Measurements.probs() when called with all wires #744

Merged
merged 9 commits into from
May 29, 2024

Conversation

maliasadi
Copy link
Member

@maliasadi maliasadi commented May 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:
All calls to qml.probs to calculate the probs of the whole system in the analytic mode, patches to the C++ Measurements.probs(wires, ...) method that's implemented for computing the probabilities of a subset of wires. There is a more dedicated method (Measurements.probs()) that skips part of the logic in Measurements.probs(wires) which is indeed required to deal with subsystems. We should call Measurements.probs() when computing the probs of the whole system instead. This PR ensures that we patch to Measurements.probs() resulting a ~12% performance boost for qubits > 10.

Description of the Change:

  • Update the C++ Measurements.probs(wires, ...) method to call Measurements.probs() in LQ and LK when requesting the probs of all wires.
  • Tidy up the src code and docs

Benefits:
This will skip the unnecessary steps required for calculating the probs of a subsystem by calling the proper C++ probs implementation in LQ and LK.

Possible Drawbacks:
Alternatively, we could fix this by calling to the proper probs C++ implementation in Python Bindings instead. I need to do a bit of investigation to find the better solution here. Any thoughts would be appreciated :)

Related GitHub Issues:
[sc-63167]
[sc-64514]

@maliasadi maliasadi changed the title Update Measurements.probs to fix the issue with patching qml.probs to the proper C++ implementations Patch Measurements.probs(wires) to Measurements.probs() when called with all wires May 28, 2024
.github/CHANGELOG.md Outdated Show resolved Hide resolved
Copy link

codecov bot commented May 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.98%. Comparing base (24e72f1) to head (acd1740).
Report is 84 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #744      +/-   ##
==========================================
- Coverage   94.07%   91.98%   -2.10%     
==========================================
  Files         102       66      -36     
  Lines       14836     9041    -5795     
==========================================
- Hits        13957     8316    -5641     
+ Misses        879      725     -154     

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

As I said before, we have proper Python bindings for probs(). The problem is that we always provide wires in the devices' class even if this is an all-wires situation. The more straightforward solution would be to have a test somewhere (like you did in this PR) and redirect when possible. The best place for that is in the C++ layer. This is a cheap check. I'm happy to approve.

@maliasadi maliasadi added the ci:build_wheels Activate wheel building. label May 29, 2024
@maliasadi maliasadi requested a review from a team May 29, 2024 14:23
@vincentmr vincentmr self-requested a review May 29, 2024 15:17
Copy link
Contributor

@vincentmr vincentmr left a comment

Choose a reason for hiding this comment

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

Thanks @maliasadi , just a couple questions but I'm basically ready to approve. Nice formatting and docstring edits.

maliasadi and others added 2 commits May 29, 2024 14:47
…rements/MeasurementsKokkos.hpp

Co-authored-by: Vincent Michaud-Rioux <[email protected]>
@maliasadi maliasadi requested a review from vincentmr May 29, 2024 18:53
Copy link
Contributor

@vincentmr vincentmr left a comment

Choose a reason for hiding this comment

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

LGTM, cheers @maliasadi .

@maliasadi maliasadi merged commit 15096e7 into master May 29, 2024
95 of 96 checks passed
@maliasadi maliasadi deleted the maa/probs-py-cpp-dispatch branch May 29, 2024 22:53
maliasadi added a commit that referenced this pull request Jun 17, 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`](../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`.

- [ ] 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 #744 patches `probs(wires=[])` to calculate the probabilities of all
wires in LightningKokkos. This PR fixes the issue to keep the
consistency among all Lightning devices as well as the integration with
Catalyst.

**Description of the Change:**

**Benefits:**
Consistent behaviour among all devices for calculating `probs(wires=[])
= [1.0]`.

**Possible Drawbacks:**

**Related GitHub Issues:**

---------

Co-authored-by: ringo-but-quantum <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:build_wheels Activate wheel building.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants