Implement mj_setConst to enable safe domain randomization #941
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.
Implement
mj_setConstfor Safe Runtime Model UpdatesThis PR implements
mj_setConstfunctionality inmujoco_warp, enabling safe runtime modification of model parameters on device, which is required for domain randomization.This work addresses Issue #893 (Implement mj_setConst).
Summary
MuJoCo allows certain model parameters (e.g., mass, inertia, spring parameters) to be modified at runtime, but requires recomputation of dependent model-constant fields via
mj_setConst.This PR ports the relevant parts of
mj_setConstintomujoco_warp.Changes
New Functionality
set_const(m, d, mjm)inmujoco_warp/_src/setconst.pyas the main entry point.Implemented Components
_set_statstat.meaninertiausing a custom Warp kernel._set_springtendon_lengthspring.qpos_spring, matching C MuJoCo behavior.API Update
put_modelinio.pyto acceptrecompute_const: bool = False.True,set_constis invoked during model creation.Tests
mujoco_warp/_src/setconst_test.py.meaninertiacomputationtendon_lengthspringrecomputationRelation to PR #905
This PR complements PR #905.
PR Add set_const function for recomputing qpos0-dependent fields. #905 focuses on:
set_fixedset_0(qpos0-dependent fields)This PR implements the remaining components:
set_stat(model statistics)set_spring(spring-related constants)Placeholders with TODOs referencing PR #905 are included to facilitate clean merging.
Verification
All added tests pass successfully, confirming correctness against C MuJoCo behavior.