Source code for scm.glompo.exitconditions.stopsafterconvergence

from .baseexitcondition import BaseExitCondition
from ...plams.core.settings import Settings

__all__ = ("StopsAfterConvergence",)


[docs]class StopsAfterConvergence(BaseExitCondition): """Evaluation based on the number of single optimizers converged and the number of optimizers stopped thereafter. Returns ``True`` after ``n_stopped`` optimizers have been stopped by GloMPO after ``n_converged`` optimizers have reached normal convergence. """ def __init__(self, n_stopped: int = 0, n_converged: int = 1): super().__init__() self.enough_conv = False self.stop_count = 0 self.n_converged = n_converged self.n_stopped = n_stopped def __amssettings__(self, s: Settings) -> Settings: s.input.ams.ExitCondition.Type = "StopsAfterConvergence" s.input.ams.ExitCondition.StopsAfterConvergence.OptimizersStopped = self.n_stopped s.input.ams.ExitCondition.StopsAfterConvergence.OptimizersConverged = self.n_converged return s def __call__(self, manager: "GloMPOManager") -> bool: if manager.conv_counter >= self.n_converged and not self.enough_conv: self.enough_conv = True self.stop_count = len(manager.stopped_opts) self.last_result = self.enough_conv and len(manager.stopped_opts) - self.stop_count >= self.n_stopped return self.last_result