feat(devices): add bounded slot physics for GENETIC (#1327)

* feat: adapt configuration for multi optimization algorithms

Decouple configuration from optimization algorithm parameters. Add to_[algorithm]_param() methods
to the configuration that derive optimization algorithm specific parameters from the configuration.
Add x-scope tags to the configuration options that describe for which specific algorithms the
configuration option is for.

The whole device settings are restructured. There are now general settings for the device classes
with the afore mentioned to_[algorithm]_param() methods. The general device settings got their own
directory `devices/settings`. By this the parameter class also does not have to be a pydantic model
which can be used for future optimization/ simulations speed up.

Also the parameter class for a device is now part of the device module. This better decouples and
also is the natural place for parameters of a device.

Besides this feature there are also fixes and improvements:

* feat: extend home appliance time window settings and simulation

  Home appliance can now be configured for multiple runs with per-cycle allowed time windows. The
  number of remaining cycles to plan is determined at runtime by reading the
  ``cycles_completed_measurement_key`` from the measurement store.

* feat: specialiced CycleTimeWindowSequence for time window sequences

  Sequence of time windows associated to cycles.

  This model specializes ``ValueTimeWindowSequence`` so that the ``value``
  field of each ``ValueTimeWindow`` encodes the **cycle index** (0-based
  integer) the window belongs to.

  Typical use: an appliance that must run ``n`` times per day, each run
  constrained to a distinct time window.  Assign ``value=0`` to windows
  for the first cycle, ``value=1`` for the second, and so on.  Multiple
  windows may share the same cycle index (their allowed regions are unioned).
  Windows with ``value=None`` are silently ignored by all cycle-aware methods.

* fix: Make test_configmigrate also regard the _ANY_SENTENIEL in key values

* chore: Make devices configurations a map instead of a list

  This makes config paths stable regardless of declaration order and lets each device settings
  class build its own config path from ``self.device_id`` without needing an external index.
  Tests are adapted likewise.

  Devices configurations are automatically migrated from lists to maps.

* chore: rename levelized_cost_of_storage_kwh to levelized_cost_of_storage_amt kwh

  This better fits in the naming scheme and also makes clear the costs are money.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>

* fix: runtime config update ignored by config file

Runtime settings were handed back to pydantic-settings as init settings,
which rank below the config file and the environment. Any key already
present in EOS.config.json or in the environment silently discarded the
update, so a bulk PUT /v1/config returned 200 without applying anything,
while the granular PUT /v1/config/{path} endpoint kept working.

Add a dedicated runtime settings source ranked directly below the command
line arguments and record granular updates there as well, so both
endpoints share one store that survives re-evaluation of the settings
sources. Environment variables keep precedence over the config file for
all keys that were not set at runtime.

Also repairs revert_settings() and update(), which passed their data
through the same init settings.

Closes #1303

* fix: env vars ignored on first config build

ConfigEOS.__init__ passed self as first positional argument to _setup,
which forwards it to pydantic_settings.BaseSettings.__init__. Its first
positional parameter is _case_sensitive, so the environment source
matched the upper case variable names against the lower case field names
and returned nothing. Environment settings only took effect after the
next configuration setup.

* docs: changelog for config priority fixes

* fix(config): preserve device identities and storage costs during migration

* fix(devices): preserve charge-rate typing and public import compatibility

* ruff format fix

* feat(devices): port slot-aware battery export and direct-use physics

Port scoped device changes from d2e2d58237. Keep PR #1256 parameter conversion structure and separate GENETIC0 devices. Validate physical flows and reprice changed simulation results.

Co-authored-by: Andreas <drbacke@gmx.de>

Co-authored-by: Christin <info@bikinibottom.capital>

* fix(cache): distinguish callables in the shared EMS cache

Include the function object in cache keys so methods of one interpolator cannot reuse a probability as a power value. Cover both call orders, keyword arguments, cache hits and separate closures with identical qualified names.

* fix(devices): constrain the physics port and validate export levels

Defer inactive EV deadline fields to the optimizer port, reject nonfinite export rates, and document the hourly Optimize boundary. Verify converter IDs, rates and LCOS, separate GENETIC0 interpolation, physical boundary flows and independent GENETIC repricing.

* docs(devices): regenerate slot-physics configuration and OpenAPI schemas

* fix(config): satisfy typed device conversion and migration contracts

* docs(config): refresh validated configuration prerequisite schemas

* test(devices): align physics regressions with strict type checking

* docs(devices): refresh API version after prerequisite merge

* docs(interpolator): use portable reStructuredText markup

* docs(devices): refresh API version after docstring compatibility fix

---------

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Co-authored-by: Bobby Noelte <b0661n0e17e@gmail.com>
Co-authored-by: r0b2g1t <r0b2g1t@users.noreply.github.com>
Co-authored-by: Christin <info@bikinibottom.capital>
This commit is contained in:
Andreas
2026-09-17 19:14:01 +02:00
committed by GitHub
co-authored by Andreas Christin Bobby Noelte r0b2g1t
parent 1a18935667
commit 3c862543a1
17 changed files with 1043 additions and 177 deletions
+41
View File
@@ -0,0 +1,41 @@
# Slot-aware GENETIC device physics
This package depends on the device-map and algorithm-converter configuration work
from PR #1256 and the runtime settings foundation from PR #1305. Parameter classes
remain in `devices/genetic`; settings remain in `devices/settings`.
Battery and inverter models accept a slot duration, apply power limits as energy
per slot, and preserve the total battery charge/discharge budget across multiple
calls within that slot. Battery export is an explicit device-simulation operation;
setting export rates does not by itself activate optimizer export states. The
converter carries stable device IDs, charge/export levels and LCOS unchanged.
Configuration LCOS uses amount/kWh; no Wh conversion is applied by the converter.
The GENETIC inverter now computes expected direct PV-to-load power from the
minute-load distribution, then converts power to interval energy. This changes
GENETIC simulation economics even at the default hourly interval. The probability
table was calibrated with hourly mean loads: use with quarter-hour means remains
an approximation, not a separately calibrated quarter-hour model. Its legacy
cumulative-probability API now clamps values at the table boundary and to [0, 1].
The GENETIC0 inverter uses a separate implementation and separate interpolation
data file; this package does not change either. Existing GENETIC0 optimization
and PDF golden tests remain required.
The shared in-memory cache must include callable identity in each key. Otherwise
the legacy cumulative probability and new direct-power method on the same object
can return each other's cached results for identical arguments. This package
includes that prerequisite fix and verifies both call orders and cache reuse.
This package alone does **not** make an Optimize mode quarter-hour capable.
GENETIC parameter preparation still forces the interval to 3600 seconds, and
`/optimize` still selects the separate GENETIC0 algorithm. Quarter-hour scheduling,
warm-start alignment, forecast/control horizons, terminal values, export states,
EV deadlines and flexible-consumer planning require the later optimizer port.
No inactive EV-deadline fields are introduced here.
Validation covers charge/discharge budgets, inverter/export limits, efficiencies,
energy conservation, interpolation boundaries, converter fields, both algorithms'
short optimization/PDF runs and unchanged GENETIC0 monetary goldens. GENETIC runs
use independent repricing of grid energy, schema checks and physical bounds rather
than requiring the previous direct-consumption model's monetary golden. Long
`--finalize` optimization runs and pinned CI environments remain separate checks.