Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mujoco_warp/_src/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,7 @@ def override_model(model: Union[types.Model, mujoco.MjModel], overrides: Union[d
}
mjw_only_fields = {"opt.broadphase", "opt.broadphase_filter", "opt.ls_parallel", "opt.graph_conditional"}
mj_only_fields = {"opt.jacobian"}
readonly_fields = {"opt.is_sparse"}

if not isinstance(overrides, dict):
overrides_dict = {}
Expand All @@ -1323,6 +1324,9 @@ def override_model(model: Union[types.Model, mujoco.MjModel], overrides: Union[d
if key in mj_only_fields and isinstance(model, types.Model):
continue

if key in readonly_fields and isinstance(model, types.Model):
raise ValueError(f"Cannot override {key} on mjw.Model: field affects model initialization and has side effects")

obj, attrs = model, key.split(".")
for i, attr in enumerate(attrs):
if not hasattr(obj, attr):
Expand Down