SAFETY-129 round 2: shorter test_safety129, pinned 5 s row, 100 s bound

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
glenn schrooyen
2026-11-06 21:24:37 +01:00
co-authored by Claude
parent 2667cf0dda
commit 85433edac6
4 changed files with 44 additions and 26 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
- Home now draws today's charge from the grid for every hour the add-on will really charge, not only the run under way ([[UX-77]]).
- When Home Assistant passes readings on late, control no longer swings on them: it waits until the battery shows its last power request, and the peak limit no longer asks for full power on them. The page says so, and if the readings stay too late every inverter goes to 0 W ([[SAFETY-128]]).
- With a 5 s meter, readings 30 s late are now noticed after about 90 seconds, not 3 minutes ([[SAFETY-129]]).
- With a 5 s meter, readings 30 s late are now noticed within 100 seconds, not 3 minutes ([[SAFETY-129]]).
## 0.20.1
@@ -69,7 +69,7 @@ The fits run all the time; the pull request has the counts.
**What it costs.**
- Found 36-68 s after a lag starts at 1-2 s meters; at a 5 s meter 30 s late
is found about 90 s after it starts (the loop first moves 100 W after 60 s,
is found within 100 s after it starts (88 s measured) (the loop first moves 100 W after 60 s,
SAFETY-129) with the export above -200 W, and 10 s late is not found. Until
then control is as before.
- A battery that answers slowly is read as late readings and held: a dead
+3 -3
View File
@@ -231,9 +231,9 @@ late5.run(ON + 300.0, lambda rig, c, t: rows5.extend(
print(f" 5 s meter, 30 s late: {sorted(set(rows5))}")
# SAFETY-129: the 5 s meter's fit finds it first (no figure); the hold then
# leaves the batteries' fit nothing to measure, so the row names no delay.
check("at a 5 s meter the row says so, and names a delay only from the "
"batteries' fit: about 20-32 s for 30 s late",
rows5 and set(rows5) <= _ok_texts)
check("at a 5 s meter the row says the readings are late, with no figure "
"(the meter alone found it)",
rows5 and set(rows5) == {str(messages.row_readings_late(None))})
check("logged once for the episode, and once when it ends, not per cycle",
n_late == 1 and n_back == 1)
check("the row goes once a fit shows the readings on time, or 2 minutes "
+39 -21
View File
@@ -13,13 +13,13 @@ DECISIONS/SAFETY-128-late-readings.md.
The REAL Controller on TEST-23's plant (tools/safety128_rig.py).
1. 5 s meter, readings 30 s late (N=2 house 1 800 W, N=1 house 1 500 W): found
within 120 s, and the export never goes below -200 W (red on c66aa7f: found
within 100 s, and the export never goes below -200 W (red on c66aa7f: found
after 190 s, export to -420 W).
2. 5 s meter, readings 10 s late: no swing, nothing to hold; and the limit that
goes with it: a battery that answers in 10 s (R2-1) is still not read as
late at a 5 s meter, which a lower slow-meter threshold would break.
3. No false holds at a slow meter: the owner's shape, HA restarts and meter
pauses at 1, 2 and 5 s, a 4 s and a 10 s meter, 6-8 s dead times: never
3. No false holds at a slow meter: the owner's shape at 2, 5 and 10 s, HA
restarts and meter pauses at 2 and 5 s, 8-10 s dead times: never
late, so the commands are those of the run without the gate.
4. The slow-meter fit at its edges.
@@ -85,20 +85,21 @@ for units, house in ((AB, 1800.0), (A, 1500.0)):
low = grid_min(r.rows, ON, ON + 300.0)
print(f" {n}: found {None if first is None else first - ON:.0f} s "
f"after the start, export to {low:.0f} W")
check(f"{n}: found within 120 s of the lag starting",
first is not None and first - ON <= 120.0)
check(f"{n}: found within 100 s of the lag starting",
first is not None and first - ON <= 100.0)
check(f"{n}: the export never goes below -200 W", low >= -200.0)
old = R.Rig(house=house, lag_s=30.0, lag_on=ON, lag_off=ON + 300.0,
units=units, p1_s=5.0)
no_gate(lambda: old.run(ON + 300.0))
check(f"{n}: without the gate the export goes below -1 kW",
grid_min(old.rows, ON, ON + 300.0) < -1000.0)
if len(units) == 2:
old = R.Rig(house=house, lag_s=30.0, lag_on=ON, lag_off=ON + 300.0,
units=units, p1_s=5.0)
no_gate(lambda: old.run(ON + 300.0))
check(f"{n}: without the gate the export goes below -1 kW",
grid_min(old.rows, ON, ON + 300.0) < -1000.0)
# --------------------------------------------------------------------------- #
print("\n2. 5 s meter, readings 10 s late; a battery that answers in 10 s")
r, secs, first = run_late(house=1800.0, lag_s=10.0, lag_on=ON,
lag_off=ON + 150.0, units=AB, p1_s=5.0,
dur=ON + 270.0)
dur=ON + 200.0)
low = grid_min(r.rows, ON, ON + 150.0)
print(f" 10 s late: export to {low:.0f} W, verdict stood {secs} s")
check("10 s late: no swing, the export never goes below -200 W", low >= -200.0)
@@ -115,7 +116,7 @@ def owner(t):
for dead in (8.0, 10.0):
r, secs, first = run_late(house=owner, noise=80.0, units=AB, p1_s=5.0,
dead_s=dead, dur=1500.0)
dead_s=dead, dur=800.0)
print(f" {dead:.0f} s dead time, 5 s meter: late {secs} s")
check(f"{dead:.0f} s dead time at a 5 s meter is not read as late "
f"(R2-1 does not get worse)", secs == 0)
@@ -125,11 +126,11 @@ for dead in (8.0, 10.0):
# tree before this card.
_slow = lateness.MeterFit.slow
secs = {}
for label in ("with", "without"):
for label in ("with", "without"): # 12 s dead time: late from about 140 s
lateness.MeterFit.slow = _slow if label == "with" else (lambda self: False)
try:
secs[label] = run_late(house=owner, noise=80.0, units=A, p1_s=5.0,
dead_s=12.0, dur=3300.0)[1]
dead_s=12.0, dur=900.0)[1]
finally:
lateness.MeterFit.slow = _slow
print(f" 12 s dead time, N=1, 5 s meter: late {secs['with']} s, with the "
@@ -156,25 +157,25 @@ def frozen(windows, meter_only):
return view
for p1 in (1.0, 2.0, 4.0, 5.0, 10.0):
for p1 in (2.0, 5.0, 10.0):
kw = dict(house=owner, noise=80.0, units=AB, p1_s=p1)
r, secs, first = run_late(dur=1500.0, **kw)
r, secs, first = run_late(dur=800.0, **kw)
new = r
old = R.Rig(**kw)
no_gate(lambda: old.run(1500.0))
no_gate(lambda: old.run(800.0))
same = max(abs(x[2] - y[2]) for x, y in zip(new.rows, old.rows))
print(f" owner shape, {p1:.0f} s meter: late {secs} s, command "
f"difference {same:.0f} W")
check(f"{p1:.0f} s meter, owner shape: never late, same commands",
secs == 0 and same == 0)
for label, windows, meter_only in (
("HA restart", ((650.0, 710.0), (1300.0, 1345.0)), False),
("meter pause", ((640.0, 700.0), (1250.0, 1300.0)), True)):
for p1 in (1.0, 2.0, 5.0):
("HA restart", ((650.0, 710.0),), False),
("meter pause", ((640.0, 700.0),), True)):
for p1 in (2.0, 5.0):
R.Plant.view = frozen(windows, meter_only)
try:
r, secs, first = run_late(house=owner, noise=80.0, units=AB,
p1_s=p1, dur=1400.0)
p1_s=p1, dur=800.0)
finally:
R.Plant.view = _view
check(f"{label} at a {p1:.0f} s meter: never late", secs == 0)
@@ -198,6 +199,23 @@ check("a 1 s, a 2 s and a 3 s meter are not slow",
not any(meter_with(p, n=60).slow() for p in (1.0, 2.0, 3.0)))
check("a pause in a 2 s meter does not make it slow",
not meter_with(2.0, pause_after=10, n=40).slow())
def fed(values):
"""Answer.watch() with the slow fit reading `values`, one per fit."""
a = lateness.Answer()
a.meter.slow = lambda: True
a.meter.estimate = a.delay.estimate = lambda: None
it = iter(values)
a.meter_slow.estimate = lambda: next(it)
for k in range(len(values)):
a.watch(2.0 * k, [], 0.0, 0.0)
return a
check("one late slow-meter fit is no fit; two in a row are one, and "
"one on time or in between is none",
fed([30.0]).fits == 0 and fed([30.0, 30.0]).fits == 1
and fed([30.0, None, 30.0]).fits == 0 and fed([30.0, 12.0]).fits == 0
and fed([3.0, 3.0]).fits == 0 and not fed([30.0, 30.0]).late_seen)
check("the slow fit asks for a longer window and a later delay than the "
"fast one", lateness.M_SLOW_FIT_S > lateness.M_FIT_S
and lateness.M_SLOW_LATE_S > lateness.M_LATE_S)