{"id":13478514,"url":"https://github.com/google-deepmind/mctx","last_synced_at":"2025-06-17T00:39:18.635Z","repository":{"id":37099682,"uuid":"464991268","full_name":"google-deepmind/mctx","owner":"google-deepmind","description":"Monte Carlo tree search in JAX","archived":false,"fork":false,"pushed_at":"2025-04-10T21:49:25.000Z","size":488,"stargazers_count":2493,"open_issues_count":3,"forks_count":204,"subscribers_count":26,"default_branch":"main","last_synced_at":"2025-06-03T13:03:16.569Z","etag":null,"topics":["jax","monte-carlo-tree-search","reinforcement-learning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/google-deepmind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-01T17:26:43.000Z","updated_at":"2025-06-03T07:42:54.000Z","dependencies_parsed_at":"2023-09-07T20:34:51.217Z","dependency_job_id":"c51f0398-6437-422f-a7f8-cdc7b9a87d18","html_url":"https://github.com/google-deepmind/mctx","commit_stats":{"total_commits":42,"total_committers":12,"mean_commits":3.5,"dds":"0.38095238095238093","last_synced_commit":"d40d32e1a18fb73030762bac33819f95fff9787c"},"previous_names":["google-deepmind/mctx","deepmind/mctx"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/google-deepmind/mctx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-deepmind%2Fmctx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-deepmind%2Fmctx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-deepmind%2Fmctx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-deepmind%2Fmctx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/google-deepmind","download_url":"https://codeload.github.com/google-deepmind/mctx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-deepmind%2Fmctx/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260268635,"owners_count":22983601,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jax","monte-carlo-tree-search","reinforcement-learning"],"created_at":"2024-07-31T16:01:58.077Z","updated_at":"2025-06-17T00:39:18.595Z","avatar_url":"https://github.com/google-deepmind.png","language":"Python","funding_links":[],"categories":["Python","Frameworks \u0026 libraries","Libraries"],"sub_categories":[],"readme":"# Mctx: MCTS-in-JAX\n\nMctx is a library with a [JAX](https://github.com/google/jax)-native\nimplementation of Monte Carlo tree search (MCTS) algorithms such as\n[AlphaZero](https://deepmind.com/blog/article/alphazero-shedding-new-light-grand-games-chess-shogi-and-go),\n[MuZero](https://deepmind.com/blog/article/muzero-mastering-go-chess-shogi-and-atari-without-rules), and\n[Gumbel MuZero](https://openreview.net/forum?id=bERaNdoegnO). For computation\nspeed up, the implementation fully supports JIT-compilation. Search algorithms\nin Mctx are defined for and operate on batches of inputs, in parallel. This\nallows to make the most of the accelerators and enables the algorithms to work\nwith large learned environment models parameterized by deep neural networks.\n\n## Installation\n\nYou can install the latest released version of Mctx from PyPI via:\n\n```sh\npip install mctx\n```\n\nor you can install the latest development version from GitHub:\n\n```sh\npip install git+https://github.com/google-deepmind/mctx.git\n```\n\n## Motivation\n\nLearning and search have been important topics since the early days of AI\nresearch. In the [words of Rich Sutton](http://www.incompleteideas.net/IncIdeas/BitterLesson.html):\n\n\u003e One thing that should be learned [...] is the great power of general purpose\n\u003e methods, of methods that continue to scale with increased computation even as\n\u003e the available computation becomes very great. The two methods that seem to\n\u003e scale arbitrarily in this way are *search* and *learning*.\n\nRecently, search algorithms have been successfully combined with learned models\nparameterized by deep neural networks, resulting in some of the most powerful\nand general reinforcement learning algorithms to date (e.g. MuZero).\nHowever, using search algorithms in combination with deep neural networks\nrequires efficient implementations, typically written in fast compiled\nlanguages; this can come at the expense of usability and hackability,\nespecially for researchers that are not familiar with C++. In turn, this limits\nadoption and further research on this critical topic.\n\nThrough this library, we hope to help researchers everywhere to contribute to\nsuch an exciting area of research. We provide JAX-native implementations of core\nsearch algorithms such as MCTS, that we believe strike a good balance between\nperformance and usability for researchers that want to investigate search-based\nalgorithms in Python. The search methods provided by Mctx are\nheavily configurable to allow researchers to explore a variety of ideas in\nthis space, and contribute to the next generation of search based agents.\n\n## Search in Reinforcement Learning\n\nIn Reinforcement Learning the *agent* must learn to interact with the\n*environment* in order to maximize a scalar *reward* signal. On each step the\nagent must select an action and receives in exchange an observation and a\nreward. We may call whatever mechanism the agent uses to select the action the\nagent's *policy*.\n\nClassically, policies are parameterized directly by a function approximator (as\nin REINFORCE), or policies are inferred by inspecting a set of learned estimates\nof the value of each action (as in Q-learning). Alternatively, search allows to\nselect actions by constructing on the fly, in each state, a policy or a value\nfunction local to the current state, by *searching* using a learned *model* of\nthe environment.\n\nExhaustive search over all possible future courses of actions is computationally\nprohibitive in any non trivial environment, hence we need search algorithms\nthat can make the best use of a finite computational budget. Typically priors\nare needed to guide which nodes in the search tree to expand (to reduce the\n*breadth* of the tree that we construct), and value functions are used to\nestimate the value of incomplete paths in the tree that don't reach an episode\ntermination (to reduce the *depth* of the search tree).\n\n## Quickstart\n\nMctx provides a low-level generic `search` function and high-level concrete\npolicies: `muzero_policy` and `gumbel_muzero_policy`.\n\nThe user needs to provide several learned components to specify the\nrepresentation, dynamics and prediction used by [MuZero](https://deepmind.com/blog/article/muzero-mastering-go-chess-shogi-and-atari-without-rules).\nIn the context of the Mctx library, the representation of the *root* state is\nspecified by a `RootFnOutput`. The `RootFnOutput` contains the `prior_logits`\nfrom a policy network, the estimated `value` of the root state, and any\n`embedding` suitable to represent the root state for the environment model.\n\nThe dynamics environment model needs to be specified by a `recurrent_fn`.\nA `recurrent_fn(params, rng_key, action, embedding)` call takes an `action` and\na state `embedding`. The call should return a tuple `(recurrent_fn_output,\nnew_embedding)` with a `RecurrentFnOutput` and the embedding of the next state.\nThe `RecurrentFnOutput` contains the `reward` and `discount` for the transition,\nand `prior_logits` and `value` for the new state.\n\nIn [`examples/visualization_demo.py`](https://github.com/google-deepmind/mctx/blob/main/examples/visualization_demo.py), you can\nsee calls to a policy:\n\n```python\npolicy_output = mctx.gumbel_muzero_policy(params, rng_key, root, recurrent_fn,\n                                          num_simulations=32)\n```\n\nThe `policy_output.action` contains the action proposed by the search. That\naction can be passed to the environment. To improve the policy, the\n`policy_output.action_weights` contain targets usable to train the policy\nprobabilities.\n\nWe recommend to use the `gumbel_muzero_policy`.\n[Gumbel MuZero](https://openreview.net/forum?id=bERaNdoegnO) guarantees a policy\nimprovement if the action values are correctly evaluated. The policy improvement\nis demonstrated in\n[`examples/policy_improvement_demo.py`](https://github.com/google-deepmind/mctx/blob/main/examples/policy_improvement_demo.py).\n\n### Example projects\nThe following projects demonstrate the Mctx usage:\n\n- [Pgx](https://github.com/sotetsuk/pgx) — A collection of 20+ vectorized\n  JAX environments, including backgammon, chess, shogi, Go, and an AlphaZero\n  example.\n- [Basic Learning Demo with Mctx](https://github.com/kenjyoung/mctx_learning_demo) —\n  AlphaZero on random mazes.\n- [a0-jax](https://github.com/NTT123/a0-jax) — AlphaZero on Connect Four,\n  Gomoku, and Go.\n- [muax](https://github.com/bwfbowen/muax) — MuZero on gym-style environments\n(CartPole, LunarLander).\n- [Classic MCTS](https://github.com/Carbon225/mctx-classic) — A simple example on Connect Four.\n- [mctx-az](https://github.com/lowrollr/mctx-az) — Mctx with AlphaZero subtree persistence.\n\nTell us about your project.\n\n## Citing Mctx\n\nThis repository is part of the DeepMind JAX Ecosystem, to cite Mctx\nplease use the citation:\n\n```bibtex\n@software{deepmind2020jax,\n  title = {The {D}eep{M}ind {JAX} {E}cosystem},\n  author = {DeepMind and Babuschkin, Igor and Baumli, Kate and Bell, Alison and Bhupatiraju, Surya and Bruce, Jake and Buchlovsky, Peter and Budden, David and Cai, Trevor and Clark, Aidan and Danihelka, Ivo and Dedieu, Antoine and Fantacci, Claudio and Godwin, Jonathan and Jones, Chris and Hemsley, Ross and Hennigan, Tom and Hessel, Matteo and Hou, Shaobo and Kapturowski, Steven and Keck, Thomas and Kemaev, Iurii and King, Michael and Kunesch, Markus and Martens, Lena and Merzic, Hamza and Mikulik, Vladimir and Norman, Tamara and Papamakarios, George and Quan, John and Ring, Roman and Ruiz, Francisco and Sanchez, Alvaro and Sartran, Laurent and Schneider, Rosalia and Sezener, Eren and Spencer, Stephen and Srinivasan, Srivatsan and Stanojevi\\'{c}, Milo\\v{s} and Stokowiec, Wojciech and Wang, Luyu and Zhou, Guangyao and Viola, Fabio},\n  url = {http://github.com/deepmind},\n  year = {2020},\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle-deepmind%2Fmctx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle-deepmind%2Fmctx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle-deepmind%2Fmctx/lists"}