Repository navigation
MDP2 Reset Viewer #9119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
StafaH
wants to merge
17
commits into
isaac-sim:main
Choose a base branch
from
StafaH:mh/mdp2-reset-viewer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
MDP2 Reset Viewer #9119
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6fde935
Add an MDP2 reset event over the shared reset-state API
StafaH 8b13f50
Add state writes, outcome resets, and per-environment draws to the re…
StafaH 399f770
Run reset event updates every step and restore commands after resampling
StafaH cb1ba08
Record, replay, and save MDP2 reset banks
StafaH 9ccd105
Bank commands from the candidates task and skip credit for manual resets
StafaH be8ad7b
Extract the candidates roller from FillFromCandidates
StafaH 1ab873b
Dump callable config objects without a name as their fields
StafaH 221f2c1
Restore only the worlds that reset from the bank
StafaH b874255
Bank reset states per group of worlds, as MDP1's lift does per object
StafaH 9da2448
Rename the MDP2 reset bank API to reset states
StafaH dd2acbb
Expose the Viser server of the Viser visualizer
StafaH 1af0a4c
Add a reset viewer for MDP2 tasks
StafaH 935c0b2
Play reset viewer episodes in real time
StafaH b1a504b
Describe which viewer episodes the reset bank credits
StafaH 90b2dbb
Rename the reset viewer to ResetStateViewer
StafaH f3a009c
Show grouped reset states in the reset viewer
StafaH c45b386
Format the reset viewer test
StafaH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). | ||
| # All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| """Generate the reset states of an MDP2 task into a file, to load them in later runs. | ||
|
|
||
| Building the task builds the reset states of its ``reset_to_states`` event from the event's source, typically | ||
| ``mdp.FromTask`` with a generator task. The script saves them. Later runs load them with | ||
| ``source=mdp.FromFile(path)``, in the same number of worlds unless the states are shared. For example:: | ||
|
|
||
| uv run python scripts/tools/generate_reset_states.py --task Isaac-Lift-KukaAllegro-MDP2 --num_envs 4096 \\ | ||
| --num_states 64 --out kuka_lift_reset_states.pt physics=newton_mjwarp | ||
| """ | ||
|
|
||
| import argparse | ||
| import dataclasses | ||
| import sys | ||
|
|
||
| import gymnasium as gym | ||
| from isaaclab_experimental.mdp2 import mdp | ||
|
|
||
| from isaaclab.app import add_launcher_args, launch_simulation | ||
|
|
||
| import isaaclab_tasks # noqa: F401 | ||
| from isaaclab_tasks.utils import resolve_task_config, setup_preset_cli | ||
|
|
||
| parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) | ||
| parser.add_argument("--task", required=True, help="Name of an MDP2 task.") | ||
| parser.add_argument("--num_envs", type=int, default=None, help="Number of worlds; default: the task's.") | ||
| parser.add_argument("--num_states", type=int, default=None, help="States per world, for a FromTask source.") | ||
| parser.add_argument("--event", default="reset", help="Name of the reset_to_states event.") | ||
| parser.add_argument("--out", required=True, help="File to save the states to.") | ||
| add_launcher_args(parser) | ||
| parser.set_defaults(device=None) # let the task select the device | ||
| args_cli, hydra_args = setup_preset_cli(parser) | ||
| sys.argv = [sys.argv[0]] + hydra_args | ||
|
|
||
| env_cfg, _ = resolve_task_config(args_cli.task, "") | ||
| if args_cli.num_envs is not None: | ||
| env_cfg.scene.num_envs = args_cli.num_envs | ||
| params = env_cfg.task.events[args_cli.event].params | ||
| if args_cli.num_states is not None: | ||
| if not isinstance(params["source"], mdp.FromTask): | ||
| raise SystemExit(f"--num_states needs a FromTask source, but the event's source is {params['source']!r}.") | ||
| params["source"] = dataclasses.replace(params["source"], num_states=args_cli.num_states) | ||
| params.pop("record", None) # only the generated states | ||
|
|
||
| with launch_simulation(env_cfg, args_cli): | ||
| env = gym.make(args_cli.task, cfg=env_cfg) | ||
| reset_states = mdp.get_reset_states(env.unwrapped.state, f"events.{args_cli.event}") | ||
| reset_states.save(args_cli.out) | ||
| worlds = "all worlds, shared" if reset_states.shared else f"each of {reset_states.num_worlds} worlds" | ||
| print(f"Saved {reset_states.size} states for {worlds} to {args_cli.out}.") | ||
| env.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). | ||
| # All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| """View the reset states of an MDP2 task: browse them, roll its generator task, and play episodes from them. | ||
|
|
||
| The panel opens in each Viser or Newton viewer, for example:: | ||
|
|
||
| uv run --extra viser python scripts/tools/view_reset_states.py --task Isaac-Lift-KukaAllegro-MDP2 \\ | ||
| --num_envs 16 --viz viser physics=newton_mjwarp | ||
|
|
||
| then open the printed URL. ``--states`` shows saved reset states instead of generating new ones. | ||
| """ | ||
|
|
||
| import argparse | ||
| import sys | ||
|
|
||
| import gymnasium as gym | ||
| import torch | ||
| from isaaclab_experimental.envs import ResetStateViewer | ||
| from isaaclab_experimental.mdp2 import mdp | ||
|
|
||
| from isaaclab.app import add_launcher_args, launch_simulation | ||
|
|
||
| import isaaclab_tasks # noqa: F401 | ||
| from isaaclab_tasks.utils import resolve_task_config, setup_preset_cli | ||
|
|
||
| parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) | ||
| parser.add_argument("--task", required=True, help="Name of an MDP2 task.") | ||
| parser.add_argument("--num_envs", type=int, default=16, help="Number of worlds.") | ||
| parser.add_argument("--event", default="reset", help="Name of the reset_to_states event.") | ||
| parser.add_argument( | ||
| "--states", default=None, help="Reset states saved by ResetStates.save or generate_reset_states.py." | ||
| ) | ||
| parser.add_argument("--policy", choices=("zero", "random"), default="zero", help="Actions of played episodes.") | ||
| add_launcher_args(parser) | ||
| parser.set_defaults(device=None) # let the task select the device | ||
| args_cli, hydra_args = setup_preset_cli(parser) | ||
| sys.argv = [sys.argv[0]] + hydra_args | ||
|
|
||
| env_cfg, _ = resolve_task_config(args_cli.task, "") | ||
| env_cfg.scene.num_envs = args_cli.num_envs | ||
| if args_cli.states is not None: | ||
| env_cfg.task.events[args_cli.event].params["source"] = mdp.FromFile(args_cli.states) | ||
|
|
||
| with launch_simulation(env_cfg, args_cli): | ||
| env = gym.make(args_cli.task, cfg=env_cfg) | ||
| env.reset() | ||
| unwrapped = env.unwrapped | ||
| shape = (unwrapped.num_envs, unwrapped.mdp.action_dim) | ||
| policy = None | ||
| if args_cli.policy == "random": | ||
| policy = lambda observations: 2.0 * torch.rand(shape, device=unwrapped.device) - 1.0 # noqa: E731 | ||
| viewer = ResetStateViewer(env, args_cli.event, policy) | ||
| if not viewer.attach(): | ||
| print("No Viser or Newton viewer is open: pass --viz viser or --viz newton_gl.") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Warning · Style Consistency — Log the missing-viewer warning This user-facing warning uses |
||
| while unwrapped.sim.is_running(): | ||
| viewer.update() | ||
| env.close() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| * Fixed :func:`~isaaclab.utils.dict.class_to_dict` failing on a callable object without a ``__name__``, such as a | ||
| configured reset bank filler; it is now serialized as its fields, so ``params/env.yaml`` can be saved. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| * Added an optional ``rng`` argument to :meth:`~isaaclab.envs.reset.ResetStateSampler.reset` so that callers' | ||
| per-environment int32 seeds, such as MDP2's random streams, drive the draws. | ||
| * Added :meth:`~isaaclab.envs.reset.ResetStateBuffer.set_state`, the inverse of ``get_state``, to replace stored states | ||
| while running, and :meth:`~isaaclab.envs.reset.ResetStateSampler.forget` to clear the outcomes of replaced entries. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| * Changed a ``state_ids`` request of -1 in :meth:`~isaaclab.envs.reset.ResetStateSampler.reset` to draw from the | ||
| scores for that environment, so that one captured reset can replay some environments and sample the others. It | ||
| was an invalid request that left the environment's start unchanged. |
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Warning · Implementation — Exit without an attached viewer
When
attach()returns zero, the script reports the missing viewer but enters a render loop with no controls. Exit before the loop.