EV-21: Solar cuts the car first for the quarter peak
infra-pin / fresh (pull_request) Successful in 2s
checks / unit (pull_request) Failing after 1h10m59s

In Solar, when the 15-minute period heads over the aim and the batteries
would have to give more, the car is lowered first: floor((car - excess) /
(230 x phases)) A, 0 under 6 A. At once without real headroom (saturated,
floor-limited, excess beyond what the batteries can add, no battery figure,
cover off, last 120 s), else after at most 15 s. One cut per episode from
its start, deeper only on a growing excess; restart with the start power
under the aim for the start time; none after a 2nd cut in the period.

Grading (formal C2): a Solar car Solar cannot cut is graded, banked and
left in the guard as in Off. A Solar car is never banked. Grey note and Why
"Solar lowered the car for the peak." Manual and Off unchanged.

Tests: test_ev21.py, test_ev21_paths.py, test_ev21_same.py; T49 in
tools/ev20_day.py; T50 in test_ev20_fuzz.py; test_ev20_guard section 8
moved from "as Manual" to "as Off" where Solar cannot cut (T51).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ems-agent
2026-11-25 17:01:07 +01:00
co-authored by Claude
parent a8e4ceb859
commit 7bc8988be0
17 changed files with 2175 additions and 85 deletions
+40 -4
View File
@@ -5,6 +5,12 @@ writers (while stopped and in shadow too), a silent meter, shadow and Stop
toggles mid-sequence, Solar / Off / Manual changes; half in the production
cycle order. N1-N3, N5, N9, N10, N12-N14 and N16 on every step (N4 is
EV-21's; N6-N8, N11 and N15 are rows of test_ev20_*.py).
EV-21 (T50) adds house loads that take the period over the aim (the peak
cut) and the cover option toggled, and on every step: graded out only while
Solar can cut (N8/T35), no write above a standing cut (N6), one cut decision
per episode at a constant or falling excess (N10 of EV-21). A cut lowers past
the 30 s rule on purpose (T3), so EV-20's N5 counts no cut write.
Mutating a module this file grades? Read MUTATION.md first (purge __pycache__).
"""
@@ -85,7 +91,7 @@ def fuzz_site(seed):
sim.ramp_w_s, sim.stop_delay_s = 300.0, 4.0
state = {"sun": rnd.uniform(3000, 11000),
"house": rnd.uniform(300, 2000)}
bad, counts, snap = [], {}, {}
bad, counts, snap, cuts = [], {}, {}, {}
seen = {"exit_since": None, "avail": None, "back": []}
def bump(k):
@@ -158,6 +164,12 @@ def fuzz_site(seed):
elif x < 0.0365:
await c.handle_action("car_sun_first", value=rnd.choice(
["batteries", "car"]))
elif x < 0.0395: # EV-21: a load over the aim
state["house"] = rnd.uniform(4000, 14000)
bump("excess")
elif x < 0.0400: # EV-21: the cover option
c.o["ev_batt_cover"] = not c.car_cover
bump("cover")
if p.ch.refuse is not None and rnd.random() < 0.02:
p.ch.refuse = None
# What the step of this second starts from (it runs after this, in
@@ -170,6 +182,21 @@ def fuzz_site(seed):
def on_cycle(p, c, t):
w, sim = c.car_solar, p.ch
r = c.car.reading
# EV-21: the cut's own checks, on every step.
st = getattr(c, "_cut", None) or {}
cuts[t] = st.get("cap")
if st.get("cap") is not None:
bump("cut")
key = (st.get("key"), st.get("since"), st.get("at"))
prev = seen.get("cut")
if prev is not None and prev[0] == key and st["cap"] < prev[1] \
and st.get("ex", 0.0) <= prev[2] + 1e-9:
bad.append((seed, t, "N10 (EV-21) a 2nd cut at a falling "
"excess", prev, st["cap"]))
seen["cut"] = (key, st["cap"], st.get("ex", 0.0))
if c.car_mode == "solar" and c.car_explains \
and not getattr(c, "_car_can", True):
bad.append((seed, t, "N8 (EV-21) graded out, Solar cannot cut"))
avail = bool(r is not None and r.available)
if avail and seen["avail"] is False:
cur = r.allowed_a if r.allowed_a is not None else r.setpoint_a
@@ -231,6 +258,10 @@ def fuzz_site(seed):
bad.append((seed, x[0], "N2 select with the setpoint up", x))
log = [x for x in c.car_solar.log if x[0] == "current"]
for kind, a, t, ok in log:
# EV-21 N6: never above a cut that stands.
cap = cuts.get(t)
if cap is not None and a > cap + 1e-9:
bad.append((seed, t, "N6 (EV-21) a write above the cut", a, cap))
s = snap.get(t) or snap.get(t - 1)
if s is None:
continue
@@ -260,7 +291,10 @@ def fuzz_site(seed):
and not dec[i - 1][2]) else 1
if tries > carmode.MAX_TRIES:
bad.append((seed, t, "N14 more than 3 tries", a))
nz = [(t, a) for t, a, ok in dec if a > 0.0]
# EV-21: a cut's own write (at the cut's value) lowers past the 30 s
# rule on purpose (T3); every other change keeps it.
nz = [(t, a) for t, a, ok in dec if a > 0.0
and not (cuts.get(t) is not None and abs(a - cuts[t]) < 1e-9)]
for (t0, a0), (t1, a1) in zip(nz, nz[1:]):
if a1 != a0 and t1 - t0 < carmode.SOLAR_WRITE_S - 1e-9 \
and not [1 for t, a, ok in dec if t0 < t < t1 and a == 0.0]:
@@ -290,10 +324,12 @@ for seed in range(SITES):
n_sel, n_zero = tally["sel"], tally["zero"]
print(f" {SITES} sites x {STEPS_PER} steps, {n_writes} charger writes; "
f"disturbances {sorted(all_counts.items())}")
check(f"T54: N1, N2, N3, N5, N9, N10, N12, N14 and N16 hold on every step "
check(f"T54: N1, N2, N3, N5, N9, N10, N12, N14 and N16 hold on every step; "
f"EV-21 T50: N6, N8 and one cut per episode "
f"({all_bad[:3]})", not all_bad)
need = ("spare", "outage", "ha", "unplug", "refuse", "refuse_exit", "other",
"other_out", "meter", "stop", "shadow", "mode")
"other_out", "meter", "stop", "shadow", "mode", "excess", "cover",
"cut")
check(f"T54: each disturbance happened, mid-sequence ones too "
f"({[k for k in need if not all_counts.get(k)]})",
all(all_counts.get(k) for k in need)