Skip to content

fix(PythonAPI/build): add NumPy 2 compatibility via Boost 1.89 upgrade #9670

Draft
JesusAnaya wants to merge 4 commits intocarla-simulator:ue4-devfrom
JesusAnaya:fix/numpy2_compatibility
Draft

fix(PythonAPI/build): add NumPy 2 compatibility via Boost 1.89 upgrade #9670
JesusAnaya wants to merge 4 commits intocarla-simulator:ue4-devfrom
JesusAnaya:fix/numpy2_compatibility

Conversation

@JesusAnaya
Copy link
Copy Markdown
Contributor

@JesusAnaya JesusAnaya commented Apr 14, 2026

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:

  1. Python level: np.bool and np.matrix were removed from the public API.
    Three example scripts used np.bool as a dtype and one used np.matrix for transform math.
  2. C ABI level (NEP 52): PyArray_Descr was made opaque, so the direct struct field
    reads 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_ in PythonAPI/examples/V2XDemo.py, manual_control_chrono.py,
    manual_control_carsim.py (DVS event dtype).
  • np.matrix(np.identity(4)) -> np.array(np.identity(4)) in client_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_numpy compiles 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:

File Change
LibCarla/source/carla/ThreadPool.h io_context::work -> executor_work_guard (removed 1.85)
LibCarla/source/carla/multigpu/listener.cpp io_context::reset() -> restart() (removed 1.86)
LibCarla/source/carla/multigpu/router.cpp address::from_string() -> make_address() (removed 1.85)
LibCarla/source/carla/multigpu/secondary.cpp same from_string fix
LibCarla/source/carla/rpc/Server.h reset() -> restart()
LibCarla/source/carla/streaming/EndPoint.h resolver::query/iterator -> range-based resolve() (removed 1.85)
LibCarla/source/carla/FileSystem.cpp added #include <boost/filesystem/directory.hpp> (split in 1.85)
LibCarla/source/test/common/test_streaming.cpp io_context::work -> executor_work_guard
LibCarla/source/test/server/test_benchmark_streaming.cpp same fix
Unreal/CarlaUE4/Plugins/CarlaTools/.../MapPreviewUserWidget.h io_service -> io_context (removed 1.85); MSVC C4459 pragma guard added
Unreal/CarlaUE4/Plugins/CarlaTools/.../MapPreviewUserWidget.cpp buffer_cast<T>() -> static_cast via streambuf::data().data() (removed 1.88)

Build script updates:

File Change
Util/BuildTools/Setup.sh version 1.84.0 -> 1.89.0, SHA256 updated, patch-apply lines removed
Util/BuildTools/Setup.bat version bump (Windows)
Util/BuildTools/BuildOSMRenderer.bat install path bump (Windows)
Util/InstallersWin/install_boost.bat zip SHA256 updated to 1.89.0 digest

Deleted: Util/Patches/boost-1.84.0/dtype.cpp.patch, verify_patch.cpp, verify_patch.sh.

Requirements widened from numpy<2.0.0 to numpy>=1.18.4 in
PythonAPI/examples/requirements.txt, PythonAPI/carla/agents/requirements.txt, and
PythonAPI/test/requirements.txt.

Docker CI test requirements: Util/Docker/requirements/3.11/test.txt and 3.12/test.txt
updated to numpy>=2.0.0 for NumPy 2.x CI coverage.

New regression-guard tests:

File Purpose
LibCarla/source/test/common/test_boost_deadline_timer.cpp 3 tests: deadline_timer / posix_time regression guard
LibCarla/source/test/common/test_boost_rtree.cpp 4 tests: geometry::index::rtree regression guard (used by TrafficManager)
PythonAPI/test/unit/test_boost_version.py asserts Boost 1.89 pinned in Setup.sh and no stale 1.84.0 patch dir or link
PythonAPI/test/unit/test_numpy_compat.py 15 tests: Python alias regression, DVS pipeline, carla C extension load under NumPy 1.x and 2.x
PythonAPI/test/unit/run_numpy_compat_matrix.sh matrix runner: creates venvs for NumPy 1.x and 2.x, installs the wheel, runs test_numpy_compat.py in each

Commit 3, b3f4d55f6, CHANGELOG:

  • Added entry noting NumPy 1.x and 2.x compatibility.

Fixes #9365

Where has this been tested?

  • Platform(s): Ubuntu 22.04
  • Python version(s): 3.8, 3.9, 3.10, 3.11, 3.12
  • Unreal Engine version(s): UE4.26

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 in
    test_boost_version.py (static Boost version pin + no stale 1.84.0 link).
  • python3 -m nose2 -v --start-dir PythonAPI/test/unit test_numpy_compat on
    Python 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:
    • NumPy 1.x venv (1.26.4): 15/15 pass.
    • NumPy 2.x venv (2.4.4): 15/15 pass. Log line confirms end-to-end load:
      carla C extension OK with NumPy 2.4.4, NumPy 2.x (NEP 52, opaque PyArray_Descr).
  • CI-equivalent full package build:
    make package ARGS="--python-version=3.10,3.11,3.12 --ros2 --chrono --no-zip --target-wheel-platform=manylinux_2_31_x86_64": SUCCESS.
  • Smoke tests (Python 3.12, port 3654): all pass.

Possible Drawbacks

  • Users with a cached Build/boost-1.84.0-c10-install/ or Build/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 clean is sufficient.
  • Windows: install_boost.bat SHA256 has been updated to the 1.89.0 zip digest. Cached
    boost-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 Reviewable

… 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.
@JesusAnaya JesusAnaya requested a review from a team as a code owner April 14, 2026 06:54
@LuisPovedaCano LuisPovedaCano self-assigned this Apr 14, 2026
@Blyron
Copy link
Copy Markdown
Contributor

Blyron commented Apr 14, 2026

Why should we merge this?

@JesusAnaya
Copy link
Copy Markdown
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.

@Blyron
Copy link
Copy Markdown
Contributor

Blyron commented Apr 14, 2026

What about using updated version of boost instead of patching it? I do not like patches.

@JesusAnaya
Copy link
Copy Markdown
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.

@Blyron
Copy link
Copy Markdown
Contributor

Blyron commented Apr 14, 2026

Look at this https://github.com/carla-simulator/carla/pull/9487/changes#diff-e69ecb8d585c244655338ab3d5b078f10bca6c28d00bf4357e064baf193d0e45

is a PR from a former CARLA collaborator.

@JesusAnaya JesusAnaya marked this pull request as draft April 14, 2026 17:15
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.
@JesusAnaya JesusAnaya force-pushed the fix/numpy2_compatibility branch from 8aa6489 to b3f4d55 Compare April 14, 2026 20:27
@JesusAnaya JesusAnaya changed the title fix(PythonAPI): NumPy 2 compatibility and Boost.Python ABI patch fix(PythonAPI/build): add NumPy 2 compatibility via Boost 1.89 upgrade Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants