-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Remove zero-probability states from Sampler's result #9248
Conversation
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
LGTM, could you add a reno since this changes the results? 🙂 |
Sure. I also need to fix some tests and a sampler gradient. |
I added a reno |
Pull Request Test Coverage Report for Build 3956431316
💛 - Coveralls |
if use_sampler == "ideal": | ||
self.assertTupleEqual(keys, ("00", "01", "10", "11")) | ||
np.testing.assert_allclose(values, [0, 0, 0, 1], atol=0.2) |
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.
Now that 0 probabilities are not included, shouldn't this just show the "11" key here? That also seems to be what the error is about 🙂
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.
Ideal case should include "00", "01", and "10" with very small probabilities. The test on Linux passes but that on Mac fails. I'm investigating the difference.
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.
I cannot reproduce the CI failure locally on MacOS with Python 3.7 🤔
The values with which "00", "01" and "10" are included are about 1e-34 maybe we don't really need to check that this is recognized as non-zero? This seems a bit volatile to me... since this is about algorithm performance rather than the technicality which element is populated and from the sampler tests we know that the zero-probability states are removed, how about just checking if the values are correct in the Grover test? E.g. like
if i in (0, 3):
values = [dist.get(key, 0) for key in ["00", "01", "10", "11"]]
np.testing.assert_allclose(values, [0, 0, 0, 1], atol=0.2)
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.
I makes sense to me to filter out probabilities like this:
For the exact distribution: Remove probabilities satisfying 1e-34
is probably safe to remove. But the former at least has a reason behind the choice. You still have to decide what is much less than one. Maybe 1e-10
For the distribution from samples, you should remove a probability if
But you want to do something to remove small probabilities in both cases. The dict
s could otherwise consume a lot of memory and be populated mostly with garbage.
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.
I will use decimals of Statevector.probabilities
to round the results.
EDIT: After looking more closely, I made further comments along the same lines, above. This looks good. I have one comment. I think we need the ability to set a threshold, which is supported by the method I suppose that could be added to the API later. EDIT: Rereading the discussion above, it looks like this is already an issue in the tests. The code in inds = (np.abs(x) > tol).nonzero()[0]
return {i: x[i] for i in inds} This will leave all of the accepted values unchanged. Dunno, maybe there is a good reason to also round them. Using But probably the best place to make that change (if at all) is in |
I'm trying to pass the CI right now, but it's quite a struggle. |
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
* Remove zero probability from Sampler's result * fix TestGrover * add reno * fix a test * round probabilities Co-authored-by: Julien Gacon <[email protected]> Co-authored-by: Ikko Hamamura <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
) * Remove zero probability from Sampler's result * fix TestGrover * add reno * fix a test * round probabilities Co-authored-by: Julien Gacon <[email protected]> Co-authored-by: Ikko Hamamura <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Summary
Fixes #9178
Requires #9258 to pass the unit tests
Details and comments