Skip to content

Fix sensor refreshes delayed by float32 clock rounding - #8160

Merged
maxkra15 merged 6 commits into
isaac-sim:developfrom
yusufdxb:fix/sensor-scheduler-float-drift
Oct 6, 2026
Merged

maxkra15 merged 6 commits into
isaac-sim:developfrom
yusufdxb:fix/sensor-scheduler-float-drift

Conversation

@yusufdxb

@yusufdxb yusufdxb commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

The sensor scheduler decides whether a sensor is due by subtracting two float32 per-env timestamps (timestamp - timestamp_last_update + 1e-6 >= update_period in update_timestamp_kernel). Both grow with the time since the env's last reset. As they grow, float32 rounding of the repeated timestamp + dt makes the computed elapsed time fall below update_period - 1e-6, so otherwise-due refreshes are delayed by one or more updates, and a lazily read sensor returns its previous data. With dt = 0.005 and update_period = 0.02 this starts at t = 16.02 s; with long periods at small dt it 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 prints stale reads: 0 / 1000.

The fix:

  • adds a private per-env buffer _elapsed_since_update (float64): the time since the last refresh, accumulated from zero and restarted at every actual refresh and every reset;
  • uses it only for the due-ness decision: elapsed >= update_period - 1e-6;
  • keeps _timestamp / _timestamp_last_update bitwise unchanged (dt is passed as float64 and cast to float32 for the timestamp; PhysX and OVPhysX still read timestamp for the timestamp == 0 reset guard);
  • advances the contact sensors' air/contact times (PhysX, Newton, OVPhysX) by the same _elapsed_since_update instead of timestamp - timestamp_last_update, so nothing subtracts the growing float32 timestamps any more;
  • preserves the scheduling semantics: the period is counted from the actual refresh (not a fixed time grid), lazy reads shift the phase, a due sensor stays due until read, update_period = 0 refreshes on every read, dt may vary between calls, and a reset still marks the env outdated;
  • changes no public API or config; the private timing buffers are allocated by a new 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 three isaaclab_ov sensors that change _num_envs after initialization (contact sensor, frame transformer, joint wrench sensor) call it instead of rebuilding the buffers, and so do the two hand-built fake sensors in test_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 with AttributeError: '_elapsed_since_update' on its first update(), and code that launches the changed Warp kernels directly must pass the new buffer. Both are covered in the isaaclab changelog.

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 fixed 1e-8 tolerance 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

  • Breaking change (existing functionality will not work without user modification)

Release backport

  • Backport this pull request to the active release branch after it merges into develop

Screenshots

Not applicable. Evidence:

Validation develop this PR
Scheduler tests (test_sensor_update_schedule.py, 4 cases) 3 fail / 1 pass 4 / 4 pass
Contact kernels of PhysX, Newton and OVPhysX, 40 s against an exact model (CPU + CUDA, substep and lazy refresh, resets): max air/contact time error 7.7e-5 s 3.9e-8 s
Same, missed first-contact/first-air with a fixed abs_tol=1e-8 (default half-interval tolerance: 0 on both) up to 34,772 of 60,085 0 (no false positives)
Reproducer in #8159, stale reads 100 / 1000 0 / 1000
Isaac-Velocity-Rough-UnitreeGo2, Isaac Sim PhysX, 8 envs, 20 s, stale height-scan reads 465 0
Same task, Newton with use_newton_actuators=False, 20 s 700 0
Same task, Newton default preset, 20 s (one update(step_dt) per step, not exposed in 20 s) 0 0
Same task, Newton default preset, 70 s 1200 0
IMU / FrameTransformer / ContactSensor (history 0) / Newton Warp camera at update_period = step_dt, 70 s, stale reads each 4400 0
Scheduler stress, real SensorBase, up to 200,000 simulated s, periods 1 to 1000 steps and non-integer, variable dt, 4096 envs with random resets early and late refreshes 0 early / late / missed

The aged-clock and variable-dt cases 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-dt case 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 three isaaclab_ov resize branches (the OVPhysX sensor tests pass on CPU and CUDA, but their scenes never take the binding count != _num_envs branch), 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; Newton test_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-ci on the pull request.

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with uv run isaaclab --format
  • I have made corresponding changes to the documentation (no public API or documented behavior changes; the private-buffer change is described in the changelog)
  • My changes generate no new warnings
  • I have validated the changed behavior with focused coverage and applied the test-audit criteria to any test changes
  • I have added a changelog fragment under source/<pkg>/changelog.d/ for every touched package (do not edit CHANGELOG.rst or bump package versions: CI handles that)
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

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]>
@yusufdxb

Copy link
Copy Markdown
Contributor Author

run-ci

@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Sep 29, 2026
@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Sep 29, 2026
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Fixes sensor refresh timing by changing float precision in update logic.

The PR appears safe to merge; the identified test-isolation and CPU-coverage issues are non-blocking.

Findings

  1. P2 Classmethod is not restored ▶
  2. P2 CPU scheduler tests are skipped ▶

Summary

The PR replaces float32 timestamp subtraction in sensor due checks with a per-environment float64 elapsed clock, resetting that clock on refresh and reset. It updates OV sensor buffer allocations and adds scheduler regression tests. The review found two test-quality issues, but no established defect in the scheduling change.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["update(dt)"] --> B["Advance float32 timestamp and float64 elapsed"]
  B --> C{"Elapsed meets due threshold?"}
  C -- Yes --> D["Mark environment outdated"]
  C -- No --> E["Keep current outdated state"]
  D --> F["Read sensor data"]
  E --> F
  F --> G{"Outdated?"}
  G -- Yes --> H["Refresh; clear outdated; zero elapsed"]
  G -- No --> I["Return existing data"]
  J["Reset environment"] --> K["Zero clocks; mark outdated"]
Loading

Reviews (1) · Last reviewed commit: "Fix sensor refreshes delayed by float32 ..."

@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 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 three isaaclab_ov sensors that revise _num_envs now duplicate all base timing-buffer allocations, including _elapsed_since_update; add a protected SensorBase resize/allocation helper so this state remains base-owned.
  • API: No public sensor class, configuration field, property, or export changes. SensorBaseCfg.update_period retains 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 _timestamp and _timestamp_last_update retain 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 in SensorBase.
  • 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, and reset paths against an independent Fraction oracle, covering aged clocks, non-integer periods, variable dt, delayed reads, partial resets, and zero periods. Remove the read_every=4 lazy-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=3 retains 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]>
@yusufdxb

Copy link
Copy Markdown
Contributor Author

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Sep 29, 2026

@AntoineRichard AntoineRichard left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@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]>
@yusufdxb
yusufdxb requested a review from hujc7 as a code owner September 30, 2026 12:28
@yusufdxb

Copy link
Copy Markdown
Contributor Author

@AntoineRichard thanks for the review. Addressed in e784a28 and e4f8998:

  • _create_timing_buffers(): added to SensorBase. It allocates the env masks, timestamps, outdated flags and the new elapsed-time buffer for the current _num_envs. _initialize_impl() and the three OVPhysX sensors that change _num_envs after initialization (contact sensor, frame transformer, joint wrench sensor) now call it, and no other code builds these buffers by hand. The two hand-built fake sensors in test_simulation_render_context.py also use it.
  • Air/contact time: moved onto the same elapsed time. On each refresh, the PhysX, Newton and OVPhysX contact kernels added timestamp - timestamp_last_update to the timers, which is the same growing-float32 subtraction. They now add _elapsed_since_update (the time since the last refresh, which is exactly what that difference was approximating), so nothing in the repo subtracts the timestamps any more. In a kernel-level check (each backend's own contact kernel driven for 40 s against an exact integer model, CPU and CUDA, history and lazy refresh, 64 envs with resets), the timer error went from up to 7.7e-5 s to at most 3.9e-8 s. With the old fixed abs_tol=1e-8, missed first-contact/first-air events went from up to 34,772 of 60,085 to 0, with no false positives. I kept the half-interval default from Fix compute_first_contact/air missing transitions as the sensor clock ages #7574, and its tests pass unchanged. Even with exact timers, a fixed 1e-8 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 the half-interval default still does real work. Happy to revisit that if you'd rather drop it here.
  • Breaking: marked the PR as breaking. The isaaclab fragment is now .major.rst, with a Breaking: entry: sensors that allocate or resize the timing buffers themselves must call _create_timing_buffers(), and code that launches the scheduler kernels directly must pass the new buffer. PhysX, Newton and OVPhysX got fix fragments for the timers.
  • Tests: reduced test_sensor_update_schedule.py from 8 tests / 16 cases (287 lines) to 3 tests / 4 cases (86 lines), with no oracle and no SimulationContext patching (the fake sensor builds itself with _create_timing_buffers()):
    • the aged clock (dt=0.005, update_period=0.02, 20 s) on CPU and CUDA, which fails on develop;
    • an unread due sensor stays due and the period restarts at the read (rejects fixed-grid scheduling);
    • the period follows the dt passed to update() (rejects counting updates, and also fails on develop).

@yusufdxb

Copy link
Copy Markdown
Contributor Author

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Sep 30, 2026

@AntoineRichard AntoineRichard left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@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]>
@yusufdxb

yusufdxb commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Oct 1, 2026
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]>
@yusufdxb

yusufdxb commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Oct 1, 2026
@maxkra15
maxkra15 self-requested a review October 6, 2026 11:57
@maxkra15
maxkra15 merged commit 32a1f33 into isaac-sim:develop Oct 6, 2026
58 checks passed
@NeoZng

NeoZng commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

@AntoineRichard Could this be backported to release/3.0.0? The reproducer from #8159 still prints stale reads: 100 / 1000; first at t = [16.02] s on release/3.0.0 (d061bf3; no sensor changes since), while develop prints stale reads: 0 / 1000.

AntoineRichard pushed a commit that referenced this pull request Nov 18, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug Report] Sensor refreshes can be delayed as float32 clocks accumulate rounding error

5 participants