Pin the conversion, plan and visualization of golden runs. Drive GENETIC0 through the optimizer registry. Move GENETIC0 into one directory with role-named modules. Prepare every run input once, run from the parameters. Fall back on bad inputs instead of cancelling the run. Simulate from frozen device dataclasses, not settings. Convert and visualize from the parameters and result only. Serve GENETIC0 from its own router, return a frozen result. Additional changes - Fix the run start of the golden runs and add a run across the DST switch. - Configure a home appliance so the conversion covers it. - Pass the warm start to the legacy preparation instead of reading the EMS. - Replace EnergyManagement.genetic0_solution() by optimizer_result(name). - Cover the warm start of the parameter preparation. - Rename Genetic0OptimizationParameters to Genetic0Request, Genetic0CommonSettings to Genetic0Settings. - Say in ADR 0007 and the skill that a move relabels baseline entries one to one. - Record the renamed OpenAPI schemas in CHANGELOG.md and the upgrade guide. - Add the observation time to the optimizer interface. - Cache the load interpolator by its backend instead of in the EMS run cache. - Add replay files that reproduce each golden result from its parameters. - Stop writing demo providers, demo devices and defaults into the configuration. - Count a NaN state of charge as invalid. - Remove the unused electricity fee check. - Record the fallbacks in CHANGELOG.md instead of the former demo providers. - Leave out a battery that is not linked to the inverter. - Count infinite forecast values as missing. - Extend a prediction.hours that leaves fewer than two hours after the start hour. - Do not charge from the grid without any known price. - Without an inverter, buy the whole load from the grid instead of planning it at no cost. - Keep the zone of the run start in the replay files. - Correct the DVhub documentation that said a missing tariff cancels the run. - Rename the request models to <Name><Thing>Request. - Move the settings' to_genetic0_*() converters into the preparation. - Remove the solution's unreachable configuration fallbacks. - Record the renamed OpenAPI schemas in CHANGELOG.md and the upgrade guide. - Add EnergyManagement.optimizer_run() and render the PDF from the run's own start. - Read the presentation series from the earlier of the run's start hours. - Render the PDF report for runs of any length, not only 48 hours. - Add the generic OptimizerProblem, rendered like EOSProblem. - Move Genetic0ParametersBaseModel into genetic0request.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Assisted-by: Claude Code (claude-opus-5-5)
3.2 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, the observation time, the warm start and run-time overrides), run() and convert()
(asynchronous), 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 returnsNone(see theenergy-domainskill); 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 passed to the preparation as an override and so becomes part of the parameters beforerun().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, the observation time (the unrounded moment measurements refer to) 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.