Skip to content

Fix Demo Scripts (h1_locomotion.py and quadcopter.py)#5866

Merged
kellyguo11 merged 6 commits into
isaac-sim:developfrom
YizeWang:yizew/fix-demo-scripts-minimal
May 31, 2026
Merged

Fix Demo Scripts (h1_locomotion.py and quadcopter.py)#5866
kellyguo11 merged 6 commits into
isaac-sim:developfrom
YizeWang:yizew/fix-demo-scripts-minimal

Conversation

@YizeWang
Copy link
Copy Markdown

@YizeWang YizeWang commented May 29, 2026

Description

This PR fixes demo scripts that were using outdated tensor/view APIs.

The quadcopter demo now reads robot mass through the public robot.data.body_mass API. The H1 locomotion demo now applies the RSL-RL deprecated config handler based on the installed rsl-rl-lib version. This PR also adds Yize Wang to CONTRIBUTORS.md.

Fixes NV Bugs:

  • 6199772 (quadcopter.py)
  • 6161743 (quadcopter.py)
  • 6120938 (h1_locomotion.py)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Documentation update

Screenshots

Fixed scripts:
h1_locomotion
quadcopter

Validation of other scripts:
arl_robot_1
arms
bipeds
multi_asset
pick_and_place
procedural_terrain
quadrupeds
hands
markers
deformables

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

Yize Wang added 5 commits May 28, 2026 14:35
Signed-off-by: Yize Wang <yizew@nvidia.com>
Signed-off-by: Yize Wang <yizew@nvidia.com>
Signed-off-by: Yize Wang <yizew@nvidia.com>
Signed-off-by: Yize Wang <yizew@nvidia.com>
Signed-off-by: Yize Wang <yizew@nvidia.com>
@YizeWang YizeWang requested a review from ooctipus as a code owner May 29, 2026 16:27
@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels May 29, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 29, 2026

Greptile Summary

This PR fixes two demo scripts that were broken by API changes: quadcopter.py migrates from the deprecated root_view.get_masses() to the public body_mass data property, and h1_locomotion.py adds handle_deprecated_rsl_rl_cfg to remain compatible across rsl-rl-lib version boundaries.

  • quadcopter.py: robot_mass now reads from robot.data.body_mass.torch[0].sum() instead of the removed root_view accessor; correct for the single-instance demo.
  • h1_locomotion.py: Imports handle_deprecated_rsl_rl_cfg and applies it immediately after parsing the agent config, matching the pattern already used in the rsl_rl/play.py and rsl_rl/train.py scripts.
  • CONTRIBUTORS.md: Author added in alphabetical order.

Confidence Score: 4/5

Both script fixes are targeted and demonstrated working via screenshots; the changes are small and low-risk.

The quadcopter fix hardcodes instance [0] for mass fetching, which is fine for the current single-robot demo but differs from a fully general approach. The h1 fix defers the metadata.version call to init rather than module-level, a minor inconsistency with the rest of the codebase. Neither causes incorrect behavior in the current scripts.

No files require special attention beyond the two demo scripts.

Important Files Changed

Filename Overview
CONTRIBUTORS.md Adds 'Yize Wang' in correct alphabetical order between 'Yijie Guo' and 'Yohan Choi'.
scripts/demos/h1_locomotion.py Adds importlib.metadata version detection and calls handle_deprecated_rsl_rl_cfg, consistent with other rsl_rl scripts. Uses inline metadata.version() call rather than a module-level variable as in play.py/train.py, but functionally correct.
scripts/demos/quadcopter.py Replaces deprecated root_view.get_masses() with the public body_mass.torch[0].sum() API. Correctly computes total mass for the single-instance demo; using [0] hardcodes instance-0 mass.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    subgraph quadcopter.py
        A[sim.reset] --> B["robot.data.body_mass.torch[0].sum()"]
        B --> C[robot_mass scalar]
        C --> D["forces[...,2] = robot_mass * gravity / 4.0"]
        D --> E[robot hover loop]
    end

    subgraph h1_locomotion.py
        F["parse_rsl_rl_cfg(TASK, args_cli)"] --> G["metadata.version('rsl-rl-lib')"]
        G --> H["handle_deprecated_rsl_rl_cfg(agent_cfg, version)"]
        H --> I[get_published_pretrained_checkpoint]
        I --> J[OnPolicyRunner.load]
        J --> K[H1 demo loop]
    end
Loading

Reviews (1): Last reviewed commit: "Remove Warp Import From quadcopter.py" | Re-trigger Greptile

# Fetch relevant parameters to make the quadcopter hover in place
prop_body_ids = robot.find_bodies("m.*_prop")[0]
robot_mass = robot.root_view.get_masses().sum()
robot_mass = robot.data.body_mass.torch[0].sum()
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.

P2 Using [0] to index the first instance ties the hover-force calculation to a single environment's mass. The body_mass tensor has shape (num_instances, num_bodies), so summing over instance 0 is correct for this single-robot demo, but the mean across all instances (or a per-instance sum) would be more robust if the demo is ever extended to spawn multiple robots. For a stricter fix, an assertion or the use of .mean(dim=0).sum() would make the intent clearer.

Suggested change
robot_mass = robot.data.body_mass.torch[0].sum()
robot_mass = robot.data.body_mass.torch.sum(dim=1).mean()

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +21 to 23
from importlib import metadata

sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../.."))
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.

P2 The other RSL-RL scripts (play.py, train.py) call metadata.version("rsl-rl-lib") once at module level and reuse the variable, which surfaces a PackageNotFoundError immediately on import rather than deferred to first construction of H1RoughDemo. Calling it inline inside __init__ delays the failure and also re-evaluates the version string on every new demo object. Storing it in a module-level constant matches the established pattern.

Suggested change
from importlib import metadata
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../.."))
from importlib import metadata
_RSL_RL_INSTALLED_VERSION = metadata.version("rsl-rl-lib")
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../.."))

Copy link
Copy Markdown

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

This PR fixes two broken demo scripts by updating deprecated APIs. The changes are straightforward and correct for their intended use case.

✅ Overall Assessment: Ship it

The fixes address real issues (broken demo scripts) with minimal, focused changes. Both API updates are appropriate and follow current Isaac Lab patterns.


Detailed Analysis

scripts/demos/quadcopter.py

Change: robot.root_view.get_masses().sum()robot.data.body_mass.torch[0].sum()

Correct fix. The root_view API was deprecated in favor of the unified data.body_mass tensor interface. The [0] indexing is appropriate here since this demo spawns exactly one robot instance (num_envs defaults to 1 for this script).

scripts/demos/h1_locomotion.py

Change: Added handle_deprecated_rsl_rl_cfg(agent_cfg, metadata.version("rsl-rl-lib"))

Correct fix. The handle_deprecated_rsl_rl_cfg function handles RSL-RL configuration compatibility across version boundaries (< 4.0.0, ≥ 4.0.0, ≥ 5.0.0). This matches the pattern used in the canonical play.py and train.py scripts.


Minor Observations (non-blocking)

🔵 Style consistencyscripts/demos/h1_locomotion.py:88

The version string is evaluated inline (metadata.version("rsl-rl-lib")) within __init__. The canonical RSL-RL scripts (play.py, train.py) evaluate this at module level for earlier failure on missing packages. For a demo script, inline evaluation is acceptable, but hoisting to module level would be more consistent with the codebase pattern.

🔵 Hardcoded instance indexscripts/demos/quadcopter.py:77

Using [0] assumes single-instance execution. This is fine for the current demo (which only spawns one robot), but a comment noting this assumption would help maintainers if the demo is later extended to multi-instance.


Checklist Verification

  • ✅ License headers present
  • ✅ Changes are minimal and focused
  • ✅ Pre-commit checks passed (per PR description)
  • ⚠️ No tests added — acceptable for demo script bug fixes; the screenshots in the PR description serve as manual verification
  • ⚠️ CHANGELOG not updated — these are fixes to demo scripts, not library APIs, so this is reasonable

LGTM with the minor style observations noted above. Nice fix! 🚀

# Fetch relevant parameters to make the quadcopter hover in place
prop_body_ids = robot.find_bodies("m.*_prop")[0]
robot_mass = robot.root_view.get_masses().sum()
robot_mass = robot.data.body_mass.torch[0].sum()
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.

what's the main reason behind why this is needed?

Copy link
Copy Markdown
Author

@YizeWang YizeWang May 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary. The shape of robot.data.body_mass.torch is (1, 5). I wanted to highlight this is the total mass of the first quadcopter (though there are no ones in this case). With or without [0], the result is equivalent for this mono-instance demo.

@kellyguo11 kellyguo11 merged commit adca72a into isaac-sim:develop May 31, 2026
60 of 61 checks passed
kellyguo11 added a commit that referenced this pull request May 31, 2026
…nvs, shutdown error, mjcf fix (#5888)

# Description

Cherry-pick PRs from develop:

- #5866 
- #5879 
- #5882 
- #5884
- #5889

---------

Signed-off-by: Yize Wang <yizew@nvidia.com>
Signed-off-by: Kelly Guo <kellyg@nvidia.com>
Co-authored-by: YizeWang <37894497+YizeWang@users.noreply.github.com>
Co-authored-by: Yize Wang <yizew@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants