Files
EOS/docs/adr/0007-architecture-test-with-shrinking-baseline.md
T
Bobby NoelteandClaude Opus 5.5 40d0fab9d2 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)
2026-11-27 13:55:41 +01:00

50 lines
3.4 KiB
Markdown

# An architecture test with a shrinking baseline enforces the optimizer boundaries
The optimizer rules ([0003](0003-optimizers-see-only-their-optimization-parameters.md) to
[0006](0006-optimizer-interface-prepare-run-convert.md)) are mostly import rules, and a skill alone
does not stop an agent or a contributor from breaking them. So `tests/test_optimizerarchitecture.py`
parses the imports of the source tree with `ast` and fails when
- an optimizer imports another optimizer,
- code outside an optimizer imports anything from it but its packages themselves (`__init__.py`),
- the shared device configuration imports an optimizer at all, so settings cannot build optimization
parameters ([0004](0004-optimizers-duplicate-code-instead-of-sharing-it.md)),
- a module of an optimizer other than its parameter preparation imports a module or name that
reads configuration, predictions, measurements or EMS state,
- parameter preparation imports EMS state or the server,
- a module of an optimizer other than `<name>optimizer.py`, its package `__init__.py` and the
parameter preparation itself imports the parameter preparation, the optimizer's own package or
`<name>optimizer.py` (both may re-export it; only the package imports `<name>optimizer.py`), so
no other module reaches the configuration through it,
- a module other than settings, request, preparation and API
([0010](0010-one-directory-and-one-naming-scheme-per-optimizer.md)) imports Pydantic
([0009](0009-optimization-parameters-are-dataclasses.md)).
The test holds the one authoritative list of these modules and names, including helpers that read
the configuration, the server (`akkudoktoreos.server`,
[0011](0011-optimizer-api-visualization-and-wizard-get-no-exception.md)), the shared device
configuration (`devices.settings`, `devices.profile`, `devices.devices`, `devices.devicesabc`) and
the contract classes that may be imported from a module that mixes them with configuration
(`optimization.optimization`). Parameter preparation is recognized by its file name,
`optimization/<name>/<name>prepare.py` or a subpackage `optimization/<name>/prepare/` (a plain
module `prepare.py` does not count); the settings
model `optimization/<name>/<name>settings.py` may import `config.configabc` to define
`optimization.<name>`. The test discovers the optimizers (every package under `optimization/`), so
adding one does not touch it; until the simulation devices have moved into the optimizer
directory, `devices/<name>` counts as part of the optimizer.
The violations that exist when the test lands are listed in a baseline in the test file. A
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. 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
- **`import-linter`**: rejected, it adds a dependency for checks a short `ast` walk can do.
- **Refactor first, then add the test without a baseline**: rejected, the boundaries would stay
unprotected for the whole migration.