vorflop_selbst: auswerten aborts when seed A of the build equals seed B of the archive run; spec

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-05 06:30:19 +01:00
co-authored by Claude Opus 5.5
parent 0165b7e863
commit acc4cd12dc
3 changed files with 54 additions and 2 deletions
@@ -4,6 +4,7 @@ Input: rows of `vorflop-selbst-archiv` (changed decisions: key, class, action na
line index `i`) and the archive description per line index (`entscheidungen.jsonl`: pos, linie, spieler, sonder). Output carries no player or hand IDs, no line indices.
"""
import collections
import re
import wert as W
@@ -11,6 +12,30 @@ SPALTEN = ["linie", "position", "spieler", "sonder", "knoten", "klasse", "gespie
RICHTUNGEN = ("MehrJam", "MehrFold", "Sonstige", "Unveraendert")
SAAT_A_STANDARD = 0x5E1B # the seed of the builds before `saat=` existed (SAAT_A in the motor)
def saat_a(stand):
"""Seed A of the build from the `stand` field of the sidecar header ("<sha>;saat=<A>;n=<n>"); None for older sidecars."""
m = re.search(r"(?:^|;)saat=(\d+)", stand or "")
return int(m.group(1)) if m else None
def saat_pruefen(stand, roh):
"""Selection (build, seed A) and valuation (archive run, seed B) need independent rollouts, otherwise the winner's curse biases the value upwards.
Returns (A, B); ValueError if the rows carry no or different seeds B or B equals A."""
a = saat_a(stand)
if a is None:
a = SAAT_A_STANDARD
bs = {r.get("saat") for r in roh}
if None in bs or len(bs) != 1:
raise ValueError("rows without a seed B or with several seeds B: %r" % sorted(bs, key=str))
b = bs.pop()
if b == a:
raise ValueError("seed B equals seed A (%d): selection and valuation would not be independent" % a)
return a, b
def mischung_text(mischung):
return ", ".join("%s %.0f%%" % (a, 100 * p) for a, p in mischung.items() if p > 0.0005)
@@ -3,7 +3,7 @@
python3 messung/innovation/vorflop_selbst/vorflop_selbst.py zaehlen
python3 .../vorflop_selbst.py aus <exe_basis> <exe_neu> [n=500] [saat=1] (switch OFF: bit-identical on real requests)
python3 .../vorflop_selbst.py auswerten [roh=<archiv-roh.jsonl>] (aenderungen-archiv.tsv on the SSD + AENDERUNGEN.md from the rows of `vorflop-selbst-archiv`)
python3 .../vorflop_selbst.py auswerten [roh=<archiv-roh.jsonl>] [sidecar=<datei>] (aborts if seed A of the build equals seed B of the archive run; aenderungen-archiv.tsv on the SSD + AENDERUNGEN.md from the rows of `vorflop-selbst-archiv`)
python3 .../vorflop_selbst.py sidecar <datei> [key=<hex> klasse=<n>] (read VSELBS02: header, node count, one class)
The computation (rollouts for V, the changed decisions, the "sonstige" analysis) runs in the motor tool `vorflop-selbst-archiv` on the farm, see docs/vorflop_selbst.md
@@ -119,6 +119,9 @@ def aus(exe_a, exe_b, opt):
def auswerten(opt):
"""Rows of `vorflop-selbst-archiv` + archive description -> TSV (SSD) and AENDERUNGEN.md (repo; sums only)."""
roh = S.archiv_zeilen(opt.get("roh", GROSS + "/archiv-roh.jsonl"))
sidecar = opt.get("sidecar", GROSS + "/sechs100-v2-suche-jam-gewinn.vselbst")
kopf_sc = S.lade(sidecar).kopf
saat_a, saat_b = A.saat_pruefen(kopf_sc["stand"], roh) # aborts when both are equal (winner's curse)
zaehlung = json.load(open(HIER + "/zaehlung.json"))
beschreibung = {z["i"]: z for z in lies(GROSS + "/entscheidungen.jsonl")}
zeilen = A.entscheidungszeilen(roh, beschreibung)
@@ -126,7 +129,8 @@ def auswerten(opt):
with open(tmp, "w") as f:
f.write(A.tsv(zeilen))
os.replace(tmp, GROSS + "/aenderungen-archiv.tsv")
kopf = "Sidecar: %s" % opt.get("kopf", "sechs100-v2-suche-jam.vselbst (VSELBS02, Modus suche+jam, Delta-Prior aus vergleich2)")
kopf = ("Sidecar: %s (VSELBS02, Modus %s, Stand %s). Auswahl: Bau mit Saat A %d; Bewertung: Archivlauf mit Saat B %d, n %s (unabhaengige Rollouts)." %
(os.path.basename(sidecar), kopf_sc["modus"], kopf_sc["stand"].split(";")[0], saat_a, saat_b, roh[0].get("n_max", "?") if roh else "?"))
text = A.markdown(zeilen, zaehlung, kopf)
with open(HIER + "/AENDERUNGEN.md", "w") as f:
f.write(text)
+23
View File
@@ -246,5 +246,28 @@ class Archivliste(unittest.TestCase):
self.assertNotIn("kennung", m.lower())
class Saaten(unittest.TestCase):
def test_saat_a_aus_dem_stand_feld(self):
self.assertEqual(A.saat_a("abc123;saat=777;n=1024"), 777)
self.assertIsNone(A.saat_a("6de8484cb"))
self.assertIsNone(A.saat_a(None))
def test_getrennte_saaten_werden_akzeptiert(self):
self.assertEqual(A.saat_pruefen("x;saat=5;n=1024", [{"saat": 9}, {"saat": 9}]), (5, 9))
def test_gleiche_saat_bricht_ab(self):
with self.assertRaises(ValueError):
A.saat_pruefen("x;saat=9;n=1024", [{"saat": 9}])
# older sidecar without seed: the historic default seed A applies
with self.assertRaises(ValueError):
A.saat_pruefen("6de8484cb", [{"saat": A.SAAT_A_STANDARD}])
def test_zeilen_ohne_oder_mit_verschiedenen_saaten_brechen_ab(self):
with self.assertRaises(ValueError):
A.saat_pruefen("x;saat=5", [{"i": 1}])
with self.assertRaises(ValueError):
A.saat_pruefen("x;saat=5", [{"saat": 1}, {"saat": 2}])
if __name__ == "__main__":
unittest.main()