Repository navigation
Fix sensor refreshes delayed by float32 clock rounding - #8160
Conversation
SensorBase decided whether a sensor is due by subtracting two float32 timestamps that grow with the episode. Their rounding error exceeds the 1e-6 tolerance after some seconds (16 s at dt=0.005 with a 4-step period, under 1 s for long periods at small dt), so sensors refreshed one step late and lazily read sensors skipped whole policy steps. Accumulate the time since the last refresh in a float64 per-env buffer that restarts at every refresh and reset, and decide due-ness on it. The float32 timestamps are kept unchanged for the kernels that read them. Signed-off-by: Yusuf Guenena <[email protected]>
|
run-ci |
|
There was a problem hiding this comment.
Isaac Lab Review Bot
The float64 elapsed-time accumulator directly addresses float32 clock drift while preserving refresh-from-last-read semantics. Before merge, centralize timing-buffer reallocation now duplicated across three isaaclab_ov sensors and remove the redundant aligned lazy-read test row.
- Design and architecture: The zero-based float64 elapsed accumulator is an appropriate owner for due-ness and preserves lazy reads, resets, variable
dt, and zero-period behavior. However, the threeisaaclab_ovsensors that revise_num_envsnow duplicate all base timing-buffer allocations, including_elapsed_since_update; add a protectedSensorBaseresize/allocation helper so this state remains base-owned. - API: No public sensor class, configuration field, property, or export changes.
SensorBaseCfg.update_periodretains its meaning and tolerance. The changed Warp kernel signatures are internal, and all supplied in-repository launch sites are updated. - Compatibility and deprecation: Breaking changes: none identified. Public sensor and configuration contracts remain unchanged, while
_timestampand_timestamp_last_updateretain their existing float32 update/reset behavior for current consumers. - Implementation: The update, reset, refresh-commit, and batch paths consistently accumulate or clear
_elapsed_since_update. The remaining maintainability issue is allocation: base-owned masks and timing arrays are manually reconstructed at each backend env-count override, so that repeated block should be consolidated inSensorBase. - Style consistency: Kernel arguments and units are documented, package changelog fragments are present, and the contributor entry follows adjacent ordering. The repeated timing-buffer allocation blocks are also a consistency concern because they reproduce base initialization details rather than using a shared owner.
- Test quality: The new scheduler suite exercises real
update,data, andresetpaths against an independentFractionoracle, covering aged clocks, non-integer periods, variabledt, delayed reads, partial resets, and zero periods. Remove theread_every=4lazy-read row: with a four-step period every read lands on a due step, so it does not exercise a due-but-unread phase shift and duplicates the integer-cadence contract;read_every=3retains the distinct lazy-phase coverage.
Minor fixes needed. Posted 2 actionable findings inline.
Automated review; human maintainers own approval decisions.
Patch SimulationContext.instance with patch.object, which restores the original classmethod from the class dictionary instead of the bound method returned by attribute access. Add CPU cases for constant and variable dt so CPU-only runs keep regression coverage, and drop the lazy-read row whose reads always coincide with the due step: it matched the aligned integer cadence case. The row that reads every 3 steps still covers the phase shift. Signed-off-by: Yusuf Guenena <[email protected]>
|
run-ci |
AntoineRichard
left a comment
There was a problem hiding this comment.
@yusufdxb Thanks a lot for the PR!
The main issue I see with it is that the buffer setup is copied in 4 different places. Could you add a helper in SensorBase called _create_timing_buffers() that _initialize_impl() and the OV sensors could call?
The air/contact time could also be moved to this solution rather than their dynamic tolerance, so the whole code-base is homogeneous?
Also, I would mark these changes as breaking. Contributed sensors that build these buffers themselves would break. It's fine, just make sure it's captured in the changelog!
Thanks again!
SensorBase._initialize_impl() and the three OVPhysX sensors that change _num_envs after initialization each built the env masks, timestamps and outdated flags themselves. They now call a single protected helper. Reduce the scheduler tests to the aged-clock cadence, a due sensor that stays due until read, and a period that follows the dt passed to update(). Mark the change as breaking in the changelog, since sensors that build these private buffers themselves must use the helper. Signed-off-by: Yusuf Guenena <[email protected]>
The PhysX, Newton and OVPhysX contact kernels advanced the air and contact timers by timestamp - timestamp_last_update, the same difference of growing float32 timestamps that delayed sensor refreshes. They now add _elapsed_since_update, the float64 time since the last refresh, so the timers no longer lose precision as the sensor clock ages. The half-interval default tolerance of compute_first_contact() and compute_first_air() is kept: even with exact timers, a fixed 1e-8 is below the float32 resolution of the timer for periods of 0.2 s and more. Signed-off-by: Yusuf Guenena <[email protected]>
|
@AntoineRichard thanks for the review. Addressed in e784a28 and e4f8998:
|
|
run-ci |
AntoineRichard
left a comment
There was a problem hiding this comment.
@yusufdxb thanks for the updates! One last change and it should be good to go!
SensorBase._create_timing_buffers() now allocates only the outdated flags, timestamps and elapsed times. The all-env and reset masks are allocated in SensorBase._initialize_impl() again, and the three OVPhysX sensors that change _num_envs reallocate them before recreating the timing buffers. Signed-off-by: Yusuf Guenena <[email protected]>
|
run-ci |
The develop changelog check now expects <slug>.<type>.rst fragments holding bullets and an empty <slug>.major marker. The entries are split with tools/changelog/cli.py split_legacy, so their text is unchanged. Signed-off-by: Yusuf Guenena <[email protected]>
|
run-ci |
|
@AntoineRichard Could this be backported to release/3.0.0? The reproducer from #8159 still prints |
…patibility (#9055) # Description Fixes sensor refreshes being delayed by float32 clock rounding on `release/3.0.0`, adapting #8160 while preserving the release branch's existing timing interfaces. With `dt=0.005` and `update_period=0.02`, the original scheduler can skip otherwise-due refreshes from about 16 s into an episode. Sensor scheduling and the built-in PhysX, Newton, and OVPhysX contact sensors now use float64 elapsed time accumulated since the last actual refresh. The original float32 timestamps retain their meaning. Related: #8159. The first commit cherry-picks #8160; the follow-up adds release compatibility. ## Release compatibility - Preserved the existing scheduler and backend contact Warp kernel names, argument order, and dtypes. Existing direct callers retain their timestamp-based timing behavior. Built-in sensors use new `*_elapsed_kernel` entry points for the precision fix. - Shared each backend's force/history/transition implementation between its old and new entry points. - Custom sensors that allocate or replace their own timestamp buffers automatically acquire elapsed-time tracking on first use, including after resizing. No call to the new timing allocator is required. The normal update path adds no allocation or extra kernel launch for compatibility; adopting replacement buffers initializes the elapsed buffer once. - Removed the original breaking-change fragment and major-bump marker; retained fix fragments for all four packages. ## Validation On the final implementation, using the worktree's isolated CPU environment with Warp 1.17.0 and Torch 2.11.0: - `test_sensor_update_schedule.py`: 3 passed, 2 CUDA-only cases skipped. The two skipped lazy-read and variable-dt scenarios were also invoked directly on CPU and passed. - `test_contact_timing_kernels.py`: 3 passed; exercises both old and new entry points for PhysX, Newton, and OVPhysX, asserting timing, transitions, force history, and masking. - `test_contact_sensor_history.py` (Newton): 2 passed using its original timestamp-based kernel signature. - `test_simulation_render_context.py`: 27 passed (existing Torch JIT deprecation warnings). - The five compatibility regressions fail against the preceding PR implementation for the expected missing-buffer or kernel-signature errors, and pass with the follow-up. - All repository pre-commit hooks passed via `uv run --no-project --with pre-commit pre-commit run --all-files`, with the changelog gate targeting the release base. `git diff --check` passed. - Verified all six original kernel signatures against the release base and checked that extracting shared contact processing preserved force/history/transition operations. The standard project synchronization is unsupported on macOS, so focused tests ran with `uv run --no-sync` and explicit workspace source paths. Full simulator/GPU runs, CUDA graph capture, and GPU performance have not been validated for this revision. ## Type of change - Bug fix (non-breaking change) --------- Signed-off-by: Yusuf Guenena <[email protected]> Co-authored-by: yusuf <[email protected]>
Description
The sensor scheduler decides whether a sensor is due by subtracting two float32 per-env timestamps (
timestamp - timestamp_last_update + 1e-6 >= update_periodinupdate_timestamp_kernel). Both grow with the time since the env's last reset. As they grow, float32 rounding of the repeatedtimestamp + dtmakes the computed elapsed time fall belowupdate_period - 1e-6, so otherwise-due refreshes are delayed by one or more updates, and a lazily read sensor returns its previous data. Withdt = 0.005andupdate_period = 0.02this starts at t = 16.02 s; with long periods at smalldtit starts within the first seconds.Reproduction (CPU only, the script in #8159): develop prints
stale reads: 100 / 1000; first at t = [16.02] s; this branch printsstale reads: 0 / 1000.The fix:
_elapsed_since_update(float64): the time since the last refresh, accumulated from zero and restarted at every actual refresh and every reset;elapsed >= update_period - 1e-6;_timestamp/_timestamp_last_updatebitwise unchanged (dtis passed as float64 and cast to float32 for the timestamp; PhysX and OVPhysX still readtimestampfor thetimestamp == 0reset guard);_elapsed_since_updateinstead oftimestamp - timestamp_last_update, so nothing subtracts the growing float32 timestamps any more;update_period = 0refreshes on every read,dtmay vary between calls, and a reset still marks the env outdated;SensorBase._create_timing_buffers().The elapsed value is bounded by the update period plus the time a due sensor waits to be read, so its rounding error no longer depends on how long the episode has run.
SensorBase._create_timing_buffers()allocates the env masks, timestamps, outdated flags and the new buffer for the current_num_envs._initialize_impl()and the threeisaaclab_ovsensors that change_num_envsafter initialization (contact sensor, frame transformer, joint wrench sensor) call it instead of rebuilding the buffers, and so do the two hand-built fake sensors intest_simulation_render_context.py.Breaking: a sensor that allocates or resizes the timing buffers itself instead of calling
SensorBase._initialize_impl()or_create_timing_buffers()fails withAttributeError: '_elapsed_since_update'on its firstupdate(), and code that launches the changed Warp kernels directly must pass the new buffer. Both are covered in theisaaclabchangelog.Related: #7283 / #7574 made
compute_first_contact()/compute_first_air()robust to the same float32 clock error by defaulting their tolerance to half the sensor update interval. With the air/contact times now advanced by the float64 elapsed time, their error no longer grows with the clock (kernel-level check below). The half-interval default is kept: even with exact timers, a fixed1e-8tolerance is below the float32 resolution of the timer for periods of 0.2 s and more (float32(0.2 + 1e-8) == float32(0.2)), so it still misses every transition there.Fixes #8159
Type of change
Release backport
developScreenshots
Not applicable. Evidence:
test_sensor_update_schedule.py, 4 cases)abs_tol=1e-8(default half-interval tolerance: 0 on both)use_newton_actuators=False, 20 supdate(step_dt)per step, not exposed in 20 s)update_period = step_dt, 70 s, stale reads eachSensorBase, up to 200,000 simulated s, periods 1 to 1000 steps and non-integer, variabledt, 4096 envs with random resetsThe aged-clock and variable-
dtcases fail on develop at the first delayed refresh. The case that passes on develop (an unread due sensor stays due until read) guards the scheduling semantics: it fails under fixed-grid scheduling, and the variable-dtcase is the only one that fails when updates are counted instead of timed (checked by mutating the patched code).Performance (desktop GPU shared with another job; alternating develop/PR processes; bootstrap 95% CI): the scheduler kernels cost slightly more (+30 to 160 ns device time per step, 1 to 8192 envs), and no statistically meaningful whole-environment step-time change was observed up to 8192 envs on the task above with the Newton default preset and with
use_newton_actuators=False(e.g. 8192 envs: 101.1 vs 100.4 ms and 102.5 vs 102.9 ms per step, CIs include 0). Memory: +8 bytes per env per sensor.Not runtime-validated: the
_create_timing_buffers()calls in the threeisaaclab_ovresize branches (the OVPhysX sensor tests pass on CPU and CUDA, but their scenes never take thebinding count != _num_envsbranch), Kit RTX cameras, PhysX-path performance, and torch 2.12 (runs used torch 2.11 + CUDA 12.8; the changed code path is Warp only). The performance numbers above are from the scheduler change; the contact kernels now read one float64 per env instead of two float32 timestamps.Tests run locally on this branch (base 09b1d54):
test_sensor_update_schedule.py,test_simulation_render_context.py,test_simulation_context.py,test_sensor_base.py,test_outdated_sensor.py; Newtontest_contact_sensor.py(including the #7574 aged-clock cases) /test_contact_sensor_history.py/test_imu.py/test_pva.py/test_frame_transformer.py; PhysX (Isaac Sim)test_contact_sensor.py/test_imu_pva_recorded_launch.py/test_joint_wrench_sensor.py; OVPhysX (ovphysx==0.6.3, one run per device)test_contact_sensor.py/test_contact_sensor_kernels.py/test_frame_transformer.py/test_joint_wrench_sensor.py/test_imu.py/test_pva.py. All pass.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 there