The module tsl.experiment contains classes and utilities for experiment pipelining, scalability and reproducibility. The main class in the package is tsl.experiment.Experiment.


class Experiment(run_fn: Callable, config_path: Optional[str] = None, config_name: Optional[str] = None, pre_run_hooks: Optional[Union[Callable, List[Callable]]] = None)[source]#

Simple class to handle the routines used to run experiments.

This class relies heavily on the Hydra framework, check Hydra docs for usage information.

Hydra is an optional dependency of tsl, to install it using pip:

pip install hydra-core
  • run_fn (callable) – Python function that actually runs the experiment when called. The run function must accept a single argument, being the experiment configuration.

  • config_path (str, optional) – Path to configuration files. If not specified the default will be used.

  • config_name (str, optional) – Name of the configuration file in config_path to be used. The yaml extension can be omitted.

  • pre_run_hooks (list) – Ordered list of functions to call on run() before the run_fn. Every hook must accept a single argument, being the experiment configuration, and act in-place on the configuration.

log_config() None[source]#

Save config as .yaml file in run_dir().

property run_dir#

Directory of the current run, where logs and artifacts are stored.


Run the experiment routine.



Extensions of PyTorch Lightning NeptuneLogger with useful logging functionalities.

class NeptuneLogger(api_key: Optional[str] = None, project_name: Optional[str] = None, experiment_name: Optional[str] = None, tags: Optional[Union[str, List]] = None, params: Optional[Mapping] = None, debug: bool = False, prefix: Optional[str] = 'logs', upload_stdout: bool = False, **kwargs)[source]#

Extensions of PyTorch Lightning NeptuneLogger with useful logging functionalities.

  • api_key (str, optional) – Neptune API token, found on https://neptune.ai upon registration. Read: how to find and set Neptune API token. It is recommended to keep it in the NEPTUNE_API_TOKEN environment variable, then you can drop api_key=None. (default: None)

  • project_name (str, optional) – Name of a project in a form of “my_workspace/my_project”. If None, the value of NEPTUNE_PROJECT environment variable will be taken. You need to create the project in https://neptune.ai first. (default: None)

  • experiment_name (str, optional) – Editable name of the run. Run name appears in the “all metadata/sys” section in Neptune UI. (default: None)

  • tags (list, optional) – List of tags of the run. (default: None)

  • params (Mapping, optional) – Mapping of the run’s parameters (are logged as "parameters" on Neptune). (default: None)

  • debug (bool) – If True, then do not log online (i.e., log in "debug" mode). Otherwise log online in "async" mode. (default: False)

  • prefix (str, optional) – Root namespace for all metadata logging. (default: "logs")

  • upload_stdout (bool) – If True, then log also stdout on Neptune. (default: False)

  • **kwargs – Additional parameters for NeptuneLogger.

log_pred_df(name, idx, y, yhat, label_y='true', label_yhat='pred')[source]#

Log a csv containing predictions and true values. Only works for univariate timeseries.

  • name – name of the file

  • idx – dataframe idx

  • y – true values

  • yhat – predictions

  • label_y – true values

  • label_yhat – predictions


log_dataframe(df: DataFrame, name: str = 'dataframe')[source]#

Log a dataframe as csv.

  • df (DataFrame) – The dataframe to be logged.

  • name (str) – The name of the file. (default: 'dataframe')

log_figure(fig, name: str = 'figure')[source]#

Log a matplotlib figure as html.

  • fig (Figure) – The matplotlib figure to be logged

  • name (str) – The name of the file. (default: 'figure')