Commit 9be8f4d
test: vary iboost and low power export across the random scenarios (#4550)
* test: vary iboost and low power export across the random scenarios
The 20-scenario byte-identical benchmark is the gate every planner change is held
to, but three feature flags were pinned by the template for all 20 runs: low power
charge always on, iboost and low power export always off. Anything guarded by the
two disabled ones could be changed - or broken - without the gate noticing.
That was not theoretical. The iboost arm of export_window_allowed, added in #4549,
could not be reached by any scenario: it needs iboost_enable, a non-empty
iboost_plan and iboost_on_export off. It is now taken 126 times across the suite.
kernel_parity did cover iboost for prediction, but it never runs the optimiser, so
nothing reached that branch.
iboost_enable is drawn at 40% (matching kernel_parity) and set_export_low_power
50/50, from an rng salted off the scenario seed rather than the main stream - the
same device the car block uses, and for the same reason: every pre-existing
parameter and stored profile is bit-identical, so a plan that moves has moved
because of the new flags and nothing else. Verified: 0 drift across all 20
scenarios, and with the flags present but unapplied the plans still match the old
baseline exactly.
The whole iboost block is written on every scenario rather than only the enabled
ones. Setting it only when enabled left the previous scenario's values behind, so
a plan depended on what ran before it - the same trap run_debug_cases documents,
and it moved all 20 scenarios instead of the 13 the flags actually touch. With the
off-case values taken from the template, the 7 scenarios neither flag touches are
byte-identical to before, which is what makes the regenerated baseline reviewable.
iboost_plan is built here on the same condition fetch_sensor_data uses, because
the scenario runner never calls fetch and an empty plan cannot reach the optimiser
path this exists to cover.
Also fixes the static context cache fixture, which ran with iboost off and no
battery temperature curves - so iboost_plan_load was 288 zeroes and every
temperature produced the identical cap. Both are what the cache reuses, so the
equivalence tests would have agreed whatever it did with them. Now 36 of 288
iboost steps are non-zero and the caps take 3 distinct values.
Baseline regenerated: 13 scenarios move, 7 are unchanged, 217 tests pass.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* test: run the random benchmark in the suite, and randomise the load scalings
Three changes to the random scenario benchmark.
The 20-scenario plan comparison now runs as part of run_all rather than only by
hand. It fails if any recorded field differs from the committed baseline, and
reports runtime without asserting on it - the suite runs on machines of wildly
different speeds, so a runtime threshold would either be so loose it caught
nothing or so tight it failed for reasons unrelated to the change under test. It
takes ~28s, so it runs under --quick too. Verified falsifiable: a 0.0001 metric
change and a changed final SoC both fail it, while multiplying every baseline
runtime by ten does not.
compare_results gains a per-scenario time_diff column and a suite total, both as
percentages as well as seconds. Absolute seconds only mean something against the
machine that produced them; the ratio survives a comparison between machines.
The load scalings for the three simulated futures are now randomised over
0.2-2.0, sorted so load_scaling90 <= load_scaling <= load_scaling10 - the order
the planner requires, PV90 being the sunny light-load future and PV10 the cloudy
heavy one. The template pinned load_scaling 0.5 and load_scaling10 0.6 and left
load_scaling90 at its 0.7 default, which the planner detects as inverted and
clamps back to 0.5. Every scenario therefore ran PV90 with exactly the central
case's load, and the warning fired on all twenty. Both clamp warnings are now
gone, and the mean gap between cost_pv90 and cost widens from 105.84 to 349.32 -
the pv90 column was previously separated from nominal only by the PV forecast,
never by load.
Drawn from their own rng stream, as the car and feature blocks are, so adding
them leaves every pre-existing scenario parameter bit-identical.
Baseline regenerated. 217 tests pass, pre-commit clean.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(test): reset the iboost carry-over between scenarios, correct a step count
Both review comments on this PR.
calculate_plan writes iboost_next back onto the instance and the scenario runner
never calls fetch_config_options, which is what resets it every cycle in the
product. A scenario therefore inherited the previous one's iboost carry-over,
which is the same order dependence this PR already fixed for the rest of the
iboost block - just incompletely. The reset now mirrors fetch_config_options:
iboost_next, the three running flags and iboost_energy_today.
No scenario's plan moves. Verified by running the full suite with and without the
reset and comparing all twenty metrics: zero differ, so this closes a real hazard
rather than a live defect, and the baseline is unchanged.
The static cache fixture docstring said iboost_plan_load would be 576 zeroes. The
fixture sets forecast_minutes to 24 hours and the kernel steps at 5 minutes, so
the arrays are 288 long - the number the comment exists to make concrete.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 308f348 commit 9be8f4d
5 files changed
Lines changed: 638 additions & 218 deletions
File tree
- apps/predbat
- tests
- coverage/cases
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
41 | 47 | | |
42 | 48 | | |
43 | 49 | | |
| |||
47 | 53 | | |
48 | 54 | | |
49 | 55 | | |
50 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
51 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
52 | 79 | | |
53 | 80 | | |
54 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
39 | 53 | | |
40 | 54 | | |
41 | 55 | | |
| |||
331 | 345 | | |
332 | 346 | | |
333 | 347 | | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
334 | 379 | | |
335 | 380 | | |
336 | 381 | | |
337 | 382 | | |
338 | 383 | | |
339 | 384 | | |
340 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
341 | 392 | | |
342 | 393 | | |
343 | 394 | | |
| |||
668 | 719 | | |
669 | 720 | | |
670 | 721 | | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
671 | 765 | | |
672 | 766 | | |
673 | 767 | | |
| |||
977 | 1071 | | |
978 | 1072 | | |
979 | 1073 | | |
980 | | - | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
981 | 1079 | | |
982 | 1080 | | |
983 | 1081 | | |
| |||
1044 | 1142 | | |
1045 | 1143 | | |
1046 | 1144 | | |
1047 | | - | |
1048 | | - | |
| 1145 | + | |
| 1146 | + | |
1049 | 1147 | | |
1050 | 1148 | | |
1051 | 1149 | | |
| |||
1103 | 1201 | | |
1104 | 1202 | | |
1105 | 1203 | | |
| 1204 | + | |
1106 | 1205 | | |
1107 | 1206 | | |
1108 | 1207 | | |
1109 | 1208 | | |
1110 | 1209 | | |
1111 | 1210 | | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
1112 | 1214 | | |
1113 | 1215 | | |
1114 | 1216 | | |
1115 | 1217 | | |
1116 | 1218 | | |
1117 | 1219 | | |
1118 | 1220 | | |
1119 | | - | |
1120 | | - | |
| 1221 | + | |
| 1222 | + | |
1121 | 1223 | | |
1122 | 1224 | | |
1123 | 1225 | | |
| |||
1176 | 1278 | | |
1177 | 1279 | | |
1178 | 1280 | | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
1179 | 1359 | | |
1180 | 1360 | | |
1181 | 1361 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
| 185 | + | |
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| |||
547 | 547 | | |
548 | 548 | | |
549 | 549 | | |
| 550 | + | |
550 | 551 | | |
551 | 552 | | |
552 | 553 | | |
| |||
0 commit comments