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

Fix Numpy 2.0 compatibility issues #1706

Merged
merged 2 commits into from
Jun 19, 2024
Merged

Conversation

speth
Copy link
Member

@speth speth commented Jun 8, 2024

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 (numpy/numpy#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

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • The pull request is ready for review

@speth speth added the Python label Jun 8, 2024
@bryanwweber
Copy link
Member

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
Copy link
Member Author

speth commented Jun 9, 2024

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
Copy link
Member

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
Copy link
Member Author

speth commented Jun 11, 2024

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.

Copy link

codecov bot commented Jun 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@           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           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@speth speth force-pushed the numpy-2.0-compat branch 8 times, most recently from 146f238 to 0cf35ea Compare June 17, 2024 22:11
Comment on lines 19 to 21
dependencies = [
"numpy>=1.19.3",
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be coming from setup.cfg, is it not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just trying things. I'm not finding the supposed ABI compatibility of the compiled module with older NumPy versions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll experiment with this tomorrow too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, from the latest runs, it seems like backwards compatibility is working as expected when building with NumPy 2.0.0. The problem is with the builds for Python 3.8 using NumPy 1.24 and then running with NumPy 1.19. And now I've finally read this page enough times to understand that this is expected not to work and we have to go the other way around in this case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got it. The dependency, at least in the sdist at wheel build time, is that "oldest-supported-numpy" option they mention. But good to know that it needs to depend on the Python versions that NumPy supports

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. It sounds like this should be a lot easier going forward -- a build-time dependency on NumPy 2.x will provide backwards compatibility with NumPy 1.x and also forward compatibility with future 2.x releases. If we want to get ahead of things, I suppose we could set the version requirement to numpy<3.

@speth speth force-pushed the numpy-2.0-compat branch 2 times, most recently from 0a94036 to df8336e Compare June 18, 2024 03:20
@speth speth marked this pull request as ready for review June 18, 2024 13:44
@bryanwweber
Copy link
Member

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. hgrecco/pint@749d77c 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
Copy link
Member

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

@bryanwweber bryanwweber merged commit f4a88d2 into Cantera:main Jun 19, 2024
48 checks passed
@speth speth deleted the numpy-2.0-compat branch June 19, 2024 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upcoming breaking changes in Numpy 2.0
2 participants