-
Notifications
You must be signed in to change notification settings - Fork 612
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 Shots.bins()
generator method
#5433
Comments
Hey @albi3ro, would it be possible for me to work on this issue? Could you please assign it to me? |
Thanks for reaching out @Tarun-Kumar07 . I've assigned you the issue. |
Hey @albi3ro, I was wondering about the method |
More of something that could make things easier in the future. An example of where this could be used is here: pennylane/pennylane/devices/qubit/sampling.py Line 268 in 04be317
Currently in So a follow-on to this task would be to improve the implementation of |
Hey @albi3ro just wanted to confirm the case when there are duplicates i.e. shot quantity is repeated twice,
|
Exactly 👍 Another quick note that the same shots class can also be created with:
|
That'd be great. Would you like to do that a separate PR or add the change into #5476 ? Basically, you would need to update Since this would just be a change in implementation details, no tests would need to be changed or added. |
**Context:** The current approach for sampling multiple shots involves handling shot vectors by sampling multiple times and processing each shot independently. However, a more efficient strategy would be to sample all shots at once and then process each bin separately. The `shots.bins()` method facilitates this by providing the lower and upper bounds for each bin. **Description of the Change:** - The `shots.bins()` method generates a sequence of tuples, where each tuple represents the lower and upper bounds of a bin. - In `_measure_with_samples_diagonalizing_gates` sample once with total number of shots and use `shots.bins()` to process each bin separately **Benefits:** This method is particularly useful for processing shot quantities in a partitioned manner, as it allows for the separate handling of each bin's range **Possible Drawbacks:** **Related GitHub Issues:** Fixes #5433 --------- Co-authored-by: Christina Lee <[email protected]> Co-authored-by: Christina Lee <[email protected]> Co-authored-by: Nathan Killoran <[email protected]>
qml.measurements.Shots
is our class for keeping track of how many shots to use in calculating measurements.One of the reasons we need a class like this is to better interact with and support shot vectors. A shot vector is when the same measurements as calculated multiple times using subsets of the total shots. For example,
shots=(1, 10, 100, 100)
requests that measurements are done with1
shot,10
shots,100
shots, and100
shots again:If we calculated 211 total shots, measurement 1 would be calculated from shots
0:1
, measurement 2 from1:11
, measurement 3 from11:111
, and 3 from111:211
.This task is to add a property that makes it easy and convenient to access these ranges as "bins", a tuple of
(lower_bound, upper_bound)
.For example:
To complete this task, the contributor should:
bins
method toShots
inpennylane/measurements/shots.py
tests/measurements/test_shots.py
Community Contributions
The text was updated successfully, but these errors were encountered: