Skip to main content

PyPI version Tests codecov docs PyPI Downloads License: MIT

gumbel-mcts

An implementation of Policy improvement by planning with Gumbel (Danihelka et al., ICLR 2022). Numba-accelerated, hundreds of thousands of simulations per second.

Gumbel MCTS replaces PUCT's UCB-based action selection with sequential halving over Gumbel-perturbed log-priors. This produces better actions under the same simulation budget — especially at low budgets, where PUCT wastes visits on bad branches it can't prune.

PushT — uniform prior, 64 sims
PushT: PUCT IoU=0.03 vs Gumbel IoU=0.85
Wall-gap PushT — push through a narrow gap, 64 sims
Wall-gap: PUCT frac=0.50 vs Gumbel frac=1.00
Robot arm — 4 joints, 2 obstacles, 64 sims
Robot arm: PUCT dist=306 vs Gumbel dist=3
Sokoban — 2-box puzzle, 32 sims
Sokoban: PUCT fails vs Gumbel solves

PUCT (left) vs Gumbel (right), same budget, same model. Click to play.

All demos are fully reproducible — see demo/ for scripts, sweep results, and instructions.

What's included

Three MCTS implementations sharing the same tree storage and batch interface:

Algorithm File Best for
PUCT puct.py Standard UCB-based MCTS. 2-20x faster than reference on CPU and GPU.
Gumbel Dense gumbel_dense.py Low-budget planning. Sequential halving over all legal actions.
Gumbel Sparse gumbel_sparse.py Large action spaces (e.g. chess). Samples a subset of actions to consider.

See gumbel-mcts-benchmark for validation against a gold-standard MCTS.

Installation

pip install gumbel-mcts

Quick start

from gumbel_mcts import GumbelDense

tree = GumbelDense(n_games=1, max_nodes=500, logic=logic, device="cpu")
tree.initialize_roots([0], board[None], np.array([player]))
action = tree.run_simulation_batch(model, [0], num_simulations=64)[0]

The interface is the same for all three algorithms — swap GumbelDense for PUCT or GumbelSparse.

How it works

Gumbel sequential halving
Improving MuZero using the Gumbel top-k trick, by Xavier O'Keefe

Standard PUCT explores actions proportionally to a UCB score that mixes prior probability and visit-based value estimates. When the budget is small, most actions get only a few visits, and the value estimates are noisy — PUCT can't reliably distinguish good actions from bad ones.

Gumbel MCTS takes a different approach: add Gumbel noise to the log-prior to create an initial ranking, then use sequential halving to eliminate half the candidates at each phase. Each phase allocates equal simulations to the surviving candidates. The result is that the budget concentrates on a shrinking set of promising actions, producing a much sharper signal with the same total simulation count.

Board game results

Head-to-head on 15x15 Gomoku across simulation budgets. Gumbel's advantage is largest at low budgets and persists as the model improves:

PUCT vs Gumbel — random model

PUCT vs Gumbel — heuristic model

With 8 simulations on 9x9 Gomoku, Gumbel concentrates visits on the strategic moves while PUCT spreads them across irrelevant squares:

Visit distribution heatmap — PUCT vs Gumbel Dense

Metadata

Release files for gumbel-mcts 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gumbel-mcts 0.2.0
File Size Uploaded
gumbel_mcts-0.2.0.tar.gz 40.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gumbel-mcts 0.2.0
File Interpreter ABI Platform
gumbel_mcts-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 76.3 kB

Release files / gumbel_mcts-0.2.0.tar.gz

Download URL gumbel_mcts-0.2.0.tar.gz
Size 40.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bec07582aa58e392ceaef1769c824ec5c6d648ae4787219e66a67a62a9adff88
BLAKE2b-256 checksum
How to use checksums
a607f8a49200e8b5d8c5b076f1f3b4d18effa432d647b06344027b63f3626abe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / gumbel_mcts-0.2.0-py3-none-any.whl

Download URL gumbel_mcts-0.2.0-py3-none-any.whl
Size 35.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf219380cd73217dd7fcb4c9ec28dd363a91e0aca5648fb63df6b72118e36a39
BLAKE2b-256 checksum
How to use checksums
3484938bd9f581786862c5a7089c67ad3d1658568d4f739687cc929d4298a49d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page