trinity.utils.monitor module#

Monitor

trinity.utils.monitor.gather_metrics(metric_list: List[Dict], prefix: str, output_stats: List[str] = ['mean', 'max', 'min']) Dict[source]#
class trinity.utils.monitor.Monitor(project: str, name: str, role: str, config: Config = None)[source]#

Bases: ABC

__init__(project: str, name: str, role: str, config: Config = None) None[source]#
abstractmethod log_table(table_name: str, experiences_table: DataFrame, step: int)[source]#

Log a table

abstractmethod log(data: dict, step: int, commit: bool = False) None[source]#

Log metrics.

abstractmethod close() None[source]#

Close the monitor

calculate_metrics(data: dict[str, List[float] | float], prefix: str | None = None) dict[str, float][source]#
classmethod default_args() Dict[source]#

Return default arguments for the monitor.

class trinity.utils.monitor.TensorboardMonitor(project: str, group: str, name: str, role: str, config: Config = None)[source]#

Bases: Monitor

__init__(project: str, group: str, name: str, role: str, config: Config = None) None[source]#
log_table(table_name: str, experiences_table: DataFrame, step: int)[source]#

Log a table

log(data: dict, step: int, commit: bool = False) None[source]#

Log metrics.

close() None[source]#

Close the monitor

class trinity.utils.monitor.WandbMonitor(project: str, group: str, name: str, role: str, config: Config = None)[source]#

Bases: Monitor

Monitor with Weights & Biases.

Parameters:
  • base_url (Optional[str]) – The base URL of the W&B server. If not provided, use the environment variable WANDB_BASE_URL.

  • api_key (Optional[str]) – The API key for W&B. If not provided, use the environment variable WANDB_API_KEY.

__init__(project: str, group: str, name: str, role: str, config: Config = None) None[source]#
log_table(table_name: str, experiences_table: DataFrame, step: int)[source]#

Log a table

log(data: dict, step: int, commit: bool = False) None[source]#

Log metrics.

close() None[source]#

Close the monitor

classmethod default_args() Dict[source]#

Return default arguments for the monitor.

class trinity.utils.monitor.MlflowMonitor(project: str, group: str, name: str, role: str, config: Config = None)[source]#

Bases: Monitor

Monitor with MLflow.

Parameters:
  • uri (Optional[str]) – The tracking server URI. If not provided, the default is http://localhost:5000.

  • username (Optional[str]) – The username to login. If not provided, the default is None.

  • password (Optional[str]) – The password to login. If not provided, the default is None.

__init__(project: str, group: str, name: str, role: str, config: Config = None) None[source]#
log_table(table_name: str, experiences_table: DataFrame, step: int)[source]#

Log a table

log(data: dict, step: int, commit: bool = False) None[source]#

Log metrics.

close() None[source]#

Close the monitor

classmethod default_args() Dict[source]#

Return default arguments for the monitor.

class trinity.utils.monitor.SwanlabMonitor(project: str, group: str, name: str, role: str, config: Config = None)[source]#

Bases: Monitor

Monitor with SwanLab.

This monitor integrates with SwanLab (https://swanlab.cn/) to track experiments.

Supported monitor_args in config.monitor.monitor_args:
  • api_key (Optional[str]): API key for swanlab.login(). If omitted, will read from env

    (SWANLAB_API_KEY, SWANLAB_APIKEY, SWANLAB_KEY, SWANLAB_TOKEN) or assume prior CLI login.

  • workspace (Optional[str]): Organization/username workspace.

  • mode (Optional[str]): “cloud” | “local” | “offline” | “disabled”.

  • logdir (Optional[str]): Local log directory when in local/offline modes.

  • experiment_name (Optional[str]): Explicit experiment name. Defaults to “{name}_{role}”.

  • description (Optional[str]): Experiment description.

  • tags (Optional[List[str]]): Tags to attach. Role and group are appended automatically.

  • id (Optional[str]): Resume target run id (21 chars) when using resume modes.

  • resume (Optional[Literal[‘must’,’allow’,’never’]|bool]): Resume policy.

  • reinit (Optional[bool]): Whether to re-init on repeated init() calls.

__init__(project: str, group: str, name: str, role: str, config: Config = None) None[source]#
log_table(table_name: str, experiences_table: DataFrame, step: int)[source]#

Log a table

log(data: dict, step: int, commit: bool = False) None[source]#

Log metrics.

close() None[source]#

Close the monitor

classmethod default_args() Dict[source]#

Return default arguments for the monitor.