#17093·qiskit

BitArray.from_counts() failure OverflowError: int too big to convert

Author: watplattCreated Sep 30, 2026Updated Sep 30, 2026
Labelsbug

Environment

  • Qiskit version: 2.5.0
  • Python version: 3.13.15
  • Operating system: Linux-5.14.0-687.34.1.el9_8.x86_64-x86_64-with-glibc2.34

What is happening?

Call: ---> 78 bit_array = BitArray.from_counts(counts, num_bits=num_modes)

yields error:

OverflowError: int too big to convert

Callback:

in qiskit/primitives/containers/bit_array.py:334,

333 num_bytes = _min_num_bytes(num_bits) --> [334] data = b"".join(val.to_bytes(num_bytes, "big") for val in ints)

from:

/qiskit/primitives/containers/bit_array.py:285,

--> [285] bit_array = BitArray.from_samples(data, num_bits)

Maybe num_bytes != (num_bits + 1) // 8 ?

How can we reproduce the issue?

This emerged from a set of measured results from a qpu.

What should happen?

I hope to see a valid bit_array.

Any suggestions?

No response