import logging
from abc import abstractmethod
from ..common.corebase import _AndCore, _CoreBase, _OrCore
__all__ = ("BaseExitCondition",)
[docs]class BaseExitCondition(_CoreBase):
"""Abstract class from which all exit conditions must inherit to be compatible with GloMPO.
:Attributes:
logger : logging.Logger
:class:`logging.Logger` instance into which status messages may be added.
"""
AMS_KEY = "ExitCondition"
def __init__(self):
self.logger = logging.getLogger("glompo.exitcondition")
super().__init__()
[docs] @abstractmethod
def __call__(self, manager: "GloMPOManager") -> bool:
"""Evaluates if the exit condition is met.
:Parameters:
manager
:class:`.GloMPOManager` instance which is managing the optimization. Its attributes can be accessed when
determining the exit criteria.
:Returns:
bool
``True`` if the exit criteria is met, ``False`` otherwise.
:Notes:
For proper functionality, the result of this method must be saved to :attr:`last_result` before
returning.
"""
def __or__(self, other: "BaseExitCondition") -> "_OrExitCondition":
return _OrExitCondition(self, other)
def __and__(self, other: "BaseExitCondition") -> "_AndExitCondition":
return _AndExitCondition(self, other)
class _OrExitCondition(_OrCore, BaseExitCondition):
def __call__(self, manager: "GloMPOManager") -> bool:
return super().__call__(manager)
class _AndExitCondition(_AndCore, BaseExitCondition):
def __call__(self, manager: "GloMPOManager") -> bool:
return super().__call__(manager)