Skip to main content

Asynchronous tournament and SPSA tuning platform for USI shogi engines

Project description

ShogiArena

CI Docs PyPI Python License

📖 Full Documentation | 日本語ドキュメント

ShogiArena is a comprehensive platform for shogi engine development and evaluation. It provides:

  • Python Wrapper for USI Engines: Easy-to-use synchronous and asynchronous interfaces (SyncUsiEngine, AsyncUsiEngine) for integrating any USI-compatible shogi engine into your Python projects
  • Advanced Tournament Environment: Flexible tournament execution with customizable rules, time controls, adjudication, and parallel game execution (Round-robin, SPRT, SPSA)
  • Real-time Dashboard: Web-based interface for monitoring live games, analyzing statistics, and visualizing rating evolution
  • Engine Parameter Tuning: Automated optimization using SPSA with gradient-based search and statistical validation via SPRT

Demo

https://github.com/user-attachments/assets/1cdebe23-b1a9-4d8e-91c0-f56ca970b569

Live tournament monitoring with real-time updates and interactive dashboard

Installation

pip install shogiarena

For development installation, see DEVELOPMENT.md.

Configuration (Optional)

While not required, running shogiarena init is recommended for:

shogiarena init

What it configures:

  • Output directories: Centralized location for tournament results and databases
  • Engine cache: Shared storage for engine binaries across projects
  • Repository integration: Access to engine repositories (e.g., YaneuraOu) via artifact references
  • Placeholder support: Use {output_dir} and {engine_dir} in configs

What you can do without it:

  • ✅ Use Python API (SyncUsiEngine, AsyncUsiEngine) with direct paths
  • ✅ Run tournaments with absolute paths in configs
  • ✅ Everything works with default paths (./shogiarena_output, temp directories)

What requires configuration:

  • ❌ Artifact references (e.g., artifact: yaneuraou@main:YaneuraOu-by-gcc)
  • ❌ Placeholder variables in configs (e.g., path: "{engine_dir}/myengine")
  • ❌ Private GitHub repository access (requires github_token in settings)

See detailed setup guide for more options.

Quick Examples

Example 1: Use Engine in Python

The simplest way to integrate a USI engine into your Python code:

from shogiarena.arena.engines.sync_usi_engine import SyncUsiEngine
from shogiarena.arena.engines.usi_think import UsiThinkRequest

# Use any USI engine
with SyncUsiEngine.from_config_path("engine.yaml") as engine:
    request = UsiThinkRequest(time_ms=5000)
    result = engine.think(sfen="startpos", request=request)
    print(f"Bestmove: {result.bestmove}, Score: {result.score_cp}cp")

Or with a direct path:

from shogiarena.arena.engines.sync_usi_engine import SyncUsiEngine

with SyncUsiEngine.from_path("/path/to/engine") as engine:
    result = engine.think(sfen="startpos", request=UsiThinkRequest(nodes=1000000))
    print(result.bestmove)

Example 2: Run Tournament via CLI

Use the provided example configuration:

# Tournament (Round-robin)
shogiarena run tournament examples/configs/run/tournament/example.yaml

# SPRT (Statistical testing)
shogiarena run sprt examples/configs/run/sprt/example.yaml

# SPSA (Parameter tuning)
shogiarena run spsa examples/configs/run/spsa/example.yaml

The dashboard will automatically open at http://localhost:8080 to monitor progress.

Note: Example configs may use placeholders like {output_dir} and {engine_dir}. You can either run shogiarena init (alias for shogiarena config init) to set them up, or replace placeholders with absolute paths. See Example Configurations for details.

Core Features

Tournament Modes

Round-Robin Tournament

shogiarena run tournament examples/configs/run/tournament/example.yaml

Run comprehensive engine comparisons with customizable time controls, opening positions, and adjudication rules.

SPRT (Sequential Probability Ratio Test)

shogiarena run sprt examples/configs/run/sprt/example.yaml

Efficiently test if one engine version is statistically stronger than another with early stopping.

SPSA (Simultaneous Perturbation Stochastic Approximation)

shogiarena run spsa examples/configs/run/spsa/example.yaml

Optimize engine parameters using gradient-based stochastic search with parallel game execution.

See Tournament Guide and SPSA Guide for detailed configuration options.

Dashboard Features

  • Live Updates: Real-time game progress and statistics
  • Interactive Visualizations: Rating evolution, win-rate matrices, parameter convergence
  • Game Browser: Replay and analyze individual games
  • SPSA Tracking: Monitor parameter values and gradient estimates

Python Library

Beyond simple engine interaction, the library provides advanced features:

Asynchronous Engine Control

import asyncio
from shogiarena.arena.engines.engine_factory import EngineFactory
from shogiarena.arena.engines.usi_think import UsiThinkRequest

async def compare_engines():
    # Create multiple engines in parallel
    engine1 = await EngineFactory.create_engine("engine1.yaml")
    engine2 = await EngineFactory.create_engine("engine2.yaml")
    await asyncio.gather(engine1.start(), engine2.start())
    
    # Analyze same position concurrently
    results = await asyncio.gather(
        engine1.think(sfen="startpos", request=UsiThinkRequest(time_ms=5000)),
        engine2.think(sfen="startpos", request=UsiThinkRequest(time_ms=5000)),
    )

Programmatic Tournament Execution

from shogiarena.arena.configs.tournament import ArenaConfig
from shogiarena.arena.runners.tournament_runner import TournamentRunner

# Run tournaments programmatically with full control
config = ArenaConfig.from_yaml("tournament.yaml")
runner = TournamentRunner(config)
runner.run_sync()  # or: await runner.run() for async

Custom Analysis Tools

from shogiarena.arena.engines.sync_usi_engine import SyncUsiEngine
from shogiarena.arena.engines.usi_think import UsiThinkRequest

# Build custom analysis workflows
with SyncUsiEngine.from_path("/path/to/engine") as engine:
    for position in my_position_list:
        result = engine.think(sfen=position, request=UsiThinkRequest(nodes=1000000))
        analyze_and_store(result)

See Python Library Guide for detailed API documentation.

Documentation

Example Configurations

The examples/configs/ directory provides ready-to-use configuration templates:

Tournament Configurations:

Engine Configurations:

Instance Configurations:

Note: Example configurations may use placeholders like {output_dir} and {engine_dir}. Run shogiarena init (alias for shogiarena config init) to configure these paths, or replace them with absolute paths.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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.1.1.tar.gz (1.2 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.1.1-py3-none-any.whl (1.2 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shogiarena-0.1.1.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for shogiarena-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ca3fe5926b6951ef3795e6656523e2344c1985c510eee106b28b03ad5cfa6742
MD5 0955a5c8d8d0a24d219bfac85456c22f
BLAKE2b-256 bbb0421eb743a4fc25f7f02970446e5ea190865ef5672b765fa4738ae522a56d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: shogiarena-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for shogiarena-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1265bcaf6b1d1d288a28ea4bd4d37b0c8ad4471fee9b8211e552ef5ebd1497fe
MD5 120033e8b1cb09c325ad9037938819b0
BLAKE2b-256 7939ebb0cda1919a3288b6397f1f1bc8006e52c4b54a28bb3de0c8b30ccb9cca

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