-
Notifications
You must be signed in to change notification settings - Fork 41
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 generate_samples() to lightning #247
Conversation
Hello. You may have forgotten to update the changelog!
|
Codecov Report
@@ Coverage Diff @@
## master #247 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 4
Lines 366 379 +13
=========================================
+ Hits 366 379 +13
Continue to review full report at Codecov.
|
Test Report (C++) on Ubuntu 1 files ± 0 1 suites ±0 0s ⏱️ ±0s Results for commit c616693. ± Comparison against base commit 1c0a973. This pull request removes 4 and adds 10 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
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 @trevor-vincent
I have a few comments and some suggestions
Co-authored-by: Lee James O'Riordan <[email protected]>
Co-authored-by: Lee James O'Riordan <[email protected]>
Co-authored-by: Lee James O'Riordan <[email protected]>
Co-authored-by: Lee James O'Riordan <[email protected]>
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 @trevor-vincent. 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.
Great job @trevor-vincent
One suggestion below, but don't see any blocker otherwise. Happy to approve after this change!
Co-authored-by: Lee James O'Riordan <[email protected]>
Context:
generate_samples() performs most of the heavy lifting for the sample() function. Currently there is no lightning version of generate_samples().
Description of the Change:
This pr adds a lightning C++ version of the generate_samples function using the alias sampling method (https://en.wikipedia.org/wiki/Alias_method). This C++ function currently single-threaded only, however a parallel version is straight-forward (e.g. insert a openmp pragma above the for loop that computes samples while being mindful that the parallel random number generation and caching is thread-safe).
Benefits:
Lightning now has it's own version of generate_samples(), getting us closer to a complete independent lightning statistics module. For low numbers of shots, the single-threaded version is faster than default.qubit (which uses numpy.random.choice) on my machine:
This benchmark times the generate_samples() function for a randomly generated 10-qubit circuit (benchmarks were single-threaded for lightning, however numpy may be multi-threaded).
Possible Drawbacks:
At higher shots, we should likely switch to a parallel version.
Related GitHub Issues: