Skip to main content

Setting Up and Running Examples

This guide explains how to set up and run the PyCRM examples. Since the examples are not packaged with the source code, you’ll need to clone the repository and set up the development environment.

Prerequisites

  • Python 3.10-3.12
  • Git
  • uv package manager (recommended)

Step 1: Clone the Repository

First, clone the PyCRM repository:

Step 2: Set Up the Development Environment

PyCRM supports both uv (recommended for faster installation) and pip for dependency management. Choose the option that works best for your setup:
Alternatively, you can use uv sync for faster installation:

Option B: Using pip

Note: If you don’t have uv installed, you can install it first:

Step 3: Navigate to Examples Directory

Change to the examples directory:

Step 4: Understanding the Example Structure

The examples are organized into several categories:

Introduction Examples (introduction/)

Basic examples demonstrating core concepts:
  • q_learning.py - Q-learning in a letter world environment
  • cq_learning.py - Counterfactual Q-learning
  • environment_example.py - Basic environment setup
  • core/ - Core components (ground environment, labelling function, reward machine)

CRM Examples (crm/)

Examples using Counting Reward Machines:
  • Continuous: SAC, TD3, DDPG, and their CRM variants (CSAC, CTD3, CDDPG)
  • Discrete: DQN and CDQN
  • Tabular: Basic tabular implementations

RM Examples (rm/)

Examples using standard Reward Machines:
  • Continuous: SAC, TD3, DDPG
  • Discrete: DQN
  • Tabular: Basic tabular implementations

Step 5: Running Examples

Basic Examples

Run the introduction examples directly:

Advanced Examples

For the CRM and RM examples, run from their respective directories:
Most examples accept command-line arguments:

Step 6: Experiment Tracking

Many examples integrate with Weights & Biases (wandb) for experiment tracking:
You can view your experiments at wandb.ai.

Step 7: Using SLURM (HPC Systems)

For high-performance computing environments, PyCRM provides SLURM scripts located in the scripts/ directory. These scripts are organized by example type and algorithm:

SLURM Script Organization

The SLURM scripts are located in scripts/examples/ and organized as follows:
  • scripts/examples/crm/ - Scripts for Counting Reward Machine examples
  • scripts/examples/rm/ - Scripts for standard Reward Machine examples
Each category contains:
  • continuous/ - Scripts for continuous control algorithms (SAC, TD3, DDPG, etc.)
  • discrete/ - Scripts for discrete control algorithms (DQN, etc.)

Running SLURM Scripts

Troubleshooting

Common Issues

  1. Import Errors: Ensure you’re running from the correct directory:
  2. Dependency Issues: Make sure all dependencies are installed:
  3. Python Version: Ensure you’re using Python 3.10-3.12:
  4. Virtual Environment: Activate the virtual environment:

Next Steps

After running the examples:
  • Check the Worked Examples for detailed tutorials
  • Explore the Core Concepts documentation
  • Try modifying the examples to experiment with different parameters