Open chriseclectic opened 3 months ago
If I understand correctly, there are two issues:
0
(seems straightforward)num_bits
from the bitstring lengths (less clear)Currently there are unit tests requiring that from_samples
runs even when given bitstrings with different numbers of bits:
I think this means that to infer num_bits
from the bitstring key lengths, we have to check each key length individually and take the maximum, or else drop support for this case of inconsistent bitstring lengths (so we can just check the length of the first key).
Quick test on laptop suggests for 10^8 bitstrings with up to 1000 bits, max(map(len, samples))
takes ~15-20 seconds.
Since checking all the key lengths seems slow, I would rather remove support for inputs containing bitstrings of inconsistent lengths. Is it safe to remove, or is there an actual use case for this / are we obligated to continue supporting it?
Can I close this issue because #12800 is merged or anything left to do?
What should happen?
The number of bits should be inferred correctly for bitstring dicts
What is the "correct" number of bits to infer from bitstring inputs? Is it based on string length, or on the values converted to integers?
E.g. for {"000":2, "001":3}
, should num_bits
be 3
or 1
?
The latter (1
) is the current behavior. If that is "correct" we can close the issue. If not, we should leave it open and look for a way to infer num_bits
from string length without too many breaking changes.
@ihincks What do you think about the behavior? Should we update it?
Environment
What is happening?
Calling
BitArray.from_counts
orBitArray.from_samples
without specifying the number of bits is supposed to infer the number of bits from the input data, however this currently only seems to work for integer keys > 0.How can we reproduce the issue?
BitArray.from_samples([s])
orBitArray.from_counts({s: shots})
errors with
for
s = 0
or a string, egs = "000"
.Calling
BitArray.from_counts
ultimately ends up callingBitArray.from_samples
and returns the same error.What should happen?
The number of bits should be inferred correctly for bitstring dicts, or for trivial case of
{0: shots}
(which should default to 1 bit)Any suggestions?
No response