Python library for playing DFA bisimulation games and wrapping other RL environments with DFA goals.
Project description
dfa-gym
This repo implements (Multi-Agent) Reinforcement Learning environments in JAX for solving objectives given as Deteministic Finite Automata (DFAs). There are three environments:
TokenEnvis a fully observable grid environment with tokens in cells. The grid can be created randomly or from a specific layout. It can be instantiated in both single- and multi-agent settings.DFAWrapperis an environment wrapper assigning tasks represented as Deterministic Finite Automata (DFAs) to the agents in the wrapped environment. DFAs are repsented asDFAxobjects.DFABisimEnvis an environment for solving DFA bisimulation games to learn RAD Embeddings, provably correct latent DFA representation, as described in this paper.
Installation
Install using pip.
pip install dfa-gym
TokenEnv
Create a grid world with token and agent positions assigned randomly.
from dfa_gym import TokenEnv
env = TokenEnv(
n_agents=1, # Single agent
n_tokens=10, # 10 different token types
n_token_repeat=2, # Each token repeated twice
grid_shape=(7, 7), # Shape of the grid
fixed_map_seed=None, # If not None, then samples the same map using the given seed
max_steps_in_episode=100, # Episode length is 100
)
Create a grid world from a given layout.
layout = """
[ 0 ][ ][ ][ ][ # ][ # ][ # ][ # ][ # ]
[ ][ ][ a ][ ][#,a][ 0 ][ ][ 2 ][ # ]
[ A ][ ][ a ][ ][#,a][ ][ 8 ][ ][ # ]
[ ][ ][ a ][ ][#,a][ 6 ][ ][ 4 ][ # ]
[ 1 ][ ][ ][ 3 ][ # ][ # ][ # ][ # ][ # ]
[ ][ ][ b ][ ][#,b][ 1 ][ ][ 3 ][ # ]
[ B ][ ][ b ][ ][#,b][ ][ 9 ][ ][ # ]
[ ][ ][ b ][ ][#,b][ 7 ][ ][ 5 ][ # ]
[ 2 ][ ][ ][ ][ # ][ # ][ # ][ # ][ # ]
"""
env = TokenEnv(
layout=layout, # Set layout, where each [] indicates a cell, uppercase letters are
# agents, # are walls, and lower case letters are buttons when alone
# and doors when paired with a wall. For example, [#,a] is a door
# that is open if an agent is on a [ a ] cell and closed otherwise.
)
DFAWrapper
Wrap a TokenEnv instance using DFAWrapper .
from dfa_gym import DFAWrapper
from dfax.samplers import ReachSampler
env = DFAWrapper(
env=TokenEnv(layout=layout),
sampler=ReachSampler()
)
DFABisimEnv
Create DFA bisimulation game.
from dfa_gym import DFABisimEnv
from dfax.samplers import RADSampler
env = DFABisimEnv(sampler=RADSampler())
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dfa_gym-0.2.15.tar.gz.
File metadata
- Download URL: dfa_gym-0.2.15.tar.gz
- Upload date:
- Size: 208.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e3b457e3850f9ceb509a712912576a25d8cde710d9c994900f14b20a4bb4703
|
|
| MD5 |
17c1010f2fa25a9d23770e20b4b05884
|
|
| BLAKE2b-256 |
a51dae97e72ffc91490f5868c0cae94b302145d8ee37794d223887240280afd0
|
File details
Details for the file dfa_gym-0.2.15-py3-none-any.whl.
File metadata
- Download URL: dfa_gym-0.2.15-py3-none-any.whl
- Upload date:
- Size: 114.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ec6a9941bcd24a95d6e926ff81ddb948d570e5cba480b53c343ef8ea408c4dd
|
|
| MD5 |
981e6e80191248932dc2ea9f9b97b097
|
|
| BLAKE2b-256 |
f740700f0117f55cd5f912be797b0bf579d0b5a50010c00e0f3bf3a2fc36d3fa
|