Skip to main content

GPU/TPU-accelerated parallel game simulators for reinforcement learning (RL)

Project description

ci

A collection of GPU/TPU-accelerated parallel game simulators for reinforcement learning (RL)

Why Pgx?

Brax, a JAX-native physics engine, provides extremely high-speed parallel simulation for RL in continuous state space. Then, what about RL in discrete state spaces like Chess, Shogi, and Go? Pgx provides a wide variety of JAX-native game simulators! Highlighted features include:

  • Super fast in parallel execution on accelerators
  • 🎲 Various game support including Backgammon, Chess, Shogi, and Go
  • 🖼️ Beautiful visualization in SVG format

Installation

pip install pgx

Usage

Note that all step functions in Pgx environments are JAX-native., i.e., they are all JIT-able.

Open In Colab

import jax
import pgx

env = pgx.make("go_19x19")
init = jax.jit(jax.vmap(env.init))  # vectorize and JIT-compile
step = jax.jit(jax.vmap(env.step))

batch_size = 1024
keys = jax.random.split(jax.random.PRNGKey(42), batch_size)
state = init(keys)  # vectorized states
while not (state.terminated | state.terminated).all():
    action = model(state.current_player, state.observation, state.legal_action_mask)
    state = step(state, action)  # state.reward (2,)

⚠️ Pgx is currently in the beta version. Therefore, API is subject to change without notice. We aim to release v1.0.0 in May 2023. Opinions and comments are more than welcome!

Supported games

Backgammon Chess Shogi Go

Use pgx.available_envs() -> Tuple[EnvId] to see the list of currently available games. Given an <EnvId>, you can create the environment via

>>> env = pgx.make(<EnvId>)

You can check the current version of each environment by

>>> env.version
Game/EnvId Visualization Version Five-word description
2048
"2048"
beta Merge tiles to create 2048.
Animal Shogi
"animal_shogi"
beta Animal-themed child-friendly shogi.
Backgammon
"backgammon"
beta Luck aids bearing off checkers.
Chess
"chess"
beta Checkmate opponent's king to win.
Connect Four
"connect_four"
beta Connect discs, win with four.
Go
"go_9x9" "go_19x19"
beta Strategically place stones, claim territory.
Hex
"hex"
beta Connect opposite sides, block opponent.
Kuhn Poker
"kuhn_poker"
beta Three-card betting and bluffing game.
Leduc hold'em
"leduc_holdem"
beta Two-suit, limited deck poker.
MinAtar/Asterix
"minatar-asterix"
beta Avoid enemies, collect treasure, survive.
MinAtar/Breakout
"minatar-breakout"
beta Paddle, ball, bricks, bounce, clear.
MinAtar/Freeway
"minatar-freeway"
beta Dodging cars, climbing up freeway.
MinAtar/Seaquest
"minatar-seaquest"
beta Underwater submarine rescue and combat.
MinAtar/SpaceInvaders
"minatar-space_invaders"
beta Alien shooter game, dodge bullets.
Othello
"othello"
beta Flip and conquer opponent's pieces.
Shogi
"shogi"
beta Japanese chess with captured pieces.
Sparrow Mahjong
"sparrow_mahjong"
beta A simplified, children-friendly Mahjong.
Tic-tac-toe
"tic_tac_toe"
beta Three in a row wins.

See also

Pgx is intended to complement these JAX-native environments with (classic) board game suits:

Combining Pgx with these JAX-native algorithms/implementations might be an interesting direction:

Citation

@article{koyamada2023pgx,
  title={Pgx: Hardware-accelerated parallel game simulation for reinforcement learning},
  author={Koyamada, Sotetsu and Okano, Shinri and Nishimori, Soichiro and Murata, Yu and Habara, Keigo and Kita, Haruka and Ishii, Shin},
  journal={arXiv preprint arXiv:2303.17503},
  year={2023}
}

LICENSE

Apache-2.0

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

pgx-0.7.3.tar.gz (227.6 kB view details)

Uploaded Source

Built Distribution

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

pgx-0.7.3-py3-none-any.whl (304.4 kB view details)

Uploaded Python 3

File details

Details for the file pgx-0.7.3.tar.gz.

File metadata

  • Download URL: pgx-0.7.3.tar.gz
  • Upload date:
  • Size: 227.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for pgx-0.7.3.tar.gz
Algorithm Hash digest
SHA256 9492fa7c8f718989d7d3e2eb786130eab540fe7a6c94063b01960d0d122eb41b
MD5 e5113ff2c8585aa751b7d0c23b0f7330
BLAKE2b-256 c9d72bb86f8c4f4a65303f0c1126ce60044f86736f639cb128d9a7230f44a59b

See more details on using hashes here.

File details

Details for the file pgx-0.7.3-py3-none-any.whl.

File metadata

  • Download URL: pgx-0.7.3-py3-none-any.whl
  • Upload date:
  • Size: 304.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for pgx-0.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5031195fa70da7f0ed7252fba9a84c0ecfde29d04a9411c96390ab5134be2e25
MD5 c6926ff344cff7fc9b8828b952a46031
BLAKE2b-256 8200b14f972b06034e5e5cdbd71188d9a05ab829f8d1e08eee0f341c95b6aa4f

See more details on using hashes here.

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