EvalServer¶
gepa.optimize_anything.EvalServer(task: Task, evaluate: Callable[..., Any] | None, budget: BudgetTracker, *, batch_evaluate: Callable[..., Any] | None = None, max_concurrency: int = DEFAULT_MAX_CONCURRENCY, output_dir: str | Path | None = None)
¶
Eval server with budget enforcement — the single source of truth.
In-process engines call :meth:evaluate directly. External engines POST
to :attr:url. Both go through the same budget counter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Task
|
Task definition (name, datasets, objective/background). |
required |
evaluate
|
Callable[..., Any] | None
|
Per-pair scoring function. Optional when |
required |
budget
|
BudgetTracker
|
Budget tracker for limiting evaluations. |
required |
batch_evaluate
|
Callable[..., Any] | None
|
Optional grouped scoring function taking a list of
|
None
|
max_concurrency
|
int
|
Max parallel evaluations. Defaults to 8. |
DEFAULT_MAX_CONCURRENCY
|
output_dir
|
str | Path | None
|
If set, each eval is persisted as |
None
|
Source code in gepa/oa/eval_server.py
Attributes¶
task = task
instance-attribute
¶
batch_fn = _normalize_batch_fn(batch_evaluate) if batch_evaluate is not None else None
instance-attribute
¶
eval_fn: Callable[..., tuple[float, dict[str, Any]]] = _normalize_eval_fn(evaluate)
instance-attribute
¶
budget = budget
instance-attribute
¶
max_concurrency = max_concurrency
instance-attribute
¶
best_score: float = float('-inf')
instance-attribute
¶
best_candidate: str | dict[str, str] = task.seed_candidate or ''
instance-attribute
¶
total_cost: float = 0.0
instance-attribute
¶
eval_log: list[dict[str, Any]] = []
instance-attribute
¶
output_dir: Path | None = None
instance-attribute
¶
progress_log: list[dict[str, Any]]
property
¶
port: int
property
¶
url: str
property
¶
Methods:¶
iter_split(split: str) -> Iterator[tuple[str, Any]]
¶
Yield (id, item) pairs for the given split (train/val).
The server holds no test split, so iter_split("test") yields
nothing; test is scored by the optimize_anything runner directly.
Source code in gepa/oa/eval_server.py
evaluate(candidate: str, example: Any | None = None, **kwargs: Any) -> tuple[float, dict[str, Any]]
¶
Evaluate a candidate with budget enforcement.
Failed attempts consume budget (launcher parity). Extra kwargs (e.g.
opt_state) are forwarded to the evaluator only if its signature
accepts them.
Raises:
| Type | Description |
|---|---|
BudgetExhausted
|
When the budget has been used up. |
Source code in gepa/oa/eval_server.py
evaluate_batch(pairs: list[tuple[str, Any]], opt_states: list[Any] | None = None) -> list[tuple[float, dict[str, Any]]]
¶
Evaluate pairs in ONE call to the user's batch_evaluate function.
The grouped analogue of :meth:evaluate (e.g. to submit a provider
batch job): the user function receives all pairs at once; each pair is
then recorded against the budget and tracked individually. The budget
is checked once up front, so a batch may overshoot the cap by at most
len(pairs) - 1 — mirroring the launcher's iteration-boundary stops.
Failed attempts consume budget (launcher parity): a failed grouped
call records one tick per pair.
Raises:
| Type | Description |
|---|---|
BudgetExhausted
|
When the budget is already used up. |
RuntimeError
|
When the server was constructed without |
Source code in gepa/oa/eval_server.py
evaluate_examples(candidate: str, example_ids: list[str] | None = None, split: str | None = None) -> tuple[float, dict[str, Any]]
¶
Evaluate a candidate on specific examples or a whole split, in parallel.
Provide either example_ids or split ("train"/"val"/
"all"); example_ids takes precedence. The server holds no
test split, so "all" means train+val. For single-task tasks,
delegates to :meth:evaluate.
Returns:
| Type | Description |
|---|---|
tuple[float, dict[str, Any]]
|
(average_score, info_dict) with per-example scores and metadata. |
Source code in gepa/oa/eval_server.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
validate(candidate: str) -> dict[str, Any]
¶
Evaluate candidate on the hidden val_set and log progress.
Source code in gepa/oa/eval_server.py
log_progress(val_score: float, candidate: str | None = None, reflection_cost: float = 0.0) -> dict[str, Any]
¶
Record a progress checkpoint.
Source code in gepa/oa/eval_server.py
start(port: int = 0) -> int
¶
Start the HTTP server. Returns the bound port.