CHSH game example error: random.randint(0, 2) generates invalid inputs #4439
CHSH game example error: random.randint(0, 2) generates invalid inputs #4439neeco1991 wants to merge 1 commit intoQiskit:mainfrom
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
Thanks for contributing to Qiskit documentation! 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. Thanks! 🙌 One or more of the following people are relevant to this code: |
|
@christopherporter1 Can we close this? This PR #4474 was merged and closes #4438, the same issue linked to the present PR, #4439. Both PRs #4474 and #4439 appear to make the same change. #4439 was opened on Dec. 18. PR #4474 was opened later, on Jan 5. Was this PR overlooked? In any case both these (identical) PRs are incorrect. There is a confusion between base python's |
The existing code that generates https://quantum.cloud.ibm.com/learning/en/courses/basics-of-quantum-information/entanglement-in-action/qiskit-implementation imports both `pi` and `random` from numpy. The notebook uses nothing else from numpy. These two objects are used only in a scalar context. In some cases, using numpy can degrade performance. In qiskit there has been an effort, reflected in PRs, to avoid using numpy habitually, when not necessary. This is done even in non-performance critical code. This PR changes the code to import `pi` from `math`. And it imports `random` from the stdlib. When producing single samples, standard library `random.randint` is about 5 times faster than `numpy.random.randint`. Furthermore, the existing code calls numpy's `random.randint(0, 1)`, which always returns zero. This was mistakenly introduced. Since this PR uses `randint` from the standard library, the range is 0 to 1, inclusive. So it may return either 0 or 1. My best understanding is that this is the original intent of the code. The following issues and PRs are on exactly the same code touched here * #4438 * #4439 * #4474 * #4643 Closes #4643 --------- Co-authored-by: abbycross <across@us.ibm.com>
Closes #4438