anhtld commited on
Commit
7ea49c1
·
verified ·
1 Parent(s): 68d6a09

Use selective ManiSkill tabletop registration for CTT rollout

Browse files
workspace/scripts/eval_ctt_generated_rollout.py CHANGED
@@ -2,12 +2,16 @@
2
  from __future__ import annotations
3
 
4
  import argparse
 
 
5
  import json
6
  import math
 
7
  import pickle
8
  import shutil
9
  import subprocess
10
  import sys
 
11
  from dataclasses import dataclass
12
  from pathlib import Path
13
  from typing import Any
@@ -155,7 +159,7 @@ def main(argv: list[str] | None = None) -> int:
155
  _append_log(log_path, "importing gymnasium/mani_skill")
156
  try:
157
  import gymnasium as gym
158
- import mani_skill # noqa: F401 - importing registers environments
159
  except ImportError as exc: # pragma: no cover - exercised in the Apptainer env
160
  raise ImportError(
161
  "CTT measured rollout requires gymnasium, mani_skill, numpy, and torch. "
@@ -954,6 +958,70 @@ def _uses_single_env_cpu_backend(sim_backend: Any) -> bool:
954
  return value in {"cpu", "physx_cpu"} or value.endswith("_cpu")
955
 
956
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
957
  def _validate_indexes(
958
  source_path: Path,
959
  source_index: dict[str, Any],
 
2
  from __future__ import annotations
3
 
4
  import argparse
5
+ import importlib
6
+ import importlib.machinery
7
  import json
8
  import math
9
+ import os
10
  import pickle
11
  import shutil
12
  import subprocess
13
  import sys
14
+ import types
15
  from dataclasses import dataclass
16
  from pathlib import Path
17
  from typing import Any
 
159
  _append_log(log_path, "importing gymnasium/mani_skill")
160
  try:
161
  import gymnasium as gym
162
+ _register_required_maniskill_envs(log_path)
163
  except ImportError as exc: # pragma: no cover - exercised in the Apptainer env
164
  raise ImportError(
165
  "CTT measured rollout requires gymnasium, mani_skill, numpy, and torch. "
 
958
  return value in {"cpu", "physx_cpu"} or value.endswith("_cpu")
959
 
960
 
961
+ def _register_required_maniskill_envs(log_path: Path | None = None) -> None:
962
+ """Register only the tabletop ManiSkill tasks used by the CIL diagnostic.
963
+
964
+ ManiSkill 3.0.1 imports all task families from its top-level package,
965
+ including digital-twin Bridge tasks that import cv2. On the current HPC
966
+ container that full import can hang before our five tabletop tasks are
967
+ registered. A lightweight package stub lets Python resolve ManiSkill
968
+ submodules without executing the top-level eager task import.
969
+ """
970
+
971
+ package = sys.modules.get("mani_skill")
972
+ if package is None:
973
+ spec = importlib.machinery.PathFinder.find_spec("mani_skill")
974
+ if spec is None or not spec.submodule_search_locations:
975
+ raise ImportError("Could not locate installed mani_skill package")
976
+ package_dir = Path(list(spec.submodule_search_locations)[0]).resolve()
977
+ package = types.ModuleType("mani_skill")
978
+ package.__file__ = str(package_dir / "__init__.py")
979
+ package.__path__ = [str(package_dir)]
980
+ package.__package__ = "mani_skill"
981
+ package.__version__ = "3.0.1"
982
+ package.PACKAGE_DIR = package_dir
983
+ package.PACKAGE_ASSET_DIR = package_dir / "assets"
984
+ asset_root = Path(
985
+ os.getenv("MS_ASSET_DIR", os.path.join(os.path.expanduser("~"), ".maniskill"))
986
+ )
987
+ package.ASSET_DIR = asset_root / "data"
988
+ package.DEMO_DIR = asset_root / "demos"
989
+ package.format_path = lambda p: p.format(
990
+ PACKAGE_DIR=package.PACKAGE_DIR,
991
+ PACKAGE_ASSET_DIR=package.PACKAGE_ASSET_DIR,
992
+ ASSET_DIR=package.ASSET_DIR,
993
+ )
994
+ sys.modules["mani_skill"] = package
995
+ _install_package_stub("mani_skill.envs", package_dir / "envs")
996
+ _install_package_stub("mani_skill.envs.tasks", package_dir / "envs" / "tasks")
997
+ _install_package_stub(
998
+ "mani_skill.envs.tasks.tabletop",
999
+ package_dir / "envs" / "tasks" / "tabletop",
1000
+ )
1001
+ package.logger = importlib.import_module("mani_skill.utils.logging_utils").logger
1002
+ _append_log(log_path, "installed lightweight mani_skill tabletop import stub")
1003
+
1004
+ modules = [
1005
+ "mani_skill.envs.tasks.tabletop.pick_cube",
1006
+ "mani_skill.envs.tasks.tabletop.pull_cube",
1007
+ "mani_skill.envs.tasks.tabletop.push_cube",
1008
+ "mani_skill.envs.tasks.tabletop.stack_cube",
1009
+ "mani_skill.envs.tasks.tabletop.lift_peg_upright",
1010
+ ]
1011
+ for module_name in modules:
1012
+ importlib.import_module(module_name)
1013
+ _append_log(log_path, "registered tabletop ManiSkill tasks selectively")
1014
+
1015
+
1016
+ def _install_package_stub(name: str, path: Path) -> None:
1017
+ if name in sys.modules:
1018
+ return
1019
+ module = types.ModuleType(name)
1020
+ module.__path__ = [str(path)]
1021
+ module.__package__ = name
1022
+ sys.modules[name] = module
1023
+
1024
+
1025
  def _validate_indexes(
1026
  source_path: Path,
1027
  source_index: dict[str, Any],