From e18a86a415a9ea721a69dd06ca898eb3c3421eaf Mon Sep 17 00:00:00 2001 From: Fatima Anes Date: Sat, 1 Aug 2026 23:48:49 -0700 Subject: [PATCH] fix(newton): size RSL-RL contact buffer to solver naconmax Base _initialize_contacts sized NewtonManager._contacts from the collision pipeline alone (rigid_contact_max = ~15/env auto-estimate = 3840 at 256 envs) and never consulted the solver's naconmax (nconmax=100 x 256 = 25600). On the use_mujoco_contacts=False (RSL-RL) path, _update_sensors -> solver.update_contacts() requires buffer >= naconmax, so Isaac-Velocity-Rough-G1 with presets=newton_mjwarp crashed at sim.reset(): ValueError: MuJoCo naconmax (25600) exceeds contacts.rigid_contact_max (3840). Grow _contacts to solver.get_max_contact_count() when the solver demands more, mirroring the existing mjwarp_manager.py override for the use_mujoco_contacts=True path. The buffer only grows; the allocation is unchanged wherever the pipeline estimate is already large enough. Verified on an NVIDIA L40 at 256 envs. Instrumenting CollisionPipeline.collide and the contact sensor shows the grown buffer holds the same contacts as an unpatched control run (4530 vs 4535 rigid contacts at reset, 421 bodies reporting >1 N in both), and the failing rsl_rl invocation runs to completion with no naconmax error. The pipeline emits ~4.5k contacts at reset, so the 3840-slot buffer was overflowing at 118% fill and silently dropping contacts even where the guard did not fire. A config-level gap=0.0 was ruled out: naconmax stayed at 25600 and the crash was unchanged. --- .../fanes-rslrl-contact-buffer-naconmax.rst | 9 +++++++++ .../isaaclab_newton/physics/newton_manager.py | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 source/isaaclab_newton/changelog.d/fanes-rslrl-contact-buffer-naconmax.rst diff --git a/source/isaaclab_newton/changelog.d/fanes-rslrl-contact-buffer-naconmax.rst b/source/isaaclab_newton/changelog.d/fanes-rslrl-contact-buffer-naconmax.rst new file mode 100644 index 000000000000..5fe8375593d9 --- /dev/null +++ b/source/isaaclab_newton/changelog.d/fanes-rslrl-contact-buffer-naconmax.rst @@ -0,0 +1,9 @@ +Fixed +^^^^^ + +* Fixed :class:`~isaaclab_newton.physics.NewtonManager` sizing its contact buffer from the + collision pipeline alone when ``use_mujoco_contacts=False``, which raised + ``MuJoCo naconmax (25600) exceeds contacts.rigid_contact_max (3840)`` at reset whenever the + MuJoCo Warp solver's ``nconmax`` demanded more contacts than the pipeline estimate. The + buffer now grows to the solver's maximum contact count, matching the + ``use_mujoco_contacts=True`` path. diff --git a/source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py b/source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py index 0e7adb3d3b4d..6e8f11df1905 100644 --- a/source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py +++ b/source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py @@ -1649,6 +1649,22 @@ def _initialize_contacts(cls) -> None: NewtonManager._collision_pipeline = CollisionPipeline(cls._model, broad_phase="explicit") if cls._contacts is None: NewtonManager._contacts = cls._collision_pipeline.contacts() + # Grow the collision-pipeline contact buffer to the solver's max when the + # solver (e.g. MuJoCo/mujoco_warp) requires more contacts than the pipeline + # auto-estimate. Without this, the RSL-RL sensor path (use_mujoco_contacts= + # False) sizes _contacts from the pipeline alone and solver.update_contacts() + # raises when naconmax (nconmax * num_envs) exceeds rigid_contact_max. + # Mirrors the mjwarp_manager.py override for the use_mujoco_contacts=True path. + _solver = cls._solver + if _solver is not None and hasattr(_solver, "get_max_contact_count"): + _need = _solver.get_max_contact_count() + if _need > NewtonManager._contacts.rigid_contact_max: + NewtonManager._contacts = Contacts( + rigid_contact_max=_need, + soft_contact_max=0, + device=PhysicsManager._device, + requested_attributes=cls._model.get_requested_contact_attributes(), + ) # ----- Solver construction (subclass contract) ------------------------