Skip to content

Keep first-stage sensordata in MJX RK4 steps - #3903

Merged
copybara-service[bot] merged 1 commit into
google-deepmind:mainfrom
sohailshk:fix/mjx-rk4-sensordata
Nov 25, 2026
Merged

copybara-service[bot] merged 1 commit into
google-deepmind:mainfrom
sohailshk:fix/mjx-rk4-sensordata

Conversation

@sohailshk

Copy link
Copy Markdown
Contributor

mj_RungeKutta evaluates stages 1 to 3 with sensors skipped, so after mj_step the sensor values belong to the state at the start of the step. mjx.rungekutta4 builds its result from the last stage's data, so sensordata holds the sensors computed at the stage-3 state and time. For a hinge with qvel = 3, dt = 0.01, after one step jointpos is 0.0316 in MJX and 0 in MuJoCo, accelerometer -3.60 vs -2.70. Euler and implicitfast already match. The Warp backend already skips sensors in these stages.

The fix restores the first-stage sensordata together with the other first-stage fields.

Tests: new ForwardTest.test_rk4_sensordata (jointpos, jointvel, accelerometer vs mj_step) fails on main (4 of 5 values differ, max 0.90) and passes with the change. forward_test (16) passes on CPU, macOS arm64; Warp not tested.

mj_RungeKutta evaluates stages 1..3 with sensors skipped, so after mj_step the
sensor values belong to the state at the start of the step. rungekutta4 built
its result from the last stage's data, whose sensordata was recomputed at the
intermediate stage state and time. Restore the first-stage sensordata along
with the other first-stage fields.
@copybara-service
copybara-service Bot merged commit edc6b96 into google-deepmind:main Nov 25, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant