-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fix BitArray.from_counts
/from_samples
to not fail for input with only 0
outcome and num_bits=None
#12800
Fix BitArray.from_counts
/from_samples
to not fail for input with only 0
outcome and num_bits=None
#12800
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 10102416610Warning: 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 |
Hi @aeddins-ibm, could you add a short release note documenting the fix? |
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.
This fix looks straightforward, I think we should include it in 1.2 and backport it to 1.1
https://github.com/Mergifyio backport stable/1.1 stable/1.2 |
❌ No backport have been created
GitHub error:
|
✅ Backports have been created
|
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
…only `0` outcome and `num_bits=None` (Qiskit#12800) * interpret `0` as represented by 1 bit * Test conversion of counts w only `0` outcome * add release note
Summary
Partial fix for #12765.
That issue points out two problems with
BitArray.from_counts
/BitArray.from_samples
. The more severe problem is that these methods fail with an error if the input (e.g. a counts dictionary) contains only the0
outcome, andnum_bits
is left at the default value ofNone
.The methods try to infer
num_bits
as the number of bits needed to represent the largest outcome (e.g. bitstring) contained in the input data. If the largest outcome is0
when converted to an integer (e.g. the bitstring"0"
), the number of bits inferred is0
, which can be surprising, and also leads to an error.This small PR interprets
0
as represented by 1 bit instead of by 0 bits, the suggested correct behavior in #12765.The less severe problem, not fixed here, is that currently any information about
num_bits
present in the input bitstring lengths gets ignored. That problem seemed less trivial to me. I put some thoughts here.