nepyope commited on
Commit
2e74e51
·
verified ·
1 Parent(s): 4481348

Update env.py

Browse files
Files changed (1) hide show
  1. env.py +13 -24
env.py CHANGED
@@ -1,5 +1,3 @@
1
- # env.py
2
-
3
  from pathlib import Path
4
  import subprocess
5
  import sys
@@ -8,23 +6,12 @@ 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,
17
- use_async_envs: bool = False,
18
- publish_images=True,
19
- camera_port=5555,
20
- cameras=None,
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,9 +20,8 @@ def make_env(
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):
@@ -54,13 +40,16 @@ def make_env(
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)
 
 
 
1
  from pathlib import Path
2
  import subprocess
3
  import sys
 
6
  import numpy as np
7
  from huggingface_hub import snapshot_download
8
 
9
+ snapshot_download("lerobot/unitree-g1-mujoco")
 
10
 
11
 
12
+ def make_env(n_envs=1, use_async_envs=False, **kwargs):
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ # define run_sim FIRST
15
  repo_dir = Path(__file__).parent
16
  run_sim = repo_dir / "run_sim.py"
17
 
 
20
  print("path:", run_sim)
21
  print("=" * 60)
22
 
23
+ # now you can launch it
24
  proc = subprocess.Popen([sys.executable, str(run_sim)])
 
25
  print(f"simulator started as pid={proc.pid}")
26
 
27
  class DummyEnv(gym.Env):
 
40
  return np.zeros(1, dtype=np.float32), 0.0, False, False, {}
41
 
42
  def close(self):
 
 
 
43
  pass
44
 
45
+ def kill_sim(self):
46
+ if self.process.poll() is None:
47
+ print("killing simulator subprocess...")
48
+ self.process.terminate()
49
+ try:
50
+ self.process.wait(timeout=2)
51
+ except subprocess.TimeoutExpired:
52
+ print("force killing simulator subprocess...")
53
+ self.process.kill()
54
 
55
  return DummyEnv(proc)