ding.envs.env.base_env¶
ding.envs.env.base_env
¶
BaseEnv
¶
Bases: Env, ABC
Overview
Basic environment class, extended from gym.Env
Interface:
__init__, reset, close, step, random_action, create_collector_env_cfg, create_evaluator_env_cfg, enable_save_replay
__init__(cfg)
abstractmethod
¶
Overview
Lazy init, only related arguments will be initialized in __init__ method, and the concrete env will be initialized the first time reset method is called.
Arguments:
- cfg (:obj:dict): Environment configuration in dict type.
reset()
abstractmethod
¶
Overview
Reset the env to an initial state and returns an initial observation.
Returns:
- obs (:obj:Any): Initial observation after reset.
close()
abstractmethod
¶
Overview
Close env and all the related resources, it should be called after the usage of env instance.
step(action)
abstractmethod
¶
Overview
Run one timestep of the environment's dynamics/simulation.
Arguments:
- action (:obj:Any): The action input to step with.
Returns:
- timestep (:obj:BaseEnv.timestep): The result timestep of env executing one step.
seed(seed)
abstractmethod
¶
Overview
Set the seed for this env's random number generator(s).
Arguments:
- seed (:obj:Any): Random seed.
__repr__()
abstractmethod
¶
Overview
Return the information string of this env instance.
Returns:
- info (:obj:str): Information of this env instance, like type and arguments.
create_collector_env_cfg(cfg)
staticmethod
¶
Overview
Return a list of all of the environment from input config, used in env manager (a series of vectorized env), and this method is mainly responsible for envs collecting data.
Arguments:
- cfg (:obj:dict): Original input env config, which needs to be transformed into the type of creating env instance actually and generated the corresponding number of configurations.
Returns:
- env_cfg_list (:obj:List[dict]): List of cfg including all the config collector envs.
.. note:: Elements(env config) in collector_env_cfg/evaluator_env_cfg can be different, such as server ip and port.
create_evaluator_env_cfg(cfg)
staticmethod
¶
Overview
Return a list of all of the environment from input config, used in env manager (a series of vectorized env), and this method is mainly responsible for envs evaluating performance.
Arguments:
- cfg (:obj:dict): Original input env config, which needs to be transformed into the type of creating env instance actually and generated the corresponding number of configurations.
Returns:
- env_cfg_list (:obj:List[dict]): List of cfg including all the config evaluator envs.
enable_save_replay(replay_path)
¶
Overview
Save replay file in the given path, and this method need to be self-implemented by each env class.
Arguments:
- replay_path (:obj:str): The path to save replay file.
random_action()
¶
Overview
Return random action generated from the original action space, usually it is convenient for test.
Returns:
- random_action (:obj:Any): Action generated randomly.
get_vec_env_setting(cfg, collect=True, eval_=True)
¶
Overview
Get vectorized env setting (env_fn, collector_env_cfg, evaluator_env_cfg).
Arguments:
- cfg (:obj:dict): Original input env config in user config, such as cfg.env.
Returns:
- env_fn (:obj:type): Callable object, call it with proper arguments and then get a new env instance.
- collector_env_cfg (:obj:List[dict]): A list contains the config of collecting data envs.
- evaluator_env_cfg (:obj: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(cfg)
¶
Overview
Get the env class by correspondng module of cfg and return the callable class.
Arguments:
- cfg (:obj:dict): Original input env config in user config, such as cfg.env.
Returns:
- env_cls_type (:obj:type): Env module as the corresponding callable class type.
create_model_env(cfg)
¶
Overview
Create model env, which is used in model-based RL.
Full Source Code
../ding/envs/env/base_env.py