ding.worker.replay_buffer.base_buffer¶
ding.worker.replay_buffer.base_buffer
¶
IBuffer
¶
Bases: ABC
Overview
Buffer interface
Interfaces: default_config, push, update, sample, clear, count, state_dict, load_state_dict
default_config()
classmethod
¶
Overview
Default config of this buffer class.
Returns:
- default_config (:obj:EasyDict)
push(data, cur_collector_envstep)
abstractmethod
¶
Overview
Push a data into buffer.
Arguments:
- data (:obj:Union[List[Any], Any]): The data which will be pushed into buffer. Can be one \
(in Any type), or many(int List[Any] type).
- cur_collector_envstep (:obj:int): Collector's current env step.
update(info)
abstractmethod
¶
Overview
Update data info, e.g. priority.
Arguments:
- info (:obj:Dict[str, list]): Info dict. Keys depends on the specific buffer type.
sample(batch_size, cur_learner_iter)
abstractmethod
¶
Overview
Sample data with length batch_size.
Arguments:
- size (:obj:int): The number of the data that will be sampled.
- cur_learner_iter (:obj:int): Learner's current iteration.
Returns:
- sampled_data (:obj:list): A list of data with length batch_size.
clear()
abstractmethod
¶
Overview
Clear all the data and reset the related variables.
count()
abstractmethod
¶
Overview
Count how many valid datas there are in the buffer.
Returns:
- count (:obj:int): Number of valid data.
save_data(file_name)
abstractmethod
¶
Overview
Save buffer data into a file.
Arguments:
- file_name (:obj:str): file name of buffer data
load_data(file_name)
abstractmethod
¶
Overview
Load buffer data from a file.
Arguments:
- file_name (:obj:str): file name of buffer data
state_dict()
abstractmethod
¶
Overview
Provide a state dict to keep a record of current buffer.
Returns:
- state_dict (:obj:Dict[str, Any]): A dict containing all important values in the buffer. With the dict, one can easily reproduce the buffer.
load_state_dict(_state_dict)
abstractmethod
¶
Overview
Load state dict to reproduce the buffer.
Returns:
- state_dict (:obj:Dict[str, Any]): A dict containing all important values in the buffer.
create_buffer(cfg, *args, **kwargs)
¶
Overview
Create a buffer according to cfg and other arguments.
Arguments:
- cfg (:obj:EasyDict): Buffer config.
ArgumentsKeys:
- necessary: type
get_buffer_cls(cfg)
¶
Overview
Get a buffer class according to cfg.
Arguments:
- cfg (:obj:EasyDict): Buffer config.
ArgumentsKeys:
- necessary: type
Full Source Code
../ding/worker/replay_buffer/base_buffer.py