uooon's picture
Initial release of LIBERO-GeoMotion
78a3b51 verified
Raw History Blame Contribute Delete
2.64 kB
"""Resource and renderer setup, before LIBERO or OpenGL is imported."""
import hashlib
import json
import os
from pathlib import Path
import sys
import tempfile
ROOT = Path(__file__).resolve().parent.parent
RESOURCES = Path(__file__).resolve().parent / "resources"
def configure(*, renderer=None, config_dir=None):
selected = renderer or os.environ.get("MUJOCO_GL", "osmesa")
if selected not in ("osmesa", "egl"):
raise ValueError("renderer must be osmesa or egl")
if "mujoco" in sys.modules and os.environ.get("MUJOCO_GL") != selected:
raise RuntimeError("renderer is already initialized; use a fresh process")
os.environ["MUJOCO_GL"] = os.environ["PYOPENGL_PLATFORM"] = selected
for name in ("OMP_NUM_THREADS", "OPENBLAS_NUM_THREADS", "MKL_NUM_THREADS"):
if not os.environ.get(name, '').isdigit() or int(os.environ[name]) < 1:
os.environ[name] = "1"
base = ROOT / "libero/libero"
extension = ROOT / "libero_rotation_planning"
paths = dict(benchmark_root=str(base), assets=str(base / "assets"),
bddl_files=str(extension / "bddl_files"),
init_states=str(extension / "init_files"),
datasets=str(RESOURCES / "expert_reference/dataset"))
cache = Path(os.environ.get("XDG_CACHE_HOME", Path.home() / ".cache"))
default = cache / "libero-geomotion" / hashlib.sha256(str(ROOT).encode()).hexdigest()[:16]
target = Path(config_dir or os.environ.get("LIBERO_CONFIG_PATH", default)).resolve()
existing_config = getattr(sys.modules.get("libero.libero"), "config_file", None)
if existing_config is not None:
existing = Path(existing_config).resolve()
if existing != target / "config.yaml":
raise RuntimeError("LIBERO config already initialized; use a fresh process")
target.mkdir(parents=True, exist_ok=True)
contents = json.dumps(paths, indent=2) + "\n"
path = target / "config.yaml"
if not path.exists() or path.read_text() != contents:
with tempfile.NamedTemporaryFile(mode="w", dir=target, delete=False) as stream:
stream.write(contents)
temporary = stream.name
os.replace(temporary, path)
os.environ["LIBERO_CONFIG_PATH"] = str(target)
return paths
def reference_manifest():
return json.loads((RESOURCES / "expert_reference/reference_manifest.json").read_text())
def evaluation_protocol():
return json.loads((RESOURCES / "evaluation_protocol.json").read_text())
def task_manifest():
path = ROOT / "libero_rotation_planning/benchmark/task_manifest.json"
return json.loads(path.read_text())