Skip to content
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

PyHmmer sets CPU float behaviour globally, potentially causing issues in other libraries #71

Open
jakobnissen opened this issue Jul 19, 2024 · 1 comment
Labels
bug Something isn't working building Related to building the package

Comments

@jakobnissen
Copy link

jakobnissen commented Jul 19, 2024

When loading pyhmmer v0.10.12 together with NumPy v1.26.4, the following warning are printed to the screen:

/home/jakni/miniconda3/envs/vamb312/lib/python3.12/site-packages/numpy/core/getlimits.py:549: UserWarning: The value of the smallest subnormal for <class 'numpy.float64'> type is zero.
  setattr(self, word, getattr(machar, word).flat[0])
/home/jakni/miniconda3/envs/vamb312/lib/python3.12/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for <class 'numpy.float64'> type is zero.
  return self._float_to_str(self.smallest_subnormal)
/home/jakni/miniconda3/envs/vamb312/lib/python3.12/site-packages/numpy/core/getlimits.py:549: UserWarning: The value of the smallest subnormal for <class 'numpy.float32'> type is zero.
  setattr(self, word, getattr(machar, word).flat[0])
/home/jakni/miniconda3/envs/vamb312/lib/python3.12/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for <class 'numpy.float32'> type is zero.
  return self._float_to_str(self.smallest_subnormal)

From a bit of googling, this is what I found out:

  • This happens when NumPy is loaded when the FTZ and/or DAZ (not sure which of the flags it is) are set in the CPU.
  • Whether this flag is on/off changes the behaviour of floating point operations. These flags are usually not safe to have enabled and can cause numerical instability in NumPy and many other libraries

It looks like C libraries compiled with either -Ofast or -ffast-math will cause the C library to set this flag when loaded.

Apart from the annoying warning, it is unsafe, and also completely unreasonable that loading one library will globally affect the CPU's behaviour for the whole process, including all other libraries.
I narrowed it down to pyhmmer 0.10.12.

This can be solved by compiling pyhmmer without these flags.

@althonos
Copy link
Owner

This is unfortunately a known problem (#38) with the CPython binaries distributed in the cibuildwheel containers, where some of them were indeed compiled with -ffast-math for some reason, and the flags were then getting into the default compilation flags reported by sysconfig and used by default in the setup.py script...

@althonos althonos added building Related to building the package bug Something isn't working labels Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working building Related to building the package
Projects
None yet
Development

No branches or pull requests

2 participants