docs(optimization): record the lessons of the GENETIC0 migration

Additional changes
- Correct a stale GENETIC0 docstring.
- Count infinite readings and predictions as missing in the energy-domain rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
This commit is contained in:
Bobby Noelte
2026-11-27 13:55:41 +01:00
co-authored by Claude Opus 5.5
parent 40d0fab9d2
commit 8c06245e8b
11 changed files with 145 additions and 19 deletions
@@ -24,3 +24,7 @@ run and the prediction series the run was optimized against.
- An optimizer can be run, tested and replayed from a stored set of optimization parameters alone.
- The optimization parameters grow to carry presentation data (time zone, device IDs, start
datetime, the prediction series used).
- The presentation data cover every entry point, not only the automatic run. A client's
optimization request may start in another time zone than the configured one or carry longer
arrays, so the prepared series span the widest window the conversion can need, and the
conversion takes its own share of them (GENETIC0 migration).
@@ -1,13 +1,15 @@
# Optimizers implement prepare, run and convert
Every optimizer follows the same three-step interface, so the energy management can drive any of
Every optimizer follows the same three-step interface (prepare, run, convert), 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`).
start, the observation time, the warm start and run-time overrides), `run()`, `convert()`
(asynchronous), which returns the optimization solution and the energy management plan, and
`api()`, which hands out the optimizer's REST router
([0011](0011-optimizer-api-visualization-and-wizard-get-no-exception.md)). 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.
@@ -14,10 +14,18 @@ proven result-identical by its golden tests.
## Consequences
- Before an optimizer is refactored, its golden tests are extended with replay files: complete
optimization parameters in the new parameter type plus the expected result.
- Before an optimizer is refactored, characterization tests pin its whole output per golden
input: the optimization solution, the energy management plan and the visualization, not only
the raw result. The raw result alone missed most of what the GENETIC0 migration moved.
- Replay files (complete optimization parameters in the new parameter type plus the expected
result) are added as soon as the optimizer has its parameter type, in the same pull request.
- Code that breaks an architecture rule in a way whose fix changes results (e.g. a parameter
preparation that writes the configuration or cancels the run) is first moved unchanged; the fix
follows in its own declared behaviour-change pull request.
- A refactoring reproduces known bugs of the old output too (GENETIC0 always reports the EV and
home appliance IDs `ev1` and `homeappliance1`); they are reported, not fixed on the way.
- GENETIC0 is migrated first, as the pilot; the registry and the interface arrive with its first
migration pull request. GENETIC follows.
migration pull request. GENETIC follows on the same path.
- A GENETIC0 bug that matters to users is fixed in GENETIC (or a new optimizer), not in GENETIC0.
- One declared exception: GENETIC0's parameter preparation follows the "optimization parameters
are always valid" rule of the `energy-domain` skill, in a behaviour-change pull request of its
@@ -20,4 +20,13 @@ requests are Pydantic models, and the settings models of the configuration stay
- An invalid optimization parameter set is a bug in parameter preparation, found by its tests,
not a validation error at run time.
- Replay files need an explicit (de)serialization of the dataclasses instead of Pydantic's.
- Replay files need an explicit (de)serialization of the dataclasses instead of Pydantic's; a
test asserts that the round trip is lossless.
- The simulation's device parameters are derived from the optimization request by pure functions
(no configuration, no clock, no change to the request), so a replay file may store the request
and derive them again. GENETIC0's home appliance still reads today's date there and writes a
default time window into the request; it is frozen.
- The optimization result is a frozen dataclass as well. Where public response models are built
from it, its values are normalised as those models validate them (NumPy arrays to lists, NaN to
`None`, the fields' number types), so the responses do not change when the result stops being
a Pydantic model.
@@ -20,7 +20,10 @@ fit a role use the `<name>` prefix as well, also inside subdirectories such as `
- The public classes are renamed (e.g. `GeneticOptimizationParameters` → `GeneticRequest`,
`GeneticCommonSettings` → `GeneticSettings`). Field names and payloads stay unchanged; the
schema names in OpenAPI and the configuration documentation change.
schema names in OpenAPI and the configuration documentation change. Nested request models are
renamed `<Name><Thing>Request` as well (e.g. `Genetic0InverterParameters` →
`Genetic0InverterRequest`); the name `<Name><Device>Parameters` belongs to the simulation's
device dataclasses.
- `devices/genetic/` and `devices/genetic0/` move into the optimizer directories. For the frozen
GENETIC0 ([0008](0008-optimizer-refactoring-preserves-results.md)) the moves and renames are
structural changes, proven by its golden tests.
@@ -13,7 +13,11 @@ state today. None of them gets an exception from
through FastAPI's `app.dependency_overrides`, using the registry. The router may import FastAPI,
Pydantic and its own optimization request, never configuration, EMS state or the server
(`akkudoktoreos.server`). No other part of the optimizer, its parameter preparation included,
imports the server either.
imports the server either. It reports errors as the generic `OptimizerProblem`, which the server
renders like its own problem responses, and it holds the public response models, built from the
optimization parameters and result. The server includes the optimizers' routers before its own
routes, so an optimizer's specific path (`.../solution/GENETIC0`) wins over a generic one
(`.../solution/{algorithm}`).
- Wizard steps are not code. They are metadata on the fields of `<name>settings.py` (which fields
the wizard asks for, and in which order), which EOSdash reads; an optimizer contains no EOSdash
code.