Skip to main content

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:

  1. TokenEnv is 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.
  2. DFAWrapper is an environment wrapper assigning tasks represented as Deterministic Finite Automata (DFAs) to the agents in the wrapped environment. DFAs are repsented as DFAx objects.
  3. DFABisimEnv is an environment for solving DFA bisimulation games to learn RAD Embeddings, provably correct latent DFA representation, as described in this paper.

Installation

This package will soon be made pip-installable. In the meantime, pull the repo and and install locally.

git clone https://github.com/rad-dfa/dfa-gym.git
pip install -e 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


Download files

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

Source Distribution

dfa_gym-0.2.0.tar.gz (82.8 kB view details)

Uploaded Source

Built Distribution

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

dfa_gym-0.2.0-py3-none-any.whl (113.6 kB view details)

Uploaded Python 3

File details

Details for the file dfa_gym-0.2.0.tar.gz.

File metadata

  • Download URL: dfa_gym-0.2.0.tar.gz
  • Upload date:
  • Size: 82.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.18

File hashes

Hashes for dfa_gym-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c47a205f74db68a4738625e7a2d91efd63b37ed4ec9b4b513989e78f85500c8a
MD5 766e7f22697e6b6d9df2b39f6e4f5c92
BLAKE2b-256 1765b7ce8af6900193992afda0451d7eae135c967ebfe08c243c5fbefa773852

See more details on using hashes here.

File details

Details for the file dfa_gym-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dfa_gym-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 113.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.18

File hashes

Hashes for dfa_gym-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd57f914a12f4b39d6f652e5fa9db89d76dc0ca784c7bfd42fadb18962462d4b
MD5 12fc2d582ce9fc7780b1785cda1d4312
BLAKE2b-256 f126fd5c09138bbbbd107f2c7a4dbc93fa9592b0b57a3e42d018aeee58b0b386

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