Check if the action and observation spaces for `env` are multidimensional or ``Tuple`` spaces. Notes ----- A multidimensional space is any space whose actions / observations have more than one element in them. This includes ``Tuple`` spaces, but also includes single act
(env)
| 255 | |
| 256 | |
| 257 | def is_multidimensional(env): |
| 258 | """ |
| 259 | Check if the action and observation spaces for `env` are multidimensional |
| 260 | or ``Tuple`` spaces. |
| 261 | |
| 262 | Notes |
| 263 | ----- |
| 264 | A multidimensional space is any space whose actions / observations have |
| 265 | more than one element in them. This includes ``Tuple`` spaces, but also |
| 266 | includes single action/observation spaces with several dimensions. |
| 267 | |
| 268 | Parameters |
| 269 | ---------- |
| 270 | env : ``gym.wrappers`` or ``gym.envs`` instance |
| 271 | The environment to evaluate. |
| 272 | |
| 273 | Returns |
| 274 | ------- |
| 275 | md_action : bool |
| 276 | Whether the `env`'s action space is multidimensional. |
| 277 | md_obs : bool |
| 278 | Whether the `env`'s observation space is multidimensional. |
| 279 | tuple_action : bool |
| 280 | Whether the `env`'s action space is a ``Tuple`` instance. |
| 281 | tuple_obs : bool |
| 282 | Whether the `env`'s observation space is a ``Tuple`` instance. |
| 283 | """ |
| 284 | md_action, md_obs = True, True |
| 285 | tuple_action, tuple_obs = is_tuple(env) |
| 286 | if not tuple_action: |
| 287 | act = env.action_space.sample() |
| 288 | md_action = isinstance(act, (list, tuple, np.ndarray)) and len(act) > 1 |
| 289 | |
| 290 | if not tuple_obs: |
| 291 | OS = env.observation_space |
| 292 | obs = OS.low if "low" in dir(OS) else OS.sample() # sample causes problems |
| 293 | md_obs = isinstance(obs, (list, tuple, np.ndarray)) and len(obs) > 1 |
| 294 | return md_action, md_obs, tuple_action, tuple_obs |
| 295 | |
| 296 | |
| 297 | def is_continuous(env, tuple_action, tuple_obs): |