netket.callbacks.ConvergenceStopping#

class netket.callbacks.ConvergenceStopping[source]#

Bases: AbstractCallback

A simple callback to stop the optimisation when the monitored quantity gets below a certain threshold for at least patience steps.

Inheritance
Inheritance diagram of netket.callbacks.ConvergenceStopping
__init__(target, monitor='mean', *, smoothing_window=10, patience=10)[source]#

Construct a callback stopping the optimisation when the monitored quantity gets below a certain threshold for at least patience steps.

Parameters:
  • target (float) – the threshold value for the monitored quantity. Training will stop if the driver drops below this value.

  • monitor (str) – a string with the name of the quantity to be monitored. This is applied to the standard loss optimised by a driver, such as the Energy for the VMC driver. Should be one of ‘mean’, ‘variance’, ‘error_of_mean’ (default: ‘mean’).

  • smoothing_window (int) – an integer number of steps over which the monitored value is averaged before comparing to target.

  • patience (int) – Number of steps to wait before stopping the execution after the tracked quantity drops below the target value (default 0, meaning that it stops immediately).

Attributes
callback_order#
target: float#

Target value for the monitored quantity. Training will stop if the driver drops below this value.

monitor: str#

Loss statistic to monitor. Should be one of ‘mean’, ‘variance’, ‘error_of_mean’.

smoothing_window: int#

The loss is smoothed over the last smoothing_window iterations to reduce statistical fluctuations.

patience: int#

The loss must be consistently below this value for this number of iterations in order to stop the optimisation.

Methods
before_parameter_update(step, log_data, driver)[source]#

Called after all update logic has been computed and the step has been accepted, but before the driver applies the parameter update.

At this point:

  • The loss and its gradient have been computed by compute_loss_and_update().

  • The step has been accepted (not rejected by on_compute_update_end()).

  • driver.step_count still refers to the current step — it has not yet been incremented.

  • The variational state parameters have not yet changed.

This is the right place to estimate additional observables, add data to log_data, or take a snapshot of the state for logging. Callbacks with a lower callback_order run first, so observables callbacks (order 0) are guaranteed to populate log_data before logger callbacks (order 10) read it.

on_compute_update_end(step, log_data, driver)[source]#

Callback called at the end of the compute update phase, after computing the loss and its gradient.

This is called before the parameters are updated, so it can be used to implement custom logic for rejecting a step based on the computed loss or gradient.

Return type:

bool

Returns:

A boolean indicating whether to reject the step (i.e. repeat it with the same parameters). If it returns None, it is treated as False.

on_compute_update_start(step, log_data, driver)[source]#
on_run_end(step, driver)[source]#
on_run_error(step, error, driver)[source]#
on_run_start(step, driver)[source]#
on_step_end(step, log_data, driver)[source]#
on_step_start(step, log_data, driver)[source]#
replace(**kwargs)[source]#

Replace the values of the fields of the object with the values of the keyword arguments. If the object is a dataclass, dataclasses.replace will be used. Otherwise, a new object will be created with the same type as the original object.

Return type:

TypeVar(P, bound= Pytree)

Parameters:
  • self (P)

  • kwargs (Any)