MuTriMCTS
MuTriMCTS is a high-performance Python package providing C++ bindings for MuZero Monte Carlo Tree Search (MCTS) operating in learned latent space.
Features
- 🚀 High Performance: C++ core with Python bindings via pybind11
- 🧠 MuZero Algorithm: MCTS in learned latent space (no game engine required during search)
- 🎯 Clean API: Simple Protocol-based network interface
- 📦 Easy Installation: Available via PyPI
- ✅ Well Tested: Comprehensive test suite
- 🔧 Configurable: Flexible search parameters (simulations, CPUCT, discount, Dirichlet noise)
Installation
From PyPI (when published)
pip install mutrimcts
From Source
git clone https://github.com/lguibr/mutrimcts.git
cd mutrimcts
pip install -e .
Development Setup
# Clone and install with dev dependencies
git clone https://github.com/lguibr/mutrimcts.git
cd mutrimcts
pip install -e ".[dev]"
# Run tests
pytest tests/
# Clean build artifacts (if needed)
# rm -rf build/ src/mutrimcts.egg-info/ dist/ src/mutrimcts/mutrimcts_cpp.*.so
Quick Start
import mutrimcts
import numpy as np
# Implement your MuZero network
class MyMuZeroNetwork(mutrimcts.MuZeroNetworkInterface):
def initial_inference(self, observation):
"""
observation → (hidden_state, policy, value)
"""
hidden_state = self.representation(observation)
policy, value = self.prediction(hidden_state)
return hidden_state, policy, value
def recurrent_inference(self, hidden_state, action):
"""
(hidden_state, action) → (next_hidden_state, reward, policy, value)
"""
next_hidden, reward = self.dynamics(hidden_state, action)
policy, value = self.prediction(next_hidden)
return next_hidden, reward, policy, value
# Configure search
config = mutrimcts.SearchConfiguration(
max_simulations=50,
max_depth=10,
cpuct=1.25,
dirichlet_alpha=0.3,
dirichlet_epsilon=0.25,
discount=0.997 # Important for MuZero!
)
# Run MCTS
network = MyMuZeroNetwork()
observation = get_current_observation()
visit_counts, root_value, mcts_policy = mutrimcts.run_mcts(
observation, network, config
)
# Use results for training and action selection
# - visit_counts: target for policy loss
# - root_value: used in value bootstrapping
# - mcts_policy: for action selection (proportional to visits)
API Reference
Network Interface
class MuZeroNetworkInterface(Protocol):
def initial_inference(self, observation: Any) -> tuple[Any, dict[int, float], float]:
"""Returns: (hidden_state, policy_dict, value)"""
...
def recurrent_inference(self, hidden_state: Any, action: int) -> tuple[Any, float, dict[int, float], float]:
"""Returns: (next_hidden_state, reward, policy_dict, value)"""
...
Search Configuration
config = SearchConfiguration(
max_simulations=50, # Number of MCTS simulations
max_depth=10, # Maximum search depth
cpuct=1.25, # PUCT exploration constant
dirichlet_alpha=0.3, # Dirichlet noise alpha
dirichlet_epsilon=0.25, # Dirichlet noise weight
discount=0.997, # Discount factor (gamma)
mcts_batch_size=1 # Batch size for network calls
)
MCTS Function
def run_mcts(
initial_observation: Any,
network_interface: MuZeroNetworkInterface,
config: SearchConfiguration
) -> tuple[dict[int, int], float, dict[int, float]]:
"""
Returns:
- visit_counts: dict[int, int] - Visit counts per action
- root_value: float - Root node value estimate
- mcts_policy: dict[int, float] - Normalized MCTS policy
"""
Project Structure
mutrimcts/
├── src/mutrimcts/ # Python package source
│ ├── __init__.py # Package exports
│ ├── config.py # SearchConfiguration
│ ├── mcts_wrapper.py # Python entry point
│ └── cpp/ # C++ source code
│ ├── bindings.cpp # pybind11 bindings
│ ├── mcts.h/.cpp # MCTS algorithm
│ ├── python_interface.h # Network interface
│ ├── config.h # Config struct
│ └── CMakeLists.txt # Build configuration
├── tests/ # Test suite
│ └── test_muzero_mcts.py
├── pyproject.toml # Package metadata
├── setup.py # Build script
└── README.md # This file
How It Works
MuTriMCTS implements the MuZero algorithm:
- Initial Inference: Converts raw observation to latent state
- Tree Search: MCTS in latent space using learned dynamics
- Recurrent Inference: Predicts next state, reward, policy, value
- Backpropagation: Discounted value accumulation
- Result: Visit counts and improved policy for training
Key Differences from AlphaZero
| Feature | AlphaZero | MuZero (MuTriMCTS) |
|---|---|---|
| Search Space | Real game states | Learned latent states |
| Game Engine | Required during search | Only at root |
| State Representation | Actual game state | Hidden state tensor |
| Rewards | Only at terminal | Predicted per transition |
| Network Calls | evaluate_state() |
initial_inference() + recurrent_inference() |
Development
Building from Source
# Install dependencies
pip install pybind11>=2.10 cmake>=3.14
# Build C++ extension
mkdir build && cd build
cmake ../src/mutrimcts/cpp
cmake --build . --config Release
# Copy to package
cp mutrimcts_cpp.*.so ../src/mutrimcts/
Running Tests
pytest tests/ -v
License
MIT License - see LICENSE file for details
Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
Citation
If you use MuTriMCTS in your research, please cite:
@software{mutrimcts2025,
author = {Luis Guilherme P. M.},
title = {MuTriMCTS: MuZero MCTS in Learned Latent Space},
year = {2025},
url = {https://github.com/lguibr/mutrimcts}
}
Links
- Repository: https://github.com/lguibr/mutrimcts
- Issues: https://github.com/lguibr/mutrimcts/issues
- PyPI: https://pypi.org/project/mutrimcts/
Acknowledgments
Based on the MuZero algorithm by DeepMind. Optimized for research and experimentation.
Metadata
Release files for mutrimcts 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 4.8 MB
Release files / mutrimcts-0.1.0-cp312-cp312-win_amd64.whl
| Download URL | mutrimcts-0.1.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 166.1 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
392e193729cb323c873e71eb37700eb5f4bbeb0edf1ed755cd8a7a7a6a537569
|
|
BLAKE2b-256 checksum How to use checksums |
c0ecb633c04730f35770e63d572e5e6d5758a8f33af1813952c2ebafe76a5fb0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2025.
Transparency logRelease files / mutrimcts-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | mutrimcts-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
e16f40eb1b7ac299f098a1420aff4f18a08f19aa8797128f14a651ae623be25f
|
|
BLAKE2b-256 checksum How to use checksums |
dbef43c876ae01b77b7920781caf7cc7c7ab690692cd8fcb170b30d05367950a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2025.
Transparency logRelease files / mutrimcts-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | mutrimcts-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 205.1 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
72fd6086d23cc954bcf0f522fc7fe16c4bdb60867242068e74401714714d2f43
|
|
BLAKE2b-256 checksum How to use checksums |
bc35e0cb744cda2d48418f2783ef73b712403d6d37765a979030d9fd0f00e215
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2025.
Transparency logRelease files / mutrimcts-0.1.0-cp312-cp312-macosx_15_0_universal2.whl
| Download URL | mutrimcts-0.1.0-cp312-cp312-macosx_15_0_universal2.whl |
|---|---|
| Size | 78.4 kB |
| Tags | CPython 3.12 macOS 15.0+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
05b82ae3c9a03cac00521d1986e015911ce976c1d65208d519f4a3e3cd27e152
|
|
BLAKE2b-256 checksum How to use checksums |
a3b08f6c052633f92ae59649927f9f636ce57aba739ebd1310c6de23dbde9cca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2025.
Transparency logRelease files / mutrimcts-0.1.0-cp311-cp311-win_amd64.whl
| Download URL | mutrimcts-0.1.0-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 163.8 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
4f81a881e1ab0ed34a090386e32b8683952a3e8cd876957e653ddcf5db9c08e4
|
|
BLAKE2b-256 checksum How to use checksums |
64e8a5fa77fad95b81e675783c9a4054b1dfc7e0981409ba4b4371a81b3d2198
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2025.
Transparency logRelease files / mutrimcts-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl
| Download URL | mutrimcts-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
70ba10d5f44f71f92538384fcdaf70b05aee7ece5d39d3d75d43f646c22b96c2
|
|
BLAKE2b-256 checksum How to use checksums |
b480bb682c1f82e97a29a6dcd127791bc1d77404fa26d09ae1abfce7d8991a4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2025.
Transparency logRelease files / mutrimcts-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | mutrimcts-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 205.1 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
44b68877c0ff8c956c0c9207d11b0f64b64e33ff2cfc468f6072713b68946164
|
|
BLAKE2b-256 checksum How to use checksums |
e52c3d54720e0c3898b02d749de81fbb46d9d55d5a44360e87e34ae18d85585f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2025.
Transparency logRelease files / mutrimcts-0.1.0-cp311-cp311-macosx_15_0_universal2.whl
| Download URL | mutrimcts-0.1.0-cp311-cp311-macosx_15_0_universal2.whl |
|---|---|
| Size | 78.2 kB |
| Tags | CPython 3.11 macOS 15.0+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
4f5afdff00457629dbe54d75592e20e0134df560cc2529476adaf047960d040d
|
|
BLAKE2b-256 checksum How to use checksums |
77051a086acddfb55d1d5db251834264ee760fa76a483615ec1876fff4060b97
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2025.
Transparency logRelease files / mutrimcts-0.1.0-cp310-cp310-win_amd64.whl
| Download URL | mutrimcts-0.1.0-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 162.4 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
1569995af6184f2cf5dff58392421a3f8c60f224f5ea1208c783d4ce2d44cc00
|
|
BLAKE2b-256 checksum How to use checksums |
5bdc1501d2bf649a2ffbe077d8ba9944912e1e94e1456cd9dd48c88c02e66e09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2025.
Transparency logRelease files / mutrimcts-0.1.0-cp310-cp310-musllinux_1_2_x86_64.whl
| Download URL | mutrimcts-0.1.0-cp310-cp310-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
2883457309e8e819398dd607a19b8517abb1d6bd6a9ebe758a187965df7d315e
|
|
BLAKE2b-256 checksum How to use checksums |
ce1585a4c53981dde5855cdff9720c81773b9a4e32d398009f7b35494d322f02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2025.
Transparency logRelease files / mutrimcts-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | mutrimcts-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 205.1 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
e3fe6fa9c512498882dfde20d5af0ae1ee23bb62cded34a1d0513500ebd40ed8
|
|
BLAKE2b-256 checksum How to use checksums |
2ee05aa0aae694a52e65bdcc54d63146698d183ba33c4d45b817c08eba3801bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2025.
Transparency logRelease files / mutrimcts-0.1.0-cp310-cp310-macosx_15_0_universal2.whl
| Download URL | mutrimcts-0.1.0-cp310-cp310-macosx_15_0_universal2.whl |
|---|---|
| Size | 77.0 kB |
| Tags | CPython 3.10 macOS 15.0+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
b9e633344428eccb3bb9e0607608aeafa68298487aeca445f4428ec747b0ba53
|
|
BLAKE2b-256 checksum How to use checksums |
527b385be0d9e74267331197b8a98351454b1bb0b298c818ac159032dbe4a44e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2025.
Transparency log