jadechoghari commited on
Commit
0cee4c9
·
verified ·
1 Parent(s): aab1503

Create env.py

Browse files
Files changed (1) hide show
  1. env.py +47 -0
env.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gymnasium as gym
2
+ from gymnasium.vector import SyncVectorEnv
3
+
4
+
5
+ def make_env(
6
+ n_envs=1,
7
+ use_async_envs=False,
8
+ config_path=None,
9
+ config_overrides=None,
10
+ **kwargs,
11
+ ):
12
+ """
13
+ Create vectorized CartPole environments with configurable options.
14
+
15
+ Args:
16
+ n_envs: Number of parallel environments
17
+ use_async_envs: Whether to use AsyncVectorEnv or SyncVectorEnv
18
+ config_path: Optional path to a config file (for demonstration)
19
+ config_overrides: Optional dict of config overrides
20
+ **kwargs: Additional configuration options
21
+
22
+ Returns:
23
+ dict mapping suite name to task environments
24
+ """
25
+ config = {}
26
+ if config_overrides:
27
+ config.update(config_overrides)
28
+ config.update(kwargs)
29
+
30
+ stored_config = {
31
+ "config_path": config_path,
32
+ "config_overrides": config_overrides,
33
+ "extra_kwargs": kwargs,
34
+ }
35
+
36
+ def _mk():
37
+ env = gym.make("CartPole-v1")
38
+ # Attach config to env for test verification
39
+ env.hub_config = stored_config
40
+ return env
41
+
42
+ Vec = gym.vector.AsyncVectorEnv if use_async_envs else SyncVectorEnv
43
+ vec_env = Vec([_mk for _ in range(n_envs)])
44
+
45
+ vec_env.hub_config = stored_config
46
+
47
+ return {"cartpole_suite": {0: vec_env}}