Skip to main content

High-performance C++ MuZero MCTS in learned latent space

Project description

MuTriMCTS

CI PyPI


MuTriMCTS Logo

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:

  1. Initial Inference: Converts raw observation to latent state
  2. Tree Search: MCTS in latent space using learned dynamics
  3. Recurrent Inference: Predicts next state, reward, policy, value
  4. Backpropagation: Discounted value accumulation
  5. 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:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. 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

Acknowledgments

Based on the MuZero algorithm by DeepMind. Optimized for research and experimentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mutrimcts-0.1.0-cp312-cp312-win_amd64.whl (166.1 kB view details)

Uploaded CPython 3.12Windows x86-64

mutrimcts-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

mutrimcts-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (205.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

mutrimcts-0.1.0-cp312-cp312-macosx_15_0_universal2.whl (78.4 kB view details)

Uploaded CPython 3.12macOS 15.0+ universal2 (ARM64, x86-64)

mutrimcts-0.1.0-cp311-cp311-win_amd64.whl (163.8 kB view details)

Uploaded CPython 3.11Windows x86-64

mutrimcts-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

mutrimcts-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (205.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

mutrimcts-0.1.0-cp311-cp311-macosx_15_0_universal2.whl (78.2 kB view details)

Uploaded CPython 3.11macOS 15.0+ universal2 (ARM64, x86-64)

mutrimcts-0.1.0-cp310-cp310-win_amd64.whl (162.4 kB view details)

Uploaded CPython 3.10Windows x86-64

mutrimcts-0.1.0-cp310-cp310-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

mutrimcts-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (205.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

mutrimcts-0.1.0-cp310-cp310-macosx_15_0_universal2.whl (77.0 kB view details)

Uploaded CPython 3.10macOS 15.0+ universal2 (ARM64, x86-64)

File details

Details for the file mutrimcts-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: mutrimcts-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 166.1 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mutrimcts-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 392e193729cb323c873e71eb37700eb5f4bbeb0edf1ed755cd8a7a7a6a537569
MD5 4b6a9c678cb506b77347f2b1c603ce85
BLAKE2b-256 c0ecb633c04730f35770e63d572e5e6d5758a8f33af1813952c2ebafe76a5fb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for mutrimcts-0.1.0-cp312-cp312-win_amd64.whl:

Publisher: ci_cd.yml on lguibr/mutrimcts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mutrimcts-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for mutrimcts-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e16f40eb1b7ac299f098a1420aff4f18a08f19aa8797128f14a651ae623be25f
MD5 e7d60fac10a922103a68c72297d9b856
BLAKE2b-256 dbef43c876ae01b77b7920781caf7cc7c7ab690692cd8fcb170b30d05367950a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mutrimcts-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: ci_cd.yml on lguibr/mutrimcts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mutrimcts-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mutrimcts-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 72fd6086d23cc954bcf0f522fc7fe16c4bdb60867242068e74401714714d2f43
MD5 336a9e589eac007d83aa3fd0bc85ebfd
BLAKE2b-256 bc35e0cb744cda2d48418f2783ef73b712403d6d37765a979030d9fd0f00e215

See more details on using hashes here.

Provenance

The following attestation bundles were made for mutrimcts-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci_cd.yml on lguibr/mutrimcts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mutrimcts-0.1.0-cp312-cp312-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for mutrimcts-0.1.0-cp312-cp312-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 05b82ae3c9a03cac00521d1986e015911ce976c1d65208d519f4a3e3cd27e152
MD5 8d1f3e3102ef9d5469894016545f883c
BLAKE2b-256 a3b08f6c052633f92ae59649927f9f636ce57aba739ebd1310c6de23dbde9cca

See more details on using hashes here.

Provenance

The following attestation bundles were made for mutrimcts-0.1.0-cp312-cp312-macosx_15_0_universal2.whl:

Publisher: ci_cd.yml on lguibr/mutrimcts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mutrimcts-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: mutrimcts-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 163.8 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mutrimcts-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4f81a881e1ab0ed34a090386e32b8683952a3e8cd876957e653ddcf5db9c08e4
MD5 445c19e26e1c061dba410222c823d190
BLAKE2b-256 64e8a5fa77fad95b81e675783c9a4054b1dfc7e0981409ba4b4371a81b3d2198

See more details on using hashes here.

Provenance

The following attestation bundles were made for mutrimcts-0.1.0-cp311-cp311-win_amd64.whl:

Publisher: ci_cd.yml on lguibr/mutrimcts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mutrimcts-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for mutrimcts-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 70ba10d5f44f71f92538384fcdaf70b05aee7ece5d39d3d75d43f646c22b96c2
MD5 277eba10c5d8c5c87cc1455e17b20d94
BLAKE2b-256 b480bb682c1f82e97a29a6dcd127791bc1d77404fa26d09ae1abfce7d8991a4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mutrimcts-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: ci_cd.yml on lguibr/mutrimcts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mutrimcts-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mutrimcts-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 44b68877c0ff8c956c0c9207d11b0f64b64e33ff2cfc468f6072713b68946164
MD5 74b0d7a98689b2136773d714d20d5420
BLAKE2b-256 e52c3d54720e0c3898b02d749de81fbb46d9d55d5a44360e87e34ae18d85585f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mutrimcts-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci_cd.yml on lguibr/mutrimcts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mutrimcts-0.1.0-cp311-cp311-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for mutrimcts-0.1.0-cp311-cp311-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 4f5afdff00457629dbe54d75592e20e0134df560cc2529476adaf047960d040d
MD5 dce03af0630851a7f796b870466f3f16
BLAKE2b-256 77051a086acddfb55d1d5db251834264ee760fa76a483615ec1876fff4060b97

See more details on using hashes here.

Provenance

The following attestation bundles were made for mutrimcts-0.1.0-cp311-cp311-macosx_15_0_universal2.whl:

Publisher: ci_cd.yml on lguibr/mutrimcts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mutrimcts-0.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: mutrimcts-0.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 162.4 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mutrimcts-0.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1569995af6184f2cf5dff58392421a3f8c60f224f5ea1208c783d4ce2d44cc00
MD5 352864b75d9a48bf31ac988281ac75cd
BLAKE2b-256 5bdc1501d2bf649a2ffbe077d8ba9944912e1e94e1456cd9dd48c88c02e66e09

See more details on using hashes here.

Provenance

The following attestation bundles were made for mutrimcts-0.1.0-cp310-cp310-win_amd64.whl:

Publisher: ci_cd.yml on lguibr/mutrimcts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mutrimcts-0.1.0-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for mutrimcts-0.1.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2883457309e8e819398dd607a19b8517abb1d6bd6a9ebe758a187965df7d315e
MD5 e972d8a72700470a488ccc8b593963b6
BLAKE2b-256 ce1585a4c53981dde5855cdff9720c81773b9a4e32d398009f7b35494d322f02

See more details on using hashes here.

Provenance

The following attestation bundles were made for mutrimcts-0.1.0-cp310-cp310-musllinux_1_2_x86_64.whl:

Publisher: ci_cd.yml on lguibr/mutrimcts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mutrimcts-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mutrimcts-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e3fe6fa9c512498882dfde20d5af0ae1ee23bb62cded34a1d0513500ebd40ed8
MD5 c439937a132ab658c5c4b0f6b35691fb
BLAKE2b-256 2ee05aa0aae694a52e65bdcc54d63146698d183ba33c4d45b817c08eba3801bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for mutrimcts-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci_cd.yml on lguibr/mutrimcts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mutrimcts-0.1.0-cp310-cp310-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for mutrimcts-0.1.0-cp310-cp310-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 b9e633344428eccb3bb9e0607608aeafa68298487aeca445f4428ec747b0ba53
MD5 227c21c5779232fb9e4d89d2a76aad1a
BLAKE2b-256 527b385be0d9e74267331197b8a98351454b1bb0b298c818ac159032dbe4a44e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mutrimcts-0.1.0-cp310-cp310-macosx_15_0_universal2.whl:

Publisher: ci_cd.yml on lguibr/mutrimcts

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