Repository navigation
Propagate Newton shape colors before cloning - #6194
rilei-nvidia merged 4 commits into
Conversation
d88b615 to
8a55d29
Compare
Greptile SummaryThis PR fixes a regression where only
Confidence Score: 4/5Safe to merge; the bug fix is well-targeted and all three builder paths are covered. The core logic change is correct and well-tested. The only issues are non-blocking: the source/isaaclab/isaaclab/sim/utils/newton_model_utils.py — stale internal docstrings and missing deduplication note. Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant NM as NewtonManager
participant RU as replicate.py
participant NCU as newton_clone_utils.py
participant UTIL as newton_model_utils.py
Note over NM: Env-split load path
NM->>NM: builder.add_usd(stage, ignore_env_paths)
NM->>UTIL: replace_newton_builder_shape_colors(builder, stage)
NM->>NM: "proto_builder.add_usd(stage, root_path=proto_path)"
NM->>UTIL: replace_newton_builder_shape_colors(proto_builder, stage)
NM->>NM: builder.finalize() → model ✅ colors already set
Note over RU: Replicate path (heterogeneous envs)
RU->>RU: global_builder.add_usd(ignore_env_paths)
RU->>UTIL: replace_newton_builder_shape_colors(global_builder, stage)
RU->>NCU: build_source_builders(stage, sources, ...)
loop per source
NCU->>NCU: "src_builder.add_usd(root_path=source)"
NCU->>NCU: src_builder.approximate_meshes(...)
NCU->>UTIL: replace_newton_builder_shape_colors(src_builder, stage)
end
RU->>RU: replicate_builder_mapping → add_builder(src_builder) × N envs
Note right of RU: Each env inherits correct colors from the single colorized source
RU->>RU: global_builder.finalize() → model ✅
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant NM as NewtonManager
participant RU as replicate.py
participant NCU as newton_clone_utils.py
participant UTIL as newton_model_utils.py
Note over NM: Env-split load path
NM->>NM: builder.add_usd(stage, ignore_env_paths)
NM->>UTIL: replace_newton_builder_shape_colors(builder, stage)
NM->>NM: "proto_builder.add_usd(stage, root_path=proto_path)"
NM->>UTIL: replace_newton_builder_shape_colors(proto_builder, stage)
NM->>NM: builder.finalize() → model ✅ colors already set
Note over RU: Replicate path (heterogeneous envs)
RU->>RU: global_builder.add_usd(ignore_env_paths)
RU->>UTIL: replace_newton_builder_shape_colors(global_builder, stage)
RU->>NCU: build_source_builders(stage, sources, ...)
loop per source
NCU->>NCU: "src_builder.add_usd(root_path=source)"
NCU->>NCU: src_builder.approximate_meshes(...)
NCU->>UTIL: replace_newton_builder_shape_colors(src_builder, stage)
end
RU->>RU: replicate_builder_mapping → add_builder(src_builder) × N envs
Note right of RU: Each env inherits correct colors from the single colorized source
RU->>RU: global_builder.finalize() → model ✅
|
| material_color_cache: dict[str, tuple[float, float, float] | None] = {} | ||
|
|
||
| unique_keys = dict.fromkeys(shape_keys) | ||
| for key in unique_keys: | ||
| color = _resolve_shape_color(stage, key, material_color_cache) | ||
| resolved_color_cache[key] = color | ||
|
|
||
| # Prepare the indices and colors for the scatter kernel: | ||
| # - Indices point to the slots in the shape_colors array that should be updated | ||
| # - Colors are the new values to write into the slots | ||
| indices_np = np.empty(num_shapes, dtype=np.int32) | ||
| colors_np = np.empty((num_shapes, 3), dtype=np.float32) | ||
|
|
||
| for i, shape_key in enumerate(shape_keys): | ||
| if rgb := resolved_color_cache.get(shape_key): | ||
| indices_np[num_color_updates] = i | ||
| colors_np[num_color_updates] = rgb | ||
| for i, label in enumerate(shape_labels): | ||
| rgb = _resolve_shape_color(stage, label, material_color_cache) | ||
| if rgb is not None: | ||
| shape_colors[i] = wp.vec3( | ||
| _linear_channel_to_srgb(rgb[0]), | ||
| _linear_channel_to_srgb(rgb[1]), | ||
| _linear_channel_to_srgb(rgb[2]), | ||
| ) | ||
| num_color_updates += 1 |
There was a problem hiding this comment.
No per-shape deduplication for unbound USD-instanced geometry
The old implementation built a resolved_color_cache keyed by _canonical_prim_lookup_key(shape_prim), which mapped instance-proxy paths to their shared prototype path. Shapes from the same USD prototype were resolved once. The new loop calls _resolve_shape_color(stage, label, material_color_cache) for every label; the material_color_cache only deduplicates at the material level. For builders with many USD-native-instanced meshes that have no material binding (displayColor only), each proxy prim is looked up separately. Correctness is preserved (instance proxies delegate to the prototype's displayColor transparently), but scenes heavy with unbound USD instancing pay for extra per-label USD traversals. Worth a comment at minimum, and the _canonical_prim_lookup_key helper is now dead code for its original deduplication purpose.
Replace the post-finalize replace_newton_shape_colors pass on the Newton model with replace_newton_builder_shape_colors, applied to each ModelBuilder before clone replication. This ensures all cloned environments automatically inherit the correct USD material and displayColor values. - Add replace_newton_builder_shape_colors to newton_model_utils - Call it in NewtonManager (flat, env, and proto-source builders), newton_clone_utils, and replicate - Update tests to exercise the new replace_newton_builder_shape_colors - Update dexsuite_kuka_hetero golden images for corrected colors
…aclab/test/sim/test_newton_manager_visualization_state.py
a530bcd to
88d0148
Compare
# Description This PR integrates @ooctipus's proposed fix for newton shape color replacement to occur pre-clone. Original PR: rilei-nvidia#1 Replace the post-finalize `replace_newton_shape_colors` pass on the Newton model with `replace_newton_builder_shape_colors`, applied to each ModelBuilder before clone replication. This ensures all cloned environments automatically inherit the correct USD material and displayColor values. This not only improves performance but also addresses the regression that @huidongc discovered last week where only env_0 (the clone source) had the right color for the robot arm, and the other cloned envs got the fallback colors - Add replace_newton_builder_shape_colors to newton_model_utils. - Removed replace_newton_shape_colors and any un-used functionality - Call it in NewtonManager (flat, env, and proto-source builders), newton_clone_utils, and replicate - Update tests to exercise the new replace_newton_builder_shape_colors - Update dexsuite_kuka_hetero golden images for correctness # Validation Validated for correctness in the Newton visualizer with (all robot arms should have the same color): ```bash ./isaaclab.sh train --rl_library rsl_rl \ --task Isaac-Lift-KukaAllegro-Camera \ presets=newton_mjwarp,newton_renderer,rgb64,single_camera \ --seed 42 \ --num_envs 4 \ --max_iterations 2 \ --visualizer newton ``` <img width="1917" height="1159" alt="image" src="https://github.com/user-attachments/assets/fabf9ef4-60f6-4e29-a11a-e266e77d7f61" /> Rendering test golden images for the dexsuite_kuka_hetero kitless suite have also been updated to reflect fix to the regression ```bash ./isaaclab.sh -p -m pytest -v -rA source/isaaclab_tasks/test/core/test_rendering_dexsuite_kuka_hetero_kitless.py::test_rendering_dexsuite_kuka_hetero_kitless[newton-newton_warp-rgb] ``` <img width="742" height="1046" alt="image" src="https://github.com/user-attachments/assets/6e357b06-5cf2-458f-886b-4b283952c94f" /> # Performance Testing on a AMD Ryzen Threadripper PRO 7965WX 24-Cores (48) @ 5.36 GHz For testing the performance impact I used the benchmark script: ```bash ./isaaclab.sh -p scripts/benchmarks/benchmark_non_rl.py \ --task Isaac-Lift-KukaAllegro-Camera \ presets=newton_mjwarp,ovrtx_renderer,rgb64,single_camera \ --seed 42 \ --num_envs "8000" \ --benchmark_backend json \ --output_path "hdc/benchmarks/20260611/heterogeneous_8000" ``` The time of replace_newton_shape_colors has been moved to calls to the new replace_newton_builder_shape_colors pre-clone: | # Env | replace_newton_shape_colors (Before) | replace_newton_builder_shape_colors (After) | | ------ | ----- | ----- | | 4000 | 2 s | 0.0045~ s| | 8000 | 4 s | 0.0045~ s| With @ooctipus's change the time for shape color propagation is not only "free" now, but constant to increasing # of environments. ## Checklist - [x] I have read and understood the [contribution guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html) - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have updated the changelog and the corresponding version in the extension's `config/extension.toml` file - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there
Description
This PR integrates @ooctipus's proposed fix for newton shape color replacement to occur pre-clone. Original PR: rilei-nvidia#1
Replace the post-finalize
replace_newton_shape_colorspass on the Newton model withreplace_newton_builder_shape_colors, applied to each ModelBuilder before clone replication. This ensures all cloned environments automatically inherit the correct USD material and displayColor values. This not only improves performance but also addresses the regression that @huidongc discovered last week where only env_0 (the clone source) had the right color for the robot arm, and the other cloned envs got the fallback colorsnewton_clone_utils, and replicate
Validation
Validated for correctness in the Newton visualizer with (all robot arms should have the same color):
./isaaclab.sh train --rl_library rsl_rl \ --task Isaac-Lift-KukaAllegro-Camera \ presets=newton_mjwarp,newton_renderer,rgb64,single_camera \ --seed 42 \ --num_envs 4 \ --max_iterations 2 \ --visualizer newtonRendering test golden images for the dexsuite_kuka_hetero kitless suite have also been updated to reflect fix to the regression
Performance
Testing on a AMD Ryzen Threadripper PRO 7965WX 24-Cores (48) @ 5.36 GHz
For testing the performance impact I used the benchmark script:
./isaaclab.sh -p scripts/benchmarks/benchmark_non_rl.py \ --task Isaac-Lift-KukaAllegro-Camera \ presets=newton_mjwarp,ovrtx_renderer,rgb64,single_camera \ --seed 42 \ --num_envs "8000" \ --benchmark_backend json \ --output_path "hdc/benchmarks/20260611/heterogeneous_8000"The time of replace_newton_shape_colors has been moved to calls to the new replace_newton_builder_shape_colors pre-clone:
With @ooctipus's change the time for shape color propagation is not only "free" now, but constant to increasing # of environments.
Checklist
pre-commitchecks with./isaaclab.sh --formatconfig/extension.tomlfileCONTRIBUTORS.mdor my name already exists there