Skip to content

NoImprovementStopper

gepa.utils.stop_condition.NoImprovementStopper(max_iterations_without_improvement: int)

Bases: StopperProtocol

Stop callback that stops after a specified number of iterations without improvement.

Source code in gepa/utils/stop_condition.py
def __init__(self, max_iterations_without_improvement: int):
    self.max_iterations_without_improvement = max_iterations_without_improvement
    self.best_score = float("-inf")
    self.iterations_without_improvement = 0

Attributes

max_iterations_without_improvement = max_iterations_without_improvement instance-attribute

best_score = float('-inf') instance-attribute

iterations_without_improvement = 0 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 max iterations without improvement reached
    try:
        current_score = (
            max(gepa_state.program_full_scores_val_set) if gepa_state.program_full_scores_val_set else 0.0
        )
        if current_score > self.best_score:
            self.best_score = current_score
            self.iterations_without_improvement = 0
        else:
            self.iterations_without_improvement += 1

        return self.iterations_without_improvement >= self.max_iterations_without_improvement
    except Exception:
        return False

reset()

Reset the counter (useful when manually improving the score).

Source code in gepa/utils/stop_condition.py
def reset(self):
    """Reset the counter (useful when manually improving the score)."""
    self.iterations_without_improvement = 0