A deck-generic card-game engine with GNN-specified active inference agents, classical Monte Carlo validation, and fair CPU-parallel benchmarking. Browse the documentation.
- Naming
- Status
- Install
- Tests
- Run an episode
- Play against a strategy in your browser
- Compare the same strategies on matched deals
- Decks and their games
- Card identity convention
- GNN pin
- Manuscript
- CI interpreter matrix
- Documentation
- License
- Contributing
- Repository:
Active_Cardference - Distribution:
gnn-cards - Import package:
gnn_cards
The repository is the project home; gnn-cards is the installable
distribution; gnn_cards is the Python import path. The handoff's §17 tree is
rooted at the package (gnn_cards/); this repository uses src/gnn_cards/ and
keeps docs/, specs/, scripts/, and tests/ at the repository root. See
docs/architecture.md for the full mapping.
All registered game declarations resolve to playable rules and appear in the dashboard. The engine includes a replayable orchestrator, exact and Monte Carlo validation, and a paired benchmark harness. The roadmap tracks future games and adapters. See the developer handoff for the framework design.
The distribution supports CPython 3.12–3.14 and requires NumPy 2.1 or later. From an activated virtual environment, install the built wheel and start the dashboard.
python -m pip install /path/to/gnn_cards-0.2.0-py3-none-any.whl
python -m gnn_cards.dashboardSelect the pymdp backend by passing backend="pymdp" to
build_game_gnn_agent. The base install includes its dependencies through
the pinned GNN wheel.
For development, run the repository commands from a Git checkout.
uv sync --locked --extra devThe base install uses the hash-pinned upstream GNN distribution to parse the shipped model documents. Cardference binds the parser's output to the game and uses NumPy for default inference. The upstream distribution also brings its own dependencies, including JAX and pymdp.
| Extra | Packages | Use |
|---|---|---|
aif |
inferactively-pymdp, jax |
optional pymdp renderer and cross-backend tests |
perf |
numba |
optional hot kernels |
plot |
matplotlib |
figures and reports |
dev |
pytest, pytest-cov, ruff, mypy, hypothesis |
tests and static checks |
The source distribution builds the installable package. Repository gates and manuscript reproduction use the Git checkout and its committed evidence. Installed package verification
run.sh is the gate. It has separately runnable arms, and CI calls
the same arms — the commands are defined once, in
scripts/gate.py:
./run.sh lint # ruff check .
./run.sh types # mypy (strict)
./run.sh test # fast suite; the default arm
./run.sh test-full # full suite, including slow/golden
./run.sh docs # links, documentation index, metrics receipt
./run.sh gnn # pinned GNN parser conformance
./run.sh package # build and verify the installed distribution
./run.sh all # lint, types, docs, test, gnnInstall once with uv sync --locked --extra dev. The suite tests
the production NumPy decisions and includes equivalence checks against
pymdp.Agent. Heavy statistical and golden suites are serial and marked
slow/golden. The GNN conformance check is its own arm (see
GNN pin). See docs/RUN_GUIDE.md for the
arms, CI, and runtime resolution, docs/testing.md for
markers and conformance exit codes, and tests/README.md for
the area map. Measured arm runtimes and suite totals live in
docs/gate-metrics.md, generated by
./run.sh measure.
from gnn_cards.aif import build_game_gnn_agent
from gnn_cards.agents.random import RandomAgent
from gnn_cards.core.rng import SeedTree
from gnn_cards.engine import Orchestrator
from gnn_cards.games import load_game
agent = build_game_gnn_agent("kuhn", seat=0, players=2)
engine = Orchestrator(load_game("kuhn"), [agent, RandomAgent()], SeedTree(7))
result = engine.play_episode(deal_id=0)
final_state = engine.replay(result)
print(result.payoffs)
decision = agent.history[0]
print(decision.posterior, decision.neg_efe, decision.q_pi, decision.action)Run a paired comparison with duplicate deals and an explicit root seed.
uv run python -m gnn_cards.bench.compare --game kuhn \
--agents random,first-legal --reference random --deals 20 --root-seed 7 \
--out docs/_build/cards-bench/kuhn.json --report docs/_build/cards-bench/kuhn.mdFor a fixed heads-up Hold’em matchup, gnn_cards.eval.equity.holdem_equity
counts wins, ties, and losses across every completion of the known board.
Pass two French52 card IDs per hand and, optionally, up to five community card
IDs. The full preflop calculation enumerates all five-card boards.
uv run --locked python -m gnn_cards.dashboardOpen the loopback URL printed by the command. Choose heads-up Five-card Draw or Texas Hold’em for fixed-limit poker, or try Kuhn, Leduc, Blackjack, Baccarat, Hearts, UNO, Hanabi, Klondike, or War. The setup offers each game’s supported seat counts and peer strategies. Use Customize peer seats to mix GNN active inference, rule-informed, stochastic, uniform random, and neural RL strategies. Each decision game also runs a GNN for your own seat. The table shows its prior, posterior, and legal policy scores, and can play its recommendation on request. Klondike is solo. War advances automatic battles, so it has no policy choices.
GNN models shows executable likelihood and transition matrices, log preferences, state priors, and policy priors. Use Inspect model matrices at the table to open the exact document behind its current beliefs. Methods & results includes the GNN inference audit and the classical records. Strategy performance and ratings compares native-unit payoffs and within-game head-to-head ratings. Strategy runtime and parameters reports decision timing, storage counts, and symbolic work. See the dashboard guide for tensor axes and provenance.
uv run --locked python -m gnn_cards.bench.tournament --games all \
--policies gnn,rule-informed,rule-stochastic,random,neural-rl \
--reference rule-informed --deals 16 --root-seed 71 --workers 4 \
--out docs/_build/cards-bench/strategy-tournament.jsonThe tournament changes the focal policy while keeping its peer roster fixed.
It replays each deal with the focal player in every seat, reports raw returns
in the game's units, and bootstraps complete deal blocks. The neural policy
uses a packaged, frozen checkpoint trained on separate seeded episodes.
To test a particular table size, select one game and pass --players.
Use --all-seat-counts for every declared size.
See the tournament protocol.
The benchmark study documents the full experiment, including all-pair contrasts, head-to-head ratings, parameter counts, and the shared-context timing protocol. The generated result tables retain estimates in each game's own units.
The catalog resolves named recipes and the inline recipes referenced by game declarations. Each game records its concrete deck, implementation status, and declared rules, default seat count, and supported seat range. Each deck records its type and instance counts and any direct recipe parents. The deck-to-game map is generated from the same catalog used in the dashboard. The game capability map separates play support, executable GNN models, and committed evidence.
from gnn_cards.catalog import build_catalog
catalog = build_catalog()
for deck in catalog.decks:
games = [game.label for game in catalog.games if game.deck == deck.recipe]
print(deck.recipe, deck.n_types, deck.n_instances, games)To build a rules instance at a supported seat count, use the same loader as the browser. The named game binds its compatible deck recipe and phases.
from gnn_cards.games import load_game
game = load_game("hanabi", players=4)
assert game.n_players == 4Card-type ids are rank-major. product(a, b, ...) enumerates in row-major
order over the declared attribute sequence, rightmost attribute fastest, so for
french52 (product(rank, suit)):
id = rank_index * 4 + suit_index
rank_index indexes [2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A]
suit_index indexes [c, d, h, s]
# 2c=0, 2d=1, 2h=2, 2s=3, 3c=4, ..., As=51
explicit(...) uses declaration order, union appends, repeat is
copy-major, and filter preserves the surviving order. The full statement is
in docs/architecture.md
and src/gnn_cards/core/deck.py.
Active inference agents are declared in GNN documents. The canonical pin is
specs/gnn-pin.json:
- repository:
ActiveInferenceInstitute/Generalized_Notation_Notation - tag:
v5.4.0 - commit:
e2bba8ae2bb5c656558a59cfa5927229f3f4e436 - parser file digests are recorded in the pin
The gnn gate invokes the pinned revision's gnn.importers reader with
python -m gnn.importers check --repo . --require-pointer --workflow .github/workflows/ci.yml --job test.
The ordinary play path checks the packaged document digest and parses the
bytes with upstream gnn through gnn_cards.spec.
Cardference reads its cards: extension, binds the model to the engine, and
runs NumPy inference. The renderer updates beliefs from seat-visible evidence,
scores policies using expected log preference and information gain, and ranks
the legal moves. The binding receipt records the parser distribution, version,
and commit used for the model.
With the aif extra installed, build_game_gnn_agent(..., backend="pymdp")
uses pymdp.Agent for an explicitly selected fixed-play renderer.
./run.sh gnn verifies the upstream conformance pin and parser file digests.
It compares the pinned parser with Cardference's independent diagnostic reader,
binds the upstream declarations and numeric values, and compares two steps of
NumPy inference. The analytical models exercise their declared derivations.
The standalone scripts/validate_gnn_spec.py
conformance checker exits 0 on pass, 1 on failure, and 2 when the pinned
runtime or checkout is unavailable.
uv run python scripts/validate_gnn_spec.py --gnn-runtime <pinned-python> --json
# or, strongest: archive and digest-verify a local checkout of the pinned commit
GNN_ROOT=<checkout> GNN_PYTHON=<parser-python> uv run python scripts/validate_gnn_spec.py --jsonRead Preprint v1 on Zenodo or download the PDF, complete offline reader, and checksums from the GitHub paper release. The reader guide links the manuscript to its evidence and reproduction instructions. The publication guide describes how to prepare a new edition.
The default workflow runs a single leg, Python 3.12 (the declared floor), on
ubuntu-latest. Heavy profiles (full golden validation, benchmarks, coverage)
are opt-in locally. The workflow runs only when dispatched.
Use ./run.sh package to check both built distributions in isolated Python
3.12, 3.13, and 3.14 environments. It also exercises the aif extra and the installed
typing interface. .github/workflows/ci.yml ·
Run guide
Start at the documentation hub for play, benchmarking, development, and publication. The documentation index lists the complete inventory.
Cardference's code, documentation, and authored models are MIT-licensed (LICENSE). See the licensing guide for upstream GNN and the third-party assets bundled with the offline paper reader.
See CONTRIBUTING.md and AGENTS.md.