Run

The configuration-driven entry point. run takes a parsed TOML config dict, dynamically imports the problem-specific components it names (data schema, adapter, checker, tools), builds a validated SolverConfig plus the run parameters, and delegates to Runner.run. main is the python -m ape command-line wrapper around it; ConfigError is raised for malformed configuration.

See the TOML configuration reference for the schema this module parses.

run

Configuration-driven runner for the APE framework.

Reads a TOML config file, dynamically imports problem-specific components (data schemas, checkers, adapters, tools), builds a fully validated :class:SolverConfig plus the remaining run parameters, and delegates execution to Runner.run().

Can be used either as a library function via run() or as a standalone entry point via python -m ape <config.toml> (python -m ape.run also works, but emits a harmless RuntimeWarning).

See docs/config.md for the full TOML schema and ape/config_reference.toml for a fully-populated example (also printable via python -m ape config-schema).

ConfigError

Bases: ValueError

Raised when the TOML configuration is malformed.

run

run(config: dict[str, Any], project_root: Path, output_dir: Path | None = None, on_batch_saved: Callable[[OutputBatch[Any, Any]], None] | None = None) -> None

Execute a full APE run driven by a parsed TOML configuration dict.

Parameters

config : dict[str, Any] The parsed TOML configuration dictionary. project_root : Path Root directory used to resolve relative paths found in the config (data files, prompt templates, etc.). output_dir : Path | None Optional directory to place output files, overriding config paths. on_batch_saved : Callable | None Optional callback invoked after each output batch has been persisted by the built-in save handler. If both this argument and a [hooks] on_batch_saved entry in the config are provided, the explicit argument wins. Exceptions raised by the callback are logged and swallowed so a faulty hook cannot lose results or stop the run.

main

main() -> None

CLI entry point for running APE from a TOML configuration file.

Usage::

python -m ape config.toml
python -m ape config.toml -r /path/to/project
python -m ape config-schema
python -m ape config-schema -o config.toml
python -m ape config-edit config.toml
python -m ape visualize output/
python -m ape visualize output/results.jsonl