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 #48

Merged
merged 3 commits into from
Aug 5, 2024
Merged

fix: numpy 2.0 compatibility #48

merged 3 commits into from
Aug 5, 2024

Conversation

lgray
Copy link
Contributor

@lgray lgray commented Jul 29, 2024

This uses latest numpy in the build system, oldest possible numpy is no longer a correct choice.

Checked on laptop with numpy 1 and this package built against numpy 2.

@lgray
Copy link
Contributor Author

lgray commented Jul 30, 2024

@tpgillam whenever you get a chance to pull this in and make a new release, it would be appreciated!

@tpgillam
Copy link
Owner

tpgillam commented Jul 30, 2024

Thanks for the contribution @lgray!

Looking at the state of the tests, I think this package is overdue a little spring cleaning first. I’ll get to that when I can, then will be great to have numpy 2 compatibility working.

Assorted list of what needs doing:

  • Extend test suite to make sure we test with a (minimal numpy, latest 1.x, latest 2.x)
  • Extend support up to python 3.12
  • Test and build wheels for for macos arm (or universal? Will need to check current recommendations)
  • (Optionally) migrate everything over to pyproject.toml

@tpgillam
Copy link
Owner

Also, as far as I can tell, oldest-supported-numpy is still maintained and recommended.

https://pypi.org/project/oldest-supported-numpy/

What breaks for you with it?

@lgray
Copy link
Contributor Author

lgray commented Jul 30, 2024

https://github.com/scipy/oldest-supported-numpy

Please have a look at the deprecation notice on their GitHub. It might be on pypi but it is no longer the right way to do things, and does indeed cause problems. There's no forwards compatibility. As given the package won't work when numpy 2 is installed.

I can update your CI as well to use the presently supported range of python 3s. Ah, it's on your list upstairs. Checking against numpy1 should be easy, you do the build, uninstall numpy 2, install numpy 1 and run tests again.

@lgray
Copy link
Contributor Author

lgray commented Jul 30, 2024

It looks like your oldest supported numpy is going to be 1.26, given that you would like to support python 3.12.

@lgray
Copy link
Contributor Author

lgray commented Jul 30, 2024

@tpgillam that should be most of the spring cleaning :-)

@lgray
Copy link
Contributor Author

lgray commented Jul 30, 2024

The only thing I need to add is to test with numpy 2 and numpy 1

@tpgillam
Copy link
Owner

Just drive-by commenting, don't have time to look in detail at your work right now, sorry!

https://github.com/scipy/oldest-supported-numpy

Thanks for the reference! I'll read this in more detail later.

It looks like your oldest supported numpy is going to be 1.26, given that you would like to support python 3.12.

I feel like it should be possible to support older versions when using a suitable python interpreter. I'm inclined to be as protective as possible towards users that might be on older systems.

@lgray
Copy link
Contributor Author

lgray commented Jul 30, 2024

and there we go.

@lgray
Copy link
Contributor Author

lgray commented Jul 30, 2024

The answer that users will get from the python core developers for anything less than python 3.9 is "that version of python is no longer supported". You're pretty well situated to rattle things around and tell people to update their systems.

The oldest numpy version supported in python 3.12 is 1.26, the newest numpy version supported in python 3.9 is 2.0.1. It's rather cut and dried as to what to do if you would like to support python 3.12.

@lgray
Copy link
Contributor Author

lgray commented Jul 30, 2024

Ah lovely - I can fix up the problems so long as you let the CI run. Thanks!

@Rupt
Copy link
Collaborator

Rupt commented Jul 30, 2024

Thanks for your diligent contributions @lgray.

I can't comment on the implementation, but your statements about NumPy compatibility surprise me, because they contradict NumPy's support specification https://scientific-python.org/specs/spec-0000/ (forwarded from https://numpy.org/neps/nep-0029-deprecation_policy.html).

I can sadly confirm that you are correct: NumPy versions <1.26 does not support Python 3.12:

PYTHON_BUILD=cpython-3.12.4+20240726-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz
wget https://github.com/indygreg/python-build-standalone/releases/download/20240726/${PYTHON_BUILD}
tar xvf ${PYTHON_BUILD}
python/bin/python --version  # Python 3.12.4
python/bin/pip install numpy==2.0  # ok
python/bin/pip install numpy==1.26  # ok
python/bin/pip install numpy==1.25  # error
python/bin/pip install numpy==1.24  # error

@lgray
Copy link
Contributor Author

lgray commented Jul 30, 2024

Ah, you're right @Rupt with respect to the numpy support window. The issue comes when you want to support 2 and 3.12 simultaneously. I don't have a machine where I can test numpy 2 vs. much older numpy (arm macos machine right now), but if you really need it we can support back to 1.22 (and I think you can do that compiling with 2).

However, there's not too much of a good reason to do that, IMO, considering current environment management practices.

src/mt2_Lallyver2.h Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
@tpgillam
Copy link
Owner

@lgray thanks for your continuing efforts to get the CI working! Wondering whether it would be easier for you to create a PR into your own fork such that you can run the CI yourself for testing (at least I presume that would work)? I'm happy to press 'approve & run' when I see it, but maybe you'd prefer to have faster iteration times.

@lgray
Copy link
Contributor Author

lgray commented Jul 30, 2024

A bunch of the failures in the wheel CI are from the wheels already existing since you seem to be uploading even in PR! A little dangerous.

I'll make it check for a release tag.

@lgray
Copy link
Contributor Author

lgray commented Jul 30, 2024

Oh, nevermind, that's just the github artifacts.

@tpgillam
Copy link
Owner

I'll make it check for a release tag.

We have this check:

if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')

maybe it can be made better.

@lgray
Copy link
Contributor Author

lgray commented Jul 31, 2024

@tpgillam could you have a look in github and see if you can kill the uploaded artifacts for this PR?

@lgray
Copy link
Contributor Author

lgray commented Jul 31, 2024

I've changed the CI so it only uploads artifacts when there's a version tag. So I think this is almost there.

@lgray
Copy link
Contributor Author

lgray commented Jul 31, 2024

ok - nice - it works back to numpy 1.19.3 when built against numpy 2, according to the tests in python 3.9. Have adjusted all the pins.

@lgray
Copy link
Contributor Author

lgray commented Jul 31, 2024

Indeed, running the CI over on my own fork everything passes now, and we correctly test numpy back to oldest supported in 3.9.

https://github.com/lgray/mt2/actions/runs/10186047164/job/28176969069?pr=1

@tpgillam
Copy link
Owner

tpgillam commented Aug 1, 2024

Thanks @lgray . github doesn't list any persisted artifacts for this workflow, so let's see what happens in this CI run.

Could you please bump the version in all appropriate places to 1.2.1 and add entry in HISTORY so that we can then tag once merged?

pyproject.toml Outdated Show resolved Hide resolved
setup.py Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
@lgray lgray requested a review from tpgillam August 1, 2024 14:35
@lgray
Copy link
Contributor Author

lgray commented Aug 2, 2024

looks like it's all good to go aside from your github options expecting a job simply called "Build"!

@lgray
Copy link
Contributor Author

lgray commented Aug 2, 2024

let me make a meta task with that name that just requires all the other jobs to pass, then it'll change as the matrix changes... sorry if I deleted that earlier.

@lgray
Copy link
Contributor Author

lgray commented Aug 2, 2024

OK - @tpgillam added two things and I think this is done.

  1. Build / pass job label represents all jobs passing, you'll need to add that to your repository config as the expected check, instead of "Build"
  2. as commits are added to a PR if there are previously running CI jobs on the same PR it will cancel them, better for GHA resources

Copy link
Owner

@tpgillam tpgillam left a comment

Choose a reason for hiding this comment

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

Thanks @lgray , this looks great!

The required checks on github are baffling me. I wish they were configurable more sensibly, but hey-ho. I've tried but so far failed to get it to match Build / pass or Build / pass (pull request).

edit: apparently the magic was just to require pass on the github side.

@tpgillam tpgillam added the enhancement New feature or request label Aug 5, 2024
@lgray
Copy link
Contributor Author

lgray commented Aug 5, 2024

Cool, thanks a lot for dealing with all the churn. :-)

Whenever you're ready, please merge and make a release!

@tpgillam tpgillam merged commit d80c34d into tpgillam:master Aug 5, 2024
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants