-
Notifications
You must be signed in to change notification settings - Fork 9
Refactor env launcher scripts #126
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |
| import numpy as np | ||
| import torch | ||
| import dexsim | ||
| import argparse | ||
| import gymnasium | ||
|
|
||
| from typing import Dict, Any, List, Tuple, Union, Sequence | ||
| from gymnasium import spaces | ||
|
|
@@ -374,8 +376,8 @@ def config_to_cfg(config: dict, manager_modules: list = None) -> "EmbodiedEnvCfg | |
| ArticulationCfg, | ||
| LightCfg, | ||
| ) | ||
| from embodichain.lab.gym.envs import EmbodiedEnvCfg | ||
| from embodichain.lab.sim.sensors import SensorCfg | ||
| from embodichain.lab.gym.envs import EmbodiedEnvCfg | ||
| from embodichain.lab.gym.envs.managers import ( | ||
| SceneEntityCfg, | ||
| EventCfg, | ||
|
|
@@ -701,3 +703,115 @@ def assign_data_to_dict( | |
|
|
||
| last_key = keys[-1] | ||
| current_data[last_key] = value | ||
|
|
||
|
|
||
| def add_env_launcher_args_to_parser(parser: argparse.ArgumentParser) -> None: | ||
| """Add common environment launcher arguments to an existing argparse parser. | ||
|
|
||
| This function adds the following arguments to the provided parser: | ||
| - --num_envs: Number of environments to run in parallel (default: 1) | ||
| - --device: Device to run the environment on (default: 'cpu') | ||
| - --headless: Whether to perform the simulation in headless mode (default: False) | ||
| - --enable_rt: Whether to use RTX rendering backend for the simulation (default: False) | ||
| - --gpu_id: The GPU ID to use for the simulation (default: 0) | ||
| - --filter_visual_rand: Whether to filter out visual randomization (default: False) | ||
| - --gym_config: Path to gym config file (default: '') | ||
| - --action_config: Path to action config file (default: None) | ||
| - --preview: Whether to preview the environment after launching (default: False) | ||
|
|
||
| Note: | ||
| 1. In preview mode, the environment will be launched and keep running in a loop for user interaction. | ||
|
|
||
| Args: | ||
| parser (argparse.ArgumentParser): The parser to which arguments will be added. | ||
| """ | ||
| parser.add_argument( | ||
| "--num_envs", | ||
| help="The number of environments to run in parallel.", | ||
| default=1, | ||
| type=int, | ||
| ) | ||
| parser.add_argument( | ||
| "--device", | ||
| type=str, | ||
| default="cpu", | ||
| help="Device to run the environment on, e.g., 'cpu' or 'cuda'.", | ||
| ) | ||
| parser.add_argument( | ||
| "--headless", | ||
| help="Whether to perform the simulation in headless mode.", | ||
| default=False, | ||
| action="store_true", | ||
| ) | ||
| parser.add_argument( | ||
| "--enable_rt", | ||
| help="Whether to use RTX rendering backend for the simulation.", | ||
| default=False, | ||
| action="store_true", | ||
| ) | ||
| parser.add_argument( | ||
| "--gpu_id", | ||
| help="The GPU ID to use for the simulation.", | ||
| default=0, | ||
| type=int, | ||
| ) | ||
| parser.add_argument( | ||
| "--filter_visual_rand", | ||
| help="Whether to filter out visual randomization.", | ||
| default=False, | ||
| action="store_true", | ||
| ) | ||
| parser.add_argument( | ||
| "--gym_config", | ||
| type=str, | ||
| help="Path to gym config file.", | ||
| default="", | ||
| required=True, | ||
| ) | ||
| parser.add_argument( | ||
| "--action_config", type=str, help="Path to action config file.", default=None | ||
| ) | ||
| parser.add_argument( | ||
| "--preview", | ||
| help="Whether to preview the environment after launching.", | ||
| default=False, | ||
| action="store_true", | ||
yuecideng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
|
|
||
| def build_env_cfg_from_args( | ||
| args: argparse.Namespace, | ||
| ) -> tuple["EmbodiedEnvCfg", dict, dict]: | ||
| """Build environment configuration from command-line arguments. | ||
|
|
||
|
Comment on lines
+782
to
+786
|
||
| Args: | ||
| args (argparse.Namespace): The parsed command-line arguments. | ||
|
|
||
| Returns: | ||
| tuple[EmbodiedEnvCfg, dict, dict]: A tuple containing the environment configuration object, | ||
| the original gym configuration dictionary, and the action configuration dictionary. | ||
| """ | ||
| from embodichain.utils.utility import load_json | ||
| from embodichain.lab.gym.envs import EmbodiedEnvCfg | ||
| from embodichain.lab.sim import SimulationManagerCfg | ||
|
|
||
| gym_config = load_json(args.gym_config) | ||
| cfg: EmbodiedEnvCfg = config_to_cfg( | ||
| gym_config, manager_modules=DEFAULT_MANAGER_MODULES | ||
| ) | ||
| cfg.filter_visual_rand = args.filter_visual_rand | ||
|
|
||
| action_config = {} | ||
| if args.action_config is not None: | ||
| action_config = load_json(args.action_config) | ||
| action_config["action_config"] = action_config | ||
|
|
||
| cfg.num_envs = args.num_envs | ||
| cfg.sim_cfg = SimulationManagerCfg( | ||
| headless=args.headless, | ||
| sim_device=args.device, | ||
| enable_rt=args.enable_rt, | ||
| gpu_id=args.gpu_id, | ||
| ) | ||
|
|
||
| return cfg, gym_config, action_config | ||
This file was deleted.
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.
import gymnasiumappears unused in this module (you already importspacesfromgymnasium). Consider removing the unused import to avoid lint issues.