Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ The model is a maximization problem. Read these before changing it:

- The suite runs with `uv run pytest`.
- `test_cases/*.json` are loaded by `tests/test_app.py`. Each file holds a `request` and an optional `expected_response`, and the test asserts the optimizer status and, with `numpy.isclose`, the objective value. Add a scenario by dropping in a JSON file.
- For behavior the data driven harness cannot assert, such as a specific charge schedule, construct an `Optimizer` directly in a dedicated test module and assert on the returned dict.
- A test case with `"strict": true` additionally compares grid import, grid export, and the battery schedules with `numpy.allclose`. Use it for features that only pick between cost neutral alternatives, where the objective value barely moves. Do not set it on scenarios with several equally optimal schedules, the comparison would be arbitrary.
- Prefer a data driven case over a dedicated test module, so a failure points at the scenario rather than at a feature specific script.
- Cover both the success and the limit violation paths.

## Writing Style
Expand Down
112 changes: 112 additions & 0 deletions test_cases/023-attenuate-demand-peaks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"strict": true,
"request": {
"strategy": {
"charging_strategy": "attenuate_demand_peaks"
},
"batteries": [
{
"charge_from_grid": true,
"discharge_to_grid": false,
"s_capacity": 20000,
"s_min": 0,
"s_max": 20000,
"s_initial": 0,
"s_goal": [
0,
0,
0,
4000
],
"c_min": 0,
"c_max": 8000,
"d_max": 0,
"p_a": 0
}
],
"time_series": {
"dt": [
3600,
3600,
3600,
3600
],
"gt": [
0,
0,
0,
0
],
"ft": [
0,
0,
0,
0
],
"p_N": [
0.3,
0.3,
0.3,
0.3
],
"p_E": [
0.0,
0.0,
0.0,
0.0
]
},
"eta_c": 0.95,
"eta_d": 0.95
},
"expected_response": {
"status": "Optimal",
"objective_value": -1263.1579199999999,
"limit_violations": {
"grid_import_limit_exceeded": false,
"grid_export_limit_hit": false
},
"batteries": [
{
"charging_power": [
1052.6316,
1052.6316,
1052.6316,
1052.6316
],
"discharging_power": [
0.0,
0.0,
0.0,
0.0
],
"state_of_charge": [
1000.0,
2000.0,
3000.0,
4000.0
]
}
],
"grid_import": [
1052.6316,
1052.6316,
1052.6316,
1052.6316
],
"grid_export": [
0.0,
0.0,
0.0,
0.0
],
"flow_direction": [
0,
0,
0,
0
],
"grid_import_overshoot": [],
"grid_export_overshoot": []
}
}
112 changes: 112 additions & 0 deletions test_cases/024-attenuate-feedin-peaks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"strict": true,
"request": {
"strategy": {
"charging_strategy": "attenuate_feedin_peaks"
},
"batteries": [
{
"charge_from_grid": false,
"discharge_to_grid": false,
"s_capacity": 20000,
"s_min": 0,
"s_max": 20000,
"s_initial": 0,
"s_goal": [
0,
0,
0,
4000
],
"c_min": 0,
"c_max": 8000,
"d_max": 0,
"p_a": 0
}
],
"time_series": {
"dt": [
3600,
3600,
3600,
3600
],
"gt": [
0,
0,
0,
0
],
"ft": [
2000,
6000,
6000,
2000
],
"p_N": [
0.3,
0.3,
0.3,
0.3
],
"p_E": [
0.1,
0.1,
0.1,
0.1
]
},
"eta_c": 0.95,
"eta_d": 0.95
},
"expected_response": {
"status": "Optimal",
"objective_value": 1178.9473600000001,
"limit_violations": {
"grid_import_limit_exceeded": false,
"grid_export_limit_hit": false
},
"batteries": [
{
"charging_power": [
0.0,
2105.2632,
2105.2632,
0.0
],
"discharging_power": [
0.0,
0.0,
0.0,
0.0
],
"state_of_charge": [
0.0,
2000.0,
4000.0,
4000.0
]
}
],
"grid_import": [
0.0,
0.0,
0.0,
0.0
],
"grid_export": [
2000.0,
3894.7368,
3894.7368,
2000.0
],
"flow_direction": [
1,
1,
1,
1
],
"grid_import_overshoot": [],
"grid_export_overshoot": []
}
}
160 changes: 160 additions & 0 deletions test_cases/025-attenuate-grid-peaks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"strict": true,
"request": {
"strategy": {
"charging_strategy": "attenuate_grid_peaks"
},
"batteries": [
{
"charge_from_grid": true,
"discharge_to_grid": false,
"s_capacity": 20000,
"s_min": 0,
"s_max": 20000,
"s_initial": 0,
"s_goal": [
0,
0,
0,
0,
0,
0,
0,
12000
],
"c_min": 0,
"c_max": 2000,
"d_max": 0,
"p_a": 0
}
],
"time_series": {
"dt": [
3600,
3600,
3600,
3600,
3600,
3600,
3600,
3600
],
"gt": [
0,
0,
0,
0,
0,
0,
0,
0
],
"ft": [
0,
0,
0,
3000,
6000,
6000,
3000,
0
],
"p_N": [
0.3,
0.3,
0.3,
0.3,
0.3,
0.3,
0.3,
0.3
],
"p_E": [
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1
]
},
"eta_c": 0.95,
"eta_d": 0.95
},
"expected_response": {
"status": "Optimal",
"objective_value": -389.47363999999993,
"limit_violations": {
"grid_import_limit_exceeded": false,
"grid_export_limit_hit": false
},
"batteries": [
{
"charging_power": [
1157.8947,
1157.8947,
1157.8947,
2000.0,
2000.0,
2000.0,
2000.0,
1157.8947
],
"discharging_power": [
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
],
"state_of_charge": [
1100.0,
2200.0,
3300.0,
5200.0,
7100.0,
9000.0,
10900.0,
12000.0
]
}
],
"grid_import": [
1157.8947,
1157.8947,
1157.8947,
0.0,
0.0,
0.0,
0.0,
1157.8947
],
"grid_export": [
0.0,
0.0,
0.0,
1000.0,
4000.0,
4000.0,
1000.0,
0.0
],
"flow_direction": [
0,
0,
0,
1,
1,
1,
1,
0
],
"grid_import_overshoot": [],
"grid_export_overshoot": []
}
}
Loading
Loading