EarlyStopping#

class pyqit.core.callbacks.EarlyStopping(monitor: str | None = None, patience: int = 5, min_delta: float = 0.0, mode: str = 'min', check_finite: bool = True, verbose: bool = True)[source]#

Bases: BaseCallback

Request a stop after patience epochs without improvement.

Parameters:
  • monitor (str, optional) – Metric to watch. None picks "val_loss" when a validation split produced a finite value and "train_loss" otherwise.

  • patience (int, default 5) – Epochs without improvement to tolerate. Counted the way lightning.pytorch.callbacks.EarlyStopping counts it, so a given value means the same number of epochs in both frameworks.

  • min_delta (float, default 0.0) – Improvement smaller than this does not count as an improvement.

  • mode ({"min", "max"}, default "min") – Whether a lower or higher value of monitor is better.

  • check_finite (bool, default True) – Stop as soon as the monitored metric is NaN or infinite. Matters on a quantum model because a diverged circuit yields NaN rather than a large loss, and NaN never trips the patience counter.

  • verbose (bool, default True) – Announce the stop through the run’s reporter.

stopped_epoch#

Epoch the stop was requested on, or None if it never was.

Type:

int or None

stopping_reason#

Human-readable reason for the stop.

Type:

str or None

best_score#

Best value of monitor seen.

Type:

float

classmethod get_test_params()#

List constructor kwargs used to parametrize this class in the test suite.

on_epoch_end(state: LoopState) → None[source]#

Update the wait counter and stop the run if patience ran out.

on_fit_end(state: LoopState) → None#

Called once, after the last epoch, including after an early stop.

on_fit_start(state: LoopState) → None#

Called once, after setup and before the first epoch.