Skip to content

fix: add class default inheritance for actuator parsing in MJCF#1503

Merged
adenzler-nvidia merged 1 commit into
newton-physics:mainfrom
adenzler-nvidia:fix/mjcf-actuator-class-defaults
Jan 30, 2026
Merged

fix: add class default inheritance for actuator parsing in MJCF#1503
adenzler-nvidia merged 1 commit into
newton-physics:mainfrom
adenzler-nvidia:fix/mjcf-actuator-class-defaults

Conversation

@adenzler-nvidia

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

Copy link
Copy Markdown
Member

Actuator elements (, , etc.) now properly inherit attributes like biasprm, gainprm, ctrlrange from their default class. This fixes parsing of menagerie robots like UR5e that rely on class defaults for actuator configuration.

Changes:

  • Use merge_attrib to combine class defaults with element attributes
  • Apply all defaults first, then class-specific defaults, then element attributes

Add tests for class default inheritance in actuator parsing.

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

    • Improved actuator parameter inheritance from default classes in MuJoCo MJCF files, ensuring proper attribute resolution for actuator gains, limits, and bias parameters.
  • Tests

    • Added comprehensive test coverage for actuator default class inheritance scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

Actuator elements (<general>, <position>, etc.) now properly inherit
attributes like biasprm, gainprm, ctrlrange from their default class.
This fixes parsing of menagerie robots like UR5e that rely on class
defaults for actuator configuration.

Changes:
- Use merge_attrib to combine class defaults with element attributes
- Apply __all__ defaults first, then class-specific defaults, then
  element attributes

Add tests for class default inheritance in actuator parsing.
@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Centralizes attribute resolution for actuators by merging class-based defaults with element-specific attributes before use. Modified the parse_actuators function to derive target names and parameters from merged attributes rather than raw element attributes. Added comprehensive test coverage for class inheritance behavior.

Changes

Cohort / File(s) Summary
Actuator Attribute Resolution
newton/_src/utils/import_mjcf.py
Refactored actuator parsing to compute merged_attrib by combining global defaults, class-specific defaults, and element attributes. Updated all actuator attribute reads (joint/body/tendon targets, kp/kv parameters, actuation name) to use merged_attrib instead of raw element attributes.
Test Coverage
newton/tests/test_import_mjcf.py
Added TestMjcfActuatorClassDefaults test class with three tests verifying that general and position actuators properly inherit biasprm, gainprm, and kp parameters from MuJoCo default classes.

Sequence Diagram

sequenceDiagram
    participant Parser as MJCF Parser
    participant Defaults as Class Defaults Resolver
    participant Merge as Attribute Merger
    participant ActParse as Actuator Parser
    participant Model as Model Builder

    Parser->>Defaults: Request class defaults hierarchy
    Defaults-->>Parser: Return resolved class defaults (with inheritance)
    
    Parser->>ActParse: Begin parsing actuator element
    ActParse->>Merge: Element attributes + class defaults
    Merge->>Merge: Combine global defaults<br/>+ class defaults<br/>+ element attributes
    Merge-->>ActParse: Return merged_attrib
    
    ActParse->>ActParse: Derive target (joint/body/tendon)<br/>from merged_attrib
    ActParse->>ActParse: Extract kp, kv, actuation name<br/>from merged_attrib
    ActParse->>ActParse: Parse custom attributes<br/>using merged_attrib
    ActParse-->>Model: Finalized actuator with<br/>inherited parameters
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • PR #1207: Adds recursive resolve_defaults step that propagates parent defaults; this PR depends on that infrastructure to merge class defaults into actuator attributes.
  • PR #1170: Modifies the same MJCF actuator parsing logic in import_mjcf.py to handle per-DOF effort_limit and actuatorfrcrange, directly overlapping with the implementation area.
🚥 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 pull request title accurately describes the main change: adding class default inheritance for actuator parsing in MJCF format.
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.

@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!

@adenzler-nvidia adenzler-nvidia added this pull request to the merge queue Jan 30, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 30, 2026
@adenzler-nvidia adenzler-nvidia added this pull request to the merge queue Jan 30, 2026
Merged via the queue into newton-physics:main with commit f4dd140 Jan 30, 2026
22 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.

2 participants