MAINT-28 fix round 5: while the pause holds, the batteries give only what the guard needs
H-1: one site limit while the pause holds (the period's largest floor, never under this cycle's), so the other pack no longer gives for the house. New live-try test (A 11 %, B 25 %, 90 min at 6.5 kW) red on 07d23d2. M-1: a 45-min rig-shape test that goes red when the settled check is forced True. M-2/L-2: DECISIONS. CHANGELOG line. test_safety84 n2_charge_banked re-pinned (quarters 3349 and 3950 W, aim 3950 W).
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
9a76f1a968
commit
de06a2c6f5
@@ -1,5 +1,9 @@
|
||||
# Changelog
|
||||
|
||||
### Not in a release yet
|
||||
|
||||
- During a real peak, a battery in its maintenance charge now stays paused instead of switching between charging and giving, and the batteries give only what keeps the peak under the limit ([[MAINT-28]]).
|
||||
|
||||
## 0.22.0
|
||||
|
||||
**A minor bump: a battery's monthly charge now gets the cheap night, the plan knows about the 7-day wait, a slow meter is followed more gently, and one peak-guard stop no longer costs a night charge its whole period. No option changes.**
|
||||
|
||||
@@ -14,12 +14,12 @@ Why 300 W: the house wanders +-50 W; once the charge resumes it settles at (aim
|
||||
|
||||
The flag lives only while the charge-only branch is taken: every cycle that reaches the maintenance loop starts it at False, so a maintenance that ended, a mode change or a missing aim cannot carry a stale True into the next charge (test_maint28.py part 1b). `cycle()` has two returns before that loop, and the flag is kept through them on purpose: "inputs missing" and "readings late" (SAFETY-128) are holds of under `stale_after` seconds that write nothing and decide nothing, so the next full cycle sees the same charge and the same peak. A missed poll must not end a peak pause; a reset there would restart the charge on it (`_maint_shape_suspended` is kept through them the same way).
|
||||
|
||||
It only ever keeps the maintenance charge off. No cut-back is delayed or weakened: the guard's claim is filed as before. While the pause is held the loop works as at 02eac3b, so A also gives for the house (quarters then sit under the aim, A's energy goes to the load: 1.67 kWh in the 45 min below, 0.45 kWh on 1b5f7c9). Measured alternative, A capped at 0 W while held and the guard idle (review scratch, same 45 min run): A gives 0.44 kWh in the load instead of 1.66, quarters 5919/5915 W, but A switches give/idle 32 times in 40 min. The uncapped give costs ~1.2 kWh round trip per 45-min peak (a few cents) and ~50 min more maintenance charge, far inside the 36 h timeout, so the steady give is kept.
|
||||
It only ever keeps the maintenance charge off. No cut-back is delayed or weakened: the guard's claim is filed as before. While the pause is held, the pack in CHARGE gives only its share of the guard's floor (0 W if the guard holds it at its reserve), and the batteries together give only what the guard needs (see Fix-forward, F-2 and H-1). The first version let A give for the house; it was dropped.
|
||||
|
||||
## Numbers (sim, real `cycle()`, A rated 2500 W)
|
||||
House 3000 -> 6500 W for 45 min -> 3000 W, +-50 W every 5 s, banked month peak 6000 W (aim 5950 W), forecast = quarter average so far plus the rest at the present grid (`scratch/MAINT-28/dev/m28_repro.py`; `test_maint28.py` runs the same shape for 15 min to keep the suite short).
|
||||
|
||||
| 45 min load | base 02eac3b | 1b5f7c9 | MAINT-28 |
|
||||
| 45 min load | base 02eac3b | 1b5f7c9 | MAINT-28 (f3f9483, without the lag) |
|
||||
|---|---|---|---|
|
||||
| A charge/give reversals | 0 | 52 | 1 (the first trip) |
|
||||
| A charging seconds in the load (of 2700) | 0 | 367 | 301 (before the first trip) |
|
||||
@@ -40,14 +40,16 @@ The sim had no battery-reading lag, and the first version said the 300 W line is
|
||||
|
||||
**F-1: the pause ends only on a settled estimate.** `Controller._batts_settled()` is False from a step UP of a unit's command (`MAINT_STEP_W` = 100 W more give or less charge, the SAFETY-128 pending size) until its reading changed `PLANT_SETTLE_S` (6 s) after the step, or `BATT_OBLIGED_S` (17 s) have passed. `peakguard.shaping_held(..., settled)` then keeps the pause. A step down makes the estimate err high, which only holds the pause, so it waits for nothing. Measured in the 45 min sim, pause on: settled, the estimate was at most 146 W under the real house (0 cycles over 300 W); not settled, up to 1933 W under (725 of 1611 cycles over 300 W). Sim, 45 min, house 6500 W: 83 of 83 releases on a stale estimate (f3f9483) -> 0; flips 148 -> 1 (1b5f7c9 210). Charge is back 4 s after the load (12 s in test_maint28b), not 0: the first settled estimate. No cut-back is touched.
|
||||
|
||||
**F-2 and the cap.** Owner 2026-11-13 ("1" = cap): while the pause holds, the pack in maintenance CHARGE gives only what the guard claims for the peak, at any SoC; other packs unchanged. Owner 2026-11-13 ("ok max", relayed by the manager): accepted "while the hold is on, the pack in maintenance CHARGE gives at most the largest floor the peak guard claimed in the current quarter" (about 0.37 kWh per 45-min peak in the sim; quarters at or under the aim).
|
||||
**F-2 and the cap.** Owner 2026-11-13 ("1" = cap): while the pause holds, the pack in maintenance CHARGE gives only what the guard claims for the peak, at any SoC; other packs unchanged (replaced by H-1 below). Owner 2026-11-13 ("ok max", relayed by the manager): accepted "while the hold is on, the pack in maintenance CHARGE gives at most the largest floor the peak guard claimed in the current quarter" (about 0.37 kWh per 45-min peak in the sim; quarters at or under the aim).
|
||||
|
||||
**H-1 (review 2026-11-14, owner decision 2026-11-14): the batteries together give only what the guard needs.** With the cap on A alone, the loop gave for the whole house with B (Cheap hours): in the live-try shape (A 11 % in CHARGE, B 25 %, house 6.5 kW for 90 min) B gave 4.6 kW, went from 25 to 10 % in 43 min, and two quarters were 6502 and 6499 W against the month peak 6000 W. So while the pause holds, `_m28_share()` also files one site limit (source `charge`, `P_MAINT_SHAPE`, per-site `_m28_site`): `hi` = the largest floor of the period, never under this cycle's floor. The guard's claim is not cut: `hi` is at least the floor, `P_PEAK` outranks `P_MAINT_SHAPE`, and `_peak_on_able` still places the whole floor. Outside the hold nothing is filed. Live try, same shape (test_maint28b): quarters 5357 to 5911 W (aim 5950), B 0.86 kWh and ends at 20.6 % (1b5f7c9: 1.0 kWh, 19.8 %), B switches give/idle once, A never. The re-pinned `n2_charge_banked` quarters are 3349 and 3950 W (aim 3950).
|
||||
|
||||
The rule as built (`Controller._m28_share()`): while the pause holds (N>=2, month aim above the cap) the pack gets a unit limit `hi` = the largest part of the guard's floor placed on it in this 15-minute period. Its part in a cycle is the floor less what the other units are placed at in this cycle's split without that limit, so a part the guard's split puts on the other pack is not this pack's. A pack the guard holds at its reserve (`peak_guard.held`) gets 0 W and its part starts again from 0 W. The largest part is kept per unit (`_m28_hi`, keyed by the unit) and dropped in a new period or when the pause ends; only one pack can be in maintenance CHARGE anyway (`maintenance.arbitrate()`, one slot per site).
|
||||
|
||||
Why the largest of the period and not the present part: the guard alone lands the quarter 9.5-10 W over its aim in the sim (SAFETY-126: its own projection ends on 5950.0 W but the meter reading it counts lags the true grid), and with the present part only, test_maint28 part 1 ends at 5960.1 W; the largest of the period lets the loop keep A up and it ends at 5925 W. Why not `hi` = 0 W: with the other pack under its reserve the guard needs this one (test_maint28b, house 12 kW, B at 18 %: A gives 1.07 kWh for the guard).
|
||||
|
||||
Tests (test_maint28b, 13-min load, A 5 kW): A at 49 %: SoC drop 0.64 point (the owner's 0.37 kWh per 45 min is 0.70 point here; the check is <= 0.70). Both packs able, B on Cheap hours: B is placed nothing, A's limit is the period's largest floor (3087 W) and A gives 3081 W. B on Solar first (gives for the house): A's limit 3294 W against a period's largest floor of 6284 W, under it by 500 W or more in 564 of 569 paused cycles; A still gives 3294 W, so the quarter ends 3843 W, far under the aim: that is the cost of the largest-of-period rule when the other pack gives for the house.
|
||||
Tests (test_maint28b, 13-min load, A 5 kW): A at 49 %: SoC drop 0.64 point (the owner's 0.37 kWh per 45 min is 0.70 point here; the check is <= 0.70). Both packs able, B on Cheap hours: B is placed nothing, A's limit is the period's largest floor (3087 W) and A gives 3081 W. B on Solar first (it gives for the house): A's limit stays under the period's largest floor by 500 W or more in 740 of 744 paused cycles, and the quarters stay under the aim.
|
||||
|
||||
Sim, rig shape, 45 min, house 6500 W: A in CHARGE at 49 %: A gives 0.17 kWh (f3f9483 0.44), SoC 50.5 -> 49.0 %, charge/give flips 1, give/idle switches 3, quarters 5358 1663 1899 2572 4476 W, charge back 4 s after the load; B (Cheap hours, not in maintenance) gives 3.04 kWh for the house (f3f9483 0.32). B at 18.2 % in CHARGE: f3f9483 gave 1.89 kWh to 10.0 %; now 0.00 kWh, 18.2 %, quarters 5948 and 5952 W (the guard alone, on A). test_safety84 n2_charge_banked: banked quarters 3349 and 3217 W against the aim 3950 W.
|
||||
Sim, rig shape, 45 min, house 6500 W (load from minute 10), A in CHARGE at 49 %, B 30 % on Cheap hours: A gives 0.17 kWh (f3f9483 0.44), SoC 50.5 -> 49.0 %, charge/give flips 1, give/idle switches 1, quarters 5358 5897 5911 5176 4477 W, charge back 4 s after the load; B gives 0.23 kWh (before H-1 3.04, f3f9483 0.32). test_safety84 n2_charge_banked: banked quarters 3349 and 3950 W against the aim 3950 W.
|
||||
|
||||
Mutants, each red: the freshness check dropped (always settled); the cap dropped; the other units' placement dropped (part = the whole floor); one cap for the site instead of per unit; the 0 W for a held pack dropped (all in `test_maint28b.py`); the period's largest dropped (present part only: `test_maint28.py` part 1 quarter 5960 W).
|
||||
Mutants, each red: the freshness check dropped (always settled); the cap dropped; the other units' placement dropped (part = the whole floor); one cap for the site instead of per unit; the 0 W for a held pack dropped (all in `test_maint28b.py`); the period's largest dropped (present part only: `test_maint28.py` part 1 quarter 5960 W); `_batts_settled()` replaced by True at the hold in ctl_cycle.py (the 45-min rig shape in `test_maint28b.py`, one stale release); the site limit dropped (the live try in `test_maint28b.py`: quarters 6502 and 6499 W, B 2.91 kWh to 10.0 %).
|
||||
|
||||
@@ -747,7 +747,9 @@ class TradeMixin:
|
||||
reserve) set to the largest part of the guard's floor left to it in
|
||||
this 15-minute period: the floor less what the other units are placed
|
||||
at in this cycle's split without the cap. Kept per unit in `_m28_hi`,
|
||||
dropped while the unit is not paused or is held.
|
||||
dropped while the unit is not paused or is held. Also one site limit,
|
||||
the period's largest floor, so the other pack does not give for the
|
||||
house (`_m28_site`).
|
||||
DECISIONS/MAINT-28-hold-the-pause-in-a-peak.md"""
|
||||
floor = max((c.lo for c in claims if c.source == peakguard.SOURCE),
|
||||
default=0.0)
|
||||
@@ -755,6 +757,8 @@ class TradeMixin:
|
||||
held = {self.actuator_of("maintenance", inv) for inv in self.inverters
|
||||
if g is not None and inv.name in g.held}
|
||||
q, seen = int(now.timestamp() // 900), set()
|
||||
site = any(c.source == "maintenance" and c.reason == M28_REASON
|
||||
and c.actuator != ACTUATOR_SITE for c in claims)
|
||||
for i, c in enumerate(claims):
|
||||
if c.source != "maintenance" or c.reason != M28_REASON \
|
||||
or c.actuator == ACTUATOR_SITE or c.actuator in held:
|
||||
@@ -771,6 +775,17 @@ class TradeMixin:
|
||||
# A unit not paused (or held at its reserve) starts again from 0 W.
|
||||
for u in set(self._m28_hi) - seen:
|
||||
del self._m28_hi[u]
|
||||
# Site: while the pause holds, the packs together give at most the
|
||||
# period's largest floor, never under this cycle's (the guard's claim
|
||||
# and P_PEAK outrank this one anyway).
|
||||
if not site:
|
||||
self._m28_site = (None, 0.0)
|
||||
return
|
||||
hi = max(floor, self._m28_site[1] if self._m28_site[0] == q else 0.0)
|
||||
self._m28_site = (q, hi)
|
||||
claims.append(Claim.limit("charge", P_MAINT_SHAPE, hi=hi,
|
||||
reason=M28_REASON,
|
||||
actuator=ACTUATOR_SITE))
|
||||
|
||||
def _m28_was(self, u, now) -> float:
|
||||
"""MAINT-28: unit `u`'s cap so far in this 15-minute period, 0 W in
|
||||
|
||||
@@ -508,6 +508,7 @@ class Controller(InputsMixin, WritesMixin, TradeMixin, CycleMixin, AlarmsMixin,
|
||||
self._maint_peak_hold = False # MAINT-28
|
||||
self._m28_step = {} # MAINT-28: unit -> (command, step at)
|
||||
self._m28_hi = {} # MAINT-28: unit -> (period, cap)
|
||||
self._m28_site = (None, 0.0) # MAINT-28: (period, site cap)
|
||||
# OPT-11: battery modes, off by default (SAFETY-10 section 1). Each
|
||||
# battery's mode and on/off switch live in the store, not in options,
|
||||
# so a change applies at once (`pack_use`, `pack_mode`).
|
||||
|
||||
@@ -28,6 +28,9 @@ peak forecast like the live sensor, house +-50 W every 5 s, 3000 W then
|
||||
4. Unchanged: the MAINT-24 live shape (A 1475 W, B no grid trade), with the
|
||||
same lag on.
|
||||
5. `peakguard.shaping_held()` with `settled`, and `Controller._batts_settled()`.
|
||||
6. H-1 (owner 2026-11-14): while the pause holds the batteries together give
|
||||
only what the guard needs. The live try (A 11 %, B 25 %, 90 min at 6.5 kW)
|
||||
and, for the F-1 wiring, the 45-min rig shape.
|
||||
Mutations: DECISIONS/MAINT-28-hold-the-pause-in-a-peak.md.
|
||||
Read MUTATION.md before you report a survivor.
|
||||
"""
|
||||
@@ -69,11 +72,11 @@ PRE, LOAD, POST = 120.0, 780.0, 120.0 # s (CI time: short runs)
|
||||
RESERVE = 20.0 # peak_soc_floor default
|
||||
|
||||
|
||||
def stepped_house(base_w, hi_w):
|
||||
def stepped_house(base_w, hi_w, load=LOAD, pre=PRE):
|
||||
rnd = random.Random(28)
|
||||
out = [(sc.UTC0.timestamp() - 10, base_w)]
|
||||
for t in range(0, int(PRE + LOAD + POST), 5):
|
||||
w = hi_w if PRE <= t < PRE + LOAD else base_w
|
||||
for t in range(0, int(pre + load + POST), 5):
|
||||
w = hi_w if pre <= t < pre + load else base_w
|
||||
out.append((T0.timestamp() + t, w + rnd.uniform(-50.0, 50.0)))
|
||||
return out
|
||||
|
||||
@@ -206,6 +209,27 @@ check("after the load A's charge is back within 20 cycles (1 s each: a 10 s "
|
||||
"register period plus its settle time, 16 s)",
|
||||
back is not None and back <= 20)
|
||||
|
||||
# M-1 (review 2026-11-14): the F-1 wiring, `_batts_settled()` read at the hold
|
||||
# in ctl_cycle.py. With `settled=True` there the 13-min load above still passes;
|
||||
# the rig shape (the load starts 10 min into the quarter, 45 min long) does not.
|
||||
RIG_PRE, RIG_LOAD = 600.0, 2700.0
|
||||
rows, st, c = scen(house=stepped_house(3000.0, 6500.0, RIG_LOAD, RIG_PRE),
|
||||
dur=RIG_PRE + RIG_LOAD + POST)
|
||||
load45 = [r for r in rows if RIG_PRE <= r["t"] < RIG_PRE + RIG_LOAD]
|
||||
rel45 = [(r, s_) for p, r in zip(rows, rows[1:])
|
||||
if RIG_PRE <= r["t"] < RIG_PRE + RIG_LOAD and p["hold"]
|
||||
and not r["hold"]
|
||||
for s_ in [r["est"] is not None and r["est"] < LINE
|
||||
and r["house"] >= LINE]]
|
||||
print(f" A 49 %, 45 min: flips {flips(load45)}, releases {len(rel45)} "
|
||||
f"(stale {sum(1 for _r, s_ in rel45 if s_)}), quarters "
|
||||
f"{[round(a[0] / a[1]) for a in st['quarters'].values()]}")
|
||||
check("45 min: A flips charge/give 3 times or fewer (f3f9483: 148)",
|
||||
flips(load45) <= 3)
|
||||
check("45 min: no release of the pause on a stale estimate (f3f9483: 83 of 83)",
|
||||
not any(s_ for _r, s_ in rel45))
|
||||
check("45 min: every quarter at or under the month aim", quarters_ok(st))
|
||||
|
||||
# ============================================================================ #
|
||||
print("\n2. the cap: while the pause holds, A gives at most the largest part "
|
||||
"of the guard's floor placed on it this period")
|
||||
@@ -292,6 +316,37 @@ check("the guard places its claim on the other pack: A under its reserve "
|
||||
sum(r["u"] for r in rows if r["u"] > 0) / 3.6e6 < 0.05
|
||||
and min(r["soc"] for r in rows) >= 18.0)
|
||||
|
||||
# H-1 (review 2026-11-14, owner decision): while the pause holds, the packs
|
||||
# together give only what the guard needs. The live try: A 11 % in CHARGE (under
|
||||
# its reserve), B 25 % on Cheap hours, 90 min at 6.5 kW.
|
||||
LIVE = 5400.0
|
||||
rp.CAP_KWH = 20.48 # the rig's B; A gives nothing here
|
||||
rows, st, c = scen(soc=11.0, other=25.0,
|
||||
house=stepped_house(3000.0, 6500.0, LIVE, RIG_PRE),
|
||||
dur=RIG_PRE + LIVE + POST)
|
||||
rp.CAP_KWH = 15.36
|
||||
qs = [a[0] / a[1] for a in st["quarters"].values()]
|
||||
load = [r for r in rows if RIG_PRE <= r["t"] < RIG_PRE + LIVE]
|
||||
gb = sum(r["o"] for r in load if r["o"] > 0) / 3.6e6
|
||||
|
||||
|
||||
def switches(k):
|
||||
g = [("give" if r[k] > 50 else "idle") for r in load]
|
||||
return sum(1 for x, y in zip(g, g[1:]) if x != y)
|
||||
|
||||
|
||||
print(f" live try: quarters {[round(q) for q in qs]}, B gives {gb:.2f} kWh, "
|
||||
f"B ends {rows[-1]['soc_o']:.1f} %, give/idle switches A "
|
||||
f"{switches('u')}, B {switches('o')}")
|
||||
check("live try: every quarter at or under the aim + 10 W (07d23d2: 6502 and "
|
||||
"6499 W against the month peak 6000 W)", max(qs) <= AIM + 10.0)
|
||||
check("live try: B gives about its guard part, under 1.5 kWh (1b5f7c9 1.0; "
|
||||
"07d23d2 4.6 kW, 25 -> 10 % in 43 min)", gb < 1.5)
|
||||
check("live try: B ends at 19.8 % or more (1b5f7c9 19.8)",
|
||||
rows[-1]["soc_o"] >= 19.8)
|
||||
check("live try: give/idle switches of B at most 40 in the 90 min",
|
||||
switches("o") <= 40)
|
||||
|
||||
# ============================================================================ #
|
||||
print("\n3. mirror: B in CHARGE at 18 % (under its reserve), A on Cheap hours")
|
||||
rows, st, c = scen(unit="b", soc=18.2, other=30.0,
|
||||
|
||||
@@ -487,9 +487,11 @@ print("\n8. the N=1 and N=2 digests")
|
||||
# (DECISIONS/MAINT-28-hold-the-pause-in-a-peak.md). MAINT-28 fix-forward
|
||||
# re-pinned it again: while the pause holds A gives at most the largest part
|
||||
# of the guard's floor placed on it this period, so rows 288-479 (t = 1440 s
|
||||
# on, 192 of 480) differ: a "peak hold" limit claim on A and A's share. Its
|
||||
# banked quarters stay under the aim 3950 W (3349 and 3217 W; f3f9483 3349 and
|
||||
# 2527 W), graded below. The other five are equal.
|
||||
# on, 192 of 480) differ: a "peak hold" limit claim on A and A's share. Round 5
|
||||
# (H-1) re-pinned it again: one site limit, the period's largest floor, so the
|
||||
# batteries give only what the guard needs. Its banked quarters stay at or
|
||||
# under the aim 3950 W (3349 and 3950 W; f3f9483 3349 and 2527 W), graded
|
||||
# below. The other five are equal.
|
||||
PINNED = {
|
||||
"n1_charge":
|
||||
"00f0a16b3ac1bd2830e9e0aaac8923fd9d1736c2bc6c543669bdd35b2fb542e9",
|
||||
@@ -502,7 +504,7 @@ PINNED = {
|
||||
"n2_charge_dear":
|
||||
"aa2bbc677a8e2274b25ba1170de1b1635e08a3bd93105e2a38a9bb1575b5b6db",
|
||||
"n2_charge_banked":
|
||||
"2da0c3bc9f0ff3857402146efcd6119180a7d4d1cc1297f1c15ec0b8c0104f42",
|
||||
"358ebd2a23fe7c7f52f441b60391e40c6605e32bcfb109fa0ff4502d4070745e",
|
||||
}
|
||||
_nb_rows, _nb = s84.run(**s84.SCENARIOS["n2_charge_banked"])
|
||||
print(f" n2_charge_banked banked quarters {[round(v, 1) for v in banked(_nb)]}"
|
||||
|
||||
Reference in New Issue
Block a user