How oxwhirl/pymarl works
Purpose and entry points
PyMARL is a PyTorch framework for cooperative deep multi-agent reinforcement learning, primarily targeting SMAC/StarCraft II. The experiment CLI is src/main.py, which resolves algorithm and environment presets before dispatching training through src/run.py. Containerized execution is supported by docker/Dockerfile, docker/build.sh, and run.sh.
Configuration-driven experiment assembly
Algorithm presets select QMIX, VDN, IQL, COMA, or QTRAN behavior; environment presets configure SC2/SMAC. Defaults and overrides are composed at launch, including CLI with parameters.
• src/config/default.yaml
• src/config/algs/qmix.yaml
• src/config/envs/sc2.yaml
Environment boundary
The framework depends on SMAC as the concrete multi-agent StarCraft II environment; MultiAgentEnv defines the internal environment contract runners consume. SC2 installation and maps are provisioned externally, including version-sensitive SC2 binaries.
• src/envs/multiagentenv.py
• src/envs/__init__.py
• install_sc2.sh
Execution and rollout stages
Runners own environment interaction, episode lifecycle, evaluation/test-mode rollouts, and collection of timestep-aligned experience. EpisodeRunner supports single-environment episodes and replay-oriented execution; ParallelRunner scales rollout collection across environments.
• src/runners/episode_runner.py
• src/runners/parallel_runner.py
Controller and action boundary
The basic multi-agent controller converts batched observations, agent state, and action availability into per-agent action values/policies, maintaining recurrent agent hidden state. Action selectors apply exploration or policy sampling separately from network inference.
• src/controllers/basic_controller.py
• src/components/action_selectors.py
• src/modules/agents/rnn_agent.py
Experience representation
Rollouts are stored as episode batches, with preprocessing transforms and fields suitable for recurrent sequence learning: observations, actions, rewards, termination, availability masks, and agent state. This is the handoff boundary between runners/controllers and learners.
• src/components/episode_buffer.py
• src/components/transforms.py
Learning algorithms and value factorisation
Learners implement algorithm-specific optimization and target updates. Q-learning variants use per-agent Q outputs and optional centralized mixers: VDN sums values, QMIX learns a monotonic mixing function, and QTRAN applies transformation constraints. COMA instead uses a centralized critic and counterfactual policy-gradient learning.
• src/learners/q_learner.py
• src/learners/coma_learner.py
• src/learners/qtran_learner.py
• src/modules/mixers/qmix.py
• src/modules/critics/coma.py
Runtime outputs and operations
Python/PyTorch is the training runtime; SMAC and StarCraft II are external simulation dependencies. Training metrics, model checkpoints, and optional SC2 replay generation flow through the run/logger layer into per-run result directories. Docker provides the reproducible GPU-oriented deployment path.
• src/utils/logging.py
• docker/Dockerfile
• run_interactive.sh
Main entry points: run.py Run dispatcher · episode_buffer.py Episode batch · main.py Experiment CLI · episode_runner.py Episode runner
Components 22
Experiment launch
- Experiment CLI · Resolves presets and CLI overrides.
src/main.py - Run dispatcher · Assembles experiments and drives training.
src/run.py - Preset configuration · Default, QMIX, and SC2 settings compose each run.
src/config/default.yaml - SC2 environment preset
src/config/envs/sc2.yaml - QMIX algorithm preset
src/config/algs/qmix.yaml
Interaction and experience
- Multi-agent environment contract · Internal contract consumed by runners.
src/envs/multiagentenv.py - SMAC / StarCraft II · Concrete multi-agent simulation dependency.
install_sc2.sh - Episode runner · Manages episode lifecycle, evaluation, and collection.
src/runners/episode_runner.py - Parallel runner · Scales rollout collection across environments.
src/runners/parallel_runner.py - Episode batch · Timestep-aligned recurrent learning data.
src/components/episode_buffer.py - Experience transforms
src/components/transforms.py
Control and learning
- Basic MAC · Maintains recurrent state and produces agent outputs.
src/controllers/basic_controller.py - RNN agent
src/modules/agents/rnn_agent.py - Action selector · Separates sampling and exploration from inference.
src/components/action_selectors.py - Q learner · Optimizes IQL, VDN, or QMIX-style Q learning.
src/learners/q_learner.py - QMIX mixer
src/modules/mixers/qmix.py - COMA learner · Uses a centralized critic and counterfactual updates.
src/learners/coma_learner.py - COMA critic
src/modules/critics/coma.py - QTRAN learner
src/learners/qtran_learner.py
Runtime and operations
- Run logger · Writes metrics, models, and optional replays per run.
src/utils/logging.py - Docker runtime · Reproducible GPU-oriented execution path.
docker/Dockerfile - Interactive launcher
run_interactive.sh
Connections 27
- Experiment CLI → Preset configuration: loads defaults
- Experiment CLI → QMIX algorithm preset: selects algorithm
- Experiment CLI → SC2 environment preset: selects environment
- Experiment CLI → Run dispatcher: dispatches
- Run dispatcher → Episode runner: runs rollouts
- Run dispatcher → Parallel runner: runs parallel rollouts
- Run dispatcher → Q learner: selects learner
- Run dispatcher → COMA learner: selects learner
- Run dispatcher → QTRAN learner: selects learner
- Episode runner → Multi-agent environment contract: interacts through
- Parallel runner → Multi-agent environment contract: interacts through
- Multi-agent environment contract → SMAC / StarCraft II: implemented by
- Episode runner → Basic MAC: requests actions
- Parallel runner → Basic MAC: requests actions
- Basic MAC → RNN agent: infers with
- Basic MAC → Action selector: selects actions via
- Episode runner → Episode batch: collects
- Parallel runner → Episode batch: collects
- Experience transforms → Episode batch: preprocesses
- Episode batch → Q learner: trains
- Episode batch → COMA learner: trains
- Episode batch → QTRAN learner: trains
- Q learner → QMIX mixer: optionally mixes values
- COMA learner → COMA critic: optimizes with
- Run dispatcher → Run logger: records outputs
- Docker runtime → Experiment CLI: containerizes execution
- Interactive launcher → Docker runtime: launches