Logging and Replay
March 11, 2026 ยท View on GitHub
This page documents session logging and replay: MetricsLogger (log file and results TSV), log_metrics() and write_results(), LogReplayer, and how replay is triggered from the CLI. For the TSV format and how it is used for plots, see Visualization.
Overview
Every run uses a MetricsLogger that writes:
- A text log file (one per session) with a header, full config (excluding tokens/API keys), and INFO lines that record which methods were called (e.g. "Called method: get_datasets").
- A results TSV (one per session) with rows = datasets, columns = dataset + model names, and cells = JSON-encoded metric dicts. This file is updated after each (dataset, model) result via
log_metrics()and is the input tocreate_plots().
LogReplayer parses a prior session log, reconstructs the config namespace, and re-runs the same sequence of method names on a new MainProcess instance so you can reproduce a workflow without re-entering options.
How it works
MetricsLogger:
- init(args): Stores
logger_args; no I/O yet. - start_log_main() or start_log_gui(): Calls
_start_file()(createslog_dir,results_dir, setsrandom_idfromPROTIFY_JOB_ID, replay path stem, or{date}-{time}_{4 letters}), then overwrites or appends to the log file and calls_minimial_logger()to set up the Python logger andlogger_data_tracking = { dataset_name: { model_name: metrics_dict } }. - log_metrics(dataset, model, metrics_dict, split_name=None): Filters out non-time keys (keeps
training_time_seconds*), updateslogger_data_tracking[dataset][model], and callswrite_results(). - write_results(): Sorts datasets and models (e.g. by mean eval_loss), writes the TSV with header
dataset+ model names, each celljson.dumps(metrics). - end_log(): Appends system info (platform, pip list, nvidia-smi, Python version) to the log file.
Replay:
- User passes
--replay_path path/to/session.log. main()createsLogReplayer(replay_path), callsreplayer.parse_log()to get a namespace of arguments (from lines likekey:\tvalue; values areast.literal_eval'd when possible). INFO lines in the log contribute to a list of method name strings.MainProcess(replay_args, GUI=False)is created; thenreplayer.run_replay(main)runsgetattr(main, method)()for each method name in order. Missing methods produce a warning.
So the "replayed script" is the sequence of method names that were logged as INFO (from the @log_method_calls decorator on MainProcess methods).
MetricsLogger API
| Method | Description |
|---|---|
_start_file() | Creates log_dir, results_dir, sets random_id, log_file, results_file. |
start_log_main() | _start_file, overwrite log with header and args, _minimial_logger. |
start_log_gui() | Same but different header handling. |
load_tsv() | Reads results_file into logger_data_tracking (e.g. for resuming). |
write_results() | Writes logger_data_tracking to results TSV (sorted). |
log_metrics(dataset, model, metrics_dict, split_name=None) | Updates tracking and writes TSV. |
end_log() | Appends system info to log file. |
Results TSV shape: Rows = dataset names, Columns = dataset + model names, Cells = JSON metrics (e.g. test_spearman, eval_loss, training_time_seconds).
LogReplayer API
| Method | Description |
|---|---|
__init__(log_file_path) | Stores path; arguments = {}, method_calls = []. |
parse_log() | Reads log; key:value lines -> arguments (literal_eval when possible); INFO lines -> method name strings. Returns SimpleNamespace(**arguments). |
run_replay(target_obj) | For each method name in method_calls, calls getattr(target_obj, method)(). Warns if method missing. |
Replay flow in main.py
When args.replay_path is set:
LogReplayer(args.replay_path)is created.replay_args = replayer.parse_log();replay_args.replay_path = args.replay_path; seed and deterministic are applied from replayed args.main = MainProcess(replay_args, GUI=False).- Full args are printed; then
replayer.run_replay(main)runs the replayed method sequence. - Normal write_results/generate_plots/end_log are not called automatically inside replay; they run only if the replayed methods include them (e.g. if the original run called
write_results, that call is replayed).
Examples
Replay a prior session
py -m src.protify.main --replay_path logs/2025-01-15-12-00_ABCD.txt
Where files go
- Log:
log_dir/{random_id}.txt(e.g.logs/2025-01-15-12-00_ABCD.txt). - Results:
results_dir/{random_id}.tsv(e.g.results/2025-01-15-12-00_ABCD.tsv).
See also
- Visualization for how the results TSV is used by create_plots
- Getting started for log_dir and results_dir
- Configuration for --replay_path and paths