logger
experiment
- class AugmentedSafeLoader(stream)[source]
Bases:
SafeLoader
Initialize the scanner.
- construct_python_tuple(node)[source]
Use PyYAML method for constructing a sequence to construct a tuple.
- yaml_constructors = {'tag:yaml.org,2002:null': <function SafeConstructor.construct_yaml_null>, 'tag:yaml.org,2002:bool': <function SafeConstructor.construct_yaml_bool>, 'tag:yaml.org,2002:int': <function SafeConstructor.construct_yaml_int>, 'tag:yaml.org,2002:float': <function SafeConstructor.construct_yaml_float>, 'tag:yaml.org,2002:binary': <function SafeConstructor.construct_yaml_binary>, 'tag:yaml.org,2002:timestamp': <function SafeConstructor.construct_yaml_timestamp>, 'tag:yaml.org,2002:omap': <function SafeConstructor.construct_yaml_omap>, 'tag:yaml.org,2002:pairs': <function SafeConstructor.construct_yaml_pairs>, 'tag:yaml.org,2002:set': <function SafeConstructor.construct_yaml_set>, 'tag:yaml.org,2002:str': <function SafeConstructor.construct_yaml_str>, 'tag:yaml.org,2002:seq': <function SafeConstructor.construct_yaml_seq>, 'tag:yaml.org,2002:map': <function SafeConstructor.construct_yaml_map>, None: <function SafeConstructor.construct_undefined>, 'tag:yaml.org,2002:python/tuple': <function AugmentedSafeLoader.construct_python_tuple>}
- class Experiment(env_name: str, algo_name: str, extra_info: Optional[str] = None, exp_id: Optional[str] = None, timestamp: Optional[datetime] = None, base_dir: str = '/home/user/SimuRLacra/Pyrado/pyrado/../data/temp', include_slurm_id: bool = True)[source]
Bases:
object
Class for defining experiments This is a path-like object, and as such it can be used everywhere a normal path would be used.
Experiment folder path: <base_dir>/<env_name>/<algo_name>/<timestamp>–<extra_info>
Constructor
- Parameters:
env_name – environment trained on
algo_name – algorithm trained with, usually also includes the policy type, e.g. ‘a2c_fnn’
extra_info – additional information on the experiment (free form)
exp_id – combined timestamp and extra_info, usually the final folder name
timestamp – experiment creation timestamp
base_dir – base storage directory
include_slurm_id – if a SLURM ID is present in the environment variables, include it in the experiment ID
- property prefix
Combination of experiment and algorithm
- ask_for_experiment(latest_only: bool = False, max_display: int = 10, env_name: Optional[str] = None, temp: bool = True, perma: bool = True, hparam_list: Optional[List[str]] = None) Experiment [source]
Ask for an experiment on the console. This is the go-to entry point for evaluation scripts.
- Parameters:
latest_only – only select the latest experiment of each type (environment-algorithm combination)
max_display – maximum number of items
env_name – filter by env name
temp – set to False to not look in the pyrado.TEMP directory
perma – set to False to not look in the pyrado.PERMA directory
hparam_list – load the hyper-parameter file and show the parameters in this list, sub-dicts can be separated with a dot
- Returns:
query asking the user for an experiment
- create_experiment_formatter(show_hparams: Optional[List[str]] = None, show_extra_info: bool = True) Callable[[Experiment], str] [source]
Returns an experiment formatter (i.e. a function that takes an experiment and produces a string) to be used in the ask-for-experiments dialog. It produces useful information like the timestamp based on the experiments’ data.
- Parameters:
show_hparams – list of “paths” to hyper-parameters that to be shown in the selection dialog; sub-dicts can be references with a dot, e.g. env.dt
show_extra_info – whether to show the information stored in the extra_info field of the experiment
- Returns:
a function that serves as the formatter
- list_experiments(env_name: Optional[str] = None, algo_name: Optional[str] = None, base_dir: Optional[str] = None, *, temp: bool = True, perma: bool = True)[source]
List all stored experiments.
- Parameters:
env_name – filter by env name
algo_name – filter by algorithm name. Requires env_name to be used too
base_dir – explicit base dir if desired. May also be a list of bases. Uses pyrado.TEMP_DIR and pyrado.EXP_DIR if not specified.
temp – set to False to not look in the pyrado.TEMP directory
perma – set to False to not look in the pyrado.PERMA directory
- load_dict_from_yaml(yaml_file: str) dict [source]
Load a list of dicts (e.g. hyper-parameters) of an experiment from a YAML-file.
- Parameters:
yaml_file – path to the YAML-file that
- Returns:
a dict containing names as keys and a dict of parameter values
- load_hyperparameters(ex_dir: PathLike, verbose: bool = True) Optional[dict] [source]
Loads the hyper-parameters-dict from the given experiment directory. The hyper-parameters file is assumed to be named hyperparams.yaml.
- Parameters:
ex_dir – experiment’s directory to load from
verbose – if True, print message if no hyper-parameter file was found
- save_dicts_to_yaml(*dicts: dict, save_dir: PathLike, file_name: str = 'hyperparams')[source]
Save a list of dicts (e.g. hyper-parameters) of an experiment a YAML-file.
- Parameters:
dicts – dicts each containing a key (name) and a value (hyper-parameter)
save_dir – directory to save the results in
file_name – name of the YAML-file without suffix
- select_by_hint(exps: Sequence[Experiment], hint: str)[source]
Select experiment by hint.
- setup_experiment(env_name: str, algo_name: str, extra_info: Optional[str] = None, base_dir: str = '/home/user/SimuRLacra/Pyrado/pyrado/../data/temp', include_slurm_id: bool = True)[source]
Setup a new experiment for recording.
- Parameters:
env_name – environment trained on
algo_name – algorithm trained with, usually also includes the policy type, e.g. ‘a2c_fnn’
extra_info – additional information on the experiment (free form)
base_dir – base storage directory
include_slurm_id – if a SLURM ID is present in the environment variables, include them in the experiment ID
- split_path_custom_common(path: ~typing.Union[str, ~pyrado.logger.experiment.Experiment]) -> (<class 'str'>, <class 'str'>)[source]
Split a path at the point where the machine-dependent and the machine-independent part can be separated.
- Parameters:
path – (complete) experiment path to be split
- Returns:
name of the base directory (‘experiments’ for pyrado.EXP_DIR or ‘temp’ for pyrado.TEMP_DIR) where the experiment was located, and machine-independent part of the path
iteration
- class IterationTracker[source]
Bases:
object
Track the current iteration/step number on multiple levels (for meta-algorithms)
Constructor
- format(scope_sep='-', label_num_sep='_')[source]
Format the current iteration stack into a string. Two parts can be customized:
- Parameters:
scope_sep – string separating the label and the number
label_num_sep – string separating each label/number pair
- Returns:
string with custom separators
- get(label: str)[source]
Get the iteration number for a labeled scope.
- Parameters:
label – scope label
- Returns:
iteration index
step
- class CSVPrinter(file: str)[source]
Bases:
StepLogPrinter
Logs step data to a CSV file
Constructor
- Parameters:
file – csv file name
- class ConsolePrinter[source]
Bases:
StepLogPrinter
Prints step data to the console
- class LoggerAware[source]
Bases:
object
Base for objects holding a StepLogger. Features automatic detection of child LoggerAware objects. Override to customize.
- property logger: StepLogger
Get or create the step logger to use for this object.
- class StepLogPrinter[source]
Bases:
ABC
Base class for log printers. Formats progress values for a step.
- class StepLogger(print_intvl: int = 1)[source]
Bases:
object
Step-based progress logger. This class collects progress values during a step. At the end, the record_step function will pass the collected values to one or more StepLogPrinters. The logger also validates that no values are added unexpectedly, which i.e. a csv printer would not support.
Constructor
- Parameters:
print_intvl – interval size, by default the logger records and prints on every call, i.e. every step
- add_value(key: str, value, round_digits: Optional[int] = None)[source]
Add a column value to the current step.
- Parameters:
key – data key
value – value to record, pass ‘’ to print nothing
round_digits – digits to rounds to, pass None (default) for no rounding
- class TensorBoardPrinter(dir)[source]
Bases:
StepLogPrinter
Class for writing tensorboard logs
Constructor
- Parameters:
dir – folder path name
- create_csv_step_logger(save_dir: PathLike, file_name: str = 'progress.csv') StepLogger [source]
Create a step-based logger which only safes to a csv-file.
- Parameters:
save_dir – parent directory to save the results in (usually the algorithm’s save_dir)
file_name – name of the cvs-file (with ending)
- Returns:
step-based logger