cfrx


Namecfrx JSON
Version 0.0.2 PyPI version JSON
download
home_page
SummaryCounterfactual Regret Minimization in Jax
upload_time2024-03-05 14:45:34
maintainer
docs_urlNone
authorRaphaël Boige
requires_python>=3.9.0
licenseMIT License Copyright (c) 2023 Raphaël Boige Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords jax game-theory reinforcement-learning cfr poker
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cfrx: Counterfactual Regret Minimization in Jax.

cfrx is an open-source library designed for efficient implementation of counterfactual regret minimization (CFR) algorithms using JAX. It focuses on computational speed and easy parallelization on hardware accelerators like GPUs and TPUs.

Key Features:

- **JIT Compilation for Speed:** cfrx makes the most out of JAX's just-in-time (JIT) compilation to minimize runtime overhead and maximize computational speed.

- **Hardware Accelerator Support:** It supports parallelization on GPUs and TPUs, enabling efficient scaling of computations for large-scale problems.

- **Python/JAX Ease of Use:** cfrx provides a Pythonic interface built on JAX, offering simplicity and accessibility compared to traditional C++ implementations or prohibitively slow pure-Python code.

## Installation

    pip install cfrx

## Getting started

An example notebook is available [here](examples/mccfr.ipynb).

Snippet for training a MCCFR-outcome sampling on the Kuhn Poker game.
```python3
import jax

from cfrx.envs.kuhn_poker.env import KuhnPoker
from cfrx.policy import TabularPolicy
from cfrx.trainers.mccfr import MCCFRTrainer

env = KuhnPoker()

policy = TabularPolicy(
    n_actions=env.n_actions,
    exploration_factor=0.6,
    info_state_idx_fn=env.info_state_idx,
)

random_key = jax.random.PRNGKey(0)

trainer = MCCFRTrainer(env=env, policy=policy)

training_state = trainer.train(
    random_key=random_key, n_iterations=100_000, metrics_period=5_000
)
```


## Implemented features and upcoming features

| Algorithms |   |
|---|---|
| MCCFR (outcome-sampling)  |  :white_check_mark: |
| MCCFR (other variants) | :x: |
| Vanilla CFR  | :x: |
|  Deep CFR | :x:  |

| Metrics |   |
|---|---|
| Exploitability | :white_check_mark: |
| Local Best Response  |  :x: |

| Environments | |
|---|---|
| Kuhn Poker |  :white_check_mark: |
| Leduc Poker | :white_check_mark: |
| Larger games | :x:  |


## Performance

Below is a small benchmark against `open_spiel` for MCCFR-outcome-sampling on Kuhn Poker and Leduc Poker. Compared to the Python API of `open_spiel`, `cfrx` has faster runtime and demonstrates similar convergence.

![benchmarck_against_open_spiel_img](imgs/bench_open_spiel_v0_0_1.png)

## See also

cfrx is heavily inspired by the amazing [google-deepmind/open_spiel](https://github.com/google-deepmind/open_spiel) library as well as by many projects from the Jax ecosystem and especially [sotetsuk/pgx](https://github.com/sotetsuk/pgx) and [google-deepmind/mctx](https://github.com/google-deepmind/mctx).


## Contributing

Contributions are welcome, refer to the [contributions guidelines](CONTRIBUTING.md).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "cfrx",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9.0",
    "maintainer_email": "",
    "keywords": "jax,game-theory,reinforcement-learning,cfr,poker",
    "author": "Rapha\u00ebl Boige",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/cf/5a/b8733324fca69ce6bc44b2d783051e8f67bd805eea1c46c58f7d1ee3c343/cfrx-0.0.2.tar.gz",
    "platform": null,
    "description": "# cfrx: Counterfactual Regret Minimization in Jax.\n\ncfrx is an open-source library designed for efficient implementation of counterfactual regret minimization (CFR) algorithms using JAX. It focuses on computational speed and easy parallelization on hardware accelerators like GPUs and TPUs.\n\nKey Features:\n\n- **JIT Compilation for Speed:** cfrx makes the most out of JAX's just-in-time (JIT) compilation to minimize runtime overhead and maximize computational speed.\n\n- **Hardware Accelerator Support:** It supports parallelization on GPUs and TPUs, enabling efficient scaling of computations for large-scale problems.\n\n- **Python/JAX Ease of Use:** cfrx provides a Pythonic interface built on JAX, offering simplicity and accessibility compared to traditional C++ implementations or prohibitively slow pure-Python code.\n\n## Installation\n\n    pip install cfrx\n\n## Getting started\n\nAn example notebook is available [here](examples/mccfr.ipynb).\n\nSnippet for training a MCCFR-outcome sampling on the Kuhn Poker game.\n```python3\nimport jax\n\nfrom cfrx.envs.kuhn_poker.env import KuhnPoker\nfrom cfrx.policy import TabularPolicy\nfrom cfrx.trainers.mccfr import MCCFRTrainer\n\nenv = KuhnPoker()\n\npolicy = TabularPolicy(\n    n_actions=env.n_actions,\n    exploration_factor=0.6,\n    info_state_idx_fn=env.info_state_idx,\n)\n\nrandom_key = jax.random.PRNGKey(0)\n\ntrainer = MCCFRTrainer(env=env, policy=policy)\n\ntraining_state = trainer.train(\n    random_key=random_key, n_iterations=100_000, metrics_period=5_000\n)\n```\n\n\n## Implemented features and upcoming features\n\n| Algorithms |   |\n|---|---|\n| MCCFR (outcome-sampling)  |  :white_check_mark: |\n| MCCFR (other variants) | :x: |\n| Vanilla CFR  | :x: |\n|  Deep CFR | :x:  |\n\n| Metrics |   |\n|---|---|\n| Exploitability | :white_check_mark: |\n| Local Best Response  |  :x: |\n\n| Environments | |\n|---|---|\n| Kuhn Poker |  :white_check_mark: |\n| Leduc Poker | :white_check_mark: |\n| Larger games | :x:  |\n\n\n## Performance\n\nBelow is a small benchmark against `open_spiel` for MCCFR-outcome-sampling on Kuhn Poker and Leduc Poker. Compared to the Python API of `open_spiel`, `cfrx` has faster runtime and demonstrates similar convergence.\n\n![benchmarck_against_open_spiel_img](imgs/bench_open_spiel_v0_0_1.png)\n\n## See also\n\ncfrx is heavily inspired by the amazing [google-deepmind/open_spiel](https://github.com/google-deepmind/open_spiel) library as well as by many projects from the Jax ecosystem and especially [sotetsuk/pgx](https://github.com/sotetsuk/pgx) and [google-deepmind/mctx](https://github.com/google-deepmind/mctx).\n\n\n## Contributing\n\nContributions are welcome, refer to the [contributions guidelines](CONTRIBUTING.md).\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Rapha\u00ebl Boige  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Counterfactual Regret Minimization in Jax",
    "version": "0.0.2",
    "project_urls": {
        "repository": "https://github.com/Egiob/cfrx"
    },
    "split_keywords": [
        "jax",
        "game-theory",
        "reinforcement-learning",
        "cfr",
        "poker"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "34077e981fbf482984f26c58e5d3a2136219016087a1c7943493119146a9ae89",
                "md5": "6411557177e3d6c20b1dd448f8dfe768",
                "sha256": "0ec287eb6798bd25bea297bc08cfc5f41bd047c200fdc1ce4eef6b0805f5a3a2"
            },
            "downloads": -1,
            "filename": "cfrx-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6411557177e3d6c20b1dd448f8dfe768",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9.0",
            "size": 33675,
            "upload_time": "2024-03-05T14:45:33",
            "upload_time_iso_8601": "2024-03-05T14:45:33.272981Z",
            "url": "https://files.pythonhosted.org/packages/34/07/7e981fbf482984f26c58e5d3a2136219016087a1c7943493119146a9ae89/cfrx-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cf5ab8733324fca69ce6bc44b2d783051e8f67bd805eea1c46c58f7d1ee3c343",
                "md5": "651cd0f379e695214565c32a1909bba3",
                "sha256": "a8aca00772662981286ce08869cc1351697beaa290b1cfa5b285af9ba9c89ab2"
            },
            "downloads": -1,
            "filename": "cfrx-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "651cd0f379e695214565c32a1909bba3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9.0",
            "size": 29872,
            "upload_time": "2024-03-05T14:45:34",
            "upload_time_iso_8601": "2024-03-05T14:45:34.657129Z",
            "url": "https://files.pythonhosted.org/packages/cf/5a/b8733324fca69ce6bc44b2d783051e8f67bd805eea1c46c58f7d1ee3c343/cfrx-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-05 14:45:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Egiob",
    "github_project": "cfrx",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "cfrx"
}
        
Elapsed time: 0.19881s