Using yaml mapping
Browse files
env.py
CHANGED
|
@@ -24,21 +24,23 @@ import logging
|
|
| 24 |
import os
|
| 25 |
import sys
|
| 26 |
from pathlib import Path
|
|
|
|
| 27 |
|
| 28 |
import gymnasium as gym
|
| 29 |
|
|
|
|
| 30 |
from lerobot.envs.configs import EnvConfig
|
| 31 |
|
| 32 |
# Hub constants for downloading additional files
|
| 33 |
HUB_REPO_ID = "nvidia/isaaclab-arena-envs"
|
| 34 |
-
|
| 35 |
|
|
|
|
|
|
|
| 36 |
|
| 37 |
def _download_and_import(filename: str):
|
| 38 |
"""Download file from Hub and import as module."""
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
local_path = hf_hub_download(repo_id=HUB_REPO_ID, filename=filename)
|
| 42 |
module_dir = os.path.dirname(local_path)
|
| 43 |
|
| 44 |
# Add directory to sys.path so modules can import each other
|
|
@@ -129,33 +131,15 @@ def validate_config(
|
|
| 129 |
logging.info(f"Validated: state_keys={state_keys}, camera_keys={camera_keys}")
|
| 130 |
|
| 131 |
|
| 132 |
-
# Module path for environment class resolution
|
| 133 |
-
ISAACLAB_ARENA_ENV_MODULE = os.environ.get("ISAACLAB_ARENA_ENV_MODULE", "isaaclab_arena.examples.example_environments")
|
| 134 |
-
|
| 135 |
-
# Environment aliases for common configurations
|
| 136 |
-
ENVIRONMENT_ALIASES: dict[str, str] = {
|
| 137 |
-
"gr1_microwave": (
|
| 138 |
-
f"{ISAACLAB_ARENA_ENV_MODULE}.gr1_open_microwave_environment.Gr1OpenMicrowaveEnvironment"
|
| 139 |
-
),
|
| 140 |
-
"galileo_pnp": (
|
| 141 |
-
f"{ISAACLAB_ARENA_ENV_MODULE}.galileo_pick_and_place_environment.GalileoPickAndPlaceEnvironment"
|
| 142 |
-
),
|
| 143 |
-
"g1_locomanip_pnp": (
|
| 144 |
-
f"{ISAACLAB_ARENA_ENV_MODULE}"
|
| 145 |
-
".galileo_g1_locomanip_pick_and_place_environment"
|
| 146 |
-
".GalileoG1LocomanipPickAndPlaceEnvironment"
|
| 147 |
-
),
|
| 148 |
-
"kitchen_pnp": (
|
| 149 |
-
f"{ISAACLAB_ARENA_ENV_MODULE}.kitchen_pick_and_place_environment.KitchenPickAndPlaceEnvironment"
|
| 150 |
-
),
|
| 151 |
-
"press_button": f"{ISAACLAB_ARENA_ENV_MODULE}.press_button_environment.PressButtonEnvironment",
|
| 152 |
-
}
|
| 153 |
-
|
| 154 |
-
|
| 155 |
def resolve_environment_alias(environment: str) -> str:
|
| 156 |
-
|
| 157 |
-
|
|
|
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
def _create_isaaclab_env(config: dict, n_envs: int) -> dict[str, dict[int, gym.vector.VectorEnv]]:
|
| 161 |
"""Create IsaacLab Arena environment from configuration.
|
|
|
|
| 24 |
import os
|
| 25 |
import sys
|
| 26 |
from pathlib import Path
|
| 27 |
+
import yaml
|
| 28 |
|
| 29 |
import gymnasium as gym
|
| 30 |
|
| 31 |
+
from huggingface_hub import hf_hub_download
|
| 32 |
from lerobot.envs.configs import EnvConfig
|
| 33 |
|
| 34 |
# Hub constants for downloading additional files
|
| 35 |
HUB_REPO_ID = "nvidia/isaaclab-arena-envs"
|
| 36 |
+
EXAMPLE_ENVS = "example_envs.yaml"
|
| 37 |
|
| 38 |
+
def _download_hub_file(filename: str):
|
| 39 |
+
return hf_hub_download(repo_id=HUB_REPO_ID, filename=filename)
|
| 40 |
|
| 41 |
def _download_and_import(filename: str):
|
| 42 |
"""Download file from Hub and import as module."""
|
| 43 |
+
local_path = _download_hub_file(filename)
|
|
|
|
|
|
|
| 44 |
module_dir = os.path.dirname(local_path)
|
| 45 |
|
| 46 |
# Add directory to sys.path so modules can import each other
|
|
|
|
| 131 |
logging.info(f"Validated: state_keys={state_keys}, camera_keys={camera_keys}")
|
| 132 |
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
def resolve_environment_alias(environment: str) -> str:
|
| 135 |
+
envs_mapping = _download_hub_file(EXAMPLE_ENVS)
|
| 136 |
+
with open(envs_mapping, "r") as f:
|
| 137 |
+
envs_mapping = yaml.safe_load(f)
|
| 138 |
|
| 139 |
+
module = (
|
| 140 |
+
f"{envs_mapping['repo']['base_module']}.{envs_mapping['repo']['envs'][environment]}"
|
| 141 |
+
)
|
| 142 |
+
return module
|
| 143 |
|
| 144 |
def _create_isaaclab_env(config: dict, n_envs: int) -> dict[str, dict[int, gym.vector.VectorEnv]]:
|
| 145 |
"""Create IsaacLab Arena environment from configuration.
|