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

Sample minimal subset of wires on LightningQubit #813

Merged
merged 23 commits into from
Jul 24, 2024
Merged

Conversation

vincentmr
Copy link
Contributor

@vincentmr vincentmr commented Jul 24, 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:
With enough qubits and shots, it is wasteful to generate samples on all wires.

Description of the Change:
LightningQubit calls generate_samples(wires) on a minimal subset of wires when executing in finite-shot mode.

Benefits:
Faster sampling and execution.
We perform a simple benchmark of

@qml.qnode(dev)
def f():
    return qml.sample(wires)

where wires takes values [0], range(0, nq//2) and range(0, nq). For a large enough number of qubits and/or samples, we observe good speed-ups (up to 8x) for the 1-wire and half-wire cases. As expected, the all-wire case yields ~1x for all simulations.

speedup_1w
speedup_whf
speedup_wall

Possible Drawbacks:

Related GitHub Issues:

Copy link

codecov bot commented Jul 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 58.78%. Comparing base (d1baa8f) to head (f53c78e).
Report is 89 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (d1baa8f) and HEAD (f53c78e). Click for more details.

HEAD has 7 uploads less than BASE
Flag BASE (d1baa8f) HEAD (f53c78e)
12 5
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #813       +/-   ##
===========================================
- Coverage   98.77%   58.78%   -40.00%     
===========================================
  Files         114       17       -97     
  Lines       17858     1895    -15963     
===========================================
- Hits        17640     1114    -16526     
- Misses        218      781      +563     

☔ 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 July 24, 2024 17:53
@vincentmr vincentmr requested a review from a team July 24, 2024 17:54
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.

The performance is excellent. Is there an actual coverage issue, or is codecov just being a nuisance?

@vincentmr
Copy link
Contributor Author

The performance is excellent. Is there an actual coverage issue, or is codecov just being a nuisance?

The patch cov is 100%, but project cov is low because C++ tests didn't run.

Copy link
Contributor

@LuisAlfredoNu LuisAlfredoNu left a comment

Choose a reason for hiding this comment

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

Nice job. The improvement in the performance is good

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.

Thank you, @vincentmr! Super cool!

@vincentmr vincentmr merged commit 073395b into master Jul 24, 2024
51 of 52 checks passed
@vincentmr vincentmr deleted the group_measure_mps branch July 24, 2024 18:57
@vincentmr
Copy link
Contributor Author

[sc-65127]

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.

4 participants