Skip to main content

Python visualization library for OpenSpiel game trees, information sets, and strategy profiles

Project description

spielviz

PyPI License: MIT Python 3.9+ CI

Python visualization library for OpenSpiel game trees, information sets, and strategy profiles.

Installation

pip install spielviz

Quick Start

import spielviz

# One-liner: render any OpenSpiel game
spielviz.quick_render("kuhn_poker", path="kuhn.png")

Or with more control:

import pyspiel
import spielviz

game = pyspiel.load_game("kuhn_poker")
root = spielviz.build_tree(game)
root = spielviz.layout_tree(root)

# Highlight information sets
colors = spielviz.auto_color_info_sets(root, player=0)
fig, ax = spielviz.render_tree(
    root,
    highlight_info_sets=colors,
    show_actions=True,
    show_payoffs=True,
    title="Kuhn Poker",
)
fig.savefig("kuhn_poker.png", dpi=150, bbox_inches="tight")

Features

Game Tree Rendering

Render any OpenSpiel game as a publication-quality tree diagram:

  • Player-colored nodes (colorblind-friendly palette)
  • Action labels on edges
  • Terminal payoffs displayed
  • Chance node probabilities

Information Set Visualization

Highlight which nodes a player cannot distinguish:

colors = spielviz.auto_color_info_sets(root, player=0)
fig, ax = spielviz.render_tree(root, highlight_info_sets=colors)

# Or draw dashed connection lines (standard game theory notation)
spielviz.draw_info_set_connections(ax, root, player=0)

Strategy Profile Visualization

Visualize policies from CFR, fictitious play, or any OpenSpiel algorithm:

from open_spiel.python.algorithms import cfr

solver = cfr.CFRSolver(game)
for _ in range(1000):
    solver.evaluate_and_update_policy()
policy = solver.average_policy()

# Bar chart of action probabilities at each info set
fig, ax = spielviz.plot_strategy_profile(game, policy, player=0)

# Strategy overlaid directly on the game tree
fig, ax = spielviz.plot_strategy_on_tree(root, game, policy, player=0)

Large Game Support

Use max_depth for games with large state spaces:

spielviz.quick_render("tic_tac_toe", max_depth=3, path="ttt.png")

API Reference

Function Description
build_tree(game, max_depth=None) Build a TreeNode hierarchy from an OpenSpiel game
layout_tree(root, algorithm="simple") Compute (x, y) positions for all nodes
collect_info_sets(root) Group nodes by information state string
render_tree(root, **kwargs) Render game tree as matplotlib figure
save_tree(root, path, **kwargs) Render and save to file (PNG, SVG, PDF)
auto_color_info_sets(root, player) Assign distinct colors to info sets
draw_info_set_connections(ax, root, player) Draw dashed lines between info set nodes
plot_strategy_profile(game, policy, player=0) Bar chart of strategy at each info set
plot_strategy_on_tree(root, game, policy, player=0) Mini bar charts overlaid on tree
quick_render(game_name, **kwargs) One-liner convenience function

Tested Games

  • kuhn_poker — 2-player Kuhn Poker
  • leduc_poker — 2-player Leduc Poker (depth-limited)
  • tic_tac_toe — Tic-Tac-Toe (depth-limited)

Contributing

Contributions welcome! Please open an issue or PR.

git clone https://github.com/kvr06-ai/spielviz.git
cd spielviz
pip install -e ".[dev]"
pytest tests/
ruff check src/

License

MIT

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

spielviz-0.1.0.tar.gz (860.8 kB view details)

Uploaded Source

Built Distribution

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

spielviz-0.1.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file spielviz-0.1.0.tar.gz.

File metadata

  • Download URL: spielviz-0.1.0.tar.gz
  • Upload date:
  • Size: 860.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spielviz-0.1.0.tar.gz
Algorithm Hash digest
SHA256 77798778c151369b65517e6e83519f51b39ae8811a5cb196e1857643d885da78
MD5 49e56eefbd06e41e5b141ff44dcb6d16
BLAKE2b-256 0fa412bc2fbff98f4b2b5d0ffe051a9929bbe65d7e410a44e4f6ac4dd198d39f

See more details on using hashes here.

Provenance

The following attestation bundles were made for spielviz-0.1.0.tar.gz:

Publisher: publish.yml on kvr06-ai/spielviz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spielviz-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: spielviz-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spielviz-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db152a029133ea7193375c4023e70c17557cca4a3a4aee1fd5a048dc77558beb
MD5 7044efe63e1b9be5fb45a3a7f1ffbfae
BLAKE2b-256 277411be7d668080e6f2fa28c95549365ba50526acdf416b182427feb4d3d999

See more details on using hashes here.

Provenance

The following attestation bundles were made for spielviz-0.1.0-py3-none-any.whl:

Publisher: publish.yml on kvr06-ai/spielviz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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