quantumlib / Qualtran

Qᴜᴀʟᴛʀᴀɴ is a Python library for expressing and analyzing Fault Tolerant Quantum algorithms.
https://qualtran.readthedocs.io/en/latest/
Apache License 2.0
132 stars 35 forks source link

Remove `bit_tools` and replace with `QDType` features #1041

Closed charlesyuan314 closed 3 weeks ago

charlesyuan314 commented 1 month ago

Replace references to iter_bits, iter_bits_twos_complement, and iter_bits_fixed_point from qualtran.cirq_interop.bit_tools as they are largely duplicated by functionality in QUInt, QInt, and QFxp respectively.

Move functionality of float_as_fixed_width_int to QFxp.to_fixed_width_int.

Modify QFxp.to_bits to enable the exactly-representable check to be bypassed and to enable overriding the twos-complement representation of negative binary fractions used by fxpmath. Previous users of iter_bits_fixed_point instead require sign-magnitude representation.

Remove bit_tools and move its tests to data_types.

Towards #811. Updates to users of classical_sim.ints_to_bits should follow in another PR.

charlesyuan314 commented 1 month ago

@mpharrigan PTAL.

As far as I can tell, classical_sim.ints_to_bits and classical_sim.bits_to_ints are currently only used in relation to classical simulation. They also use np.uint64 for what I assume to be performance reasons. So I haven't touched those at this point.