EV-18 review round 2: the contradiction latch touches only the alarm; an unknown energy reading is not a contradiction
checks / unit (pull_request) Successful in 27m50s
infra-pin / fresh (pull_request) Successful in 2s

- [Critical] The latch set `w = None` before `_car_quarter`, so with cover
  off the guard's input (`car_exclude`) counted the car as house and the
  batteries discharged. The latch now changes only the figure graded for the
  alarm; the car's energy count, the guard's input and the car-over row keep
  the unlatched `car_alarm_w()`. Cover-off N4 twins (energy gap, T9(c) liar,
  SoC 60 % and at the reserve) give the same commands as without the latch.
- [Major] `corroborated()` is False for an unknown energy reading, so one
  missing reading latched a correct figure for the quarter. New
  `CarTracker.contradicted()`: only a meter that answered over a whole window
  and fell short. R1 (energy entity unknown 1 s at E+200, T2 and T3 shapes):
  red for that cycle only, explained from the next.
- Minors: unit checks that a contradiction in our own pause latches nothing
  (MF) and that the latch ends with the quarter (MG).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ems-agent
2026-11-19 12:18:06 +01:00
co-authored by Claude
parent 5db56b5f28
commit 93c6628eca
4 changed files with 153 additions and 18 deletions
+105 -2
View File
@@ -241,6 +241,65 @@ check("T8 unit: the same with the charger unavailable (unknown car): the "
"alarm stands while unknown and is released at E+60 (Expected 5)",
not any(run_of(exu, 0, 59)) and all(run_of(exu, 60, 899)))
# --- the contradiction latch (owner 2026-11-19), unit ----------------------- #
class _TrackerC:
"""A charging car whose energy meter contradicts it when `contra(t)`."""
def __init__(self, contra):
self.contra = contra
self.reading = CH.ChargerReading(available=True, state="C",
charging=True, power_w=CAR)
def car_w(self, _now):
return CAR
def stuck(self, _now):
return False
def contradicted(self, now):
return self.contra(now - 10000.0)
def car_w_paused(self, _now):
return CAR
@staticmethod
def status(*_a):
return "charging"
class _CarC(_Car):
def __init__(self, contra, own):
super().__init__()
self.car, self.own = _TrackerC(contra), own
def car_manual(self):
return True
def _car_own_pause(self, mono):
return self.own(mono - 10000.0)
def contra_run(contra, own, secs):
c = _CarC(contra, own)
_c, ex = urun(secs, const(13000.0 + CAR), const(0.0),
lambda t: None if contra(t) or own(t) else CAR, c=c)
return ex
never = lambda t: False # noqa: E731
exg = contra_run(lambda t: 300 <= t < 306, never, range(0, 1100))
check("contradiction (T3 shape): the meter contradicts the figure at E+300: "
"not explained from E+300 to the quarter's end, though trusted again "
"from E+306", all(run_of(exg, 0, 299)) and not any(run_of(exg, 300, 899))
and len(run_of(exg, 300, 899)) == 600)
check("contradiction: released by the next quarter (review MG): explained "
"again from E+900", all(run_of(exg, 900, 1099))
and len(run_of(exg, 900, 1099)) == 200)
exf = contra_run(lambda t: 100 <= t < 130, lambda t: 100 <= t < 130,
range(0, 400))
check("contradiction during our own pause (EV-15) latches nothing (review "
"MF): the stand-in explains in it, the trusted figure after it",
all(run_of(exf, 0, 399)) and len(run_of(exf, 0, 399)) == 400)
# --- T10(a) unit: the battery reading lost for one cycle --------------------- #
cA, eA = urun(range(-3, 10), const(14000.0 + CAR - 800.0),
lambda t: None if t == 1 else 800.0, const(CAR))
@@ -557,6 +616,18 @@ for nm, kw in (("T2", dict(house=H.shape(14000.0), b=const(800.0))),
H.alarms(r10b) == T5_BASE and all(
x["alarm"] for x in H.window(tr10b, E + 1, E + 899)))
# --- R1 (review round 2): the energy reading unknown for one cycle ----------- #
for nm, kw in (("T2", dict(house=H.shape(14000.0), b=const(800.0))),
("T3", dict(house=H.shape(13000.0), b=ZERO))):
rg, trg = H.run(a=ZERO, extra=H.energy_gap(E + 200), **kw)
summary(f"R1 {nm} energy gap at E+200", rg, trg)
check(f"R1 {nm}: the charger's energy entity unknown for one cycle "
f"(E+200) on a correct car: unknown, not contradicted, so red for "
f"that cycle only and explained from the next (Expected 5)",
H.red_secs(trg) == [E + 200] and H.edges(trg) == [E + 200]
and all(x["explains"] for x in H.window(trg, E + 201, E + 899)
if x["lim"]))
# --- T11: one battery first (SAFETY-87) --------------------------------------- #
for nm, house in (("(i) 17 500 W", 17500.0), ("(ii) 19 000 W", 19000.0)):
r11, tr11 = H.run(honest(house), soc={"a": 19.0, "b": 35.0})
@@ -709,6 +780,31 @@ for nm, kw in (("T2", dict(house=H.shape(14000.0), b=const(800.0))),
f"charger writes are identical whether the car explains or not",
H.commands(ra, tra) == H.commands(rb, trb))
# N4 with "Batteries help with the peak" off (review round 2): the guard's
# input is `car_exclude`, which reads the car's energy count. The
# contradiction latch must not touch it: the same commands with the latch off.
for nm, kw in (
("SoC 60 %, energy gap at E+200",
dict(house=H.shape(13000.0), soc={"a": 60.0, "b": 60.0},
extra=H.energy_gap(E + 200))),
("at the reserve, energy gap at E+200",
dict(house=H.shape(13000.0), a=ZERO, b=ZERO,
extra=H.energy_gap(E + 200))),
("SoC 60 %, the T9(c) liar",
dict(house=honest(13900.0), soc={"a": 60.0, "b": 60.0},
sim=Draw(100.0, 1380.0, setpoint_a=6))),
("at the reserve, the T9(c) liar",
dict(house=honest(13900.0), a=ZERO, b=ZERO,
sim=Draw(100.0, 1380.0, setpoint_a=6)))):
ra, tra = H.run(cover=False, **kw)
if "sim" in kw:
kw = dict(kw, sim=Draw(100.0, 1380.0, setpoint_a=6))
rb, trb = H.run(cover=False, latch_off=True, **kw)
summary(f"N4 cover off, {nm}", ra, tra)
check(f"N4 cover off, {nm}: the claim, the floor, the setpoints and the "
f"charger writes are those of the same run without the "
f"contradiction latch", H.commands(ra, tra) == H.commands(rb, trb))
# --- N5: at most one floor-alarm edge per quarter ---------------------------- #
def per_quarter(ts):
out = {}
@@ -717,12 +813,19 @@ def per_quarter(ts):
return out
# Cover off, the T9(c) liar at the reserve: the guard's own engagement flips
# as the liar's figure is corroborated now and then (its input is
# `car_exclude`), pre-existing (base: 4 edges). Printed, not graded here.
LIAR_OFF = "N4 cover off, at the reserve, the T9(c) liar"
print(f" {LIAR_OFF}: alarm edges "
f"{[[t - E for t in ts] for nm, ts in RUNS if nm == LIAR_OFF]}")
many = [(nm, ts) for nm, ts in RUNS
if any(v > 1 for v in per_quarter(
if nm != LIAR_OFF and any(v > 1 for v in per_quarter(
[t for t in ts if not nm.startswith("T15 x10") or t < F2_FROM])
.values())]
check(f"N5: at most one floor-alarm edge per quarter in every run "
f"({len(RUNS)} runs; x10 to E+500): {many}", many == [])
f"({len(RUNS)} runs; x10 to E+500; the cover-off liar apart): "
f"{many}", many == [])
print()
print("FAIL: " + ", ".join(fails) if fails else "PASS: every check passed")