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

Numpy.core.getlimits.py UserWarning: The value of the smallest subnormal for <class 'numpy.float32'> type is zero. #347

Open
oschwengers opened this issue Nov 15, 2024 · 9 comments
Assignees
Labels
help wanted Extra attention is needed upstream Should be reported upstream

Comments

@oschwengers
Copy link
Owner

Unfortunately, somewhere on the last mile towards v1.10.0, the following numpy UserWarning started to appeared in each invocation of Bakta:

conda-envs/bakta-test/lib/python3.11/site-packages/numpy/_core/getlimits.py:555: UserWarning: The value of the smallest subnormal for <class 'numpy.float32'> type is zero.
  setattr(self, word, getattr(machar, word).flat[0])
conda-envs/bakta-test/lib/python3.11/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)
conda-envs/bakta-test/lib/python3.11/site-packages/numpy/_core/getlimits.py:555: UserWarning: The value of the smallest subnormal for <class 'numpy.float64'> type is zero.
  setattr(self, word, getattr(machar, word).flat[0])
conda-envs/bakta-test/lib/python3.11/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)

As reported in #346 and discudded here, it seems to be related to some ffast-math compilation flag set by any of Bakta's dependency - or dependency's dependency...

If someone has an idea or solution how to solve or circumvent this, please let us know.

@oschwengers oschwengers added help wanted Extra attention is needed upstream Should be reported upstream labels Nov 15, 2024
@oschwengers oschwengers self-assigned this Nov 18, 2024
@oschwengers oschwengers pinned this issue Nov 25, 2024
@eri-lim
Copy link

eri-lim commented Jan 21, 2025

Hi, just for info - would like to report that this has occurred in v1.10.1 as well.

@pjbiggs
Copy link

pjbiggs commented Jan 22, 2025

Hi - and also in v1.10.3 too. thanks.

@oschwengers
Copy link
Owner Author

Thanks for the update. I'm pretty sure, that this error is actually not caused by Bakta itself but some 3rd /4th/5th-party dependency within the Bakta Conda environment. Unfortunately, I have currently no clue what is causing this and also no resources to dive deeper into this. But, since this is not an error but only a warning I tend to let it go and hope that someone will fix this within the causing Conda package.

@eri-lim
Copy link

eri-lim commented Jan 28, 2025

Thank you. Just to clarify, it was a fatal error - something like in #346, and then Bakta crashes with that Numpy message. So, just notifying in case anyone else experiences this.

@oschwengers
Copy link
Owner Author

OK, thanks for letting us know, but these are two unrelated things: one warning (the subject of this issue) and then, an addition fatal error. To keep these things apart from each other, could you please open a dedicated issue for the fatal error describing it in more detail (input/output/logs/etc)?

@eri-lim
Copy link

eri-lim commented Jan 28, 2025

I went to obtain the details but it seems I am now unable to reproduce the crash (it runs again, but also I have redownloaded the database in the process, using the light database). Thanks for the instructions regarding the error. If I encounter it reproducibly, I will open a dedicated issue.

Thank you for your hard work on Bakta!

@snail123815
Copy link

Hi,

I added this to __init__.py to make warnings fail:

import warnings
warnings.simplefilter("error", UserWarning)

And got the following Traceback. I will suggest checking settings related with color. Or, maybe different versions of matplotlib + numpy combination?

Traceback (most recent call last):
  File "/vol/local/conda_envs/bakta/bin/bakta", line 6, in <module>
    from bakta.main import main
  File "/vol/local/conda_envs/bakta/lib/python3.11/site-packages/bakta/main.py", line 37, in <module>
    import bakta.plot as plot
  File "/vol/local/conda_envs/bakta/lib/python3.11/site-packages/bakta/plot.py", line 15, in <module>
    from matplotlib.patches import Patch
  File "/vol/local/conda_envs/bakta/lib/python3.11/site-packages/matplotlib/__init__.py", line 997, in <module>
    rcParamsDefault = _rc_params_in_file(
                      ^^^^^^^^^^^^^^^^^^^
  File "/vol/local/conda_envs/bakta/lib/python3.11/site-packages/matplotlib/__init__.py", line 934, in _rc_params_in_file
    config[key] = val  # try to convert to proper type or raise
    ~~~~~~^^^^^
  File "/vol/local/conda_envs/bakta/lib/python3.11/site-packages/matplotlib/__init__.py", line 769, in __setitem__
    cval = self.validate[key](val)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/vol/local/conda_envs/bakta/lib/python3.11/site-packages/matplotlib/rcsetup.py", line 342, in validate_color
    if is_color_like(s):
       ^^^^^^^^^^^^^^^^
  File "/vol/local/conda_envs/bakta/lib/python3.11/site-packages/matplotlib/colors.py", line 229, in is_color_like
    to_rgba(c)
  File "/vol/local/conda_envs/bakta/lib/python3.11/site-packages/matplotlib/colors.py", line 316, in to_rgba
    rgba = _to_rgba_no_colorcycle(c, alpha)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/vol/local/conda_envs/bakta/lib/python3.11/site-packages/matplotlib/colors.py", line 338, in _to_rgba_no_colorcycle
    if c is np.ma.masked:
            ^^^^^
  File "/vol/local/conda_envs/bakta/lib/python3.11/site-packages/numpy/__init__.py", line 346, in __getattr__
    import numpy.ma as ma
  File "/vol/local/conda_envs/bakta/lib/python3.11/site-packages/numpy/ma/__init__.py", line 42, in <module>
    from . import core
  File "/vol/local/conda_envs/bakta/lib/python3.11/site-packages/numpy/ma/core.py", line 201, in <module>
    info = np.finfo(sctype)
           ^^^^^^^^^^^^^^^^
  File "/vol/local/conda_envs/bakta/lib/python3.11/site-packages/numpy/_core/getlimits.py", line 544, in __new__
    obj = object.__new__(cls)._init(dtype)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/vol/local/conda_envs/bakta/lib/python3.11/site-packages/numpy/_core/getlimits.py", line 558, in _init
    setattr(self, word, getattr(machar, word).flat[0])
                        ^^^^^^^^^^^^^^^^^^^^^
  File "/vol/local/conda_envs/bakta/lib/python3.11/site-packages/numpy/_core/getlimits.py", line 81, in smallest_subnormal
    warnings.warn(
UserWarning: The value of the smallest subnormal for <class 'numpy.float32'> type is zero.

@oschwengers
Copy link
Owner Author

Thank you very much @snail123815 ! This really helps to trace and identify the source of this behavior. However, I'm still puzzled how to deactivate this...

@snail123815
Copy link

So am I @oschwengers. After some search it seems that the problem is more upstream and not consistent in different environments. Seems to be related with the building of some packages with -ffast-math switch.

I found this post Qiskit/qiskit-aer#1469 which might be useful.


For me, downgrade numpy to version 1 (1.26) and the warning is gone.

Or ignore this warning explicitly by adding in the __init__.py

import warnings
warnings.filterwarnings("ignore", message="The value of the smallest subnormal for")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed upstream Should be reported upstream
Projects
None yet
Development

No branches or pull requests

4 participants