Skip to content

Adds USD-level randomization mode to event manager - #2040

Merged
kellyguo11 merged 13 commits into
mainfrom
feature/usd-events
Mar 13, 2025
Merged

kellyguo11 merged 13 commits into
mainfrom
feature/usd-events

Conversation

@Mayankm96

@Mayankm96 Mayankm96 commented Mar 7, 2025 •

Copy link
Copy Markdown
Contributor

Description

Certain scene-level randomizations (such as randomizing the scale) must happen before the simulation starts playing. To this end, the MR adds a new event mode called "prestartup," which gets called right after the scene design is complete and before the simulation is played.

Since the scene entities cannot be resolved before the simulation starts playing (as we currently rely on PhysX to provide us with the joint/body ordering), the MR adds a callback to resolve the scene entity configurations separately once the simulation plays.

This MR replaces the prior implementation in #1165

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Screenshots

If you execute:

./isaaclab.sh -p scripts/tutorials/03_envs/create_cube_base_env.py --num_envs 32

Output:

image

Checklist

  • 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

@jsmith-bdai jsmith-bdai 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.

LGTM! I feel like mode = 'usd' could be named a little better for ease of understanding, e.g. 'pre-play', or 'pre-start', but this is definitely not a blocker / big deal.

Thanks!

@jsmith-bdai

Copy link
Copy Markdown
Contributor

How do we want to handle the other PRs that were previously on top of #1165? We can change them to point to this branch? Or are they now out-of-date?

Co-authored-by: James Smith <[email protected]>
Signed-off-by: Mayank Mittal <[email protected]>
@Mayankm96 Mayankm96 added the enhancement New feature or request label Mar 11, 2025
@Mayankm96
Mayankm96 requested a review from hhansen-bdai as a code owner March 11, 2025 19:02
@Mayankm96

Copy link
Copy Markdown
Contributor Author

@jsmith-bdai Other MRs will have to rebase themselves on top of this branch

@kellyguo11
kellyguo11 merged commit 6b794ac into main Mar 13, 2025
@kellyguo11
kellyguo11 deleted the feature/usd-events branch March 13, 2025 04:07
@kousheekc

kousheekc commented Mar 13, 2025 •

Copy link
Copy Markdown
Contributor

@Mayankm96 Thanks for this update! Had a quick question: in the prior implementation in #1165 there was the attempt to add a randomize_shape_color function in events.py is that still in the pipeline? I have tried adding this myself in the following way:

def randomize_shape_color(
        env: ManagerBasedEnv, 
        env_ids: torch.Tensor | None, 
        asset_cfg: SceneEntityCfg
):
    # extract the used quantities (to enable type-hinting)
    asset: RigidObject = env.scene[asset_cfg.name]

    # resolve environment ids
    if env_ids is None:
        env_ids = torch.arange(env.scene.num_envs, device="cpu")
    else:
        env_ids = env_ids.cpu()

    # acquire stage
    stage = omni.usd.get_context().get_stage()
    # resolve prim paths for spawning and cloning
    prim_paths = sim_utils.find_matching_prim_paths(asset.cfg.prim_path)

    # sample values
    rand_samples = math_utils.sample_uniform(0.0, 1.0, (len(env_ids), 3), device="cpu").tolist()

    # use sdf changeblock for faster processing of USD properties
    with Sdf.ChangeBlock():
        for i, env_id in enumerate(env_ids):
            # spawn single instance
            prim_spec = Sdf.CreatePrimInLayer(stage.GetRootLayer(), prim_paths[env_id])

            # get the attribute to randomize
            color_spec = prim_spec.GetAttributeAtPath(
                prim_paths[env_id] + "/geometry/material/Shader.inputs:diffuseColor"
            )
            color_spec.default = Gf.Vec3f(*rand_samples[i])

but I get the following error when using this event in my manager based environment:

  File "/home/kousheek/Dev/rl_aphi/envs/hover/mdp/events.py", line 92, in randomize_shape_color
   color_spec.default = Gf.Vec3f(*rand_samples[i])
AttributeError: 'NoneType' object has no attribute 'default'

I have double checked if the prim paths exist. And for clarification I am using this like this:

    randomize_shape_color = EventTerm(
        func=mdp.randomize_shape_color,
        mode="interval",
        interval_range_s=(0.5,3),
        params={
            "asset_cfg": SceneEntityCfg("wall", body_names=".*"),
        },
    )

The wall object is defined like this:

    wall: RigidObjectCfg = RigidObjectCfg(
        prim_path="{ENV_REGEX_NS}/wall",
        spawn=sim_utils.CuboidCfg(
            size=[2,0.2,2],
            rigid_props=sim_utils.RigidBodyPropertiesCfg(kinematic_enabled=True),
            mass_props=sim_utils.MassPropertiesCfg(mass=10000.0),
            collision_props=sim_utils.CollisionPropertiesCfg(collision_enabled=True),
            visual_material=sim_utils.PreviewSurfaceCfg(diffuse_color=(0.1, 0.9, 0.9), metallic=0.2),
            physics_material=sim_utils.RigidBodyMaterialCfg(static_friction=0.9, dynamic_friction=0.2)
        ),
        init_state=RigidObjectCfg.InitialStateCfg(pos=[0.0,0.0,1.0]),
    )

Thanks is advance!

kellyguo11 added a commit that referenced this pull request Mar 26, 2025
# Description

To support creation of managers before the simulation starts playing (as
needed by the event manager for USD randomizations), the MR in #2040
added a callback to resolve scene entities at runtime. However, certain
class-based manager terms can also not be initialized if the simulation
is not playing. Those terms may often rely on parameters that are only
available once simulation plays (for instance, joint position limits).

This MR moves the initializations of class-based manager terms to the
callback too.

Fixes #2136

## Type of change

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

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] 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
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Co-authored-by: Kelly Guo <[email protected]>
jtigue-bdai pushed a commit that referenced this pull request Apr 14, 2025
# Description

Certain scene-level randomizations (such as randomizing the scale) must
happen before the simulation starts playing. To this end, the MR adds a
new event mode called "prestartup," which gets called right after the
scene design is complete and before the simulation is played.

Since the scene entities cannot be resolved before the simulation starts
playing (as we currently rely on PhysX to provide us with the joint/body
ordering), the MR adds a callback to resolve the scene entity
configurations separately once the simulation plays.

This MR replaces the prior implementation in #1165

## Type of change

- New feature (non-breaking change which adds functionality)
- This change requires a documentation update

## Screenshots

If you execute:

```bash
./isaaclab.sh -p scripts/tutorials/03_envs/create_cube_base_env.py --num_envs 32
```

Output:


![image](https://github.com/user-attachments/assets/a4b3a5e7-ff5c-4593-97ce-3b5af19bfde2)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] 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
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Signed-off-by: Mayank Mittal <[email protected]>
Co-authored-by: James Smith <[email protected]>
Co-authored-by: Kelly Guo <[email protected]>
ToxicNS pushed a commit to ToxicNS/IsaacLab that referenced this pull request Apr 24, 2025
# Description

Certain scene-level randomizations (such as randomizing the scale) must
happen before the simulation starts playing. To this end, the MR adds a
new event mode called "prestartup," which gets called right after the
scene design is complete and before the simulation is played.

Since the scene entities cannot be resolved before the simulation starts
playing (as we currently rely on PhysX to provide us with the joint/body
ordering), the MR adds a callback to resolve the scene entity
configurations separately once the simulation plays.

This MR replaces the prior implementation in isaac-sim#1165

## Type of change

- New feature (non-breaking change which adds functionality)
- This change requires a documentation update

## Screenshots

If you execute:

```bash
./isaaclab.sh -p scripts/tutorials/03_envs/create_cube_base_env.py --num_envs 32
```

Output:


![image](https://github.com/user-attachments/assets/a4b3a5e7-ff5c-4593-97ce-3b5af19bfde2)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] 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
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Signed-off-by: Mayank Mittal <[email protected]>
Co-authored-by: James Smith <[email protected]>
Co-authored-by: Kelly Guo <[email protected]>
ToxicNS pushed a commit to ToxicNS/IsaacLab that referenced this pull request Apr 24, 2025
# Description

To support creation of managers before the simulation starts playing (as
needed by the event manager for USD randomizations), the MR in isaac-sim#2040
added a callback to resolve scene entities at runtime. However, certain
class-based manager terms can also not be initialized if the simulation
is not playing. Those terms may often rely on parameters that are only
available once simulation plays (for instance, joint position limits).

This MR moves the initializations of class-based manager terms to the
callback too.

Fixes isaac-sim#2136

## Type of change

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

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] 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
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Co-authored-by: Kelly Guo <[email protected]>
yrh012 pushed a commit to aica-technology/isaac-lab that referenced this pull request Jun 16, 2025
# Description

To support creation of managers before the simulation starts playing (as
needed by the event manager for USD randomizations), the MR in isaac-sim#2040
added a callback to resolve scene entities at runtime. However, certain
class-based manager terms can also not be initialized if the simulation
is not playing. Those terms may often rely on parameters that are only
available once simulation plays (for instance, joint position limits).

This MR moves the initializations of class-based manager terms to the
callback too.

Fixes isaac-sim#2136

## Type of change

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

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] 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
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Co-authored-by: Kelly Guo <[email protected]>
LJones-alt pushed a commit to LJones-alt/IsaacLab-Laura that referenced this pull request Jul 1, 2026
# Description

Certain scene-level randomizations (such as randomizing the scale) must
happen before the simulation starts playing. To this end, the MR adds a
new event mode called "prestartup," which gets called right after the
scene design is complete and before the simulation is played.

Since the scene entities cannot be resolved before the simulation starts
playing (as we currently rely on PhysX to provide us with the joint/body
ordering), the MR adds a callback to resolve the scene entity
configurations separately once the simulation plays.

This MR replaces the prior implementation in isaac-sim#1165

## Type of change

- New feature (non-breaking change which adds functionality)
- This change requires a documentation update

## Screenshots

If you execute:

```bash
./isaaclab.sh -p scripts/tutorials/03_envs/create_cube_base_env.py --num_envs 32
```

Output:


![image](https://github.com/user-attachments/assets/a4b3a5e7-ff5c-4593-97ce-3b5af19bfde2)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] 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
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Signed-off-by: Mayank Mittal <[email protected]>
Co-authored-by: James Smith <[email protected]>
Co-authored-by: Kelly Guo <[email protected]>
LJones-alt pushed a commit to LJones-alt/IsaacLab-Laura that referenced this pull request Jul 1, 2026
# Description

To support creation of managers before the simulation starts playing (as
needed by the event manager for USD randomizations), the MR in isaac-sim#2040
added a callback to resolve scene entities at runtime. However, certain
class-based manager terms can also not be initialized if the simulation
is not playing. Those terms may often rely on parameters that are only
available once simulation plays (for instance, joint position limits).

This MR moves the initializations of class-based manager terms to the
callback too.

Fixes isaac-sim#2136

## Type of change

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

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] 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
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Co-authored-by: Kelly Guo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants