rlberry.utils.writers
.DefaultWriter¶
- class rlberry.utils.writers.DefaultWriter(name: str, print_log: bool = True, style_log: str = 'multi_line', log_interval: int = 3, tensorboard_kwargs: dict | None = None, execution_metadata: ExecutionMetadata | None = None, maxlen: int | None = None, maxlen_by_tag: dict | None = {})[source]¶
Bases:
object
Default writer to be used by the agents, optionally wraps an instance of tensorboard.SummaryWriter.
Can be used in the fit() method of the agents, so that training data can be handled by ExperimentManager and RemoteExperimentManager.
- Parameters:
- namestr
Name of the writer.
- print_logbool, default=True
If True, print logs to stderr.
- log_intervalint
Minimum number of seconds between consecutive logs (with logging module).
- style_log: str
Possible values are “multi_line”, “one_line” and “progressbar”. Define the style of the logs.
- tensorboard_kwargsOptional[dict]
Parameters for tensorboard SummaryWriter. If provided, DefaultWriter will behave as tensorboard.SummaryWriter, and will keep utilities to handle data added with the add_scalar method.
- execution_metadatametadata_utils.ExecutionMetadata
Execution metadata about the object that is using the writer.
- maxlenOptional[int], default: None
If given, data stored by self._data (accessed through the property self.data) is limited to maxlen entries.
- maxlen_by_tag: Optional[dict], default: {}
If given, applies the maxlen logic tag by tag, using the above maxlen as default.
- Attributes:
- data
- summary_writer
Methods
add_scalar
(tag, scalar_value[, global_step, ...])Behaves as SummaryWriter.add_scalar().
add_scalars
([main_tag, tag_scalar_dict, ...])Behaves as add_scalar, but for a list instead of a single scalar value.
read_first_tag_value
(tag[, main_tag])Reads the first value for the tag tag.
read_last_tag_value
(tag[, main_tag])Reads the last value for the tag tag.
read_tag_value
(tag[, main_tag])Reads the values for the tag tag.
reset
()Clear data.
set_max_global_step
- add_scalar(tag: str, scalar_value: float, global_step: int | None = None, walltime=None, new_style=False)[source]¶
Behaves as SummaryWriter.add_scalar().
WARNING: ‘global_step’ can be confusing when a scalar is written at each episode and another is written at each iteration. The global step 1 may be associated to first episode and first step in environment.
- Parameters:
- tagstr
Tag for the scalar.
- scalar_valuefloat
Value of the scalar.
- global_stepint
Step where scalar was added. If None, global steps will no longer be stored for the current tag.
- walltimefloat
Optional override default walltime (time.time()) with seconds after epoch of event
- new_stylebool
Whether to use new style (tensor field) or old style (simple_value field). New style could lead to faster data loading.
- add_scalars(main_tag: str = '', tag_scalar_dict: dict = {}, global_step: int | None = None, walltime=None)[source]¶
Behaves as add_scalar, but for a list instead of a single scalar value.
WARNING: ‘global_step’ can be confusing when a scalar is written at each episode and another is written at each iteration. The global step 1 may be associated to first episode and first step in environment.
- Parameters:
- main_tagstring
The parent name for the tags.
- tag_scalar_dictdict
Key-value pair storing the tag and corresponding values.
- global_stepint
Step where scalar was added. If None, global steps will no longer be stored for the current tag.
- walltimefloat
Optional override default walltime (time.time()) with seconds after epoch of event
- read_first_tag_value(tag, main_tag: str = '')[source]¶
Reads the first value for the tag tag. If a main_tag is given, the tag will be a concatenation of main_tag, underscore and tag.
- Parameters:
- tag: string
Tag to be searched
- main_tag: string, default=””
Main tag. If main_tag == “” then use only tag.
- Returns:
- The first value encountered with tag tag.
- read_last_tag_value(tag, main_tag: str = '')[source]¶
Reads the last value for the tag tag. If a main_tag is given, the tag will be a concatenation of main_tag, underscore and tag.
- Parameters:
- tag: string
Tag to be searched
- main_tag: string, default=””
Main tag. If main_tag == “” then use only tag.
- Returns:
- The last value with tag tag encountered by the writer.
- read_tag_value(tag, main_tag: str = '')[source]¶
Reads the values for the tag tag. If a main_tag is given, the tag will be a concatenation of main_tag, underscore and tag.
- Parameters:
- tag: string
Tag to be searched
- main_tag: string, default=””
Main tag. If main_tag == “” then use only tag.
- Returns:
- The writer values for the tag, a pandas Series.