Asynchronous tournament and SPSA tuning platform for USI shogi engines
Project description
ShogiArena
ShogiArena は、USI 将棋エンジン同士の自動対局、トーナメント管理、SPRT による統計検定、SPSA パラメータチューニングをまとめて扱う実行基盤です。 設定ファイルを書いて CLI から実行することも、Python API から呼び出して自動化することもできます。
[!NOTE] v1.0.0以降の安定APIは、CLI、公開設定schema、および
shogiarena.engine/shogiarena.tournamentの通常利用向け入口です。shogiarena.compositionと高度なrunner/storage構築用型はprovisionalであり、1.xでも変更される場合があります。詳細は公開APIを参照してください。
ドキュメント: https://nyoki-mtl.github.io/ShogiArena/
デモ
https://github.com/user-attachments/assets/1cdebe23-b1a9-4d8e-91c0-f56ca970b569
リアルタイム更新に対応したダッシュボードで、進行中の対局、順位表、棋譜、SPSA の更新状況を確認できます。
できること
round_robin/gauntlet形式のトーナメント実行- 2 エンジン間の GSPRT / SPRT 検定と早期停止
- SPSA による USI オプションと評価パラメータのチューニング
- 実行中と完了後の Web ダッシュボード表示
- SFEN / KIF / CSA などの棋譜保存と結果集計
- エンジン内蔵定跡の検証、provenance 記録、Book タブでの out-of-book 分析
- ローカル実行と SSH インスタンスを使った分散実行
shogiarena.engine/shogiarena.tournamentによる Python からの自動化
インストール
Python 3.11 以上が必要です。
pip install shogiarena
ビルド済み wheel は Windows x86_64、Linux x86_64 / arm64、macOS Intel / Apple Silicon に提供されます(Windows on ARM は対象外)。 x86_64 で AVX2 版へ差し替える方法はインストールを参照してください。
ソースから開発する場合は uv を使います。
git clone https://github.com/nyoki-mtl/ShogiArena.git
cd ShogiArena
uv sync
uv run shogiarena --help
出力先やエンジン配置先の既定値は、次のコマンドで初期化できます。
shogiarena config init
初期化しておくと、{output_dir} / {engine_dir} プレースホルダー、artifact ベースのエンジン解決、共有キャッシュを設定ファイルから利用できます。
クイックスタート
エンジン設定を 2 つ用意します。
# engine_a.yaml
name: "EngineA"
engine_path: "/path/to/engine_a"
options:
Threads: 2
USI_Hash: 256
# engine_b.yaml
name: "EngineB"
engine_path: "/path/to/engine_b"
options:
Threads: 2
USI_Hash: 256
トーナメント設定を作成します。
# tournament.yaml
experiment_name: "my_first_tournament"
engines:
- engine_path: "engine_a.yaml"
- engine_path: "engine_b.yaml"
tournament:
scheduler: round_robin
games_per_pair: 10
num_parallel: 2
rules:
time_control:
time_ms: 10000
increment_ms: 100
dashboard:
enabled: true
api_port: 8080
--dry-run で設定を検証し、問題がなければそのまま実行します。
shogiarena run tournament tournament.yaml --dry-run
shogiarena run tournament tournament.yaml
dashboard.enabled: true の場合は http://localhost:8080 でダッシュボードを開けます。
よく使うコマンド
以下の examples/ はこのリポジトリのテンプレートです。
pip でインストールした場合は同梱されないため、examples ディレクトリから取得してください。
# トーナメント(テンプレートを編集してから実行)
cp examples/configs/run/tournament/example.yaml tournament.yaml
shogiarena run tournament tournament.yaml --dry-run
# SPRT(テンプレートを編集してから実行)
cp examples/configs/run/sprt/example.yaml sprt.yaml
shogiarena run sprt sprt.yaml --dry-run
# SPSA(テンプレートを編集してから実行)
cp examples/configs/run/spsa/example.yaml spsa.yaml
shogiarena run spsa spsa.yaml --dry-run
# 自己対局による棋譜生成(テンプレートを編集してから実行)
cp examples/configs/run/generate/example.yaml generate.yaml
shogiarena run generate generate.yaml --dry-run
# 保存済み run のダッシュボード表示
shogiarena dashboard serve --run-dir /path/to/run
# 結果集計
shogiarena results summary /path/to/run --format text
Python API
公開入口は次のモジュールです。
shogiarena.engineshogiarena.tournamentshogiarena.clishogiarena.composition
shogiarena._core 配下は内部実装です。import できても後方互換性は保証されません。
CLI、公開設定schema、create_engine*()、UsiEngineSession、load_tournament_config()、run_tournament()、TournamentRunResultは安定面です。
shogiarena.compositionとbuild_tournament_runner()等の高度な組み立てAPIはprovisional面です。
USI エンジンを使う
import asyncio
from shogiarena.engine import UsiThinkRequest, create_engine
async def main() -> None:
async with await create_engine("engine.yaml") as engine:
result = await engine.think(
sfen="startpos",
request=UsiThinkRequest(movetime=5_000),
)
print(result.bestmove)
asyncio.run(main())
トーナメントを実行する
import asyncio
from shogiarena.tournament import run_tournament
async def main() -> None:
await run_tournament(
"tournament.yaml",
run_dir="runs/example",
)
asyncio.run(main())
ドキュメント
ライセンス
MIT ライセンスです。詳細は LICENSE を参照してください。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shogiarena-1.0.0.tar.gz.
File metadata
- Download URL: shogiarena-1.0.0.tar.gz
- Upload date:
- Size: 1.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad5d8e0830d9568369c7ced99f6fcb64484f2782ad731b9b7b126d921e1acea2
|
|
| MD5 |
ba7977ac7a807a0253dbdae9ad633a83
|
|
| BLAKE2b-256 |
730a01ae2f89875999c8325832b1bc605744529f4b407a1fafb406c57bc44ff7
|
Provenance
The following attestation bundles were made for shogiarena-1.0.0.tar.gz:
Publisher:
public-release.yml on nyoki-mtl/ShogiArena
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
shogiarena-1.0.0.tar.gz -
Subject digest:
ad5d8e0830d9568369c7ced99f6fcb64484f2782ad731b9b7b126d921e1acea2 - Sigstore transparency entry: 2210079604
- Sigstore integration time:
-
Permalink:
nyoki-mtl/ShogiArena@6e0a9ba85f7f3483f663b5df798d06b9241c5344 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/nyoki-mtl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
public-release.yml@6e0a9ba85f7f3483f663b5df798d06b9241c5344 -
Trigger Event:
push
-
Statement type:
File details
Details for the file shogiarena-1.0.0-py3-none-any.whl.
File metadata
- Download URL: shogiarena-1.0.0-py3-none-any.whl
- Upload date:
- Size: 1.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b31872f73ac8277ec682b4156c2c041214f3cd66bf5680a4890d3c8083fbd5a
|
|
| MD5 |
ee5284b48f34dfa3054c58faa3fd82ab
|
|
| BLAKE2b-256 |
31e74bb254260f2adefd4746b7c88e262180b3623060af6d60d99fe88f1037ba
|
Provenance
The following attestation bundles were made for shogiarena-1.0.0-py3-none-any.whl:
Publisher:
public-release.yml on nyoki-mtl/ShogiArena
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
shogiarena-1.0.0-py3-none-any.whl -
Subject digest:
1b31872f73ac8277ec682b4156c2c041214f3cd66bf5680a4890d3c8083fbd5a - Sigstore transparency entry: 2210079628
- Sigstore integration time:
-
Permalink:
nyoki-mtl/ShogiArena@6e0a9ba85f7f3483f663b5df798d06b9241c5344 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/nyoki-mtl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
public-release.yml@6e0a9ba85f7f3483f663b5df798d06b9241c5344 -
Trigger Event:
push
-
Statement type: