Timeout
timeout ¶
Timeout stopper for evolution termination after elapsed time.
This module provides a TimeoutStopper that terminates evolution after a specified wall-clock duration, useful for fitting evolutions into CI/CD pipelines and controlling resource usage.
| ATTRIBUTE | DESCRIPTION |
|---|---|
TimeoutStopper | Stop evolution after a specified timeout. TYPE: |
Examples:
Basic usage with evolution config:
from gepa_adk.adapters.stoppers import TimeoutStopper
stopper = TimeoutStopper(300.0) # 5 minutes
# Use stopper in evolution config
Note
This stopper is the simplest implementation and serves as a good template for other stoppers.
TimeoutStopper ¶
Stop evolution after a specified timeout.
Terminates evolution when wall-clock time exceeds the configured timeout duration. Useful for resource management and CI/CD pipelines.
| ATTRIBUTE | DESCRIPTION |
|---|---|
timeout_seconds | Maximum wall-clock time for evolution. TYPE: |
Examples:
Creating a 5-minute timeout:
from gepa_adk.adapters.stoppers import TimeoutStopper
from gepa_adk.domain.stopper import StopperState
stopper = TimeoutStopper(300.0) # 5 minutes
state = StopperState(
iteration=10,
best_score=0.8,
stagnation_counter=2,
total_evaluations=50,
candidates_count=3,
elapsed_seconds=400.0, # Exceeds timeout
)
stopper(state) # Returns True (should stop)
Note
All timeout values must be positive. Zero and negative values raise ValueError to prevent invalid configurations.
Source code in src/gepa_adk/adapters/stoppers/timeout.py
30 31 32 33 34 35 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 | |
__init__ ¶
Initialize timeout stopper with maximum duration.
| PARAMETER | DESCRIPTION |
|---|---|
timeout_seconds | Maximum wall-clock time for evolution in seconds. Must be a positive value. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
ValueError | If timeout_seconds is zero or negative. |
Examples:
Note
Consider using reasonable timeouts for your use case. Very short timeouts may not allow sufficient evolution progress.
Source code in src/gepa_adk/adapters/stoppers/timeout.py
__call__ ¶
__call__(state: StopperState) -> bool
Check if evolution should stop due to timeout.
| PARAMETER | DESCRIPTION |
|---|---|
state | Current evolution state snapshot containing elapsed_seconds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bool | True if elapsed time meets or exceeds timeout, False otherwise. |
Examples:
stopper = TimeoutStopper(60.0)
# Not yet timed out
state1 = StopperState(
iteration=5,
best_score=0.5,
stagnation_counter=0,
total_evaluations=25,
candidates_count=1,
elapsed_seconds=30.0,
)
stopper(state1) # False
# Timed out
state2 = StopperState(
iteration=10,
best_score=0.7,
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 time limit is reached.