envs.env

base_env

Please Reference ding/ding/envs/env/base_env.py for usage

BaseEnv

class ding.envs.env.base_env.BaseEnv(cfg: dict)[source]
Overview:

basic environment class, extended from gym.Env

Interface:

__init__, reset, close, step, info, create_collector_env_cfg, create_evaluator_env_cfg, enable_save_replay

abstract __init__(cfg: dict) None[source]
Overview:

Lazy init, only parameters will be initialized in self.__init__()

abstract close() None[source]
Overview:

Environments will automatically close() themselves when garbage collected or exits. Abstract Method from gym.Env.

static create_collector_env_cfg(cfg: dict) List[dict][source]
Overview:

Return a list of all of the environment from input config.

Arguments:
  • cfg (Dict) Env config, same config where self.__init__() takes arguments from

Returns:
  • List of cfg including all of the collector env’s config

static create_evaluator_env_cfg(cfg: dict) List[dict][source]
Overview:

Return a list of all of the environment from input config.

Arguments:
  • cfg (Dict) Env config, same config where self.__init__() takes arguments from

Returns:
  • List of cfg including all of the evaluator env’s config

enable_save_replay(replay_path: str) None[source]
Overview:

Save replay file in the given path, need to be self-implemented.

Arguments:
  • replay_path(str): Storage path.

abstract info() ding.envs.env.base_env.BaseEnvInfo[source]
Overview:

Show space in code and return namedlist.

Returns:
  • info (BaseEnvInfo)

abstract reset() Any[source]
Overview:

Resets the env to an initial state and returns an initial observation. Abstract Method from gym.Env.

abstract step(action: Any) BaseEnv.timestep[source]
Overview:

Run one timestep of the environment’s dynamics. Abstract Method from gym.Env.

Arguments:
  • action (Any): the action input to step with

Returns:
  • timestep (BaseEnv.timestep)

get_vec_env_setting

ding.envs.env.base_env.get_vec_env_setting(cfg: dict) Tuple[type, List[dict], List[dict]][source]
Overview:

Get vectorized env setting(env_fn, collector_env_cfg, evaluator_env_cfg)

Arguments:
  • cfg (Dict) Env config, same config where self.__init__() takes arguments from

Returns:
  • env_fn (type): Callable object, call it with proper arguments and then get a new env instance.

  • collector_env_cfg (List[dict]): A list contains the config of collecting data envs.

  • evaluator_env_cfg (List[dict]): A list contains the config of evaluation envs.

Note

elements(env config) in collector_env_cfg/evaluator_env_cfg can be different, such as server ip and port.

get_env_cls

ding.envs.env.base_env.get_env_cls(cfg: easydict.EasyDict) type[source]
Overview:

Get the env class by correspondng module of cfg and return the callable class

Arguments:
  • cfg (Dict) Env config, same config where self.__init__() takes arguments from

Returns:
  • Env module as the corresponding callable class