Skip to main content

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.

Snippet for training a MCCFR-outcome sampling on the Kuhn Poker game.

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) ✅
MCCFR (other variants) ❌
Vanilla CFR ❌
Deep CFR ❌
Metrics
Exploitability ✅
Local Best Response ❌
Environments
Kuhn Poker ✅
Leduc Poker ✅
Larger games ❌

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

See also

cfrx is heavily inspired by the amazing google-deepmind/open_spiel library as well as by many projects from the Jax ecosystem and especially sotetsuk/pgx and google-deepmind/mctx.

Contributing

Contributions are welcome, refer to the contributions guidelines.

Metadata

Release files for cfrx 0.0.2

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

Source distribution (sdist)

Source distribution for cfrx 0.0.2
File Size Uploaded Provenance Actions
cfrx-0.0.2.tar.gz 29.9 kB Without provenance Details for cfrx-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cfrx 0.0.2
File Interpreter ABI Platform Actions
cfrx-0.0.2-py3-none-any.whl Python 3 none any Details for cfrx-0.0.2-py3-none-any.whl

Total release size: 63.5 kB

Release files / cfrx-0.0.2.tar.gz

Download URL cfrx-0.0.2.tar.gz
Size 29.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a8aca00772662981286ce08869cc1351697beaa290b1cfa5b285af9ba9c89ab2
BLAKE2b-256 checksum
How to use checksums
cf5ab8733324fca69ce6bc44b2d783051e8f67bd805eea1c46c58f7d1ee3c343
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.13

Release files / cfrx-0.0.2-py3-none-any.whl

Download URL cfrx-0.0.2-py3-none-any.whl
Size 33.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ec287eb6798bd25bea297bc08cfc5f41bd047c200fdc1ce4eef6b0805f5a3a2
BLAKE2b-256 checksum
How to use checksums
34077e981fbf482984f26c58e5d3a2136219016087a1c7943493119146a9ae89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.13

Security for cfrx 0.0.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

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