Three coordinated hygiene changes; none target the diagnosed
selection-bias bottleneck. They make the codebase honestly reflect the
pure-self-play stance and reduce dashboard noise.
Bot rename (drop the unhelpful safe_ prefix; suffixes describe behaviour):
- safe_heuristic_loose -> heuristic_aggressive
- safe_heuristic -> heuristic_balanced
- safe_heuristic_strict -> heuristic_cautious
- noisy_safe -> heuristic_noisy
- passive_discard -> discard_only
Class renames in bots/: SafeHeuristicBot -> HeuristicBot,
SafeHeuristicParams -> HeuristicParams, PassiveDiscardBot -> DiscardOnlyBot,
plus loose/strict parameter constants. Backwards compatibility was dropped
intentionally per user instruction; no aliases. Active configs, docs,
scripts, tests updated. Archive directories (configs/archive,
docs/archive, runs/archive) left intact and may still reference old
names per their read-only policy. The src/.../bots/passive.py module was
renamed to discard_only.py via git mv.
Analyze plot curation (deep_cfr/analyze.py):
- Added analysis_00_core.png as the canonical daily dashboard with 10
heuristic-free metrics (loss/{advantage,strategy}; vs heuristic_cautious:
avg_score_diff0, win_rate0, avg_opened_colors, positive_expedition_rate,
bonus_expedition_rate, score_per_opened_color, policy_entropy; vs random:
win_rate0).
- Removed analysis_05_open_quality.png (bad/weak/good open rates,
recoverable score) and analysis_07_calibration.png (calibration gap,
recoverable mean) - both relied on the heuristic recoverable_score
classifier already dropped from inputs.
- Removed SELECTIVITY_PLOTS and plot_selectivity (heuristic-laden).
- SUMMARY_EVAL_METRICS no longer includes bad_open_rate or
calibration_gap.
- PlotSpec gained an opponents allowlist so the new core section can pin
a specific opponent per panel without restructuring plot_section.
Tiered evaluation cadence (EvaluationConfig):
- Added extended_opponents and extended_eval_every (default 0 = disabled).
- opponents_for_iteration(iteration) returns the core list every
eval_every and appends extended_opponents (de-duplicated) when
iteration is also a multiple of extended_eval_every.
- default.yaml now uses 3 core opponents (random, discard_only,
heuristic_cautious) every 5 iterations and 3 extended opponents
(heuristic_balanced, heuristic_aggressive, heuristic_noisy) every 50
iterations. random is the floor sanity. discard_only is the
zero-pit detector / absolute-score reference (its score is always 0,
so eval/discard_only/avg_score_diff0 directly equals the model's raw
average score). heuristic_cautious is the ceiling and the
archive-comparable benchmark used in the prior diagnostic sections.
Net eval cost reduction: roughly 50% (3 opponents x every 5 iter, plus
6 opponents x every 50 iter, vs the prior 6 x every 5).
Documented in docs/plans/deep-cfr-selectivity.md section 9.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
106 lines
3.3 KiB
Python
106 lines
3.3 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from coolrl_lost_cities.games.classic.game import GameState, LostCitiesConfig
|
|
|
|
from coolrl_lost_cities.games.classic.bots.heuristic_py import HeuristicBot
|
|
from coolrl_lost_cities.games.classic.bots.registry import (
|
|
AGGRESSIVE_HEURISTIC_PARAMS,
|
|
CAUTIOUS_HEURISTIC_PARAMS,
|
|
)
|
|
|
|
VARIANTS = {
|
|
"default": None,
|
|
"loose": AGGRESSIVE_HEURISTIC_PARAMS,
|
|
"strict": CAUTIOUS_HEURISTIC_PARAMS,
|
|
}
|
|
|
|
|
|
def parse_args() -> argparse.Namespace:
|
|
parser = argparse.ArgumentParser(
|
|
description="Export heuristic bot parity snapshots for external implementations."
|
|
)
|
|
parser.add_argument("--output", required=True, help="JSONL output path.")
|
|
parser.add_argument("--seeds", type=int, default=50, help="Number of seeds per config.")
|
|
parser.add_argument("--max-steps", type=int, default=10_000)
|
|
return parser.parse_args()
|
|
|
|
|
|
def _configs() -> list[tuple[str, LostCitiesConfig]]:
|
|
return [
|
|
("classic", LostCitiesConfig()),
|
|
("small", LostCitiesConfig(n_colors=2, n_ranks=8, hand_size=3)),
|
|
(
|
|
"no-handshakes",
|
|
LostCitiesConfig(n_colors=3, n_ranks=5, n_handshakes=0, hand_size=5),
|
|
),
|
|
]
|
|
|
|
|
|
def _record(
|
|
*,
|
|
config_name: str,
|
|
variant_name: str,
|
|
seed: int,
|
|
turn: int,
|
|
state: GameState,
|
|
action: int,
|
|
) -> dict[str, Any]:
|
|
return {
|
|
"config_name": config_name,
|
|
"variant": variant_name,
|
|
"seed": seed,
|
|
"turn": turn,
|
|
"phase": state.phase,
|
|
"current_player": state.current_player,
|
|
"expected_action": action,
|
|
"state": state.to_snapshot(),
|
|
}
|
|
|
|
|
|
def main() -> None:
|
|
args = parse_args()
|
|
output = Path(args.output)
|
|
output.parent.mkdir(parents=True, exist_ok=True)
|
|
count = 0
|
|
with output.open("w", encoding="utf-8") as handle:
|
|
for config_name, config in _configs():
|
|
for variant_name, params in VARIANTS.items():
|
|
for seed in range(args.seeds):
|
|
bot = HeuristicBot(params)
|
|
state = GameState.new_game(config, seed=seed)
|
|
for turn in range(args.max_steps):
|
|
if state.terminal:
|
|
break
|
|
action = bot.act(state)
|
|
handle.write(
|
|
json.dumps(
|
|
_record(
|
|
config_name=config_name,
|
|
variant_name=variant_name,
|
|
seed=seed,
|
|
turn=turn,
|
|
state=state,
|
|
action=action,
|
|
),
|
|
sort_keys=True,
|
|
)
|
|
+ "\n"
|
|
)
|
|
count += 1
|
|
state.apply_action(action)
|
|
else:
|
|
raise RuntimeError(
|
|
f"game did not terminate: config={config_name} "
|
|
f"variant={variant_name} seed={seed}"
|
|
)
|
|
print(f"Wrote {count} snapshots to {output}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|