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.1.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.1-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spielviz-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 7aa4aa94a2ea1c3fcf88f6706657a3917861a68518c609f4228edefb6b28ff27
MD5 a00bcc934a8b24c062c714aec3feb070
BLAKE2b-256 4f0d324f6a762e3f85f94c5b3f71a419a083ab5e66edb60a3c5a1650efd4c698

See more details on using hashes here.

Provenance

The following attestation bundles were made for spielviz-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: spielviz-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8f63424bc6dad2d0501ea206d903dc083adcef1cc78ce9492b5080abc4a5b03b
MD5 fbf36ae4d74f1eaa454a3691fcec866b
BLAKE2b-256 5416645a60d7d290b8fe3274736706168fc478a572109c5a8906dbfe07030ff5

See more details on using hashes here.

Provenance

The following attestation bundles were made for spielviz-0.1.1-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