Update env.py
Browse files
env.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
|
| 2 |
from pathlib import Path
|
| 3 |
import subprocess
|
|
@@ -6,7 +7,10 @@ import gymnasium as gym
|
|
| 6 |
from gymnasium import spaces
|
| 7 |
import numpy as np
|
| 8 |
from huggingface_hub import snapshot_download
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def make_env(
|
| 12 |
n_envs=1,
|
|
@@ -17,11 +21,10 @@ def make_env(
|
|
| 17 |
**kwargs,
|
| 18 |
):
|
| 19 |
"""
|
| 20 |
-
|
| 21 |
then return a dummy gym env.
|
| 22 |
"""
|
| 23 |
|
| 24 |
-
# path to this repo's run_sim.py
|
| 25 |
repo_dir = Path(__file__).parent
|
| 26 |
run_sim = repo_dir / "run_sim.py"
|
| 27 |
|
|
@@ -30,16 +33,11 @@ def make_env(
|
|
| 30 |
print("path:", run_sim)
|
| 31 |
print("=" * 60)
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
proc = subprocess.Popen(
|
| 35 |
-
[sys.executable, str(run_sim)],
|
| 36 |
-
stdout=subprocess.PIPE,
|
| 37 |
-
stderr=subprocess.STDOUT,
|
| 38 |
-
)
|
| 39 |
|
| 40 |
print(f"simulator started as pid={proc.pid}")
|
| 41 |
|
| 42 |
-
# minimal env for envhub
|
| 43 |
class DummyEnv(gym.Env):
|
| 44 |
metadata = {"render_modes": []}
|
| 45 |
|
|
@@ -56,11 +54,13 @@ def make_env(
|
|
| 56 |
return np.zeros(1, dtype=np.float32), 0.0, False, False, {}
|
| 57 |
|
| 58 |
def close(self):
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
| 62 |
|
| 63 |
def run(self):
|
|
|
|
| 64 |
pass
|
| 65 |
|
| 66 |
return DummyEnv(proc)
|
|
|
|
| 1 |
+
# env.py
|
| 2 |
|
| 3 |
from pathlib import Path
|
| 4 |
import subprocess
|
|
|
|
| 7 |
from gymnasium import spaces
|
| 8 |
import numpy as np
|
| 9 |
from huggingface_hub import snapshot_download
|
| 10 |
+
|
| 11 |
+
# ensure the repo snapshot exists (no-op if already cached)
|
| 12 |
+
snapshot_download(repo_id="lerobot/unitree-g1-mujoco", revision=None, cache_dir=None)
|
| 13 |
+
|
| 14 |
|
| 15 |
def make_env(
|
| 16 |
n_envs=1,
|
|
|
|
| 21 |
**kwargs,
|
| 22 |
):
|
| 23 |
"""
|
| 24 |
+
launch run_sim.py as a subprocess (non-blocking),
|
| 25 |
then return a dummy gym env.
|
| 26 |
"""
|
| 27 |
|
|
|
|
| 28 |
repo_dir = Path(__file__).parent
|
| 29 |
run_sim = repo_dir / "run_sim.py"
|
| 30 |
|
|
|
|
| 33 |
print("path:", run_sim)
|
| 34 |
print("=" * 60)
|
| 35 |
|
| 36 |
+
# start simulator as independent process, inherit stdout/stderr
|
| 37 |
+
proc = subprocess.Popen([sys.executable, str(run_sim)])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
print(f"simulator started as pid={proc.pid}")
|
| 40 |
|
|
|
|
| 41 |
class DummyEnv(gym.Env):
|
| 42 |
metadata = {"render_modes": []}
|
| 43 |
|
|
|
|
| 54 |
return np.zeros(1, dtype=np.float32), 0.0, False, False, {}
|
| 55 |
|
| 56 |
def close(self):
|
| 57 |
+
# important: do NOT kill the simulator here
|
| 58 |
+
# envhub / launch_env will call close() immediately;
|
| 59 |
+
# we want run_sim.py to keep running.
|
| 60 |
+
pass
|
| 61 |
|
| 62 |
def run(self):
|
| 63 |
+
# kept for api symmetry, but unused when wrapped in SyncVectorEnv
|
| 64 |
pass
|
| 65 |
|
| 66 |
return DummyEnv(proc)
|