Repository navigation
Conversation
NewtonManager.add_contact_sensor keyed the Newton SensorContact by the sensing and filter expressions, but built a new one on every call and replaced the registered entry. Contact sensors that differ only in settings Isaac Lab applies itself (update period, history, air time) kept the arrays of the replaced Newton sensor, which was no longer updated, so all but the last one created reported zero forces. add_contact_sensor now reuses the registered sensor for an identical request instead of building a new one. A Newton sensor belongs to one model, so a hard reset now drops the registry: the sensors register again on PHYSICS_READY and get a Newton sensor built for the new model, which also requests the contact force attribute from it.
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryNewton contact sensors with identical expressions now share one Newton sensor instead of replacing each other.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Register contact sensor] --> B{Expressions already registered?}
B -->|Yes| C[Reuse Newton sensor]
B -->|No| D[Build and register Newton sensor]
C --> E[Copy outputs into each caller's own buffers]
D --> E
F[Hard reset] --> G[Mark sensors uninitialized and clear registry]
G --> H[Build new model]
H --> A
Reviews (1) · Last reviewed commit: "Share one Newton sensor among contact se..." · Reviewed by Greptile |
There was a problem hiding this comment.
Isaac Lab Review Bot
Needs attention: Test quality (1). Other reviewed categories look good.
- PR description: The title and scope match the diff; correct the conflicting 113/114 manager-test counts and remove the repeated baseline/fixed validation narrative.
- Design and architecture: Architecture looks good.
- Scope and over-engineering: No over-engineering issues.
- API: API changes look good.
- Compatibility and deprecation: No breaking changes identified.
- Implementation: Implementation looks good.
- Style consistency: Style consistency looks good.
- Test quality: The regression distinctly covers shared expressions and hard resets, but its single undamped force sample uses a 2% band despite documented solver oscillation; average settled samples before asserting.
Minor fixes needed. Posted 1 inline finding.
Automated review; human maintainers own approval decisions.
| perform_sim_step(sim, scene, SIM_DT) | ||
| # One row per sensor: the 1 kg box rests on the ground. | ||
| force_z = torch.stack([sensor.data.net_normal_forces_w.torch[..., 2] for sensor in sensors]) | ||
| torch.testing.assert_close(force_z, torch.full_like(force_z, gravity_magnitude), rtol=0.02, atol=0.0) |
There was a problem hiding this comment.
🟡 Warning · Test Quality — Force assertion sampled from a single step
test_resting_object_contact_force in this file settles 90 steps and averages 20 samples because per-step solver oscillation exceeds a 2% band. This asserts the same band from one sample after 40 steps on an undamped box. Average…
AntoineRichard
left a comment
There was a problem hiding this comment.
Thanks for the PR @NeoZng! The fix looks great. Please look at the comment for the test.
|
|
||
| # Sensor registration is host-side bookkeeping, identical on every device. | ||
| @pytest.mark.parametrize("device", test_devices(DeviceScope.CUDA)) | ||
| def test_sensors_with_identical_expressions(device: str): |
There was a problem hiding this comment.
The test fails for the right reason, and it doesn't pin the sharing itself, which is good. But it builds a second simulation for the fixture test_resting_object_contact_force already has, and it's weaker than that test:
- It checks one reading after 40 steps on an undamped box, with a 2% band. The sibling averages the last 20 of 90 steps because the resting force oscillates from step to step.
- The expected force is
gravity_magnitudeonly becausecreate_shape_cfguses 1 kg. - With a constant resting force, the
update_periodandhistory_lengthsensor reads the same as the plain one, so those settings aren't exercised. Fine to keep as a copy of the issue's repro, but the docstring suggests otherwise.
Could you fold it into test_resting_object_contact_force instead? Add a third sensor on BoxA and run the settle twice:
# Same expression as sensor A; differs only in settings Isaac Lab applies itself.
scene_cfg.contact_sensor_c = ContactSensorCfg(
prim_path="{ENV_REGEX_NS}/BoxA", update_period=4 * SIM_DT, history_length=3
)
scene = InteractiveScene(scene_cfg)
sensor_a: ContactSensor = scene["contact_sensor_a"]
sensor_b: ContactSensor = scene["contact_sensor_b"]
sensor_c: ContactSensor = scene["contact_sensor_c"]
# The second sim.reset() is a hard reset: it finalizes a new model, for which the sensors register again.
for reset_pass in range(2):
sim.reset()
scene.reset()
# ... existing settle and 20-sample average, also collecting sensor_c ...
errs: list[str] = []
for env_idx in range(num_envs):
# ... existing BoxA / BoxB checks, with the pass in the message ...
fc = force_mags_c[env_idx].max().item()
if abs(fc - expected_force_a) >= 0.02 * expected_force_a:
errs.append(
f"Pass {reset_pass}, env {env_idx}: second BoxA sensor should read"
f" ~{expected_force_a:.2f} N. Got {fc:.2f} N"
)
assert not errs, "\n".join(errs)Without the early return, the existing BoxA check reads 0 N. Without the clear(), the second pass raises the force error. This also covers both contact pipelines and 4 envs, and saves a simulation build. Could you check that both of those mutations turn it red?
There was a problem hiding this comment.
@AntoineRichard Done in d88ff8e: folded into test_resting_object_contact_force as you suggested, and the separate test is gone. Both mutations turn it red on both pipelines: without the early return, BoxA reads 0.00 N in the first pass; without the clear(), the first step of the second pass raises the force error (SensorContact requires contact-force solver observables).
…-sensor-shared-key # Conflicts: # source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py
|
Superseded by #8733, which keeps Newton contact sensors on the backend and returns the existing sensor for identical expressions; this PR's test passes on main without its source change, so I'm closing this. |
Description
On the Newton backend,
ContactSensors with identical body and filter expressions all reported zero forces exceptthe last one created.
NewtonManager.add_contact_sensorkeyed the NewtonSensorContactby these expressions, butbuilt a new one on every call and replaced the registered entry. Sensors that differ only in settings Isaac Lab
applies itself (update period, history, air time) kept the arrays of the replaced Newton sensor, which was no longer
updated.
add_contact_sensornow reuses the registered sensor for an identical request instead of building a new one. EachIsaac Lab sensor copies the shared Newton arrays into its own buffers and applies its update period, history and
air time there, so sharing changes nothing else.
sim.reset(), which finalizes a new model) nowdrops the registry. The sensors register again on
PHYSICS_READYand get a Newton sensor built for the new model.Without this, a reused sensor would belong to the old model. The new model would then never request the contact
forceattribute, and the first step after the reset would raiseSensorContact requires contact-force solver observables.Open draft #8218 (Newton manager rewrite) also lets identical requests share one sensor. This is the minimal fix for
the current manager.
Fixes #8648
Type of change
Release backport
developOn release/3.0.0 the hard-reset hunk conflicts, because that branch's reset block has no view or callback cleanup.
The two added lines go right after the
STOPdispatch.Screenshots
Repro script from the issue, Newton:
contact_a(history_length=3)contact_b(update_period=0.02)Checklist
Docker and GPU tests run on demand. Push the commits you want tested, then
comment
run-cion the pull request.pre-commitchecks withuv run isaaclab --formatsource/<pkg>/changelog.d/for every touched package (do not editCHANGELOG.rstor bump package versions — CI handles that)CONTRIBUTORS.mdor my name already exists thereTests
isaaclab_newton/test/sensors/test_contact_sensor.py::test_resting_object_contact_force: a second sensor on BoxA,differing only in update period and history length, must also report its weight, and the settle runs twice (the
second
sim.reset()is a hard reset). Without the reuse, the first BoxA sensor reads 0 N. Without the registryclear, the second pass raises the
forceerror above. Both fail on both contact pipelines.test_contact_sensor.pyon develop5088b326c7(Newton 71eeba16, MuJoCo Warp 3.15.0): 24 passed, 4 skipped byexisting skip marks.