154 lines
6.6 KiB
Nim
154 lines
6.6 KiB
Nim
## G6 ablation ladder — probes x carry-over (CHIMERA M5.5). LIVE, Java required.
|
|
##
|
|
## Four arms over the same 8x5 pinned-opponent protocol, using the UNIFIED
|
|
## idTicks metric (round-relative, max posterior > 0.8; median/p90/id-fraction
|
|
## over all rounds):
|
|
## * on — probes ON, cross-round carry-over ON (default build)
|
|
## * off — probes OFF, carry-over ON (-d:chimeraNoProbes)
|
|
## * reset — probes ON, fresh-round reset ON (-d:chimeraFreshRound)
|
|
## * offreset — probes OFF, fresh-round reset ON (both defines)
|
|
##
|
|
## Primary G6 read: probes must cut the MOVING-subset median identification
|
|
## ticks by >= 20% (`on` vs `off`), reported for the full suite too. The
|
|
## carry-over effect is `on` vs `reset`.
|
|
##
|
|
## ON telemetry archived to /tmp/chimera_g6_on (input to bench_g5p.nim).
|
|
## Run: `nim c -r --hints:off -d:release tests/bench_g6.nim`
|
|
|
|
import std/[os, osproc, strutils, sequtils, math, tables, algorithm, times]
|
|
import bench_common
|
|
import test_framework/server_manager
|
|
|
|
const
|
|
Rounds = 5
|
|
Repeat = 3
|
|
Telemetry = getTempDir() / "chimera_twin"
|
|
ArmTags = ["on", "off", "reset", "offreset"]
|
|
|
|
proc armDefines(tag: string): seq[string] =
|
|
case tag
|
|
of "on": @[]
|
|
of "off": @["-d:chimeraNoProbes"]
|
|
of "reset": @["-d:chimeraFreshRound"]
|
|
else: @["-d:chimeraNoProbes", "-d:chimeraFreshRound"]
|
|
|
|
proc runArm(tag: string): Table[string, seq[int]] =
|
|
let botDir = stageBot("g6_" & tag, armDefines(tag))
|
|
removeDir(Telemetry)
|
|
let armDir = getTempDir() / ("chimera_g6_" & tag)
|
|
removeDir(armDir)
|
|
createDir(armDir)
|
|
for opp in sorted(toSeq(Expected.keys)):
|
|
restartServer()
|
|
var url = serverUrl()
|
|
putEnv("CHIMERA_OPPONENT", opp)
|
|
putEnv("CHIMERA_TELEMETRY_DIR", Telemetry)
|
|
let sampleBot = SampleRoot / opp
|
|
var ids: seq[int]
|
|
for run in 1 .. Repeat:
|
|
var ok = false
|
|
let t0 = epochTime()
|
|
for attempt in 1 .. MaxAttempts:
|
|
removeDir(Telemetry)
|
|
sleep(500)
|
|
if runBattleHard(url, @[botDir, sampleBot], Rounds, 90000):
|
|
ok = true
|
|
break
|
|
echo " ", tag, " ", opp, " run", run, " attempt", attempt,
|
|
": battle failed/timeout"
|
|
killStaleBots()
|
|
restartServer()
|
|
url = serverUrl()
|
|
echo " [", tag, "] ", opp, " run", run, " ok=", ok, " in ",
|
|
formatFloat(epochTime() - t0, ffDecimal, 1), "s (attempts used)"
|
|
if not ok: continue
|
|
let runDir = armDir / (opp & "-run" & $run)
|
|
copyDir(Telemetry, runDir)
|
|
for f in toSeq(walkFiles(runDir / "*.jsonl")):
|
|
let rs = parseFile(f, Expected[opp])
|
|
if rs.sumTicks == 0: continue
|
|
ids.add(if rs.identified: rs.idTick else: -1)
|
|
result[opp] = ids
|
|
|
|
proc pooled(arm: Table[string, seq[int]], opps: seq[string]): seq[int] =
|
|
for opp in opps:
|
|
if opp in arm: result.add arm[opp]
|
|
|
|
proc cutPct(onMed, offMed: int): float64 =
|
|
if offMed <= 0: 0.0 else: 100.0 * float(offMed - onMed) / float(offMed)
|
|
|
|
proc main() =
|
|
guardSkip()
|
|
echo "[G6] 4 arms x ", Repeat, " runs x ", Rounds, " rounds"
|
|
var tabs = initTable[string, Table[string, seq[int]]]()
|
|
for tag in ArmTags:
|
|
tabs[tag] = runArm(tag)
|
|
|
|
echo "\n=== G6 arms: unified idTicks median / id-fraction% (", Repeat,
|
|
" runs x ", Rounds, " rounds) ==="
|
|
echo "Opponent on med id% off med id% reset med id% offreset med id%"
|
|
var lines: seq[string]
|
|
lines.add("# G6 ablation ladder (M5.5): probes x carry-over\n")
|
|
lines.add("Unified idTicks (round-relative, max posterior > 0.8), median over " &
|
|
$Repeat & " runs x " & $Rounds & " rounds; id% = fraction of rounds identified. " &
|
|
"Arms: on = probes+carry, off = -probes, reset = -carry, offreset = both. " &
|
|
"Generated by `tests/bench_g6.nim`.\n")
|
|
lines.add("| opponent | on med | on id% | off med | off id% | reset med | reset id% | offreset med | offreset id% |")
|
|
lines.add("|---|---:|---:|---:|---:|---:|---:|---:|---:|")
|
|
for opp in sorted(toSeq(Expected.keys)):
|
|
var cells: seq[string]
|
|
var textLine = " " & alignLeft(opp, 12)
|
|
var row = "| " & opp & " |"
|
|
for tag in ArmTags:
|
|
if opp in tabs[tag]:
|
|
let s = idStats(tabs[tag][opp])
|
|
let m = if s.median < 0: "-" else: $s.median
|
|
textLine.add align(m, 8) & align(formatFloat(s.idFraction, ffDecimal, 0), 5)
|
|
row.add " " & m & " | " & formatFloat(s.idFraction, ffDecimal, 1) & " |"
|
|
else:
|
|
textLine.add align("-", 8) & align("-", 5)
|
|
row.add " - | - |"
|
|
echo textLine
|
|
lines.add row
|
|
|
|
let full = @["Crazy", "SpinBot", "RamFire", "Corners", "Walls",
|
|
"TrackFire", "Fire", "VelociBot"]
|
|
echo ""
|
|
echo "Metric on off reset offreset"
|
|
for (label, opps) in [("MOVING-subset", MovingOpponents), ("FULL-suite", full)]:
|
|
var st: Table[string, IdStats]
|
|
for tag in ArmTags:
|
|
st[tag] = idStats(pooled(tabs[tag], opps))
|
|
echo alignLeft(label, 18),
|
|
align($st["on"].median, 7), align($st["off"].median, 8),
|
|
align($st["reset"].median, 8), align($st["offreset"].median, 10),
|
|
" (id%: ", formatFloat(st["on"].idFraction, ffDecimal, 0), "/",
|
|
formatFloat(st["off"].idFraction, ffDecimal, 0), "/",
|
|
formatFloat(st["reset"].idFraction, ffDecimal, 0), "/",
|
|
formatFloat(st["offreset"].idFraction, ffDecimal, 0), ")"
|
|
let cut = cutPct(st["on"].median, st["off"].median)
|
|
let carryGain = if st["reset"].median > 0:
|
|
100.0 * float(st["reset"].median - st["on"].median) / float(st["reset"].median)
|
|
else: 0.0
|
|
echo " probes cut (off->on) = ", formatFloat(cut, ffDecimal, 1),
|
|
"% carry-over gain (reset->on) = ", formatFloat(carryGain, ffDecimal, 1), "%"
|
|
lines.add "\n**" & label & "** pooled: on " & $st["on"].median & " (id " &
|
|
formatFloat(st["on"].idFraction, ffDecimal, 1) & "%), off " &
|
|
$st["off"].median & " (id " & formatFloat(st["off"].idFraction, ffDecimal, 1) &
|
|
"%), reset " & $st["reset"].median & " (id " &
|
|
formatFloat(st["reset"].idFraction, ffDecimal, 1) & "%), offreset " &
|
|
$st["offreset"].median & " (id " &
|
|
formatFloat(st["offreset"].idFraction, ffDecimal, 1) & "%). Probes cut = " &
|
|
formatFloat(cut, ffDecimal, 1) & "%, carry-over gain = " &
|
|
formatFloat(carryGain, ffDecimal, 1) & "%. **G6 bar (>=20% cut, " & label & "): " &
|
|
(if cut >= 20.0: "PASS" else: "FAIL") & "**."
|
|
|
|
let art = currentSourcePath().parentDir.parentDir / "benchmarks" / "m5_5_g6.md"
|
|
createDir(art.parentDir)
|
|
writeFile(art, lines.join("\n") & "\n")
|
|
echo "Artifact: ", art
|
|
echo "ON telemetry archived at ", getTempDir() / "chimera_g6_on"
|
|
|
|
when isMainModule:
|
|
main()
|