fix(PythonAPI/build): add NumPy 2 compatibility via Boost 1.89 upgrade #9670
Draft
JesusAnaya wants to merge 4 commits intocarla-simulator:ue4-devfrom
Draft
fix(PythonAPI/build): add NumPy 2 compatibility via Boost 1.89 upgrade #9670JesusAnaya wants to merge 4 commits intocarla-simulator:ue4-devfrom
JesusAnaya wants to merge 4 commits intocarla-simulator:ue4-devfrom
Conversation
… compatibility Replace np.bool with np.bool_ in DVS event dtype in V2XDemo.py, manual_control_chrono.py, and manual_control_carsim.py (removed in NumPy 1.24). Replace np.matrix with np.array in client_bounding_boxes.py (deprecated in NumPy 1.x, removed in NumPy 2.x). All replacements are backward-compatible with NumPy >= 1.18.4.
Contributor
|
Why should we merge this? |
Contributor
Author
|
Fair enough. I expect NumPy 1.x to reach end of life, and downstream libraries are already moving to require NumPy 2 (e.g., opencv-python >= 4.12). Having this compatibility in place before it becomes urgent seems better than scrambling later, but I understand if the priority isn't there yet. |
Contributor
|
What about using updated version of boost instead of patching it? I do not like patches. |
Contributor
Author
|
Good point. I went with a patch to avoid a full Boost version bump, which could be quite invasive in this refactoring, since we only needed to change a few things from Boost. But if you’d prefer to upgrade Boost instead, I can look into it and send a new commit. |
Contributor
|
is a PR from a former CARLA collaborator. |
Drop the in-tree dtype.cpp.patch against Boost 1.84.0 and upgrade to Boost 1.89.0, which carries the upstream NumPy 2 C ABI fix from boostorg/python#432 natively. libboost_numpy now compiles against both NumPy 1.x (>=1.18.4) and NumPy 2.x headers without any vendored patches. Boost 1.84 -> 1.89 removed several deprecated Asio and Filesystem APIs; all call sites in LibCarla and the CarlaTools UE4 plugin updated: - io_context::work -> executor_work_guard (removed 1.85) - io_context::reset() -> restart() (removed 1.86) - address::from_string() -> make_address() (removed 1.85) - resolver::query/iterator -> range-based resolve() (removed 1.85) - buffer_cast<T>() -> static_cast via streambuf::data().data() (removed 1.88) - io_service typedef -> io_context (removed 1.85) - boost/filesystem/operations.hpp no longer includes directory.hpp (1.85) Windows installer (install_boost.bat) SHA256 updated to the 1.89.0 zip digest. MSVC C4459 pragma guard added around boost/asio.hpp in MapPreviewUserWidget.h to prevent warnings-as-errors failure. New regression-guard tests: test_boost_deadline_timer.cpp (3 tests), test_boost_rtree.cpp (4 tests), test_boost_version.py.
8aa6489 to
b3f4d55
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Makes CARLA's PythonAPI compatible with both NumPy 1.x (>= 1.18.4) and NumPy 2.x.
NumPy 1.x support is preserved, not dropped.
NumPy 2.0 introduced two breaking changes relevant to CARLA:
np.boolandnp.matrixwere removed from the public API.Three example scripts used
np.boolas a dtype and one usednp.matrixfor transform math.PyArray_Descrwas made opaque, so the direct struct fieldreads in Boost.Python's
libs/python/src/numpy/dtype.cpp(->elsize,->typeobj)no longer compile against NumPy 2.x headers. Boost 1.89.0 carries the upstream fix for
this from boostorg/python#432 natively.
Commit 1,
95c97d602, Python alias fixes (4 files):np.bool->np.bool_inPythonAPI/examples/V2XDemo.py,manual_control_chrono.py,manual_control_carsim.py(DVS event dtype).np.matrix(np.identity(4))->np.array(np.identity(4))inclient_bounding_boxes.py.Safe because the only consumer is
np.dot(), not the*operator.Commit 2,
7968a0428, Boost 1.89.0 upgrade and build/test infrastructure (25 files):Upgrades Boost from 1.84.0 to 1.89.0. Boost 1.89 ships the NEP 52 fix natively, so
libboost_numpycompiles against both NumPy 1.x and 2.x headers without any vendored patches.Boost 1.84 -> 1.89 removed several deprecated Asio and Filesystem APIs. All affected call
sites in LibCarla and the CarlaTools UE4 plugin are updated:
LibCarla/source/carla/ThreadPool.hio_context::work->executor_work_guard(removed 1.85)LibCarla/source/carla/multigpu/listener.cppio_context::reset()->restart()(removed 1.86)LibCarla/source/carla/multigpu/router.cppaddress::from_string()->make_address()(removed 1.85)LibCarla/source/carla/multigpu/secondary.cppfrom_stringfixLibCarla/source/carla/rpc/Server.hreset()->restart()LibCarla/source/carla/streaming/EndPoint.hresolver::query/iterator-> range-basedresolve()(removed 1.85)LibCarla/source/carla/FileSystem.cpp#include <boost/filesystem/directory.hpp>(split in 1.85)LibCarla/source/test/common/test_streaming.cppio_context::work->executor_work_guardLibCarla/source/test/server/test_benchmark_streaming.cppUnreal/CarlaUE4/Plugins/CarlaTools/.../MapPreviewUserWidget.hio_service->io_context(removed 1.85); MSVC C4459 pragma guard addedUnreal/CarlaUE4/Plugins/CarlaTools/.../MapPreviewUserWidget.cppbuffer_cast<T>()->static_castviastreambuf::data().data()(removed 1.88)Build script updates:
Util/BuildTools/Setup.shUtil/BuildTools/Setup.batUtil/BuildTools/BuildOSMRenderer.batUtil/InstallersWin/install_boost.batDeleted:
Util/Patches/boost-1.84.0/dtype.cpp.patch,verify_patch.cpp,verify_patch.sh.Requirements widened from
numpy<2.0.0tonumpy>=1.18.4inPythonAPI/examples/requirements.txt,PythonAPI/carla/agents/requirements.txt, andPythonAPI/test/requirements.txt.Docker CI test requirements:
Util/Docker/requirements/3.11/test.txtand3.12/test.txtupdated to
numpy>=2.0.0for NumPy 2.x CI coverage.New regression-guard tests:
LibCarla/source/test/common/test_boost_deadline_timer.cppdeadline_timer/posix_timeregression guardLibCarla/source/test/common/test_boost_rtree.cppgeometry::index::rtreeregression guard (used by TrafficManager)PythonAPI/test/unit/test_boost_version.pyPythonAPI/test/unit/test_numpy_compat.pyPythonAPI/test/unit/run_numpy_compat_matrix.shtest_numpy_compat.pyin eachCommit 3,
b3f4d55f6, CHANGELOG:Fixes #9365
Where has this been tested?
Results:
make check.LibCarla: all LibCarla tests pass (121/121 server, 63/63 client).make check.PythonAPI: all Python unit tests pass, including all 5 tests intest_boost_version.py(static Boost version pin + no stale 1.84.0 link).python3 -m nose2 -v --start-dir PythonAPI/test/unit test_numpy_compatonPython 3.12 + NumPy 2.4.4 with the carla wheel installed: 15/15 pass.
bash PythonAPI/test/unit/run_numpy_compat_matrix.sh python3.12:carla C extension OK with NumPy 2.4.4, NumPy 2.x (NEP 52, opaque PyArray_Descr).make package ARGS="--python-version=3.10,3.11,3.12 --ros2 --chrono --no-zip --target-wheel-platform=manylinux_2_31_x86_64": SUCCESS.Possible Drawbacks
Build/boost-1.84.0-c10-install/orBuild/boost-1.84.0-install/tree from a previous checkout need to remove it before building, so the 1.89.0 source is
fetched and compiled. Running
make cleanis sufficient.install_boost.batSHA256 has been updated to the 1.89.0 zip digest. Cachedboost-1.84.0-install/directories on Windows build agents must likewise be removed.The Windows CI path does not build ROS2, so none of the Asio/Filesystem call-site changes
affect the Windows CI build.
This change is