Skip to content

CompositeStopper

gepa.utils.stop_condition.CompositeStopper(*stoppers: StopperProtocol, mode: Literal['any', 'all'] = 'any')

Bases: StopperProtocol

Stop callback that combines multiple stopping conditions.

Allows combining several stoppers and stopping when any or all of them are triggered.

Source code in gepa/utils/stop_condition.py
def __init__(self, *stoppers: StopperProtocol, mode: Literal["any", "all"] = "any"):
    # initialize composite stopper

    self.stoppers = stoppers
    self.mode = mode

Attributes

stoppers = stoppers instance-attribute

mode = mode instance-attribute

Functions

__call__(gepa_state: GEPAState) -> bool

Source code in gepa/utils/stop_condition.py
def __call__(self, gepa_state: GEPAState) -> bool:
    # return true if stopping condition is met
    if self.mode == "any":
        return any(stopper(gepa_state) for stopper in self.stoppers)
    elif self.mode == "all":
        return all(stopper(gepa_state) for stopper in self.stoppers)
    else:
        raise ValueError(f"Unknown mode: {self.mode}")