Skip to main content

Python package for RL with Reward Machines and Counting Reward Machines.

Project description

PyCRM

CI codecov Python 3.10+ License: MIT Documentation arXiv

A Python framework for formal task specification and efficient reinforcement learning with Reward Machines (RMs) and Counting Reward Machines (CRMs).

Documentation | Paper | Quick Start

Overview

PyCRM provides a unified framework for Reward Machines (RMs) and Counting Reward Machines (CRMs), offering a formal approach to reward specification in reinforcement learning. RMs handle regular tasks with finite-state automata, while CRMs extend this with counters for Turing-complete expressiveness, enabling efficient learning through structured reward functions and counterfactual experiences.

Features

  • Unified RM/CRM Support: First-class support for both Reward Machines and Counting Reward Machines
  • Reinforcement Learning Integration: Ready-to-use agents that leverage counterfactual experiences
  • Cross-Product Environments: Framework for combining ground environments with RMs or CRMs
  • Modular Design: Composable automata for complex task specifications
  • Expressive Power: From regular languages (RMs) to Turing-complete specifications (CRMs)
  • Example Environments: Complete worked examples for both RMs and CRMs

Quick Start

Installation

pip install pyrewardmachines

For detailed installation instructions and troubleshooting, see the Installation Guide.

Basic Usage

See the Quick Start Guide for complete examples of creating and using both Reward Machines and Counting Reward Machines, including:

  • Setting up ground environments, labelling functions, and automata (RMs or CRMs)
  • Creating cross-product environments
  • Training agents with counterfactual experiences

For a comprehensive introduction to the framework, see the Introduction.

Key Components

The PyCRM framework consists of several key components:

  • Ground Environment: The base environment (typically a Gymnasium environment)
  • Labelling Function: Maps environment observations to symbolic events
  • Automaton: Formal specification of the task (either a Reward Machine or Counting Reward Machine)
  • Cross-Product Environment: Combines all components into a learning environment
  • RL Agents: Algorithms that leverage counterfactual experiences for improved sample efficiency

For detailed explanations of these components, see the Core Concepts section in the documentation.

Applications

  • Task-Oriented RL: Specify complex objectives with structured reward functions
  • Robotics: Define temporally extended tasks with symbolic events
  • Formal Verification: Guarantee task completion through CRM properties
  • Curriculum Learning: Progressively build task complexity

For complete worked examples demonstrating these applications, see the Worked Examples section in the documentation.

Citation

If you use Counting Reward Machines in your research, please cite:

@article{bester2023counting,
  title={Counting Reward Automata: Sample Efficient Reinforcement Learning Through the Exploitation of Reward Function Structure},
  author={Bester, Tristan and Rosman, Benjamin and James, Steven and Tasse, Geraud Nangue},
  journal={arXiv preprint arXiv:2312.11364},
  year={2023}
}

Contributing

Contributions are welcome. To get started:

# Clone repository
git clone https://github.com/TristanBester/pycrm.git
cd pycrm

# Set up virtual environment
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install development dependencies
uv pip install -e ".[dev]"

# Run tests
uv run pytest

# Run comprehensive testing across environments
uv pip install tox
uv run tox

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

pyrewardmachines-1.0.2.tar.gz (295.2 kB view details)

Uploaded Source

Built Distribution

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

pyrewardmachines-1.0.2-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file pyrewardmachines-1.0.2.tar.gz.

File metadata

  • Download URL: pyrewardmachines-1.0.2.tar.gz
  • Upload date:
  • Size: 295.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.5

File hashes

Hashes for pyrewardmachines-1.0.2.tar.gz
Algorithm Hash digest
SHA256 0009379fd6d646bc3f9a37abe3676ce3540fededba188a3e74c74febad5b7b59
MD5 95c63c176287fcaa1cb307e2635b6c00
BLAKE2b-256 d432f1cc75e5c83b2bf569a41a1ec486636263c64bab5664df84ebb462c24b92

See more details on using hashes here.

File details

Details for the file pyrewardmachines-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pyrewardmachines-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e3e475da001c71367ba411705610360db0da9edf1e4e8a1b4ae03cadd5ddc47f
MD5 b064c93b401c65f6e6eeab0fbc91cad4
BLAKE2b-256 9a4aa6c3d16fb0510c8112ad49ffaf04c8630f2cd99e2402f0e4f8ce312c87e8

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