Files
EOS/docs/adr/0006-optimizer-interface-prepare-run-convert.md
T
Bobby NoelteandClaude Opus 5.5 9adf7b8be2 docs(optimization): add optimizer architecture ADRs, skill and test (#1572)
Additional changes
- Add the optimizer terms to the glossary.
- Point to the skill from AGENTS.md, docs/develop/ai.md and the energy-domain skill.
- Match module names case-exactly, also on case-insensitive file systems.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-27 13:55:41 +01:00

3.0 KiB

Optimizers implement prepare, run and convert

Every optimizer follows the same three-step interface, so the energy management can drive any of them the same way and every run can be replayed from its optimization parameters. The interface is a Protocol generic in the optimizer's optimization parameters P, optimization request Q and optimization result R, with prepare() and prepare_from_request() (asynchronous, given the run start and the warm start), run() and convert(), the latter returning the optimization solution and the energy management plan. Its current signature is kept in one place, the optimizer-architecture skill (ai/skills/optimizer-architecture/SKILL.md).

  • prepare() is the parameter preparation. It never fails and never returns None (see the energy-domain skill); the energy management never cancels a run because of it.
  • run() is CPU-bound and deterministic: the same optimization parameters give the same result. All algorithm settings (generations, individuals, seed, penalties) are part of the optimization parameters; a REST override such as ?ngen= is applied to the parameters before run().
  • convert() is the solution conversion and uses only the parameters and the result.

The energy management is the only owner of run state. It keeps the last result per optimizer and passes the run start and that result (the warm start) to prepare() as arguments, so no part of an optimizer reads EMS state; the warm start and its start datetime travel into run() inside the optimization parameters.

Optimization requests from clients (the parameters accepted by POST /optimize and the GENETIC0 legacy endpoint, and ConfigOptimizationRequest) never go straight into run(). They keep their public schema (Q) and go through the optimizer's parameter preparation, prepare_from_request(), which fills everything the request does not carry (time zone, device IDs, algorithm settings) from the configuration and applies the same fallback rules as prepare(). A malformed request is still rejected (422) before preparation; a request that is valid but incomplete is completed, never rejected. So run() and convert() only ever see complete optimization parameters, whatever the entry point.

Considered Options

  • Preparation reads the previous result from the energy management: rejected. It keeps the optimizer coupled to EMS internals (today get_ems().genetic_solution()), and a run cannot be reproduced from its parameters alone.
  • Algorithm settings passed beside the parameters: rejected. A stored parameter set would not be enough to replay a run.
  • Clients send complete optimization parameters: rejected. The presentation data required by 0003 would break every existing client of the public API.

Consequences

  • The energy management stores results per optimizer in one generic slot, not one attribute per optimizer.
  • An optimization run that cannot be reproduced from its stored optimization parameters is a bug.