-
Notifications
You must be signed in to change notification settings - Fork 39
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
Conversation
Measurements.probs
to fix the issue with patching qml.probs
to the proper C++ implementations
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
pennylane_lightning/core/src/simulators/lightning_kokkos/measurements/MeasurementsKokkos.hpp
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
There was a problem hiding this 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.
pennylane_lightning/core/src/simulators/lightning_kokkos/measurements/MeasurementsKokkos.hpp
Show resolved
Hide resolved
pennylane_lightning/core/src/simulators/lightning_kokkos/measurements/MeasurementsKokkos.hpp
Outdated
Show resolved
Hide resolved
…rements/MeasurementsKokkos.hpp Co-authored-by: Vincent Michaud-Rioux <vincentm@nanoacademic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, cheers @maliasadi .
### 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 <github-ringo-but-quantum@xanadu.ai>
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 thechange, 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 inMeasurements.probs(wires)
which is indeed required to deal with subsystems. We should callMeasurements.probs()
when computing the probs of the whole system instead. This PR ensures that we patch toMeasurements.probs()
resulting a ~12% performance boost for qubits > 10.Description of the Change:
Measurements.probs(wires, ...)
method to callMeasurements.probs()
in LQ and LK when requesting the probs of all wires.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]