Python visualization library for OpenSpiel game trees, information sets, and strategy profiles
Project description
spielviz
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 Pokerleduc_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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77798778c151369b65517e6e83519f51b39ae8811a5cb196e1857643d885da78
|
|
| MD5 |
49e56eefbd06e41e5b141ff44dcb6d16
|
|
| BLAKE2b-256 |
0fa412bc2fbff98f4b2b5d0ffe051a9929bbe65d7e410a44e4f6ac4dd198d39f
|
Provenance
The following attestation bundles were made for spielviz-0.1.0.tar.gz:
Publisher:
publish.yml on kvr06-ai/spielviz
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spielviz-0.1.0.tar.gz -
Subject digest:
77798778c151369b65517e6e83519f51b39ae8811a5cb196e1857643d885da78 - Sigstore transparency entry: 1132887280
- Sigstore integration time:
-
Permalink:
kvr06-ai/spielviz@13e1c1bf4cdf2bff223f562a8194172aa4cee8d9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kvr06-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@13e1c1bf4cdf2bff223f562a8194172aa4cee8d9 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db152a029133ea7193375c4023e70c17557cca4a3a4aee1fd5a048dc77558beb
|
|
| MD5 |
7044efe63e1b9be5fb45a3a7f1ffbfae
|
|
| BLAKE2b-256 |
277411be7d668080e6f2fa28c95549365ba50526acdf416b182427feb4d3d999
|
Provenance
The following attestation bundles were made for spielviz-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on kvr06-ai/spielviz
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spielviz-0.1.0-py3-none-any.whl -
Subject digest:
db152a029133ea7193375c4023e70c17557cca4a3a4aee1fd5a048dc77558beb - Sigstore transparency entry: 1132887330
- Sigstore integration time:
-
Permalink:
kvr06-ai/spielviz@13e1c1bf4cdf2bff223f562a8194172aa4cee8d9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kvr06-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@13e1c1bf4cdf2bff223f562a8194172aa4cee8d9 -
Trigger Event:
push
-
Statement type: