refactor(genetic): refactor GENETIC to the consolidated optimizer architecture

Pin result, conversion, plan and visualization of golden runs.
Drive GENETIC through the optimizer interface and registry.
Move GENETIC into one directory with role-named modules.
Prepare every run input once, run from the parameters.
Fall back instead of cancelling the optimization run.
Simulate battery, EV and inverter from frozen dataclasses.
Simulate the home appliance from frozen dataclasses.
Convert and visualize from the parameters and result only.
Serve GENETIC from its own router.
Return a frozen result, build responses in the API.
Echo the request as sent, not with an invented time window.

Additional changes
- Pin that the result does not depend on the number of evaluation workers.
- Run the golden module in UTC: until the request date-times are held in UTC they render in the host time zone.
- Add Optimizer.run_clock(), so the EMS gets slot length and time zone without GENETIC settings.
- Rename ConfigOptimizationRequest, RuntimeForecasts and GeneticCommonSettings as ADR 0010 asks.
- Correct the request example in ADR 0010.
- Record the renamed OpenAPI schemas in CHANGELOG.md and the upgrade guide.
- Add replay files that reproduce each golden result from its parameters.
- Drop OptimizationBase from the algorithm.
- Give the replay and worker tests own review files against xdist races.
- Handle a failing preparation in the EMS like a failing run, no separate cancel path.
- Record the fallbacks in CHANGELOG.md and the upgrade guide.
- Without an inverter, buy the whole load from the grid instead of planning it at no cost.
- Do not charge from the grid without any known price.
- Treat an infinite value after the control horizon as a gap.
- Correct the documentation that said missing forecasts cancel the run.
- Copy the efficiency helpers and the self-consumption table evaluation into GENETIC.
- Add CycleTimeWindowSequence, ConsumerScheduleMode and ConsumerDeadlinePolicy as contract names.
- Hold the date-times of battery, EV and home appliance requests in UTC, so they render the same on every host.
- Drop the UTC pin of the GENETIC golden module; the request date-times no longer depend on the host.
- Copy the time window logic GENETIC needs into genetictimewindow.py.
- Add ValueTimeWindow as a contract name.
- Move the settings' to_genetic_*() converters into the preparation.
- Drop the conversion's prediction reads and configuration fallbacks, which runs never reached.
- Make the moved docstrings valid reST.
- Remove the generic optimization solution route; each optimizer serves its own path.
- Import the GENETIC settings from the package.
- Record the removed route in CHANGELOG.md and the upgrade guide.
- Make the terminal and tail value models frozen dataclasses.
- Move the response models into geneticapi; remove geneticsolution and geneticabc.
- Remove the legacy appliance start arrays and API, which read the wall clock.
- Remove the time window helpers only they used.
- Echo a start_solution without start_solution_datetime as sent.
- Carry the previous solution's start in the run parameters.
- Plan the home appliance cycles that fit, or leave the appliance out, instead of failing.
- Move the appliance layout rules into geneticappliancelayout for the preparation.
- Leave out a DAILY home appliance whose open windows leave no room for a run, with an error log, instead of silently.
- Name the reason of the SoC fallback instead of Python's exception text.
- Answer a solution request for an unknown algorithm with a 404 problem response.
- Record the fixes in CHANGELOG.md and the upgrade guide.

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 b108335ee4
commit b3d5334d3e
156 changed files with 146594 additions and 7766 deletions
+523
View File
@@ -0,0 +1,523 @@
{
"expected_result": "golden_2_tail_result.json",
"parameters": {
"request": {
"ems": {
"pv_forecast_wh": [
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
8.05,
352.91,
728.51,
930.28,
1043.25,
1106.74,
1161.69,
6018.82,
5519.07,
3969.88,
3017.96,
1943.07,
1007.17,
319.67,
7.88,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
5.04,
335.59,
705.32,
1121.12,
1604.79,
2157.38,
1433.25,
5718.49,
4553.96,
3027.55,
2574.46,
1720.4,
963.4,
383.3,
0.0,
0.0,
0.0
],
"electricity_price_per_wh": [
0.0003384,
0.0003318,
0.0003284,
0.0003283,
0.0003289,
0.0003334,
0.000329,
0.0003302,
0.0003042,
0.000243,
0.000228,
0.0002212,
0.0002093,
0.0001879,
0.0001838,
0.0002004,
0.0002198,
0.000227,
0.0002997,
0.0003195,
0.0003081,
0.0002969,
0.0002921,
0.000278,
0.0003384,
0.0003318,
0.0003284,
0.0003283,
0.0003289,
0.0003334,
0.000329,
0.0003302,
0.0003042,
0.000243,
0.000228,
0.0002212,
0.0002093,
0.0001879,
0.0001838,
0.0002004,
0.0002198,
0.000227,
0.0002997,
0.0003195,
0.0003081,
0.0002969,
0.0002921,
0.000278
],
"feed_in_tariff_per_wh": 7e-05,
"price_per_wh_battery": 0.0,
"total_load": [
676.71,
876.19,
527.13,
468.88,
531.38,
517.95,
483.15,
472.28,
1011.68,
995.0,
1053.07,
1063.91,
1320.56,
1132.03,
1163.67,
1176.82,
1216.22,
1103.78,
1129.12,
1178.71,
1050.98,
988.56,
912.38,
704.61,
516.37,
868.05,
694.34,
608.79,
556.31,
488.89,
506.91,
804.89,
1141.98,
1056.97,
992.46,
1155.99,
827.01,
1257.98,
1232.67,
871.26,
860.88,
1158.03,
1222.72,
1221.04,
949.99,
987.01,
733.99,
592.97
],
"pv_prognose_wh": [
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
8.05,
352.91,
728.51,
930.28,
1043.25,
1106.74,
1161.69,
6018.82,
5519.07,
3969.88,
3017.96,
1943.07,
1007.17,
319.67,
7.88,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
5.04,
335.59,
705.32,
1121.12,
1604.79,
2157.38,
1433.25,
5718.49,
4553.96,
3027.55,
2574.46,
1720.4,
963.4,
383.3,
0.0,
0.0,
0.0
],
"strompreis_euro_pro_wh": [
0.0003384,
0.0003318,
0.0003284,
0.0003283,
0.0003289,
0.0003334,
0.000329,
0.0003302,
0.0003042,
0.000243,
0.000228,
0.0002212,
0.0002093,
0.0001879,
0.0001838,
0.0002004,
0.0002198,
0.000227,
0.0002997,
0.0003195,
0.0003081,
0.0002969,
0.0002921,
0.000278,
0.0003384,
0.0003318,
0.0003284,
0.0003283,
0.0003289,
0.0003334,
0.000329,
0.0003302,
0.0003042,
0.000243,
0.000228,
0.0002212,
0.0002093,
0.0001879,
0.0001838,
0.0002004,
0.0002198,
0.000227,
0.0002997,
0.0003195,
0.0003081,
0.0002969,
0.0002921,
0.000278
],
"einspeiseverguetung_euro_pro_wh": 7e-05,
"preis_euro_pro_wh_akku": 0.0,
"gesamtlast": [
676.71,
876.19,
527.13,
468.88,
531.38,
517.95,
483.15,
472.28,
1011.68,
995.0,
1053.07,
1063.91,
1320.56,
1132.03,
1163.67,
1176.82,
1216.22,
1103.78,
1129.12,
1178.71,
1050.98,
988.56,
912.38,
704.61,
516.37,
868.05,
694.34,
608.79,
556.31,
488.89,
506.91,
804.89,
1141.98,
1056.97,
992.46,
1155.99,
827.01,
1257.98,
1232.67,
871.26,
860.88,
1158.03,
1222.72,
1221.04,
949.99,
987.01,
733.99,
592.97
]
},
"pv_battery": {
"device_id": "battery1",
"hours": null,
"capacity_wh": 26400,
"charging_efficiency": 0.88,
"discharging_efficiency": 0.88,
"max_charge_power_w": 5000.0,
"max_discharge_power_w": null,
"initial_soc_percentage": 80,
"min_soc_percentage": 0,
"max_soc_percentage": 100,
"charge_rates": null,
"grid_export_rates": null,
"charge_power_limit_w_by_soc": null,
"discharge_power_limit_w_by_soc": null,
"charging_efficiency_curve": null,
"discharging_efficiency_curve": null,
"levelized_cost_of_storage_kwh": 0.0,
"full_charge_soc_percentage": null,
"full_charge_deadline_datetime": null
},
"inverter": {
"device_id": "inverter1",
"hours": null,
"max_power_wh": 10000.0,
"battery_id": "battery1",
"ac_to_dc_efficiency": 1.0,
"dc_to_ac_efficiency": 1.0,
"dc_to_ac_efficiency_curve": null,
"dc_to_ac_efficiency_reference_load_fraction": 0.06,
"ac_to_dc_efficiency_curve": null,
"max_ac_charge_power_w": null,
"ac_charge_limits_total_charge": false
},
"ev": {
"device_id": "ev1",
"hours": null,
"capacity_wh": 60000,
"charging_efficiency": 0.95,
"discharging_efficiency": 1.0,
"max_charge_power_w": 11040.0,
"max_discharge_power_w": null,
"initial_soc_percentage": 5,
"min_soc_percentage": 80,
"max_soc_percentage": 100,
"charge_rates": null,
"grid_export_rates": null,
"charge_power_limit_w_by_soc": null,
"discharge_power_limit_w_by_soc": null,
"charging_efficiency_curve": null,
"discharging_efficiency_curve": null,
"min_soc_deadline_datetime": null,
"min_soc_max_duration_h": null
},
"dishwasher": {
"device_id": "dishwasher1",
"hours": null,
"consumption_wh": 5000,
"duration_h": 2,
"num_cycles": 1,
"completed_cycles": 0,
"run_started_datetime": null,
"min_cycle_gap_h": 0,
"time_windows": null,
"shared_time_windows": null,
"load_profile_power_w": null,
"load_profile_interval_seconds": null,
"schedule_mode": "ONCE",
"earliest_start_datetime": null,
"deadline_datetime": null,
"deadline_policy": "BEST_EFFORT"
},
"temperature_forecast": [
18.3,
17.8,
16.9,
16.2,
15.6,
15.1,
14.6,
14.2,
14.3,
14.8,
15.7,
16.7,
17.4,
18.0,
18.6,
19.2,
19.1,
18.7,
18.5,
17.7,
16.2,
14.6,
13.6,
13.0,
12.6,
12.2,
11.7,
11.6,
11.3,
11.0,
10.7,
10.2,
11.4,
14.4,
16.4,
18.3,
19.5,
20.7,
21.9,
22.7,
23.1,
23.1,
22.8,
21.8,
20.2,
19.1,
18.0,
17.4
],
"start_solution": null,
"forecast_interval_seconds": null,
"home_appliances": null,
"start_solution_datetime": null,
"pv_akku": {
"device_id": "battery1",
"hours": null,
"capacity_wh": 26400,
"charging_efficiency": 0.88,
"discharging_efficiency": 0.88,
"max_charge_power_w": 5000.0,
"max_discharge_power_w": null,
"initial_soc_percentage": 80,
"min_soc_percentage": 0,
"max_soc_percentage": 100,
"charge_rates": null,
"grid_export_rates": null,
"charge_power_limit_w_by_soc": null,
"discharge_power_limit_w_by_soc": null,
"charging_efficiency_curve": null,
"discharging_efficiency_curve": null,
"levelized_cost_of_storage_kwh": 0.0,
"full_charge_soc_percentage": null,
"full_charge_deadline_datetime": null
},
"eauto": {
"device_id": "ev1",
"hours": null,
"capacity_wh": 60000,
"charging_efficiency": 0.95,
"discharging_efficiency": 1.0,
"max_charge_power_w": 11040.0,
"max_discharge_power_w": null,
"initial_soc_percentage": 5,
"min_soc_percentage": 80,
"max_soc_percentage": 100,
"charge_rates": null,
"grid_export_rates": null,
"charge_power_limit_w_by_soc": null,
"discharge_power_limit_w_by_soc": null,
"charging_efficiency_curve": null,
"discharging_efficiency_curve": null,
"min_soc_deadline_datetime": null,
"min_soc_max_duration_h": null
}
},
"start_hour": 10,
"settings": {
"interval_sec": 3600,
"horizon_hours": 24,
"tail_horizon_hours": 24,
"prediction_hours": 48,
"individuals": 300,
"generations": 3,
"seed": 42,
"penalties": {
"ev_soc_miss": 10,
"ac_charge_break_even": 1
},
"workers": null,
"pin_workers": true,
"fitness_cache_max_entries": null,
"terminal_value_mode": "AUTO",
"terminal_value_window_hours": 24,
"direct_marketing_enabled": false,
"battery_charge_rates": null,
"battery_grid_export_rates": null,
"ev_charge_rates": [
0.0,
0.375,
0.5,
0.625,
0.75,
0.875,
1.0
],
"start_datetime": {
"datetime": "2026-09-16T10:00:00+02:00",
"timezone": "Europe/Berlin"
},
"observation_datetime": {
"datetime": "2026-09-16T10:00:00+02:00",
"timezone": "Europe/Berlin"
},
"timezone": "Europe/Berlin",
"self_consumption_interpolator": "scipy",
"verbose": false
},
"start_solution_datetime": null
}
}