ding.worker.collector.base_serial_collector¶
ding.worker.collector.base_serial_collector
¶
ISerialCollector
¶
Bases: ABC
Overview
Abstract baseclass for serial collector.
Interfaces: default_config, reset_env, reset_policy, reset, collect Property: envstep
default_config()
classmethod
¶
Overview
Get collector's default config. We merge collector's default config with other default configs and user's config to get the final config.
Return:
cfg: (:obj:EasyDict): collector's default config
reset_env(_env=None)
abstractmethod
¶
Overview
Reset collector's environment. In some case, we need collector use the same policy to collect data in different environments. We can use reset_env to reset the environment.
reset_policy(_policy=None)
abstractmethod
¶
Overview
Reset collector's policy. In some case, we need collector work in this same environment but use different policy to collect data. We can use reset_policy to reset the policy.
reset(_policy=None, _env=None)
abstractmethod
¶
Overview
Reset collector's policy and environment. Use new policy and environment to collect data.
collect(per_collect_target)
abstractmethod
¶
Overview
Collect the corresponding data according to the specified target and return. There are different definitions in episode and sample mode.
envstep()
¶
Overview
Get the total envstep num.
CachePool
¶
Bases: object
Overview
CachePool is the repository of cache items.
Interfaces: init, update, getitem, reset
__init__(name, env_num, deepcopy=False)
¶
Overview
Initialization method.
Arguments:
- name (:obj:str): name of cache
- env_num (:obj:int): number of environments
- deepcopy (:obj:bool): whether to deepcopy data
update(data)
¶
Overview
Update elements in cache pool.
Arguments:
- data (:obj:Dict[int, Any]): A dict containing update index-value pairs. Key is index in cache pool, and value is the new element.
__getitem__(idx)
¶
Overview
Get item in cache pool.
Arguments:
- idx (:obj:int): The index of the item we need to get.
Return:
- item (:obj:Any): The item we get.
reset(idx)
¶
Overview
Reset the cache pool.
Arguments:
- idx (:obj:int): The index of the position we need to reset.
TrajBuffer
¶
Bases: list
Overview
TrajBuffer is used to store traj_len pieces of transitions.
Interfaces: init, append
create_serial_collector(cfg, **kwargs)
¶
Overview
Create a specific collector instance based on the config.
get_serial_collector_cls(cfg)
¶
Overview
Get the specific collector class according to the config.
to_tensor_transitions(data, shallow_copy_next_obs=True)
¶
Overview
Transform ths original transition return from env to tensor format.
Argument:
- data (:obj:List[Dict[str, Any]]): The data that will be transformed to tensor.
- shallow_copy_next_obs (:obj:bool): Whether to shallow copy next_obs. Default: True.
Return:
- data (:obj:List[Dict[str, Any]]): The transformed tensor-like data.
.. tip::
In order to save memory, If there are next_obs in the passed data, we do special treatment on next_obs so that the next_obs of each state in the data fragment is the next state's obs and the next_obs of the last state is its own next_obsself. Besides, we set transform_scalar to False to avoid the extra .item() operation.
Full Source Code
../ding/worker/collector/base_serial_collector.py