Repository navigation
Keep first-stage sensordata in MJX RK4 steps - #3903
Merged
copybara-service[bot] merged 1 commit intoNov 25, 2026
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mj_RungeKuttaevaluates stages 1 to 3 with sensors skipped, so aftermj_stepthe sensor values belong to the state at the start of the step.mjx.rungekutta4builds its result from the last stage's data, sosensordataholds the sensors computed at the stage-3 state and time. For a hinge withqvel = 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
sensordatatogether with the other first-stage fields.Tests: new
ForwardTest.test_rk4_sensordata(jointpos, jointvel, accelerometer vsmj_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.