-
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
Bitarray postselect #12693
Bitarray postselect #12693
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 following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 9719523525Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9725434498Details
💛 - Coveralls |
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 following people are relevant to this code:
|
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 for opening the PR!
This change will also need a reno.
Co-authored-by: Ian Hincks <[email protected]>
Co-authored-by: Ian Hincks <[email protected]>
Pull Request Test Coverage Report for Build 9767937070Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9768517825Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
- fix bugs with checking that ValueError is raised. - addtionally run all tests on a "flat" data input
We immediately check the lengths of these args, so they should be Sequences, not Iterables.
Before merging and committing to this function signature, should we consider if there are more general postselection conditions we could easily support? For example, a plausible use case is someone wants all shots where, for all even k, -- |
If you have any use case of |
I think it's OK to merge as-is. The use-case I imagined above can at least be done in a linear number of calls to this function, which seems tolerable for now. There are other hypothetical use cases that would require an exponential number of calls AFAICT. Like if we wanted only those shots where there are an odd number of 1's (odd parity) in a set of N bits, for large N. Then I think one would need to call So I think it's better to leave Someday, if we want to add support for e.g. selecting shots with a certain parity on many bits, we might instead add a separate method Frankly, we could also use this approach instead of having a Anyway, that's all to say I agree this PR is good to merge. Thanks for your patient reviewing! |
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.
Thank you for your contributions. LGTM.
Post-selection with parity sounds an interesting use case. I agree to think of a separate method to realize it.
In case it's any use as a future reference, here is one approach to compute parity of specified bits. This snippet uses
|
Co-authored-by: Takashi Imamichi <[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.
LGTM
Could you review this again, @ihincks? I would like to merge it if there is no problem. |
Since there is no comment from @ihincks, I will merge this PR once CI gets recovered. |
Neko won't block the merge queue so I think we can already add the PR to the queue :) |
* define BitArray.postselect() * add test for BitArray.postselect() * lint * remove redundant docstring text * Update qiskit/primitives/containers/bit_array.py Co-authored-by: Ian Hincks <[email protected]> * docstring ticks (BitArray.postselect()) Co-authored-by: Ian Hincks <[email protected]> * Simpler tests for BitArray.postselect * lint * add release note * check postselect() arg lengths match * fix postselect tests - fix bugs with checking that ValueError is raised. - addtionally run all tests on a "flat" data input * lint * Fix type-hint We immediately check the lengths of these args, so they should be Sequences, not Iterables. * remove spurious print() * lint * lint * use bitwise operations for faster postselect - Also added support for negative indices - Also updated tests * remove spurious print() * end final line of release note * try to fix docstring formatting * fix bitarray test assertion Co-authored-by: Takashi Imamichi <[email protected]> * disallow postselect positional kwarg Co-authored-by: Takashi Imamichi <[email protected]> * fix numpy dtype args * Simpler kwarg: "assume_unique" * lint (line too long) * simplification: remove assume_unique kwarg * improve misleading comment * raise IndexError if indices out of range - Change ValueError to IndexError. - Add check for out-of-range negative indices. - Simplify use of mod - Update test conditions (include checks for off-by-one errors) * lint * add negative-contradiction test * Update docstring with IndexErrors * lint * change slice_bits error from ValueError to IndexError * update slice_bits test to use IndexError * change ValueError to IndexError in slice_shots also update tests for this error * update error type in slice_shots docstring * Revert ValueError to IndexError changes Reverting these changes as they will instead be made in a separate PR. This reverts commit 8f32178. Revert "update error type in slice_shots docstring" This reverts commit 50545ef. Revert "change ValueError to IndexError in slice_shots" This reverts commit c4becd9. Revert "update slice_bits test to use IndexError" This reverts commit c2b0039. * fix docstring formatting Co-authored-by: Takashi Imamichi <[email protected]> * allow selection to be int instead of bool * In tests, give selection as type int * lint * add example to release note * fix typo in test case * add check of test Co-authored-by: Takashi Imamichi <[email protected]> * lint --------- Co-authored-by: Ian Hincks <[email protected]> Co-authored-by: Takashi Imamichi <[email protected]> (cherry picked from commit 0c03808)
* define BitArray.postselect() * add test for BitArray.postselect() * lint * remove redundant docstring text * Update qiskit/primitives/containers/bit_array.py Co-authored-by: Ian Hincks <[email protected]> * docstring ticks (BitArray.postselect()) Co-authored-by: Ian Hincks <[email protected]> * Simpler tests for BitArray.postselect * lint * add release note * check postselect() arg lengths match * fix postselect tests - fix bugs with checking that ValueError is raised. - addtionally run all tests on a "flat" data input * lint * Fix type-hint We immediately check the lengths of these args, so they should be Sequences, not Iterables. * remove spurious print() * lint * lint * use bitwise operations for faster postselect - Also added support for negative indices - Also updated tests * remove spurious print() * end final line of release note * try to fix docstring formatting * fix bitarray test assertion Co-authored-by: Takashi Imamichi <[email protected]> * disallow postselect positional kwarg Co-authored-by: Takashi Imamichi <[email protected]> * fix numpy dtype args * Simpler kwarg: "assume_unique" * lint (line too long) * simplification: remove assume_unique kwarg * improve misleading comment * raise IndexError if indices out of range - Change ValueError to IndexError. - Add check for out-of-range negative indices. - Simplify use of mod - Update test conditions (include checks for off-by-one errors) * lint * add negative-contradiction test * Update docstring with IndexErrors * lint * change slice_bits error from ValueError to IndexError * update slice_bits test to use IndexError * change ValueError to IndexError in slice_shots also update tests for this error * update error type in slice_shots docstring * Revert ValueError to IndexError changes Reverting these changes as they will instead be made in a separate PR. This reverts commit 8f32178. Revert "update error type in slice_shots docstring" This reverts commit 50545ef. Revert "change ValueError to IndexError in slice_shots" This reverts commit c4becd9. Revert "update slice_bits test to use IndexError" This reverts commit c2b0039. * fix docstring formatting Co-authored-by: Takashi Imamichi <[email protected]> * allow selection to be int instead of bool * In tests, give selection as type int * lint * add example to release note * fix typo in test case * add check of test Co-authored-by: Takashi Imamichi <[email protected]> * lint --------- Co-authored-by: Ian Hincks <[email protected]> Co-authored-by: Takashi Imamichi <[email protected]> (cherry picked from commit 0c03808) Co-authored-by: aeddins-ibm <[email protected]>
* define BitArray.postselect() * add test for BitArray.postselect() * lint * remove redundant docstring text * Update qiskit/primitives/containers/bit_array.py Co-authored-by: Ian Hincks <[email protected]> * docstring ticks (BitArray.postselect()) Co-authored-by: Ian Hincks <[email protected]> * Simpler tests for BitArray.postselect * lint * add release note * check postselect() arg lengths match * fix postselect tests - fix bugs with checking that ValueError is raised. - addtionally run all tests on a "flat" data input * lint * Fix type-hint We immediately check the lengths of these args, so they should be Sequences, not Iterables. * remove spurious print() * lint * lint * use bitwise operations for faster postselect - Also added support for negative indices - Also updated tests * remove spurious print() * end final line of release note * try to fix docstring formatting * fix bitarray test assertion Co-authored-by: Takashi Imamichi <[email protected]> * disallow postselect positional kwarg Co-authored-by: Takashi Imamichi <[email protected]> * fix numpy dtype args * Simpler kwarg: "assume_unique" * lint (line too long) * simplification: remove assume_unique kwarg * improve misleading comment * raise IndexError if indices out of range - Change ValueError to IndexError. - Add check for out-of-range negative indices. - Simplify use of mod - Update test conditions (include checks for off-by-one errors) * lint * add negative-contradiction test * Update docstring with IndexErrors * lint * change slice_bits error from ValueError to IndexError * update slice_bits test to use IndexError * change ValueError to IndexError in slice_shots also update tests for this error * update error type in slice_shots docstring * Revert ValueError to IndexError changes Reverting these changes as they will instead be made in a separate PR. This reverts commit 8f32178. Revert "update error type in slice_shots docstring" This reverts commit 50545ef. Revert "change ValueError to IndexError in slice_shots" This reverts commit c4becd9. Revert "update slice_bits test to use IndexError" This reverts commit c2b0039. * fix docstring formatting Co-authored-by: Takashi Imamichi <[email protected]> * allow selection to be int instead of bool * In tests, give selection as type int * lint * add example to release note * fix typo in test case * add check of test Co-authored-by: Takashi Imamichi <[email protected]> * lint --------- Co-authored-by: Ian Hincks <[email protected]> Co-authored-by: Takashi Imamichi <[email protected]>
Summary
Add method
BitArray.postselect()
, per issue #12688 .[edit July 22, 2024: deleting outdated, distracting details from this description. See linked issue and the method docstring for more information.]