casanovoutils.graphloss#

Plot Casanovo training and validation loss.

This script reads one or more Casanovo training logs (either a log file or a metrics.csv file) and produces a PNG plot of training and validation loss as a function of step/iteration.

Output is written to <root>.png.

Attributes#

Functions#

read_from_logfile(→ tuple[LossSeries, LossSeries])

Read train/validation loss series from a Casanovo log file.

read_from_csvfile(→ tuple[LossSeries, LossSeries])

Read train/validation loss series from a Casanovo metrics.csv file.

detect_input_format(→ str)

Determine whether the input is a log file or a metrics CSV.

read_from_file(→ tuple[LossSeries, LossSeries])

Read losses from a Casanovo log file or metrics CSV.

plot_losses(→ None)

Create and save the loss plot.

plot(→ None)

Read Casanovo log and/or metrics.csv files and plot training/validation loss.

main(→ None)

Module Contents#

type casanovoutils.graphloss.LossSeries = list[tuple[int, float]]#
casanovoutils.graphloss.read_from_logfile(input_path: pathlib.Path) tuple[LossSeries, LossSeries]#

Read train/validation loss series from a Casanovo log file.

Parameters:

input_path – Path to a text log file produced during Casanovo training.

Returns:

Two lists of (step, loss) tuples.

Return type:

(train_losses, val_losses)

casanovoutils.graphloss.read_from_csvfile(input_path: pathlib.Path) tuple[LossSeries, LossSeries]#

Read train/validation loss series from a Casanovo metrics.csv file.

Parameters:

input_path – Path to a CSV file containing Casanovo metrics.

Returns:

Two lists of (step, loss) tuples.

Return type:

(train_losses, val_losses)

casanovoutils.graphloss.detect_input_format(input_path: pathlib.Path) str#

Determine whether the input is a log file or a metrics CSV.

The detection is based on filename conventions and a quick header sniff.

Parameters:

input_path – Path to an input file.

Returns:

Either "csv" or "log".

Return type:

format

casanovoutils.graphloss.read_from_file(input_path: pathlib.Path) tuple[LossSeries, LossSeries]#

Read losses from a Casanovo log file or metrics CSV.

casanovoutils.graphloss.plot_losses(root: str, train_loss_lists: list[LossSeries], val_loss_lists: list[LossSeries], max_y: float | None) None#

Create and save the loss plot.

Parameters:
  • root – Output file root name. Output is written to {root}.png.

  • train_loss_lists – A sequence of training loss series.

  • val_loss_lists – A sequence of validation loss series.

  • max_y – Optional y-axis maximum.

casanovoutils.graphloss.plot(root: str, inputs: list[str], max_y: float | None = None) None#

Read Casanovo log and/or metrics.csv files and plot training/validation loss.

Parameters:
  • root – Output file root; plot will be written to <root>.png and log to <root>.log.

  • inputs – One or more input files (Casanovo log files or metrics.csv files).

  • max_y – Optional y-axis maximum.

casanovoutils.graphloss.COMMANDS: casanovoutils.types.Commands#
casanovoutils.graphloss.main() None#