def _pack_digits(digits: np.ndarray, pack_bits: str = 'auto') -> tuple[str, bool]:
    """Returns a string of packed digits and a boolean indicating whether the
    digits were packed as binary values.

    Args:
        digits: A numpy array.
        pack_bits: If 'auto' (the default), automatically pack binary digits
            using `np.packbits` to save space. If 'never', do not pack binary
            digits. If 'force', use `np.packbits` without checking for
            compatibility.

    Raises:
        ValueError: If `pack_bits` is not `auto`, `force`, or `never`.
    """
    # If digits are binary, pack them better to save space

    if pack_bits == 'force':
        return _pack_bits(digits), True
    if pack_bits not in ['auto', 'never']:
        raise ValueError("Please set `pack_bits` to 'auto', 'force', or 'never'.")
        # Do error checking here, otherwise the following logic will work
        # for both "auto" and "never".

    if pack_bits == 'auto' and np.array_equal(digits, digits.astype(np.bool_)):
        return _pack_bits(digits.astype(np.bool_)), True

    buffer = io.BytesIO()
    np.save(buffer, digits, allow_pickle=False)
    buffer.seek(0)
    packed_digits = buffer.read().hex()
    buffer.close()
    return packed_digits, False
Returns a string of packed digits and a boolean indicating whether the
    digits were packed as binary values.

    Args:
        digits: A numpy array.
        pack_bits: If 'auto' (the default), automatically pack binary digits
            using `np.packbits` to save space. If 'never', do not pack binary
            digits. If 'force', use `np.packbits` without checking for
            compatibility.

    Raises:
        ValueError: If `pack_bits` is not `auto`, `force`, or `never`.
    
cirq-core/cirq/study/result.py