Threshold
threshold ¶
Score threshold stopper for evolution termination at target performance.
This module provides a ScoreThresholdStopper that terminates evolution when the best score meets or exceeds a threshold, enabling "early success" termination to avoid wasting compute once "good enough" performance is achieved.
| ATTRIBUTE | DESCRIPTION |
|---|---|
ScoreThresholdStopper | Stop evolution when best score reaches threshold. TYPE: |
Examples:
Basic usage with evolution config:
from gepa_adk.adapters.stoppers import ScoreThresholdStopper
stopper = ScoreThresholdStopper(0.95) # Stop at 95% accuracy
# Use stopper in evolution config
Note
This stopper is useful when you have a known target score and want to terminate as soon as it is reached, rather than continuing unnecessarily.
See Also
gepa_adk.ports.stopper.StopperProtocol: Protocol interface for stop conditions.gepa_adk.domain.stopper.StopperState: Immutable snapshot of evolution state for stopper decisions.
ScoreThresholdStopper ¶
Stop evolution when best score reaches threshold.
Terminates evolution when the best achieved score meets or exceeds the configured threshold. Useful for "early success" scenarios where continued evolution beyond a target performance is unnecessary.
| ATTRIBUTE | DESCRIPTION |
|---|---|
threshold | Target score to achieve (evolution stops when best_score >= threshold). TYPE: |
Examples:
Creating a 95% accuracy threshold:
from gepa_adk.adapters.stoppers import ScoreThresholdStopper
from gepa_adk.domain.stopper import StopperState
stopper = ScoreThresholdStopper(0.95)
state = StopperState(
iteration=10,
best_score=0.97,
stagnation_counter=2,
total_evaluations=50,
candidates_count=3,
elapsed_seconds=120.0,
)
stopper(state) # Returns True (should stop)
Note
Any float value can be used as threshold, including negative numbers for domains where scores can be negative (e.g., loss minimization).
Source code in src/gepa_adk/adapters/stoppers/threshold.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
__init__ ¶
Initialize threshold stopper with target score.
| PARAMETER | DESCRIPTION |
|---|---|
threshold | Target score to achieve. Evolution stops when best_score >= threshold. Can be any float value including negative numbers. TYPE: |
Examples:
stopper = ScoreThresholdStopper(0.9) # 90% target
stopper = ScoreThresholdStopper(-0.5) # For negative score domains
Note
Compared to timeout values, threshold has no restrictions on sign or magnitude since score domains vary by application.
Source code in src/gepa_adk/adapters/stoppers/threshold.py
__call__ ¶
__call__(state: StopperState) -> bool
Check if evolution should stop due to reaching threshold.
| PARAMETER | DESCRIPTION |
|---|---|
state | Current evolution state snapshot containing best_score. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bool | True if best score meets or exceeds threshold, False otherwise. |
Examples:
stopper = ScoreThresholdStopper(0.9)
# Below threshold
state1 = StopperState(
iteration=5,
best_score=0.85,
stagnation_counter=0,
total_evaluations=25,
candidates_count=1,
elapsed_seconds=30.0,
)
stopper(state1) # False
# At threshold
state2 = StopperState(
iteration=10,
best_score=0.9,
stagnation_counter=1,
total_evaluations=50,
candidates_count=2,
elapsed_seconds=65.0,
)
stopper(state2) # True
Note
Often called after each iteration. Returns True as soon as the threshold is reached.