scikit-hep / iminuit

Jupyter-friendly Python interface for C++ MINUIT2
https://scikit-hep.org/iminuit
Other
283 stars 76 forks source link

Support NumPy 2 #977

Closed henryiii closed 5 months ago

henryiii commented 6 months ago

A new release of iMinuit needs to be made with pybind11 2.12 in order to support numpy 2. All binaries must be rebuilt with pybind11 2.12+ in order to support NumPy 2.

That should happen automatically, but I took the opportunity to update a few things while I was adding a NumPy 2 test. (which I actually forgot to do, will make draft until I add that!)

henryiii commented 6 months ago

VisibleDeprecationWarning has been removed in NumPy 2. Actually, I think it was always supposed to be numpy.exceptions.VisibleDeprecationWarning, it just used to be leaked into the main namespace in NumPy 1.

Edit: Ahh, no, it's moved now, but it wasn't always there. I'll work on this in a couple of days. I think we have about at least a week before release.

FYI, Python has a visible Deprecation warning. It's called FutureWarning: Base class for warnings about deprecated features when those warnings are intended for end users of applications that are written in Python. (Wording was updated in a PEP a few years ago to clarify it is intended to be a deprecation warning)

henryiii commented 6 months ago

Successful wheel build: https://github.com/henryiii/iminuit/actions/runs/8520504460/job/23336798970

henryiii commented 6 months ago

SciPy 1.13 has shipped! One step closer to NumPy 2.0 releasing. pip install iminuit will start breaking in Python 3.9+ once NumPy 2 ships if we don’t make a new release. Boost-histogram and awkward have released new compatible versions.

HDembinski commented 6 months ago

FYI, Python has a visible Deprecation warning. It's called FutureWarning: Base class for warnings about deprecated features when those warnings are intended for end users of applications that are written in Python. (Wording was updated in a PEP a few years ago to clarify it is intended to be a deprecation warning)

Ok, I shall use that in the future.

HDembinski commented 6 months ago

Thank you for the extensive patch and the pointers. If feasible, I would prefer to install the right versions of dependencies via environment markers declared in pyproject.toml. This should be possible for the numpy version at least. scipy is an optional dependency, I don't know whether these can be declared with environment markers as well. If it is cannot be done easily, then installing the right scipy version in the CI workflow is ok.

HDembinski commented 5 months ago

Thank you for the nice patch.

matthewfeickert commented 4 months ago

:wave: @HDembinski would it be possible to get a release of some sort (I'm not sure given the development that has happened since release v2.25.2 what SemVer type it should be, that's up to you, but looks like a patch release(?)) to support NumPy 2?

$ docker run --rm -ti python:3.12 /bin/bash
root@f790da29487c:/# python -m venv venv && . venv/bin/activate
(venv) root@f790da29487c:/# python -m venv venv && . venv/bin/activate
(venv) root@f790da29487c:/# python -m pip --quiet install --upgrade pip wheel
(venv) root@f790da29487c:/# python -m pip install --upgrade iminuit
Collecting iminuit
  Downloading iminuit-2.25.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (11 kB)
Collecting numpy>=1.21 (from iminuit)
  Downloading numpy-1.26.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.0/61.0 kB 926.1 kB/s eta 0:00:00
Downloading iminuit-2.25.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (423 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 423.9/423.9 kB 6.2 MB/s eta 0:00:00
Downloading numpy-1.26.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.0 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.0/18.0 MB 42.7 MB/s eta 0:00:00
Installing collected packages: numpy, iminuit
Successfully installed iminuit-2.25.2 numpy-1.26.4
(venv) root@f790da29487c:/# python -m pip install --upgrade --pre numpy
Requirement already satisfied: numpy in /venv/lib/python3.12/site-packages (1.26.4)
Collecting numpy
  Downloading numpy-2.0.0rc2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (60 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.9/60.9 kB 937.6 kB/s eta 0:00:00
Downloading numpy-2.0.0rc2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.0 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 19.0/19.0 MB 52.2 MB/s eta 0:00:00
Installing collected packages: numpy
  Attempting uninstall: numpy
    Found existing installation: numpy 1.26.4
    Uninstalling numpy-1.26.4:
      Successfully uninstalled numpy-1.26.4
Successfully installed numpy-2.0.0rc2
(venv) root@f790da29487c:/# python
Python 3.12.3 (main, Apr 24 2024, 11:17:35) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import iminuit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/venv/lib/python3.12/site-packages/iminuit/__init__.py", line 24, in <module>
    from iminuit.minuit import Minuit
  File "/venv/lib/python3.12/site-packages/iminuit/minuit.py", line 6, in <module>
    from iminuit import util as mutil
  File "/venv/lib/python3.12/site-packages/iminuit/util.py", line 11, in <module>
    from iminuit import _repr_html, _repr_text, _deprecated
  File "/venv/lib/python3.12/site-packages/iminuit/_deprecated.py", line 2, in <module>
    from numpy import VisibleDeprecationWarning
ImportError: cannot import name 'VisibleDeprecationWarning' from 'numpy' (/venv/lib/python3.12/site-packages/numpy/__init__.py)

I've started to see this in some environments where other dependencies are testing against the release candidates of NumPy, and it would be great if iminuit could have a release that supports them, as these changes are already in the repository.

henryiii commented 4 months ago

NumPy 2 will be released mid June. June 16 IIRC. I would highly recommend releasing an iminuit release supporting it before then!

HDembinski commented 4 months ago

@henryiii @matthewfeickert Release is in progress.

henryiii commented 4 months ago

Fantastic, thanks! I think this means all our key libraries are now ready for NumPy 2.