Rename bot family, curate analyze plots, tier evaluation cadence
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>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
from coolrl_lost_cities.games.classic.game import Card, GameState, LostCitiesConfig
|
||||
|
||||
from coolrl_lost_cities.games.classic.bots import (
|
||||
HeuristicBot,
|
||||
LostCitiesPolicy,
|
||||
RandomBot,
|
||||
SafeHeuristicBot,
|
||||
)
|
||||
from coolrl_lost_cities.games.classic.bots.heuristic import draw_from_discard_action
|
||||
from coolrl_lost_cities.games.classic.evaluation import play_game_for_evaluation
|
||||
@@ -19,13 +19,13 @@ def _expeditions(config: LostCitiesConfig) -> list[list[list[Card]]]:
|
||||
|
||||
def test_builtin_bots_implement_lost_cities_policy() -> None:
|
||||
assert isinstance(RandomBot(1), LostCitiesPolicy)
|
||||
assert isinstance(SafeHeuristicBot(), LostCitiesPolicy)
|
||||
assert isinstance(HeuristicBot(), LostCitiesPolicy)
|
||||
|
||||
|
||||
def test_safe_heuristic_mirror_match_finishes() -> None:
|
||||
def test_heuristic_mirror_match_finishes() -> None:
|
||||
state, result = play_game_for_evaluation(
|
||||
SafeHeuristicBot(),
|
||||
SafeHeuristicBot(),
|
||||
HeuristicBot(),
|
||||
HeuristicBot(),
|
||||
LostCitiesConfig(n_colors=3, n_ranks=5, n_handshakes=1, hand_size=5),
|
||||
seed=2000,
|
||||
max_steps=200,
|
||||
@@ -34,9 +34,9 @@ def test_safe_heuristic_mirror_match_finishes() -> None:
|
||||
assert result.timed_out is False
|
||||
|
||||
|
||||
def test_safe_heuristic_opponent_value_ignores_hidden_hand() -> None:
|
||||
def test_heuristic_opponent_value_ignores_hidden_hand() -> None:
|
||||
config = LostCitiesConfig(n_colors=2, n_ranks=8, hand_size=3)
|
||||
bot = SafeHeuristicBot()
|
||||
bot = HeuristicBot()
|
||||
discard_card = Card(color=0, rank=6)
|
||||
|
||||
expeditions_a = _expeditions(config)
|
||||
@@ -76,9 +76,9 @@ def test_safe_heuristic_opponent_value_ignores_hidden_hand() -> None:
|
||||
assert value_a == value_b
|
||||
|
||||
|
||||
def test_safe_heuristic_started_expedition_value_ignores_invalid_lower_followup() -> None:
|
||||
def test_heuristic_started_expedition_value_ignores_invalid_lower_followup() -> None:
|
||||
config = LostCitiesConfig(n_colors=2, n_ranks=8, hand_size=3)
|
||||
bot = SafeHeuristicBot()
|
||||
bot = HeuristicBot()
|
||||
high_card = Card(color=0, rank=8)
|
||||
|
||||
base_expeditions = _expeditions(config)
|
||||
@@ -115,9 +115,9 @@ def test_safe_heuristic_started_expedition_value_ignores_invalid_lower_followup(
|
||||
assert lower_followup_value == base_value
|
||||
|
||||
|
||||
def test_safe_heuristic_draws_playable_discard_instead_of_deck() -> None:
|
||||
def test_heuristic_draws_playable_discard_instead_of_deck() -> None:
|
||||
config = LostCitiesConfig(n_colors=2, n_ranks=8, hand_size=3)
|
||||
bot = SafeHeuristicBot()
|
||||
bot = HeuristicBot()
|
||||
|
||||
expeditions = _expeditions(config)
|
||||
expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
@@ -132,9 +132,9 @@ def test_safe_heuristic_draws_playable_discard_instead_of_deck() -> None:
|
||||
assert bot._act_draw(state) == draw_from_discard_action(0)
|
||||
|
||||
|
||||
def test_safe_heuristic_can_draw_discard_to_deny_opponent_when_losing() -> None:
|
||||
def test_heuristic_can_draw_discard_to_deny_opponent_when_losing() -> None:
|
||||
config = LostCitiesConfig(n_colors=2, n_ranks=8, hand_size=4)
|
||||
bot = SafeHeuristicBot()
|
||||
bot = HeuristicBot()
|
||||
|
||||
expeditions = _expeditions(config)
|
||||
expeditions[0][1] = [Card(color=1, rank=8)]
|
||||
@@ -158,9 +158,9 @@ def test_safe_heuristic_can_draw_discard_to_deny_opponent_when_losing() -> None:
|
||||
assert bot._act_draw(state) == draw_from_discard_action(0)
|
||||
|
||||
|
||||
def test_safe_heuristic_classic_self_play_opens_expeditions() -> None:
|
||||
def test_heuristic_classic_self_play_opens_expeditions() -> None:
|
||||
state = GameState.new_game(LostCitiesConfig(), seed=1)
|
||||
bot = SafeHeuristicBot()
|
||||
bot = HeuristicBot()
|
||||
player0_actions: list[int] = []
|
||||
|
||||
for _ in range(60):
|
||||
@@ -182,9 +182,9 @@ def test_safe_heuristic_classic_self_play_opens_expeditions() -> None:
|
||||
assert any(state.expeditions[0][color] for color in range(state.config.n_colors))
|
||||
|
||||
|
||||
def test_safe_heuristic_avoids_opening_weak_fifth_color() -> None:
|
||||
def test_heuristic_avoids_opening_weak_fifth_color() -> None:
|
||||
config = LostCitiesConfig(n_colors=5, n_ranks=8, hand_size=8)
|
||||
bot = SafeHeuristicBot()
|
||||
bot = HeuristicBot()
|
||||
expeditions = _expeditions(config)
|
||||
expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
expeditions[0][1] = [Card(color=1, rank=4)]
|
||||
@@ -211,9 +211,9 @@ def test_safe_heuristic_avoids_opening_weak_fifth_color() -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_safe_heuristic_prefers_followup_on_started_expedition() -> None:
|
||||
def test_heuristic_prefers_followup_on_started_expedition() -> None:
|
||||
config = LostCitiesConfig(n_colors=3, n_ranks=8, hand_size=5)
|
||||
bot = SafeHeuristicBot()
|
||||
bot = HeuristicBot()
|
||||
expeditions = _expeditions(config)
|
||||
expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
state = make_state(
|
||||
@@ -233,9 +233,9 @@ def test_safe_heuristic_prefers_followup_on_started_expedition() -> None:
|
||||
assert chosen.color == 0
|
||||
|
||||
|
||||
def test_safe_heuristic_avoids_unopened_discard_draw_after_four_opens() -> None:
|
||||
def test_heuristic_avoids_unopened_discard_draw_after_four_opens() -> None:
|
||||
config = LostCitiesConfig(n_colors=5, n_ranks=8, hand_size=8)
|
||||
bot = SafeHeuristicBot()
|
||||
bot = HeuristicBot()
|
||||
expeditions = _expeditions(config)
|
||||
expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
expeditions[0][1] = [Card(color=1, rank=4)]
|
||||
|
||||
@@ -3,13 +3,13 @@ from __future__ import annotations
|
||||
from coolrl_lost_cities.games.classic.game import LostCitiesConfig
|
||||
|
||||
from coolrl_lost_cities.games.classic.deep_cfr.imitation import (
|
||||
collect_safe_heuristic_samples,
|
||||
collect_heuristic_samples,
|
||||
new_pretrained_strategy_network,
|
||||
)
|
||||
|
||||
|
||||
def test_collect_safe_heuristic_samples_shapes() -> None:
|
||||
x, y, legal = collect_safe_heuristic_samples(LostCitiesConfig(seed=61), games=1, seed=61)
|
||||
def test_collect_heuristic_samples_shapes() -> None:
|
||||
x, y, legal = collect_heuristic_samples(LostCitiesConfig(seed=61), games=1, seed=61)
|
||||
|
||||
assert len(x) == len(y) == len(legal)
|
||||
assert x.ndim == 2
|
||||
|
||||
@@ -1494,3 +1494,83 @@ def test_interleaved_regret_matching_no_fallback_unchanged_by_mode() -> None:
|
||||
assert fallback_a is False
|
||||
assert np.allclose(policy_uniform, policy_argmax)
|
||||
assert np.allclose(policy_uniform.sum(), 1.0)
|
||||
|
||||
|
||||
def test_evaluation_opponents_for_iteration_core_only_when_extended_disabled() -> None:
|
||||
from coolrl_lost_cities.games.classic.deep_cfr.config import EvaluationConfig
|
||||
|
||||
cfg = EvaluationConfig(
|
||||
eval_every=5,
|
||||
opponents=("random", "discard_only", "heuristic_cautious"),
|
||||
extended_eval_every=0,
|
||||
extended_opponents=("heuristic_balanced",),
|
||||
)
|
||||
assert cfg.opponents_for_iteration(0) == ()
|
||||
assert cfg.opponents_for_iteration(3) == ()
|
||||
assert cfg.opponents_for_iteration(5) == (
|
||||
"random",
|
||||
"discard_only",
|
||||
"heuristic_cautious",
|
||||
)
|
||||
assert cfg.opponents_for_iteration(50) == (
|
||||
"random",
|
||||
"discard_only",
|
||||
"heuristic_cautious",
|
||||
)
|
||||
|
||||
|
||||
def test_evaluation_opponents_for_iteration_extends_on_extended_cadence() -> None:
|
||||
from coolrl_lost_cities.games.classic.deep_cfr.config import EvaluationConfig
|
||||
|
||||
cfg = EvaluationConfig(
|
||||
eval_every=5,
|
||||
opponents=("random", "discard_only", "heuristic_cautious"),
|
||||
extended_eval_every=50,
|
||||
extended_opponents=(
|
||||
"heuristic_balanced",
|
||||
"heuristic_aggressive",
|
||||
"heuristic_noisy",
|
||||
),
|
||||
)
|
||||
assert cfg.opponents_for_iteration(5) == (
|
||||
"random",
|
||||
"discard_only",
|
||||
"heuristic_cautious",
|
||||
)
|
||||
assert cfg.opponents_for_iteration(45) == (
|
||||
"random",
|
||||
"discard_only",
|
||||
"heuristic_cautious",
|
||||
)
|
||||
assert cfg.opponents_for_iteration(50) == (
|
||||
"random",
|
||||
"discard_only",
|
||||
"heuristic_cautious",
|
||||
"heuristic_balanced",
|
||||
"heuristic_aggressive",
|
||||
"heuristic_noisy",
|
||||
)
|
||||
assert cfg.opponents_for_iteration(100) == (
|
||||
"random",
|
||||
"discard_only",
|
||||
"heuristic_cautious",
|
||||
"heuristic_balanced",
|
||||
"heuristic_aggressive",
|
||||
"heuristic_noisy",
|
||||
)
|
||||
|
||||
|
||||
def test_evaluation_opponents_for_iteration_dedupes_overlap() -> None:
|
||||
from coolrl_lost_cities.games.classic.deep_cfr.config import EvaluationConfig
|
||||
|
||||
cfg = EvaluationConfig(
|
||||
eval_every=5,
|
||||
opponents=("random", "heuristic_cautious"),
|
||||
extended_eval_every=10,
|
||||
extended_opponents=("heuristic_cautious", "heuristic_balanced"),
|
||||
)
|
||||
assert cfg.opponents_for_iteration(10) == (
|
||||
"random",
|
||||
"heuristic_cautious",
|
||||
"heuristic_balanced",
|
||||
)
|
||||
|
||||
@@ -13,7 +13,7 @@ def test_play_game_for_evaluation_finishes_small_match() -> None:
|
||||
|
||||
state, result = play_game_for_evaluation(
|
||||
build_bot("random", seed=1),
|
||||
build_bot("passive-discard", seed=2),
|
||||
build_bot("discard-only", seed=2),
|
||||
config,
|
||||
seed=3,
|
||||
max_steps=200,
|
||||
@@ -30,7 +30,7 @@ def test_play_match_alternates_seats_and_reports_rates() -> None:
|
||||
|
||||
result = play_match(
|
||||
make_policy_factory("random"),
|
||||
make_policy_factory("passive-discard"),
|
||||
make_policy_factory("discard-only"),
|
||||
config,
|
||||
games=4,
|
||||
seed=10,
|
||||
@@ -50,7 +50,7 @@ def test_evaluation_cli_smoke_json(capsys) -> None:
|
||||
"--bot0",
|
||||
"random",
|
||||
"--bot1",
|
||||
"passive-discard",
|
||||
"discard-only",
|
||||
"--games",
|
||||
"2",
|
||||
"--seed",
|
||||
|
||||
@@ -43,10 +43,10 @@ def test_classic_package_exports_bot_registry_helpers() -> None:
|
||||
def test_classic_bot_registry_accepts_reproduction_opponent_names() -> None:
|
||||
for name in [
|
||||
"random",
|
||||
"passive_discard",
|
||||
"safe_heuristic",
|
||||
"safe_heuristic_loose",
|
||||
"safe_heuristic_strict",
|
||||
"noisy_safe",
|
||||
"discard_only",
|
||||
"heuristic_balanced",
|
||||
"heuristic_aggressive",
|
||||
"heuristic_cautious",
|
||||
"heuristic_noisy",
|
||||
]:
|
||||
assert isinstance(classic.build_bot(name, seed=1), classic.LostCitiesPolicy)
|
||||
|
||||
@@ -11,7 +11,7 @@ def test_gui_argparser_accepts_classic_options() -> None:
|
||||
"--mode",
|
||||
"pvc",
|
||||
"--bot",
|
||||
"safe-heuristic",
|
||||
"heuristic-balanced",
|
||||
"--seed",
|
||||
"7",
|
||||
"--width",
|
||||
@@ -22,7 +22,7 @@ def test_gui_argparser_accepts_classic_options() -> None:
|
||||
)
|
||||
|
||||
assert args.mode == "pvc"
|
||||
assert args.bot == "safe-heuristic"
|
||||
assert args.bot == "heuristic-balanced"
|
||||
assert args.seed == 7
|
||||
assert args.width == 1024
|
||||
assert args.height == 768
|
||||
|
||||
@@ -3,19 +3,19 @@ from __future__ import annotations
|
||||
import pytest
|
||||
from coolrl_lost_cities.games.classic.game import GameState, LostCitiesConfig
|
||||
|
||||
from coolrl_lost_cities.games.classic.bots.heuristic import SafeHeuristicBot
|
||||
from coolrl_lost_cities.games.classic.bots.heuristic import HeuristicBot
|
||||
from coolrl_lost_cities.games.classic.bots.heuristic_py import (
|
||||
SafeHeuristicBot as PythonSafeHeuristicBot,
|
||||
HeuristicBot as PythonHeuristicBot,
|
||||
)
|
||||
from coolrl_lost_cities.games.classic.bots.registry import (
|
||||
LOOSE_SAFE_HEURISTIC_PARAMS,
|
||||
STRICT_SAFE_HEURISTIC_PARAMS,
|
||||
AGGRESSIVE_HEURISTIC_PARAMS,
|
||||
CAUTIOUS_HEURISTIC_PARAMS,
|
||||
)
|
||||
|
||||
VARIANTS = (
|
||||
("default", None),
|
||||
("loose", LOOSE_SAFE_HEURISTIC_PARAMS),
|
||||
("strict", STRICT_SAFE_HEURISTIC_PARAMS),
|
||||
("loose", AGGRESSIVE_HEURISTIC_PARAMS),
|
||||
("strict", CAUTIOUS_HEURISTIC_PARAMS),
|
||||
)
|
||||
|
||||
CONFIGS = (
|
||||
@@ -28,14 +28,14 @@ CONFIGS = (
|
||||
@pytest.mark.parametrize(("variant_name", "params"), VARIANTS)
|
||||
@pytest.mark.parametrize("config", CONFIGS)
|
||||
@pytest.mark.parametrize("seed", range(2))
|
||||
def test_cython_safe_heuristic_matches_python_action_sequence(
|
||||
def test_cython_heuristic_matches_python_action_sequence(
|
||||
variant_name: str,
|
||||
params,
|
||||
config: LostCitiesConfig,
|
||||
seed: int,
|
||||
) -> None:
|
||||
py_bot = PythonSafeHeuristicBot(params)
|
||||
cy_bot = SafeHeuristicBot(params)
|
||||
py_bot = PythonHeuristicBot(params)
|
||||
cy_bot = HeuristicBot(params)
|
||||
py_state = GameState.new_game(config, seed=seed)
|
||||
cy_state = GameState.new_game(config, seed=seed)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user