Skip to content

Commit 9b3a2c8

Browse files
committed
add imitation learning
1 parent d4a35a1 commit 9b3a2c8

22 files changed

+4421
-14
lines changed

scripts/environments/list_envs.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright (c) 2022-2025, The Isaac Lab Project Developers.
2+
# All rights reserved.
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
6+
"""
7+
Script to print all the available environments in Isaac Lab.
8+
9+
The script iterates over all registered environments and stores the details in a table.
10+
It prints the name of the environment, the entry point and the config file.
11+
12+
All the environments are registered in the `isaaclab_tasks` extension. They start
13+
with `Isaac` in their name.
14+
"""
15+
16+
"""Launch Isaac Sim Simulator first."""
17+
18+
from isaaclab.app import AppLauncher
19+
20+
# launch omniverse app
21+
app_launcher = AppLauncher(headless=True)
22+
simulation_app = app_launcher.app
23+
24+
25+
"""Rest everything follows."""
26+
27+
import gymnasium as gym
28+
from prettytable import PrettyTable
29+
30+
import isaaclab_tasks # noqa: F401
31+
32+
33+
def main():
34+
"""Print all environments registered in `isaaclab_tasks` extension."""
35+
# print all the available environments
36+
table = PrettyTable(["S. No.", "Task Name", "Entry Point", "Config"])
37+
table.title = "Available Environments in Isaac Lab"
38+
# set alignment of table columns
39+
table.align["Task Name"] = "l"
40+
table.align["Entry Point"] = "l"
41+
table.align["Config"] = "l"
42+
43+
# count of environments
44+
index = 0
45+
# acquire all Isaac environments names
46+
for task_spec in gym.registry.values():
47+
if "Isaac" in task_spec.id:
48+
# add details to table
49+
table.add_row([index + 1, task_spec.id, task_spec.entry_point, task_spec.kwargs["env_cfg_entry_point"]])
50+
# increment count
51+
index += 1
52+
53+
print(table)
54+
55+
56+
if __name__ == "__main__":
57+
try:
58+
# run the main function
59+
main()
60+
except Exception as e:
61+
raise e
62+
finally:
63+
# close the app
64+
simulation_app.close()

scripts/environments/random_agent.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright (c) 2022-2025, The Isaac Lab Project Developers.
2+
# All rights reserved.
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
6+
"""Script to an environment with random action agent."""
7+
8+
"""Launch Isaac Sim Simulator first."""
9+
10+
import argparse
11+
12+
from isaaclab.app import AppLauncher
13+
14+
# add argparse arguments
15+
parser = argparse.ArgumentParser(description="Random agent for Isaac Lab environments.")
16+
parser.add_argument(
17+
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
18+
)
19+
parser.add_argument("--num_envs", type=int, default=None, help="Number of environments to simulate.")
20+
parser.add_argument("--task", type=str, default=None, help="Name of the task.")
21+
# append AppLauncher cli args
22+
AppLauncher.add_app_launcher_args(parser)
23+
# parse the arguments
24+
args_cli = parser.parse_args()
25+
26+
# launch omniverse app
27+
app_launcher = AppLauncher(args_cli)
28+
simulation_app = app_launcher.app
29+
30+
"""Rest everything follows."""
31+
32+
import gymnasium as gym
33+
import torch
34+
35+
import isaaclab_tasks # noqa: F401
36+
from isaaclab_tasks.utils import parse_env_cfg
37+
38+
39+
def main():
40+
"""Random actions agent with Isaac Lab environment."""
41+
# create environment configuration
42+
env_cfg = parse_env_cfg(
43+
args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
44+
)
45+
# create environment
46+
env = gym.make(args_cli.task, cfg=env_cfg)
47+
48+
# print info (this is vectorized environment)
49+
print(f"[INFO]: Gym observation space: {env.observation_space}")
50+
print(f"[INFO]: Gym action space: {env.action_space}")
51+
# reset environment
52+
env.reset()
53+
# simulate environment
54+
while simulation_app.is_running():
55+
# run everything in inference mode
56+
with torch.inference_mode():
57+
# sample actions from -1 to 1
58+
actions = 2 * torch.rand(env.action_space.shape, device=env.unwrapped.device) - 1
59+
# apply actions
60+
env.step(actions)
61+
62+
# close the simulator
63+
env.close()
64+
65+
66+
if __name__ == "__main__":
67+
# run the main function
68+
main()
69+
# close sim app
70+
simulation_app.close()

0 commit comments

Comments
 (0)