Skip to main content

Asynchronous tournament and SPSA tuning platform for USI shogi engines

Project description

ShogiArena

CI Docs PyPI Python License

ShogiArena は、USI 将棋エンジン同士の自動対局、トーナメント管理、SPRT による統計検定、SPSA パラメータチューニングをまとめて扱うための実行基盤です。CLI からすぐ動かせることと、Python API から自動化しやすいことを重視しています。

[!NOTE] 本プロジェクトは開発中です。公開 API は shogiarena.engine / shogiarena.tournament を中心に整理中で、破壊的変更を含む更新が入ることがあります。変更履歴は CHANGELOG.md を参照してください。

ドキュメント: 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

ソースから開発する場合は uv を使います。

git clone https://github.com/nyoki-mtl/ShogiArena.git
cd ShogiArena
uv sync --all-extras
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

まず検証し、問題なければ実行します。

shogiarena run tournament tournament.yaml --dry-run
shogiarena run tournament tournament.yaml

dashboard.enabled: true の場合は http://localhost:8080 でダッシュボードを開けます。

よく使うコマンド

# トーナメント(テンプレートを編集してから実行)
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.engine
  • shogiarena.tournament
  • shogiarena.cli
  • shogiarena.composition

shogiarena._core 配下は内部実装です。import できても後方互換性は保証されません。

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shogiarena-0.5.3.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shogiarena-0.5.3-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

File details

Details for the file shogiarena-0.5.3.tar.gz.

File metadata

  • Download URL: shogiarena-0.5.3.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for shogiarena-0.5.3.tar.gz
Algorithm Hash digest
SHA256 27cd7b0135919e967bea6e2752f8864efe32cf6d0661900ea4e91eeec5e3189a
MD5 6a3d113188ff761048b72edbaef7faa4
BLAKE2b-256 f7d7d35fb6b3eb6a51e392e80d9919b756182d3e700a9aa7afc8590eec361b3e

See more details on using hashes here.

File details

Details for the file shogiarena-0.5.3-py3-none-any.whl.

File metadata

  • Download URL: shogiarena-0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for shogiarena-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a6950d05002ff63acf8962afc864611b71994f31f2b8a9448dee3a65d1430491
MD5 5182b9208162da496f3d7b60c9dc0d87
BLAKE2b-256 9fa839928cc8b1cd2b2e5f226a78cf4ef52988331968bc86859d0490e91a438b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page