# hub.domain.gym.compatibility

A compatibility wrapper converting an old-style environment into a valid environment.

Domain specification

Domain

# convert_to_terminated_truncated_step_api

convert_to_terminated_truncated_step_api(
  step_returns: typing.Union[typing.Tuple[typing.Union[~ObsType, numpy.ndarray], typing.Union[typing.SupportsFloat, numpy.ndarray], typing.Union[bool, numpy.ndarray], typing.Union[dict, list]], typing.Tuple[typing.Union[~ObsType, numpy.ndarray], typing.Union[typing.SupportsFloat, numpy.ndarray], typing.Union[bool, numpy.ndarray], typing.Union[bool, numpy.ndarray], typing.Union[dict, list]]],
is_vector_env = False
) -> typing.Tuple[typing.Union[~ObsType, numpy.ndarray], typing.Union[typing.SupportsFloat, numpy.ndarray], typing.Union[bool, numpy.ndarray], typing.Union[bool, numpy.ndarray], typing.Union[dict, list]]

Function to transform step returns to new step API irrespective of input API.

Args: step_returns (tuple): Items returned by step(). Can be (obs, rew, done, info) or (obs, rew, terminated, truncated, info) is_vector_env (bool): Whether the step_returns are from a vector environment

# LegacyEnv

A protocol for environments using the old step API.

# close LegacyEnv

close(
  self
)

Close the environment.

# render LegacyEnv

render(
  self,
mode: typing.Optional[str] = human
) -> typing.Any

Render the environment.

# reset LegacyEnv

reset(
  self
) -> typing.Any

Reset the environment and return the initial observation.

# seed LegacyEnv

seed(
  self,
seed: typing.Optional[int] = None
)

Set the seed for this env's random number generator(s).

# step LegacyEnv

step(
  self,
action: typing.Any
) -> typing.Tuple[typing.Any, float, bool, typing.Dict]

Run one timestep of the environment's dynamics.

# EnvCompatibility

A wrapper which can transform an environment from the old API to the new API.

Old step API refers to step() method returning (observation, reward, done, info), and reset() only retuning the observation. New step API refers to step() method returning (observation, reward, terminated, truncated, info) and reset() returning (observation, info). (Refer to docs for details on the API change)

Known limitations:

  • Environments that use self.np_random might not work as expected.

# Constructor EnvCompatibility

EnvCompatibility(
  old_env: ,
render_mode: typing.Optional[str] = None
)

A wrapper which converts old-style envs to valid modern envs.

Some information may be lost in the conversion, so we recommend updating your environment.

Args: old_env (LegacyEnv): the env to wrap, implemented with the old API render_mode (str): the render mode to use when rendering the environment, passed automatically to env.render

# close Env

close(
  self
)

Closes the environment.

# get_wrapper_attr Env

get_wrapper_attr(
  self,
name: str
) -> Any

Gets the attribute name from the environment.

# has_wrapper_attr Env

has_wrapper_attr(
  self,
name: str
) -> bool

Checks if the attribute name exists in the environment.

# render Env

render(
  self
) -> typing.Any

Renders the environment.

Returns: The rendering of the environment, depending on the render mode

# reset Env

reset(
  self,
seed: typing.Optional[int] = None,
options: typing.Optional[dict] = None
) -> typing.Tuple[~ObsType, dict]

Resets the environment.

Args: seed: the seed to reset the environment with options: the options to reset the environment with

Returns: (observation, info)

# set_wrapper_attr Env

set_wrapper_attr(
  self,
name: str,
value: Any,
force: bool = True
) -> bool

Sets the attribute name on the environment with value, see Wrapper.set_wrapper_attr for more info.

# step Env

step(
  self,
action: typing.Any
) -> typing.Tuple[typing.Any, float, bool, bool, typing.Dict]

Steps through the environment.

Args: action: action to step through the environment with

Returns: (observation, reward, terminated, truncated, info)