Scales reinforcement learning with PufferLib for high-throughput parallel training, vectorized environments, and multi-agent systems. Achieves 2-10x speedups over standard implementations.
Ships in alterlab-data-science. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
PufferLib is a high-performance reinforcement learning library designed for fast parallel environment simulation and training. It achieves training at millions of steps per second through optimized vectorization, native multi-agent support, and efficient PPO implementation (PuffeRL). The library provides the Ocean suite of 20+ environments and seamless integration with Gymnasium, PettingZoo, and specialized RL frameworks.
Use this skill when:
| Scenario | Use Instead |
|---|---|
| Quick single-agent prototype with a standard, well-documented PPO/SAC/DQN implementation | alterlab-stable-baselines3 |
| Supervised deep-learning training loops (classification, regression) with checkpointing and multi-GPU | alterlab-pytorch-lightning |
| Agent-based simulation of social systems with rule-based agents and no learning | alterlab-abm-mesa |
Hand-off rule. When the request matches a row above, open your answer by naming that skill by its exact id (for example alterlab-stable-baselines3) and saying in one line why it fits better, then stop applying this skill's procedure. Name it even when you also need to ask for missing input. If only part of the request is out of scope, name the skill for that part and do only the in-scope part. A brief general pointer is fine; the named skill does the work.
PuffeRL is PufferLib's optimized PPO trainer (CleanRL-derived, with optional LSTM via models.LSTMWrapper) built for high-throughput training.
Recommended path — CLI / high-level helper. Drive training from a config (an .ini in pufferlib/config/) rather than hand-wiring the trainer:
# CLI: env name resolves to a config in pufferlib/config/ + an Ocean env
puffer train puffer_breakout --train.device cuda --train.learning-rate 0.015
# Resume from a checkpoint (top-level flag, not a [train] key)
puffer train puffer_breakout --load-model-path latest
import pufferlib.pufferl as pufferl
# train(env_name, args=None, vecenv=None, policy=None, logger=None)
pufferl.train('puffer_breakout')
Manual loop. PuffeRL(config, vecenv, policy, logger=None) — note the first arg is a config dict (not flat kwargs), the env arg is vecenv, and the loop is driven by global_step. The three loop methods are real: evaluate(), train(), mean_and_log().
import pufferlib.vector
from pufferlib.pufferl import PuffeRL, load_config
# Native PufferEnv -> default backend=PufferEnv. For wrapped (Gymnasium/
# PettingZoo) envs you MUST pass backend=pufferlib.vector.Multiprocessing.
vecenv = pufferlib.vector.make(MyPufferEnv, num_envs=256)
# load_config returns a nested args dict (sections: 'train', 'vec', 'env', ...)
# with defaults from pufferlib/config/*.ini. PuffeRL takes the 'train' section.
args = load_config('puffer_breakout')
config = {**args['train'], 'env': 'puffer_breakout'}
config['device'] = 'cuda'
trainer = PuffeRL(config, vecenv, my_policy)
while trainer.global_step < config['total_timesteps']:
trainer.evaluate() # Collect rollouts
trainer.train() # Train on batch
trainer.mean_and_log() # Aggregate + log
For comprehensive training guidance, read references/training.md for:
Create custom high-performance environments with the PufferEnv API.
Basic environment structure:
import numpy as np
import gymnasium
from pufferlib import PufferEnv
class MyEnvironment(PufferEnv):
def __init__(self, buf=None):
# Define spaces BEFORE calling super().__init__(buf)
self.single_observation_space = gymnasium.spaces.Box(
low=-np.inf, high=np.inf, shape=(4,), dtype=np.float32)
self.single_action_space = gymnasium.spaces.Discrete(4)
self.num_agents = 1
super().__init__(buf)
def reset(self, seed=None):
# Reset state and return (observation, info-list)
obs = self._get_observation()
return obs, []
def step(self, action):
# Execute action, compute reward, check termination/truncation
obs = self._get_observation()
rewards = self._compute_reward()
terminals = self._is_done()
truncations = self._is_truncated()
info = []
return obs, rewards, terminals, truncations, info
Use the template script: scripts/env_template.py provides complete single-agent and multi-agent environment templates with examples of:
For complete environment development, read references/environments.md for:
Achieve maximum throughput with optimized parallel simulation.
Vectorization setup:
import pufferlib.vector
# Pass an env-constructor callable. Default backend=PufferEnv is native-only;
# for wrapped (Gymnasium/PettingZoo) envs add backend=pufferlib.vector.Multiprocessing.
env = pufferlib.vector.make(env_creator, num_envs=256, num_workers=8)
# Performance benchmarks (PufferLib's published figures; vary by env/hardware):
# - Pure Python envs: 100k-500k SPS
# - C-based envs: 100M+ SPS
# - With training: 400k-4M total SPS
Key optimizations:
For vectorization optimization, read references/vectorization.md for:
Build policies as standard PyTorch modules with optional utilities.
Basic policy structure:
import torch.nn as nn
from pufferlib.pytorch import layer_init
class Policy(nn.Module):
def __init__(self, observation_space, action_space):
super().__init__()
# Encoder
self.encoder = nn.Sequential(
layer_init(nn.Linear(obs_dim, 256)),
nn.ReLU(),
layer_init(nn.Linear(256, 256)),
nn.ReLU()
)
# Actor and critic heads
self.actor = layer_init(nn.Linear(256, num_actions), std=0.01)
self.critic = layer_init(nn.Linear(256, 1), std=1.0)
def forward(self, observations):
features = self.encoder(observations)
return self.actor(features), self.critic(features)
For complete policy development, read references/policies.md for:
Seamlessly integrate environments from popular RL frameworks.
Gymnasium integration:
import gymnasium as gym
import pufferlib.emulation
import pufferlib.vector
# Wrap a Gymnasium env in a GymnasiumPufferEnv, then vectorize.
# Wrapped (non-native) envs require an explicit backend (Serial or Multiprocessing);
# the default backend=PufferEnv is only for native PufferEnvs.
def env_creator():
return pufferlib.emulation.GymnasiumPufferEnv(
env_creator=lambda: gym.make('CartPole-v1'))
env = pufferlib.vector.make(
env_creator, num_envs=256, backend=pufferlib.vector.Multiprocessing)
PettingZoo multi-agent:
import pufferlib.emulation
import pufferlib.vector
from pettingzoo.butterfly import knights_archers_zombies_v10
# Wrap a PettingZoo env in a PettingZooPufferEnv, then vectorize.
def env_creator():
return pufferlib.emulation.PettingZooPufferEnv(
env_creator=lambda: knights_archers_zombies_v10.parallel_env())
env = pufferlib.vector.make(
env_creator, num_envs=128, backend=pufferlib.vector.Multiprocessing)
Supported frameworks:
For integration details, read references/integration.md for:
scripts/train_template.py as starting pointreferences/training.md for optimizationscripts/env_template.pyreset() and step() methodspufferlib.emulation.GymnasiumPufferEnv and vectorize with pufferlib.vector.make()references/environments.md for advanced patternsreferences/vectorization.md if neededlayer_init for proper weight initializationreferences/policies.mdreferences/vectorization.md for systematic optimizationtrain_template.py - Complete training script template with:
env_template.py - Environment implementation templates:
training.md - Comprehensive training guide:
environments.md - Environment development guide:
vectorization.md - Vectorization optimization:
policies.md - Policy architecture guide:
integration.md - Framework integration guide:
Start simple: Begin with Ocean environments or Gymnasium integration before creating custom environments
Profile early: Measure steps per second from the start to identify bottlenecks
Use templates: scripts/train_template.py and scripts/env_template.py provide solid starting points
Read references as needed: Each reference file is self-contained and focused on a specific capability
Optimize progressively: Start with Python, profile, then optimize critical paths with C if needed
Leverage vectorization: PufferLib's vectorization is key to achieving high throughput
Monitor training: Use WandB or Neptune to track experiments and identify issues early
Test environments: Validate environment logic before scaling up training
Check existing environments: Ocean suite provides 20+ pre-built environments
Use proper initialization: Always use layer_init from pufferlib.pytorch for policies
import pufferlib.vector
# Atari (pass an env-constructor callable)
env = pufferlib.vector.make(make_pong_env, num_envs=256)
# Procgen
env = pufferlib.vector.make(make_coinrun_env, num_envs=256)
# Minigrid
env = pufferlib.vector.make(make_minigrid_env, num_envs=256)
import pufferlib.vector
# PettingZoo, wrapped via PettingZooPufferEnv (needs an explicit backend)
env = pufferlib.vector.make(
make_pistonball_env, num_envs=128, backend=pufferlib.vector.Multiprocessing)
# One shared policy serves all agents (single_observation_space / single_action_space
# are per-agent). Pass config (dict), vecenv, policy positionally to PuffeRL.
policy = create_policy(env.single_observation_space, env.single_action_space)
trainer = PuffeRL(config, env, policy)
import pufferlib.vector
# Create custom environment (a native PufferEnv subclass)
class MyTask(PufferEnv):
# ... implement environment ...
# Native PufferEnv -> default backend=PufferEnv is fine here.
env = pufferlib.vector.make(MyTask, num_envs=256)
trainer = PuffeRL(config, env, my_policy) # config is a dict (see Training above)
import pufferlib.vector
# Maximize throughput (pass an env-constructor callable)
env = pufferlib.vector.make(
my_env_creator, # env constructor callable
num_envs=1024, # Large batch
num_workers=16, # Many workers
backend=pufferlib.vector.Multiprocessing,
)
# Pin the 3.0 line — the config-dict trainer API and import paths in this skill
# target it. PyPI ships only an sdist, so a C compiler is needed to build it.
uv run --python ">=3.12" --with "pufferlib==3.0.*" python train.py # no install step; uv builds once and caches
# torch already importable? run with plain `python`. CPU-only machine: add --index https://download.pytorch.org/whl/cpu (no CUDA wheels)
PufferLib 5.0 is a different product. The upstream default branch (5.0) is a C/CUDA
trainer built from source via PufferTank (./build.sh ENV, ./puffer train). It has no pip
package, has dropped the third-party (Gymnasium/PettingZoo-style) integrations, and offers
CPU evaluation but no CPU training, so do not assume the Python APIs in this skill (PuffeRL,
pufferlib.vector.make, pufferlib.emulation) exist there. If a user is on 5.0, say so and
point them to its docs rather than adapting 3.0 code.
evals/evals.json (opens in a new tab)references/environments.md (opens in a new tab)references/integration.md (opens in a new tab)references/policies.md (opens in a new tab)references/training.md (opens in a new tab)references/vectorization.md (opens in a new tab)scripts/env_template.py (opens in a new tab)scripts/train_template.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
2 plugins in one repository ship this exact skill · first indexed Nov 9, 2026
22 skills in this plugin
/alterlab-daskScales pandas/NumPy workflows beyond memory with Dask distributed computing — parallel DataFrames, arrays, delayed task graphs, and cluster execution. Use when existing pandas/NumPy code must run on larger-than-RAM data or across clusters, for parallel file processing, distributed ML, or integration with existing pandas code. For out-of-core analytics on a single machine prefer vaex; for in-memory speed prefer polars. Part of the AlterLab Academic Skills suite./alterlab-edaExploratory data analysis (EDA) on a scientific data file — auto-detects the format, runs structure/quality/statistics checks, and writes a markdown EDA report with downstream recommendations. Use when asked to "explore", "analyze", "summarize", "profile", or "QC" a data file, or to understand its structure/content/quality before deciding what analysis to run. Covers tabular (.csv .tsv .xlsx .parquet), arrays (.npy .npz .hdf5 .h5 .mat .fits), sequence/genomics (.fasta .fastq .sam .bam .vcf .bed .gff .gtf .h5ad), microscopy (.tif .nd2 .czi .lif .ims .dcm .nii), spectroscopy/MS (.mzML .mzXML .mgf .fid .jdx), chemistry (.pdb .cif .mol .sdf .xyz .gro), and proteomics/metabolomics (.pepXML .mzid .mzTab). For zero-shot forecasting of a series use alterlab-timesfm; to create/configure a chunked cloud array store use alterlab-zarr. Part of the AlterLab Academic Skills suite./alterlab-data-science:alterlab-pufferlibfrom alterlab-data-science
npx claudepluginhub alterlab-ieu/alterlab-academic-skills --plugin alterlab-data-scienceOther plugins' skills for the same job