RobotLocomotion / drake

Model-based design and verification for robotics.
https://drake.mit.edu
Other
3.16k stars 1.24k forks source link

NumPy 2.0 support (AttributeError: "itemset") #21577

Open jwnimmer-tri opened 2 weeks ago

jwnimmer-tri commented 2 weeks ago

Is your feature request related to a problem? Please describe.

NumPy 2.0 has been released. See https://numpy.org/devdocs/numpy_2_0_migration_guide.html.

Currently, importing certain pydrake versions crashes with this error:

AttributeError: `itemset` was removed from the ndarray class in NumPy 2.0.

Known to fail:

Describe the solution you'd like

Drake should be compatible with both NumPy 1.x and 2.x.

Describe alternatives you've considered

In the meantime, pydrake users should depend on numpy < 2 in their requirements file.

Alternatively, you can use a nightly build (which itself depends on numpy < 2).

jwnimmer-tri commented 2 weeks ago

For starters we need to merge up our pybind11 fork to incorporate https://github.com/pybind/pybind11/pull/5050, i.e., to v2.12.0. That means:

jwnimmer-tri commented 2 weeks ago

To unbreak our wheel builds, I believe can do something along these lines:

--- a/tools/wheel/image/provision-python.sh
+++ b/tools/wheel/image/provision-python.sh
@@ -42,7 +42,7 @@ ln -s /usr/local/bin/python /usr/bin/python
 # keeping them up to date if they are?
 pip install \
     matplotlib \
-    numpy \
+    'numpy < 2' \
     pyyaml \
     semantic-version \
     setuptools \
ggould-tri commented 2 weeks ago

https://drake-jenkins.csail.mit.edu/view/Production/job/linux-jammy-unprovisioned-gcc-wheel-nightly-release/111 is this issue; I am using the magic word //:install in this comment so that future buildcop searches will find this issue when they search for the failing target.

jwnimmer-tri commented 1 week ago

I think possibly the last remaining obstacle is to figure out how to rework https://github.com/RobotLocomotion/pybind11/commit/0da7ac7bda9d0cecd6a576e47afcfd4954f4bfcc to no longer rely on itemset, which is related to https://github.com/pybind/pybind11/issues/1181 and https://github.com/pybind/pybind11/pull/1152.

jwnimmer-tri commented 1 week ago

The first thing to try is if we can call __setitem__ with a slice, instead of itemset.