mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-12-02 18:36:28 +01:00
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:
co-authored by
Claude Opus 5.5
parent
9adf7b8be2
commit
40d0fab9d2
@@ -13,7 +13,7 @@ parameters**, **solution conversion**, **warm start**. The decisions and their r
|
||||
|
||||
| Part | May use |
|
||||
|---|---|
|
||||
| Parameter preparation (`<name>prepare.py` or `prepare/`) | configuration, predictions, measurements, and the run start and warm start passed in as arguments |
|
||||
| Parameter preparation (`<name>prepare.py` or `prepare/`) | configuration, predictions, measurements, and the run start, observation time and warm start passed in as arguments |
|
||||
| Algorithm (`run()`) | the optimization parameters only |
|
||||
| Simulation and simulation devices | the optimization parameters only |
|
||||
| Solution conversion (`convert()`) | the optimization parameters and the result of the run only |
|
||||
@@ -51,17 +51,33 @@ This is the one maintained copy of the interface; ADR 0006 records the decision
|
||||
```python
|
||||
class Optimizer(Protocol[P, Q, R]):
|
||||
name: str
|
||||
async def prepare(self, start_datetime: DateTime, warm_start: R | None) -> P
|
||||
async def prepare(
|
||||
self, start_datetime: DateTime, observation_datetime: DateTime,
|
||||
warm_start: R | None, overrides: Mapping[str, Any] | None = None,
|
||||
) -> P
|
||||
async def prepare_from_request(
|
||||
self, request: Q, start_datetime: DateTime, warm_start: R | None
|
||||
self, request: Q, start_datetime: DateTime, observation_datetime: DateTime,
|
||||
warm_start: R | None, overrides: Mapping[str, Any] | None = None,
|
||||
) -> P
|
||||
def run(self, parameters: P) -> R
|
||||
def convert(self, parameters: P, result: R) -> tuple[OptimizationSolution, EnergyManagementPlan]
|
||||
def api(self) -> OptimizerApi | None
|
||||
async def convert(
|
||||
self, parameters: P, result: R
|
||||
) -> tuple[OptimizationSolution, EnergyManagementPlan]
|
||||
```
|
||||
|
||||
The code is `akkudoktoreos.optimization.optimizer.Optimizer`; the energy management finds an
|
||||
optimizer through `akkudoktoreos.optimization.optimizerregistry.get_optimizer(name)` and keeps
|
||||
the last parameters and result per optimizer (`OptimizerRun`); the result is the next warm start.
|
||||
`start_datetime` is the start of the run's first slot; `observation_datetime` is the unrounded
|
||||
moment of the run that measurements (e.g. a measured state of charge) refer to.
|
||||
|
||||
- `run()` is deterministic: the same optimization parameters give the same result. Generations,
|
||||
individuals, seed and penalties are part of the optimization parameters; apply a REST override
|
||||
(e.g. `?ngen=`) to the parameters before `run()`, never beside them.
|
||||
individuals, seed and penalties are part of the optimization parameters. A run-time override
|
||||
(e.g. `?ngen=`) reaches the preparation as `overrides` (`{"generations": 10}`), never beside the
|
||||
parameters; the preparation applies the keys it knows and logs an error for any other key.
|
||||
- `convert()` is `async`, so that an optimizer can migrate step by step while its conversion
|
||||
still awaits reads; once it uses only the parameters and the result, it awaits nothing.
|
||||
- **Optimization parameters (`P`), including the simulation's device
|
||||
parameters, are plain dataclasses, never Pydantic models** (ADR 0009). They
|
||||
are valid because parameter preparation builds them valid, not because a
|
||||
@@ -139,10 +155,14 @@ None of these gets an exception from the hard rule (ADR 0011):
|
||||
- `<name>visualize.py` renders from the optimization parameters and result
|
||||
only, like `convert()`.
|
||||
- `<name>api.py` fetches nothing itself. It declares placeholder dependency
|
||||
functions for the last parameters and result and the run trigger; the
|
||||
generic server fills them in through `app.dependency_overrides` from the
|
||||
registry. It imports FastAPI, Pydantic and its request, never
|
||||
configuration, EMS state or `akkudoktoreos.server`.
|
||||
functions for the last parameters and result and the run trigger and hands
|
||||
them out with its router as `OptimizerApi(router, last_run, run)` through
|
||||
`api()`; the generic server includes every registered router (before its own
|
||||
routes, so a specific path wins) and fills the placeholders through
|
||||
`app.dependency_overrides`. Errors are `OptimizerProblem`s, which the server
|
||||
renders like its own RFC 7807 problems. It imports FastAPI, Pydantic and its
|
||||
request, never configuration, EMS state or `akkudoktoreos.server`. The public
|
||||
response models live there and are built from the parameters and the result.
|
||||
- Wizard steps are field metadata in `<name>settings.py` that EOSdash reads;
|
||||
no EOSdash code inside an optimizer.
|
||||
|
||||
@@ -173,6 +193,8 @@ against `BASELINE`, the violations that existed when it was introduced.
|
||||
- Otherwise never add an entry to `BASELINE`, and never rename a module to
|
||||
`*prepare.py` or `*settings.py` just to pass the test. Remove the entries
|
||||
your change fixes; the test fails on stale entries.
|
||||
- Moving or splitting a module relabels its entries to the new module one to
|
||||
one, in the same commit and named in the pull request; it adds none.
|
||||
- The test discovers optimizers (every package under `optimization/`); do not
|
||||
hard-code optimizer names in it.
|
||||
- It cannot detect simulation physics moved into a new shared module, nor a
|
||||
|
||||
Reference in New Issue
Block a user