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 bothuv (recommended for faster installation) and pip for dependency management. Choose the option that works best for your setup:
Option A: Using uv (Recommended)
uv sync for faster installation:
Option B: Using pip
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 environmentcq_learning.py- Counterfactual Q-learningenvironment_example.py- Basic environment setupcore/- 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:Step 6: Experiment Tracking
Many examples integrate with Weights & Biases (wandb) for experiment tracking:Step 7: Using SLURM (HPC Systems)
For high-performance computing environments, PyCRM provides SLURM scripts located in thescripts/ directory. These scripts are organized by example type and algorithm:
SLURM Script Organization
The SLURM scripts are located inscripts/examples/ and organized as follows:
scripts/examples/crm/- Scripts for Counting Reward Machine examplesscripts/examples/rm/- Scripts for standard Reward Machine examples
continuous/- Scripts for continuous control algorithms (SAC, TD3, DDPG, etc.)discrete/- Scripts for discrete control algorithms (DQN, etc.)
Running SLURM Scripts
Troubleshooting
Common Issues
-
Import Errors: Ensure you’re running from the correct directory:
-
Dependency Issues: Make sure all dependencies are installed:
-
Python Version: Ensure you’re using Python 3.10-3.12:
-
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