twocan.SaveTrialsDFCallback

class twocan.SaveTrialsDFCallback(filepath: str, save_frequency: int = 1)[source]

Bases: object

Callback to save optimization trials to a CSV file during study execution.

This callback writes trial results to a CSV file after each trial completion, allowing for real-time monitoring and persistent storage of optimization progress. Useful for long-running optimizations or when resuming studies.

Parameters:
  • filepath (str) – Path to the CSV file where trial data will be saved. File will be created if it doesn’t exist.

  • save_frequency (int, default=1) – Number of trials between saves. Set to 1 to save after every trial, higher values for less frequent saves to reduce I/O overhead.

filepath

Current filepath for saving trial data.

Type:

str

save_frequency

Current save frequency setting.

Type:

int

trial_count

Internal counter tracking number of completed trials.

Type:

int