Persistent state tracking the complete optimization history.
This is the heart of GEPA - all candidates, scores, Pareto fronts, and lineage are stored here.
Summary
Functions
Add a runtime-only budget hook.
Add a new program to the state and update Pareto fronts.
Return whether the state has internally consistent candidate-indexed fields.
Build state from a persisted dictionary or legacy map payload.
Return the active Pareto-front mapping for the configured frontier type.
Return average validation score and evaluated-count for a program.
Get average score for a program across evaluated validation examples.
Increment metric evaluation count and notify budget hooks.
Load persisted state from a run directory.
Load persisted state from a run directory or raise.
Create new state from seed candidate and initial evaluation.
Persist state to a run directory.
Return per-program average validation scores in candidate-index order.
Upgrade a persisted state dictionary into the current GEPA.State struct.
Return the current persisted state schema version.
Return validation ids and program indices that have evaluated them.
Write generated validation outputs to the run-directory inspection tree.
Types
@type t() :: %GEPA.State{ adapter_state: map(), best_outputs_valset: %{required(GEPA.Types.data_id()) => [{GEPA.Types.program_idx(), term()}]} | nil, budget_hooks: [(non_neg_integer(), non_neg_integer() -> term())], evaluation_cache: term() | nil, frontier_type: :instance | :objective | :hybrid | :cartesian, full_program_trace: [map()], i: integer(), list_of_named_predictors: [String.t()], named_predictor_id_to_update_next_for_program_candidate: [non_neg_integer()], num_full_ds_evals: non_neg_integer(), num_metric_calls_by_discovery: [non_neg_integer()], objective_pareto_front: %{required(String.t()) => float()}, parent_program_for_candidate: [[GEPA.Types.program_idx() | nil]], pareto_front_cartesian: %{ required({GEPA.Types.data_id(), String.t()}) => float() }, pareto_front_valset: %{required(GEPA.Types.data_id()) => float()}, prog_candidate_objective_scores: [%{required(String.t()) => float()}], prog_candidate_val_subscores: [GEPA.Types.sparse_scores()], program_at_pareto_front_cartesian: %{ required({GEPA.Types.data_id(), String.t()}) => MapSet.t(GEPA.Types.program_idx()) }, program_at_pareto_front_objectives: %{ required(String.t()) => MapSet.t(GEPA.Types.program_idx()) }, program_at_pareto_front_valset: GEPA.Types.pareto_fronts(), program_candidates: [GEPA.Types.candidate()], total_num_evals: non_neg_integer(), validation_schema_version: pos_integer() }
Functions
@spec add_budget_hook(t(), (non_neg_integer(), non_neg_integer() -> term())) :: t()
Add a runtime-only budget hook.
Hooks are invoked by increment_evals/2 and intentionally omitted from
persisted state.
@spec add_program( t(), GEPA.Types.candidate(), [GEPA.Types.program_idx()], GEPA.Types.sparse_scores(), Keyword.t() ) :: {t(), GEPA.Types.program_idx()}
Add a new program to the state and update Pareto fronts.
Parameters
state: Current statenew_candidate: New program to addparent_program_ids: List of parent indicesval_scores: Map of val_id -> score for new program
Returns
{new_state, new_program_idx} tuple
Return whether the state has internally consistent candidate-indexed fields.
Build state from a persisted dictionary or legacy map payload.
Return the active Pareto-front mapping for the configured frontier type.
@spec get_program_average_val_subset(t(), GEPA.Types.program_idx()) :: {float(), non_neg_integer()}
Return average validation score and evaluated-count for a program.
@spec get_program_score(t(), GEPA.Types.program_idx()) :: {float(), non_neg_integer()}
Get average score for a program across evaluated validation examples.
Returns
{average_score, count} tuple
@spec increment_evals(t(), non_neg_integer()) :: t()
Increment metric evaluation count and notify budget hooks.
Load persisted state from a run directory.
Load persisted state from a run directory or raise.
@spec new( GEPA.Types.candidate(), GEPA.EvaluationBatch.t(), [GEPA.Types.data_id()], Keyword.t() ) :: t()
Create new state from seed candidate and initial evaluation.
Parameters
seed_candidate: Initial program as map of component name -> texteval_batch: Results from evaluating seed on validation setvalset_ids: List of validation example IDs
Returns
New GEPA.State struct initialized with seed program
Persist state to a run directory.
GEPA Ex writes gepa_state.etf instead of upstream Python's pickle-based
gepa_state.bin, and also writes human-readable candidates.json and
run_log.json when available.
Return per-program average validation scores in candidate-index order.
Upgrade a persisted state dictionary into the current GEPA.State struct.
Accepts atom or string keys and migrates legacy list-shaped validation fields to sparse maps.
@spec validation_schema_version() :: pos_integer()
Return the current persisted state schema version.
@spec valset_evaluations(t()) :: %{ required(GEPA.Types.data_id()) => [GEPA.Types.program_idx()] }
Return validation ids and program indices that have evaluated them.
@spec write_valset_outputs( Path.t() | nil, [GEPA.Types.data_id()], [term()], integer(), GEPA.Types.program_idx() ) :: :ok
Write generated validation outputs to the run-directory inspection tree.