Skip to content

MJCF import: auto-enable actuator *limited flags when *range is specified in MJCF#1504

Merged
adenzler-nvidia merged 2 commits into
newton-physics:mainfrom
adenzler-nvidia:fix/mjcf-actuator-auto-limited
Feb 5, 2026
Merged

MJCF import: auto-enable actuator *limited flags when *range is specified in MJCF#1504
adenzler-nvidia merged 2 commits into
newton-physics:mainfrom
adenzler-nvidia:fix/mjcf-actuator-auto-limited

Conversation

@adenzler-nvidia

@adenzler-nvidia adenzler-nvidia commented Jan 30, 2026

Copy link
Copy Markdown
Member

Implements MuJoCo's auto-inference behavior: if ctrllimited/forcelimited/actlimited is not explicitly set in MJCF but the corresponding range attribute has valid values (range[0] < range[1]), automatically enable the limit flag.

This matches native MuJoCo behavior where specifying a range implicitly enables the corresponding limit unless explicitly disabled.

Changes:

  • Add resolution logic in MJCF parser after parsing custom attributes
  • Add comments to solver_mujoco.py custom attribute definitions

Tests:

  • test_ctrllimited_auto_enabled_when_ctrlrange_specified
  • test_ctrllimited_not_auto_enabled_without_ctrlrange
  • test_ctrllimited_explicit_false_not_overridden
  • test_forcelimited_auto_enabled_when_forcerange_specified
  • test_actlimited_auto_enabled_when_actrange_specified

Before your PR is "Ready for review"

  • Necessary tests have been added and new examples are tested (see newton/tests/test_examples.py)
  • Documentation is up-to-date
  • Code passes formatting and linting checks with pre-commit run -a

Summary by CodeRabbit

  • Bug Fixes

    • Actuator limitation flags are now auto-enabled when corresponding range constraints are present in MuJoCo MJCF, improving model parsing.
  • Documentation

    • Clarified MJCF attribute defaults with inline comments to explain parser behavior.
  • Tests

    • Added and updated tests covering actuator auto-enablement and adjusted expectations/renamed a test to reflect override behavior.

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds automatic resolution of MuJoCo actuator limited flags (ctrllimited, forcelimited, actlimited) based on corresponding range attributes when the limited flags are not explicitly specified; adds inline MJCF comments and new tests validating this behavior.

Changes

Cohort / File(s) Summary
Documentation & Comments
newton/_src/solvers/mujoco/solver_mujoco.py
Inserted inline comments next to three default=0 MJCF actuator attribute declarations noting the MJCF parser auto-enables these when corresponding ranges are provided.
Core Implementation
newton/_src/utils/import_mjcf.py
In parse_actuators, added logic to auto-set ctrllimited, forcelimited, and actlimited to 1 when their respective range attributes (ctrlrange, forcerange, actrange) are present with valid bounds and the limited flags are not explicitly specified.
Tests
newton/tests/test_import_mjcf.py
Added TestMjcfActuatorAutoLimited with tests for auto-enabling/disabling of actuator limited flags and explicit overrides; updated TestMjcfActuatorClassDefaults assertions to expect integer biasprm values and renamed one test to reflect override behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • jvonmuralt
  • eric-heiden
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately summarizes the main change: auto-enabling actuator limited flags based on range specifications in MJCF imports.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

… MJCF

Implements MuJoCo's auto-inference behavior: if ctrllimited/forcelimited/actlimited
is not explicitly set in MJCF but the corresponding range attribute has valid values
(range[0] < range[1]), automatically enable the limit flag.

This matches native MuJoCo behavior where specifying a range implicitly enables
the corresponding limit unless explicitly disabled.

Changes:
- Add resolution logic in MJCF parser after parsing custom attributes
- Add comments to solver_mujoco.py custom attribute definitions

Tests:
- test_ctrllimited_auto_enabled_when_ctrlrange_specified
- test_ctrllimited_not_auto_enabled_without_ctrlrange
- test_ctrllimited_explicit_false_not_overridden
- test_forcelimited_auto_enabled_when_forcerange_specified
- test_actlimited_auto_enabled_when_actrange_specified
@adenzler-nvidia adenzler-nvidia force-pushed the fix/mjcf-actuator-auto-limited branch from e48ebd1 to 3fa2891 Compare January 30, 2026 16:25
@codecov

codecov Bot commented Jan 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

eric-heiden
eric-heiden previously approved these changes Feb 3, 2026
@eric-heiden

Copy link
Copy Markdown
Member

Depending if #1510 gets merged before, these limited flags I think should be boolean custom attributes. I've changed that in #1510.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@newton/_src/utils/import_mjcf.py`:
- Around line 1871-1884: The limit auto-enable logic is incorrectly reading
actuator_elem.attrib directly and checking for limited_attr there, which ignores
defaults; update the loop that resolves ("ctrllimited","ctrlrange",...),
("forcelimited","forcerange",...), ("actlimited","actrange",...) to use
merged_attrib for both the presence check and for reading the range string
(i.e., check if limited_attr not in merged_attrib and get range_str =
merged_attrib.get(range_attr, "")), then keep the existing parsing and setting
parsed_attrs[limited_key] = 1 when range_vals[0] < range_vals[1]; this ensures
default-derived range and limited flags are respected for actuator_elem.

In `@newton/tests/test_import_mjcf.py`:
- Around line 4361-4478: The tests in TestMjcfActuatorAutoLimited access
model.mujoco.actuator_* arrays but never call
SolverMuJoCo.register_custom_attributes, so add a registration step before the
tests run (e.g., in a class-level setUpClass or a shared helper invoked at the
top of each test) to ensure MuJoCo actuator custom attributes are registered;
call SolverMuJoCo.register_custom_attributes(...) once before using
ModelBuilder().add_mjcf()/finalize() in tests like
test_ctrllimited_auto_enabled_when_ctrlrange_specified,
test_ctrllimited_not_auto_enabled_without_ctrlrange,
test_ctrllimited_explicit_false_not_overridden,
test_forcelimited_auto_enabled_when_forcerange_specified, and
test_actlimited_auto_enabled_when_actrange_specified.

Comment thread newton/_src/utils/import_mjcf.py
Comment thread newton/tests/test_import_mjcf.py
@adenzler-nvidia adenzler-nvidia force-pushed the fix/mjcf-actuator-auto-limited branch from 3dd6c95 to 2583712 Compare February 5, 2026 12:24
@adenzler-nvidia adenzler-nvidia added this pull request to the merge queue Feb 5, 2026
Merged via the queue into newton-physics:main with commit 7a82df9 Feb 5, 2026
22 checks passed
dylanturpin pushed a commit to dylanturpin/newton-collab that referenced this pull request Feb 13, 2026
mmacklin pushed a commit to mmacklin/newton that referenced this pull request Apr 7, 2026
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.

3 participants