Cantera / cantera

Chemical kinetics, thermodynamics, and transport tool suite
https://cantera.org
Other
580 stars 341 forks source link

Fix Numpy 2.0 compatibility issues #1706

Closed speth closed 1 week ago

speth commented 2 weeks ago

Changes proposed in this pull request

Fix usage of functions that were removed or deprecated in NumPy 2.0.

We can make sure that at least some of the CI tests are using NumPy 2.0 once the official release is made on June 16 (https://github.com/numpy/numpy/issues/24300), and then merge this PR.

If applicable, fill in the issue number this pull request is fixing

Partially resolves #1675. I think the issues with matching versions of NumPy for packaged versions of Cantera will need to be resolved in the various packaging scripts, but we can leave the issue open until those changes are made.

If applicable, provide an example illustrating new features this pull request is introducing

Checklist

bryanwweber commented 2 weeks ago

Is this backwards compatible? In other words, will Cantera 3.1 require NumPy >=2.0, or can we support 1.x and 2.x simultaneously?

speth commented 2 weeks ago

This is meant to be backwards compatible, at least in terms of the source -- all the changes for us are pretty minor. I think the conda and PyPI packages will have to be specific to one version or another. I was hoping for your help in figuring some of that out. 😁

bryanwweber commented 2 weeks ago

I think the conda and PyPI packages will have to be specific to one version or another. I was hoping for your help in figuring some of that out. 😁

Yeah, the NumPy headers are different, right? I haven't looked into how that's meant to be handled. I'll see if there's anything out there, I assume NumPy have gotten out ahead of this.

speth commented 2 weeks ago

This may be easier than I thought. According to the NumPy Docs:

When you build wheels for your package using a NumPy 2.x version at build time, those will work with NumPy 1.xx.

codecov[bot] commented 1 week ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 72.83%. Comparing base (9f48b07) to head (8e2e1ce).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1706 +/- ## ======================================= Coverage 72.82% 72.83% ======================================= Files 379 379 Lines 53593 53593 Branches 9123 9123 ======================================= + Hits 39031 39032 +1 + Misses 11610 11609 -1 Partials 2952 2952 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

bryanwweber commented 1 week ago

One tricky thing I found here is that Pint 0.24 supports Python 3.10 and up, and only Pint >=0.24 supports NumPy 2.0. https://github.com/hgrecco/pint/commit/749d77c69abc755b374553fc7152df1c0a89e557 for the Python 3.10 stuff and I'm having test failures on Python 3.9 with cibuildwheel because it's installing 0.23.2 of Pint and 2.0 of NumPy.

I think the solution is to edit the setup.cfg to force numpy<2.0 if the units extra is selected and Python is < 3.9

bryanwweber commented 1 week ago

Thanks @speth I'm going to merge this and move any further work to #1713