Implementation Recipes¶
更新日: 2026-07-05
よくある変更作業の手順書である。変更対象、関連 docs、テストを一緒に確認する。
新しい search value profile を追加する¶
読む docs:
手順:
src/pca/search/mcts.pyのSearchValueConfigに必要な weight を追加する。search_value_config_for_profile()に profile 名と default weight を追加する。- self-play CLI の
--search-value-profilechoices を更新する。 - evaluation CLI の
--search-value-profilechoices を更新する。 - 必要なら
src/pca/training/selfplay/cli.py/src/pca/evaluation/tournament/impl.pyの default 補正を追加する。 tests/test_encoder.pyに value sign、terminal value、aux/progress の期待値を追加する。docs/architecture/modules/search.mdとsource-design.mdを更新する。
確認:
PYTHONPATH=src uv run python -m unittest tests.test_encoder tests.test_module_boundaries
self-play JSONL に field を追加する¶
読む docs:
手順:
- schema field なら
src/pca/training/targets.pyの dataclass に default 付きで追加する。 - game 中に作る値なら
training/selfplay/records.pyまたはrecord_targets.py/record_metadata.pyに追加する。 - JSONL load 互換のため
training/data/records.pyのrecord_from_dict()を確認する。 - batch tensor に必要なら
training/data/search_collate.pyまたはbelief_collate.pyに追加する。 - loss に使うなら
training/policy_value/losses.pyに metrics と mask を追加する。 - round-trip / backward compatibility test を追加する。
- artifacts.md の schema 説明を更新する。
確認:
PYTHONPATH=src uv run python -m unittest tests.test_selfplay_summary tests.test_training
新しい model head を追加する¶
読む docs:
手順:
src/pca/models/policy_value_unified/heads.pyに head module を追加する。model.pyの output dict に head output を追加する。- target が必要なら
training/targets.pyと JSONL generation を更新する。 training/data/search_collate.pyで target tensor と mask を作る。training/policy_value/losses.pyで loss と metrics を追加する。training/policy_value/checkpointing.pyに config metadata を保存する。training/policy_value/model_config.pyで checkpoint 互換を確認する。- model forward / loss / checkpoint load のテストを追加する。
確認:
PYTHONPATH=src uv run python -m unittest tests.test_training tests.test_encoder
新しい rule agent を追加する¶
読む docs:
手順:
src/pca/rule_agents/agents/<agent_id>/に agent package を作る。- package の
__init__.pyからAgentを export する。 - 必要な heuristic を
heuristics.pyまたは agent 内に実装する。 - registry YAML に
agent_id,class_path,deck_csv, compatibility metadata を追加する。 rule_pool_policy_factory()で assignment metadata が付くことを確認する。- teacher policy weight を使う場合は
decision.metaの weight keys を確認する。 - rule-agent test と self-play record test を追加する。
確認:
PYTHONPATH=src uv run python -m unittest tests.test_rule_agents tests.test_selfplay_summary
evaluation metric を追加する¶
読む docs:
手順:
- metric の元データが self-play/evaluation summary にあるか確認する。
evaluation/tournament/types.pyの dataclass に field を追加する場合は default を付ける。evaluation/tournament/impl.pyの match loop で値を集める。evaluation/tournament/summaries.pyで aggregate と CSV row を更新する。- CLI output / JSON output の互換を確認する。
- tests に summary aggregation と CSV output の期待値を追加する。
確認:
PYTHONPATH=src uv run python -m unittest tests.test_encoder tests.test_module_boundaries
public API / facade を追加する¶
読む docs:
手順:
- 実体 module の
__all__に公開名を追加する。 - package facade (
__init__.py,types.py,summary.py,dataset.pyなど) に re-export する。 tests/test_module_boundaries.pyにassertIsと__module__の期待値を追加する。api-reference.mdと対応 module docs に API を追加する。
確認:
PYTHONPATH=src uv run python -m unittest tests.test_module_boundaries
最新デフォルト CLI profile を更新する¶
読む docs:
手順:
- 新しい世代の標準 config を
configs/vNN/に追加する。 configs/default.yamlのcommandsでselfplay,train,eval,selfplay-trainが新 config を指すようにする。- 必要なら
README.mdの default profile 説明を更新する。 pca --print-command trainで delegated command が想定通りか確認する。tests/test_app_config.pyに profile load / argv 変換の期待値を追加する。
確認:
PYTHONPATH=src uv run python -m unittest tests.test_app_config tests.test_cli_config
pca commands
pca --print-command train --input data/selfplay/custom.jsonl