| | import gymnasium as gym |
| | from gymnasium.vector import SyncVectorEnv |
| |
|
| |
|
| | def make_env( |
| | n_envs=1, |
| | use_async_envs=False, |
| | config_path=None, |
| | config_overrides=None, |
| | **kwargs, |
| | ): |
| | """ |
| | Create vectorized CartPole environments with configurable options. |
| | |
| | Args: |
| | n_envs: Number of parallel environments |
| | use_async_envs: Whether to use AsyncVectorEnv or SyncVectorEnv |
| | config_path: Optional path to a config file (for demonstration) |
| | config_overrides: Optional dict of config overrides |
| | **kwargs: Additional configuration options |
| | |
| | Returns: |
| | dict mapping suite name to task environments |
| | """ |
| | config = {} |
| | if config_overrides: |
| | config.update(config_overrides) |
| | config.update(kwargs) |
| |
|
| | stored_config = { |
| | "config_path": config_path, |
| | "config_overrides": config_overrides, |
| | "extra_kwargs": kwargs, |
| | } |
| |
|
| | def _mk(): |
| | env = gym.make("CartPole-v1") |
| | |
| | env.hub_config = stored_config |
| | return env |
| |
|
| | Vec = gym.vector.AsyncVectorEnv if use_async_envs else SyncVectorEnv |
| | vec_env = Vec([_mk for _ in range(n_envs)]) |
| |
|
| | vec_env.hub_config = stored_config |
| |
|
| | return {"cartpole_suite": {0: vec_env}} |
| |
|