refactor(genetic0): refactor GENETIC0 to consolidated optimizer architecture

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)
This commit is contained in:
Bobby Noelte
2026-11-27 13:55:41 +01:00
co-authored by Claude Opus 5.5
parent 9adf7b8be2
commit 40d0fab9d2
89 changed files with 44476 additions and 3933 deletions
+1 -1
View File
@@ -10,7 +10,7 @@
| algorithm | `EOS_OPTIMIZATION__ALGORITHM` | `<enum 'OptimizationAlgorithm'>` | `rw` | `required` | Optimization algorithm [GENETIC | GENETIC0]. Defaults to GENETIC. |
| algorithms | | `list[str]` | `ro` | `N/A` | Available optimization algorithms. |
| genetic | `EOS_OPTIMIZATION__GENETIC` | `GeneticCommonSettings` | `rw` | `required` | GENETIC optimization algorithm configuration. |
| genetic0 | `EOS_OPTIMIZATION__GENETIC0` | `Genetic0CommonSettings` | `rw` | `required` | GENETIC0 optimization algorithm configuration. |
| genetic0 | `EOS_OPTIMIZATION__GENETIC0` | `Genetic0Settings` | `rw` | `required` | GENETIC0 optimization algorithm configuration. |
| keys | | `list[str]` | `ro` | `N/A` | The keys of the solution. |
| self_consumption_interpolator | `EOS_OPTIMIZATION__SELF_CONSUMPTION_INTERPOLATOR` | `<enum 'GridInterpolatorBackend'>` | `rw` | `scipy` | How the inverter's self-consumption probability table is evaluated [scipy | numpy]. 'scipy' (default) uses scipy.interpolate. 'numpy' gives the same values without importing SciPy, which saves about 35 MB RSS after the first optimization run (useful on devices with little RAM); a run takes about 2.5 % longer. |
:::
+33 -1
View File
@@ -143,7 +143,7 @@ Note:
**Request Body**:
- `application/json`: {
"$ref": "#/components/schemas/Genetic0OptimizationParameters-Input"
"$ref": "#/components/schemas/Genetic0Request-Input"
}
**Responses**:
@@ -776,6 +776,28 @@ The legacy /visualization_results.pdf route continues to serve GENETIC0.
---
## GET /v1/energy-management/optimization/solution/GENETIC0
<!-- pyml disable line-length -->
**Links**: [local](http://localhost:8503/docs#/default/fastapi_energy_management_optimization_solution_genetic0_get_v1_energy-management_optimization_solution_genetic0_get), [eos](https://petstore3.swagger.io/?url=https://raw.githubusercontent.com/Akkudoktor-EOS/EOS/refs/heads/main/openapi.json#/default/fastapi_energy_management_optimization_solution_genetic0_get_v1_energy-management_optimization_solution_genetic0_get)
<!-- pyml enable line-length -->
Fastapi Energy Management Optimization Solution Genetic0 Get
<!-- pyml disable line-length -->
```python
"""
Get the latest GENETIC0 specific solution of the optimization.
"""
```
<!-- pyml enable line-length -->
**Responses**:
- **200**: Successful Response
---
## GET /v1/energy-management/optimization/solution/{algorithm}
<!-- pyml disable line-length -->
@@ -789,6 +811,8 @@ Fastapi Energy Management Optimization Solution Algorithm Get
"""
Get the latest algorithm specific solution of the optimization.
Optimizers of the registry serve their own solution path (e.g. ``.../solution/GENETIC0``).
Args:
algorithm: Optimization algorithm
"""
@@ -2380,6 +2404,14 @@ Return:
Get Pdf
<!-- pyml disable line-length -->
```python
"""
PDF report of the latest GENETIC0 run.
"""
```
<!-- pyml enable line-length -->
**Responses**:
- **200**: Successful Response
@@ -4,21 +4,23 @@ Every optimizer follows the same three-step interface, so the energy management
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
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 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()`.
parameters; a REST override such as `?ngen=` is passed to the preparation as an override and
so becomes part of 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.
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
@@ -37,8 +37,10 @@ The violations that exist when the test lands are listed in a baseline in the te
violation missing from the baseline fails, and so does a baseline entry that no longer occurs, so
the baseline only shrinks and every exception is visible in review. The one exception: when a
module or helper that reads the configuration is added to the list, the existing uses it reveals
are added to the baseline in the same commit. The test cannot see simulation physics moved into a
new shared module, nor a helper missing from its list; both rely on review.
are added to the baseline in the same commit. Moving or splitting a module is no exception: its
entries are relabelled to the new module one to one, in the same commit and named in the pull
request, and no entry is added. The test cannot see simulation physics moved into a new shared
module, nor a helper missing from its list; both rely on review.
## Considered Options
@@ -19,3 +19,7 @@ proven result-identical by its golden tests.
- GENETIC0 is migrated first, as the pilot; the registry and the interface arrive with its first
migration pull request. GENETIC follows.
- 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
own. It no longer writes demo providers or devices into the configuration and no longer cancels
a run; results with a complete configuration stay the same.
+3 -2
View File
@@ -412,8 +412,9 @@ as `feed_in_tariff_wh` in EUR/Wh, converted from the API's EUR/MWh prices. These
are raw market prices; no import charges or VAT are added.
Only published prices are stored. If the data does not cover the configured
GENETIC or GENETIC0 control horizon, automatic optimization cancels with a
missing tariff error instead of extending the final known price. Request, response, and storage
GENETIC control horizon, automatic optimization cancels with a missing tariff error
instead of extending the final known price. GENETIC0 carries the last known tariff
forward and logs the missing tariff as an error. Request, response, and storage
errors also fail the update, including when older prices are already stored.
Set the control horizon within the published day-ahead window to use this
provider for automatic optimization.
+4
View File
@@ -108,6 +108,10 @@ time, charging power and supported charge rates.
- Pass the previous plan's timestamp with a warmstart so it can be aligned to the new run.
Recheck custom parsers of GENETIC results; its native result and report are not the
legacy GENETIC0 response format.
- The OpenAPI schema names of the optimizers follow one scheme; fields and paths are unchanged:
GENETIC0's `Genetic0OptimizationParameters` is `Genetic0Request`, its device and forecast
models are `Genetic0<Thing>Request` and `Genetic0CommonSettings` is `Genetic0Settings`.
Clients generated from `openapi.json` must follow the new names.
The new report endpoint is
`GET /v1/energy-management/optimization/solution/GENETIC/pdf`. It renders the stored