Farm: schnelleres Tor-3-Duplikat - gemeinsamer SHARINGAN-Antwortspeicher je Lauf (sh6c.py, bitgleich, Stichprobenpruefung), Speicherschwelle und Abstand als Parameter, Messlauf ohne Beleg-Ablage
SHARINGANs Flop-Suche (200k, 1 Faden) ist ~95 % der Wanduhr eines Tisches; Basis- und Kandidatentisch stellen bei gleichem Spiel dieselbe Frage mit derselben Saat. Der Speicher rechnet jede Frage einmal fuer beide Arme. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
fdc7a16b20
commit
44a18b9ad3
@@ -0,0 +1,141 @@
|
||||
"""SHARINGAN-Bruecke wie sh6.py (pruef6), mit gemeinsamem Antwortspeicher fuer das gepaarte Duplikat (Tor 3).
|
||||
|
||||
Warum: Im Duplikat spielen Basis- und Kandidaten-Tisch dieselben Blaetter mit denselben Saaten. Solange beide Motoren
|
||||
gleich spielen, stellen beide Tische SHARINGAN exakt dieselbe Frage (gleiche Karten, gleicher Verlauf, gleiche Saat).
|
||||
SHARINGAN laeuft mit 1 Faden bitgleich: dieselbe Frage gibt dieselbe Antwort. Die Flop-Suche (200k Iterationen) kostet
|
||||
im Mittel 6-11 s und ist ~95 % der Wanduhr eines Tisches (05.12., temperatur-86911151-tor3). Der Speicher teilt die
|
||||
Antwort: wer zuerst fragt, rechnet; der andere Tisch liest sie. Das Ergebnis je Tisch ist identisch zu sh6.py.
|
||||
|
||||
Schluessel: sha256 der ActRequest-Zeile ohne das Feld "id" (Zaehler des Prozesses, geht nicht in die Entscheidung ein;
|
||||
die Saat steht in options.seed). Speicher: ein Ordner, je Schluessel eine Datei <hash>.json (atomar ueber .tmp und
|
||||
rename). Wer rechnet, legt vorher <hash>.lock exklusiv an; ein zweiter Tisch wartet auf die Antwort (bis SH_CACHE_WARTE_S,
|
||||
danach rechnet er selbst). Probe auf Bitgleichheit: Anteil SH_CACHE_PRUEF (z. B. 0.02) der Treffer wird trotzdem
|
||||
gerechnet und verglichen; Abweichungen zaehlen in <ordner>/pruef.jsonl.
|
||||
|
||||
Aufruf wie sh6.py: sh6c.py <sharingan-stdio.exe> <blueprint.plcp> <buckets-ordner> <sizing> [weitere Flags]
|
||||
Umgebung: SH_CACHE=<ordner> (Pflicht), SH_PROTOKOLL wie sh6.py (Quelle "cache" bei Treffern, ms = 0),
|
||||
SH6_PFAD=<ordner mit sh6.py> (Uebersetzung anfrage() wird von dort genommen, nicht kopiert).
|
||||
"""
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
sys.path.insert(0, os.environ.get("SH6_PFAD", os.path.dirname(os.path.abspath(__file__))))
|
||||
import sh6 # noqa: E402 (Uebersetzung Vertrag -> ActRequest, unveraendert)
|
||||
|
||||
CACHE = os.environ["SH_CACHE"]
|
||||
WARTE_S = float(os.environ.get("SH_CACHE_WARTE_S", "180"))
|
||||
PRUEF = float(os.environ.get("SH_CACHE_PRUEF", "0"))
|
||||
PROTOKOLL = os.environ.get("SH_PROTOKOLL")
|
||||
|
||||
|
||||
def schluessel(q):
|
||||
ohne = {k: v for k, v in q.items() if k != "id"}
|
||||
return hashlib.sha256(json.dumps(ohne, sort_keys=True, separators=(",", ":")).encode()).hexdigest()
|
||||
|
||||
|
||||
def lies(pfad):
|
||||
try:
|
||||
with open(pfad, encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except (OSError, ValueError):
|
||||
return None
|
||||
|
||||
|
||||
def schreibe(pfad, r):
|
||||
tmp = "%s.%d.tmp" % (pfad, os.getpid())
|
||||
with open(tmp, "w", encoding="utf-8") as f:
|
||||
json.dump(r, f, separators=(",", ":"))
|
||||
os.replace(tmp, pfad)
|
||||
|
||||
|
||||
def vergleichbar(r):
|
||||
"""Antwort ohne Zeitangaben (timing) fuer die Bitgleich-Probe."""
|
||||
if not isinstance(r, dict):
|
||||
return r
|
||||
o = dict(r.get("response") or {})
|
||||
o.pop("timing", None)
|
||||
return {"ok": r.get("ok"), "action": o.get("action"), "source": o.get("source"), "probs": o.get("probs")}
|
||||
|
||||
|
||||
def main():
|
||||
exe, bp, bk, sz, *rest = sys.argv[1:]
|
||||
os.makedirs(CACHE, exist_ok=True)
|
||||
env = dict(os.environ, STDIO_THREADS="1")
|
||||
p = subprocess.Popen([exe, "--blueprint", bp, "--buckets", bk, "--sizing", sz, "--bind", "127.0.0.1:0"] + rest,
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE, env=env, text=True, encoding="utf-8", bufsize=1,
|
||||
creationflags=0x08000000 if sys.platform == "win32" else 0)
|
||||
prot = open(PROTOKOLL, "a", encoding="utf-8") if PROTOKOLL else None
|
||||
rnd = random.Random(os.getpid())
|
||||
|
||||
def rechne(q):
|
||||
p.stdin.write(json.dumps(q, separators=(",", ":")) + "\n")
|
||||
p.stdin.flush()
|
||||
return json.loads(p.stdout.readline())
|
||||
|
||||
nr = 0
|
||||
for zeile in sys.stdin:
|
||||
if not zeile.strip():
|
||||
continue
|
||||
nr += 1
|
||||
a = json.loads(zeile)
|
||||
bb = float(a["bigBlind"])
|
||||
quelle_cache = False
|
||||
try:
|
||||
q = sh6.anfrage(a, nr)
|
||||
k = schluessel(q)
|
||||
ziel, sperre = os.path.join(CACHE, k + ".json"), os.path.join(CACHE, k + ".lock")
|
||||
r = lies(ziel)
|
||||
if r is None:
|
||||
try:
|
||||
fd = os.open(sperre, os.O_CREAT | os.O_EXCL | os.O_WRONLY)
|
||||
os.close(fd)
|
||||
eigen = True
|
||||
except FileExistsError:
|
||||
eigen = False
|
||||
if not eigen:
|
||||
ende = time.monotonic() + WARTE_S
|
||||
while r is None and time.monotonic() < ende:
|
||||
time.sleep(0.05)
|
||||
r = lies(ziel)
|
||||
if r is None:
|
||||
r = rechne(q)
|
||||
if r.get("ok"):
|
||||
schreibe(ziel, r)
|
||||
else:
|
||||
quelle_cache = True
|
||||
else:
|
||||
quelle_cache = True
|
||||
if quelle_cache and PRUEF > 0 and rnd.random() < PRUEF:
|
||||
r2 = rechne(q)
|
||||
with open(os.path.join(CACHE, "pruef.jsonl"), "a", encoding="utf-8") as f:
|
||||
f.write(json.dumps({"k": k, "gleich": vergleichbar(r2) == vergleichbar(r),
|
||||
"strasse": (r2.get("response") or {}).get("street")}) + "\n")
|
||||
except Exception as e: # noqa: BLE001
|
||||
r = {"ok": False, "error": {"code": "bruecke", "message": str(e)}}
|
||||
if r.get("ok"):
|
||||
o = r["response"]
|
||||
akt = o["action"]
|
||||
t = akt["type"]
|
||||
w = {"action": t.upper(), "size": round(akt["to"] * bb / 100, 6) if t == "raise" else None,
|
||||
"confidence": 1, "reason": "sharingan %s %s" % (o["source"], o.get("fallback_reason") or "")}
|
||||
if prot:
|
||||
prot.write("%s %s %s %.0f\n" % ("cache" if quelle_cache else o["source"],
|
||||
(o.get("fallback_reason") or "-").split(":")[0].replace(" ", "_"),
|
||||
o["street"], 0 if quelle_cache else o["timing"]["total_ms"]))
|
||||
else:
|
||||
w = {"action": "CHECK" if "CHECK" in (a.get("legalActions") or []) else "FOLD", "size": None, "confidence": 0,
|
||||
"reason": "sharingan Fehler %s" % json.dumps(r.get("error"))[:200]}
|
||||
if prot:
|
||||
prot.write("fehler %s - 0\n" % (r.get("error") or {}).get("code"))
|
||||
if prot:
|
||||
prot.flush()
|
||||
print(json.dumps(w), flush=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -5,7 +5,7 @@
|
||||
# MOTOR_POOL_UNSERE: Wissen ueber echte Gegner; ausserdem schreibt so kein Simlauf in die Live-Gedaechtnisse). Alles andere der Zeile bleibt.
|
||||
# Beide Arme mit normalen Tafeln (grundstrategie-mitzaehler, ~9,5 GB je Motor), dieselben Tische und Saaten (32 Bit), Aufstellungen 1v5/3v3/5v1.
|
||||
# pokerbench-temperatur-duplikat.ps1 -Minuten 15 -Tischliste 1,1,1,3,3,3,5,5,5 (Hauptsession 05.12.: alle Tore zusammen hoechstens 15 min; fenster_min im Beleg)
|
||||
param([string]$Kandidat = '86911151', [string]$Etikett = '', [int]$Minuten = 15, [string]$Tischliste = '1,1,3,5', [int]$Saat = 2026120400, [int]$Blaetter = 5000, [switch]$Fortsetzen, [int]$Ziel = 0)
|
||||
param([string]$Kandidat = '86911151', [string]$Etikett = '', [int]$Minuten = 15, [string]$Tischliste = '1,1,3,5', [int]$Saat = 2026120400, [int]$Blaetter = 5000, [switch]$Fortsetzen, [int]$Ziel = 0, [switch]$Cache, [int]$MinFreiGB = 25, [int]$Abstand = 15, [switch]$OhneBeleg)
|
||||
$f = 'D:\Projects\pf-batterie\messung\farm'; $o = "$f\temperatur-$Kandidat-tor3$Etikett"; New-Item -ItemType Directory -Force $o | Out-Null; $log = "$o\kette.log"
|
||||
Set-Content "$o\STARTER.pid" $PID
|
||||
function Log($t) { Add-Content -Path $log -Value ((Get-Date -Format 'HH:mm:ss') + ' ' + $t) -Encoding UTF8 }
|
||||
@@ -15,6 +15,7 @@ $py = (Get-Command python).Source; $pruef = 'D:\Projects\pokerfreak\.claude\work
|
||||
$D = 'D:/Projects/pokerfreak-daten/grundstrategie-mitzaehler'
|
||||
$P6 = 'D:/Projects/pokerfreak/.claude/worktrees/motor-pruef6-3b22d4/messung/motor/pruef6/sharingan'; $shOrdner = 'D:/pokerfreak-fremd/sharingan'
|
||||
$sh = "py:$P6/sh6.py $shOrdner/code/target/serve/pokerbench-pruef6-sharingan.exe $shOrdner/weights/B-local-2e10.plcp $shOrdner/data/buckets-200 local --search-threads 1 --search-concurrency 1 --budget-ms 600000 --set iters=200000"
|
||||
if ($Cache) { $sh = $sh.Replace("py:$P6/sh6.py", "py:$f/nacht-0112/werkzeuge/sh6c.py"); $env:SH_CACHE = "$o\sh-cache"; $env:SH6_PFAD = $P6; $env:SH_CACHE_PRUEF = '0.03' }
|
||||
$motorArgs = "dienst sechs100 $D 2000-600-400 200 $D/sechs100-v2.bin genau hu=$D/hu100-v1.bin,$D/hu200-v2.bin"
|
||||
$basisSchalter = 'D:\Projects\pokerfreak\scratch\basis-rein-temperatur\kern_schalter.txt'
|
||||
$kandSchalter = "D:\Projects\pokerfreak-daten\pruefstand\temperatur-uhr-$Kandidat\kern_schalter.txt"
|
||||
@@ -28,7 +29,7 @@ $basisExe = ExeAus $basisSchalter; $kandExe = ExeAus $kandSchalter
|
||||
Log ("Schalter basis {0} {1} | kandidat {2} {3}" -f $basisSchalter, (Get-FileHash $basisSchalter).Hash, $kandSchalter, (Get-FileHash $kandSchalter).Hash)
|
||||
$arme = [ordered]@{ 'basis' = @($basisExe, ("MOTOR_NL2=0 " + (Zeile $basisSchalter))); 'kandidat' = @($kandExe, ("MOTOR_NL2=0 " + (Zeile $kandSchalter))) }
|
||||
foreach ($a in $arme.Keys) { Log ("Arm {0}: {1} {2} | {3}" -f $a, $arme[$a][0], (Get-FileHash $arme[$a][0]).Hash, $arme[$a][1]) }
|
||||
Log "SHARINGAN: $sh"
|
||||
Log "SHARINGAN: $sh"; Log "Optionen: Cache=$Cache MinFreiGB=$MinFreiGB Abstand=$Abstand Tischliste=$Tischliste OhneBeleg=$OhneBeleg"
|
||||
Add-Type -Namespace FarmR -Name Sp -MemberDefinition @'
|
||||
[StructLayout(LayoutKind.Sequential)] public struct MS { public uint l; public uint last; public ulong phys, physfrei, zusage, zusagefrei, virt, virtfrei, x; }
|
||||
[DllImport("kernel32.dll")] public static extern bool GlobalMemoryStatusEx(ref MS m);
|
||||
@@ -53,8 +54,8 @@ while ((Get-Date) -lt $ende) {
|
||||
foreach ($t in $plan.Keys) {
|
||||
$p = $laeufe[$t]; if ($p -and -not $p.HasExited) { continue }
|
||||
if ($p) { Log "Tisch $t endete (Rueckgabe $($p.ExitCode)); Neustart mit Fortsetzen"; if (-not $Fortsetzen) { continue } }
|
||||
if ([FarmR.Sp]::FreiGB() -lt 25) { continue }
|
||||
Starte $t; Start-Sleep 15 # Tafeln laden erst, dann zaehlt der Speicher
|
||||
if ([FarmR.Sp]::FreiGB() -lt $MinFreiGB) { continue }
|
||||
Starte $t; Start-Sleep $Abstand # Tafeln laden erst, dann zaehlt der Speicher
|
||||
}
|
||||
if ($Ziel -gt 0 -and (Get-Date) -ge $naechstePruefung) {
|
||||
$n = Gepaart; Log "gepaarte Blaetter: $n (Ziel $Ziel), frei $([math]::Round([FarmR.Sp]::FreiGB(),1)) GB"; $naechstePruefung = (Get-Date).AddMinutes(5)
|
||||
@@ -66,6 +67,7 @@ BeendeAlle
|
||||
if ($Ziel -gt 0) { Log "Ende: gepaarte Blaetter $(Gepaart)" }
|
||||
Log "=== FERTIG nach $Minuten min"
|
||||
Remove-Item "$o\STARTER.pid" -EA 0
|
||||
if ($OhneBeleg) { $null = Gepaart; Log "Ende ohne Beleg-Ablage: $o\duplikat-sharingan-b.json"; Remove-Item "$o\STARTER.pid" -EA 0; exit 0 }
|
||||
# Beleg fuer fassung_tor.py: Auswertung mit Exes/Schaltern ergaenzen und atomar unter pruefstand\temperatur-uhr-<Kandidat>\ ablegen
|
||||
$null = Gepaart
|
||||
$zielBeleg = "D:\Projects\pokerfreak-daten\pruefstand\temperatur-uhr-$Kandidat\duplikat-sharingan-b.json"
|
||||
|
||||
Reference in New Issue
Block a user