Skip to content

[Newton] Streamline contact and raycast sensor startup - #7296

Closed
ooctipus wants to merge 3 commits into
isaac-sim:developfrom
ooctipus:ooctipus/newton-sensor-startup
Closed

ooctipus wants to merge 3 commits into
isaac-sim:developfrom
ooctipus:ooctipus/newton-sensor-startup

Conversation

@ooctipus

Copy link
Copy Markdown
Collaborator

Summary

This is the third and final scoped startup PR. It keeps sensor selection and shared scene-query resources explicit:

  • contact body/shape selectors are compiled once as regular expressions and full-matched by Newton;
  • the obsolete bare-label and regex-to-glob rewrites are removed;
  • contact access uses Newton 1.4's non-deprecated sensing_* names;
  • a raycast sensor declares COLLIDE_SHAPES before clone builders are created, so model finalization builds the shared shape BVH once;
  • generic sensor-task registration no longer carries a raycast-only flag, late rebuild fallback, or duplicate “has collision shapes” state.

The production diff against the pinned base is +34/-56 (net -22).

This carries forward the contact-regex work from #7269 and replaces its BVH fallback path with the deterministic scene lifecycle above. The other two PRs in the series are #7292 and #7295.

Startup benchmark

RTX 5090, CUDA device 1, 4096 environments, three fresh processes per revision/task. Values are median end-to-end startup wall time; raw runs are included below. Base: 7666bd8369a. PR: 2bb0293da19.

Task Base PR Change
Isaac-Cartpole 8.103 s 8.111 s +0.1% (neutral)
Isaac-Velocity-Rough-UnitreeGo2 18.154 s 15.454 s -14.9%
Isaac-Lift-KukaAllegro-Camera 41.030 s 37.087 s -9.6%

Raw totals:

  • Cartpole base: 8.101, 8.152, 8.103 s; PR: 8.111, 8.183, 8.063 s.
  • Go2 rough base: 18.406, 18.154, 17.765 s; PR: 15.471, 15.454, 15.378 s.
  • Kuka-camera base: 44.868, 41.030, 40.101 s; PR: 37.470, 37.087, 36.946 s.

Phase medians explain the sensor-heavy gains:

  • Go2 contact construction: 0.11 -> 0.04 s; simulation start: 8.35 -> 5.85 s.
  • Kuka contact construction: 1.32 -> 0.24 s; scene creation: 21.70 -> 19.24 s; simulation start: 11.35 -> 10.21 s.

Test plan

  • 261 passed, 8 xpassed across the full Newton manager, contact-sensor, and raycast-sensor modules (CPU/CUDA, eager/CUDA graph).
  • Repository formatting and pre-commit checks pass.
  • Contact and BVH regressions were applied to 7666bd8369a: the contact contract fails during collection and both BVH architecture gates fail; all pass on this branch.
  • The three 4096-environment benchmark tasks pass on all three branch runs.

camevor and others added 3 commits August 22, 2026 00:05
Newton 1.4 deprecated the `sensing_obj_*` spellings on SensorContact.
Newton's deprecated properties return the new attributes unchanged, so
this is a pure rename with no behavior change, and it keeps the sensor
working when Newton removes the aliases.
@ooctipus
ooctipus requested a review from a team August 22, 2026 07:19
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Aug 22, 2026

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isaac Lab Review Bot

The contact-selector regex migration is documented and the raycast BVH requirement is moved to model finalization, but the retained registration-time fallback can still build a visible-only BVH and omit collision-only geometry.

  • Design and architecture: Selecting COLLIDE_SHAPES before builder creation is a sound lifecycle simplification for the standard scene path. However, _register_sensor_task remains a supported fallback owner for missing shape BVHs and does not apply the manager’s selected shape flags.
  • API: The breaking change from glob and bare-label rewriting to full-matched regular expressions is documented in the public configuration docstrings and changelog migration guidance. The Newton 1.4 sensing_* migration is internal to the backend integration.
  • Implementation: When raycast registration encounters a model with shapes but no existing shape BVH, line 2599 calls bvh_build_shapes(state) with the default visible-only selection. It should pass shape_flags=cls._sensor_bvh_shape_flags so this fallback preserves the raycast requirement to include collision-only shapes.

Minor fixes needed. Posted 1 actionable finding inline.

Automated review; human maintainers own approval decisions.

NewtonManager._sensor_bvh_has_collision_shapes = True
elif model.bvh_shapes is None:
model.bvh_build_shapes(state)
if model.shape_count > 0 and model.bvh_shapes is None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Design Architecture — Fallback BVH build ignores sensor shape flags

_sensor_bvh_shape_flags now owns which shapes the shared BVH must cover, but this retained fallback still calls model.bvh_build_shapes(state) with Newton's default visible-only flags. Whenever the model reaches registration without a shape BVH (the exact case this branch exists for, e.g. a builder not produced by create_builder or the lazily built shadow model from get_model()), a ray-cast sensor silently queries a BVH lacking COLLIDE_SHAPES and misses collision-only geometry that the removed rebuild covered. Pass shape_flags=cls._sensor_bvh_shape_flags here.

@greptile-apps

greptile-apps Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR moves Newton contact selection to compiled full-match regular expressions and configures collision-shape BVH construction before model finalization to avoid raycast-time rebuilding.

  • Migrates contact access to the current Newton sensing API.
  • Removes legacy glob conversion, bare-label normalization, and late BVH widening.
  • Adds contact-selector and raycast-BVH lifecycle regression tests.

Confidence Score: 4/5

The PR should not merge until selector lists preserve independently valid regular expressions instead of potentially failing contact-sensor initialization.

Joining selector entries before compilation makes a valid later expression containing global inline flags syntactically invalid, causing scene startup to fail for that configuration.

Files Needing Attention: source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py

Important Files Changed

Filename Overview
source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py Replaces legacy contact-selector normalization with compiled regex patterns and moves BVH flags into builder creation; selector-list concatenation breaks some independently valid regex entries.
source/isaaclab_newton/isaaclab_newton/sensors/ray_caster/newton_raycast_sensor.py Declares collision-shape BVH requirements during sensor construction before the standard scene lifecycle creates builders.
source/isaaclab_newton/isaaclab_newton/sensors/contact_sensor/contact_sensor.py Migrates contact metadata access to Newton's current sensing property names.
source/isaaclab_newton/test/sensors/test_contact_sensor.py Adds coverage for full-match regex semantics, alternation, shape descendants, absent selectors, and malformed expressions, but not independent list entries containing inline flags.
source/isaaclab_newton/test/sensors/test_newton_raycast_sensor.py Verifies that configured raycast scenes finalize builders with visible and collision shapes enabled.

Sequence Diagram

sequenceDiagram
    participant Scene as InteractiveScene
    participant Ray as NewtonRaycastSensor
    participant Manager as NewtonManager
    participant Builder as ModelBuilder
    participant Model as Newton Model
    Scene->>Ray: construct configured sensor
    Ray->>Manager: add COLLIDE_SHAPES flag
    Manager->>Builder: create_builder(shape_flags)
    Builder->>Model: finalize shared shape BVH
    Ray->>Manager: register raycast task
    Manager->>Model: reuse finalized BVH
Loading

Reviews (1): Last reviewed commit: "Build the raycast BVH once during model ..." | Re-trigger Greptile

"""Compile selector expressions for Newton's full label matching."""
if not expr:
return None
return re.compile("|".join((expr,) if isinstance(expr, str) else expr))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Selector alternation breaks regex flags

When a selector list has a later entry containing a valid global inline flag, such as (?i)bar, joining the entries before compilation places that flag in the middle of one expression, causing re.compile to raise and preventing the contact sensor and scene from initializing.

@ooctipus

Copy link
Copy Markdown
Collaborator Author

Superseded by #7269. Chris's PR now contains the reviewed contact/raycast implementation on top of #7292, retains his original commit authorship, and carries the exact-head startup benchmark.

@ooctipus ooctipus closed this Aug 22, 2026
ooctipus added a commit that referenced this pull request Aug 22, 2026
## Summary

This PR is now the contact/raycast part of the Newton startup work:

- compile contact-sensor full-path expressions once and match them
directly, without regex-to-glob conversion or stage globbing;
- use Newton's current contact-sensing API names;
- declare raycast collision-shape requirements before model
finalization, so the model builds one correctly configured BVH instead
of rebuilding it during sensor initialization.

The contact-selector and sensing-API commits retain Chris's (`camevor`)
original authorship. The BVH lifecycle change incorporates the review
from #7296 while keeping this as Chris's PR.

The related ownership work is intentionally split by component: #7292
handles explicit global ownership, and #7295 handles model/articulation
startup. This PR contains no inactive-solver registration or
articulation-view changes and supersedes #7296.

Production code is `+29/-56` (net `-27`) against `909cc5decc5`.

## Startup benchmark

RTX 5090, CUDA device 1, 4096 environments, three fresh processes per
revision/task. Values are median end-to-end startup wall time. Base:
`909cc5decc5`. PR: `5d0e1b1595e`.

| Task | Base | PR | Change |
|---|---:|---:|---:|
| `Isaac-Cartpole` | 8.316 s | 8.410 s | +1.1% |
| `Isaac-Velocity-Rough-UnitreeGo2` | 16.363 s | 15.682 s | -4.2% |
| `Isaac-Lift-KukaAllegro-Camera` | 39.473 s | 37.605 s | -4.7% |

Cartpole has no contact/raycast workload here and is neutral within
process-startup noise. The sensor-heavy tasks show the intended gain:

| Median phase | Go2 base | Go2 PR | Kuka base | Kuka PR |
|---|---:|---:|---:|---:|
| `newton_contact_sensor` | 0.10 s | 0.04 s | 1.32 s | 0.24 s |
| `simulation_start` | 6.36 s | 5.91 s | 11.48 s | 10.39 s |

Raw end-to-end totals:

- Cartpole base: 9.368, 8.316, 8.195 s; PR: 8.410, 8.370, 8.476 s.
- Go2 rough base: 19.900, 16.363, 16.091 s; PR: 15.669, 15.682, 15.984
s.
- Kuka camera base: 41.328, 38.625, 39.473 s; PR: 37.580, 37.605, 38.785
s.

## Test plan

- `261 passed, 8 xpassed` across the Newton manager abstraction,
contact-sensor, and raycast-sensor suites.
- Repository formatting and pre-commit checks pass.
- Architecture checks reject the removed regex-to-glob path, deprecated
sensing names, duplicate BVH state, and late BVH fallback.
- The three 4096-environment benchmark tasks also provide end-to-end
Newton MJWarp startup coverage.

## Type of change

- Performance improvement
- Bug fix

---------

Co-authored-by: Octi Zhang <[email protected]>
ooctipus added a commit to ooctipus/IsaacLab that referenced this pull request Aug 22, 2026
## Summary

This PR is now the contact/raycast part of the Newton startup work:

- compile contact-sensor full-path expressions once and match them
directly, without regex-to-glob conversion or stage globbing;
- use Newton's current contact-sensing API names;
- declare raycast collision-shape requirements before model
finalization, so the model builds one correctly configured BVH instead
of rebuilding it during sensor initialization.

The contact-selector and sensing-API commits retain Chris's (`camevor`)
original authorship. The BVH lifecycle change incorporates the review
from isaac-sim#7296 while keeping this as Chris's PR.

The related ownership work is intentionally split by component: isaac-sim#7292
handles explicit global ownership, and isaac-sim#7295 handles model/articulation
startup. This PR contains no inactive-solver registration or
articulation-view changes and supersedes isaac-sim#7296.

Production code is `+29/-56` (net `-27`) against `909cc5decc5`.

## Startup benchmark

RTX 5090, CUDA device 1, 4096 environments, three fresh processes per
revision/task. Values are median end-to-end startup wall time. Base:
`909cc5decc5`. PR: `5d0e1b1595e`.

| Task | Base | PR | Change |
|---|---:|---:|---:|
| `Isaac-Cartpole` | 8.316 s | 8.410 s | +1.1% |
| `Isaac-Velocity-Rough-UnitreeGo2` | 16.363 s | 15.682 s | -4.2% |
| `Isaac-Lift-KukaAllegro-Camera` | 39.473 s | 37.605 s | -4.7% |

Cartpole has no contact/raycast workload here and is neutral within
process-startup noise. The sensor-heavy tasks show the intended gain:

| Median phase | Go2 base | Go2 PR | Kuka base | Kuka PR |
|---|---:|---:|---:|---:|
| `newton_contact_sensor` | 0.10 s | 0.04 s | 1.32 s | 0.24 s |
| `simulation_start` | 6.36 s | 5.91 s | 11.48 s | 10.39 s |

Raw end-to-end totals:

- Cartpole base: 9.368, 8.316, 8.195 s; PR: 8.410, 8.370, 8.476 s.
- Go2 rough base: 19.900, 16.363, 16.091 s; PR: 15.669, 15.682, 15.984
s.
- Kuka camera base: 41.328, 38.625, 39.473 s; PR: 37.580, 37.605, 38.785
s.

## Test plan

- `261 passed, 8 xpassed` across the Newton manager abstraction,
contact-sensor, and raycast-sensor suites.
- Repository formatting and pre-commit checks pass.
- Architecture checks reject the removed regex-to-glob path, deprecated
sensing names, duplicate BVH state, and late BVH fallback.
- The three 4096-environment benchmark tasks also provide end-to-end
Newton MJWarp startup coverage.

## Type of change

- Performance improvement
- Bug fix

---------

Co-authored-by: Octi Zhang <[email protected]>
(cherry picked from commit 21bc111)
@ooctipus
ooctipus deleted the ooctipus/newton-sensor-startup branch October 14, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants