# toni-sm/skrl architecture

> Architecture diagram of the GitHub repository toni-sm/skrl, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/toni-sm/skrl
- Repository: https://github.com/toni-sm/skrl

## Overview

1. **What this repo is**
   - `skrl` is a Python reinforcement learning library organized as a modular package.
   - The architecture is intentionally split by execution backend: **PyTorch**, **JAX**, and **NVIDIA Warp**. Most major abstractions exist in each backend-specific subtree.

2. **Top-level execution pipeline**
   - The core flow is: **environment wrapper/loaders → trainer → agent → model/resources → memory/logging**.
   - Trainers drive the interaction loop, agents implement learning algorithms, and models provide policy/value function approximators. Memories buffer experience for off-policy or batched updates.

3. **Agent subsystem**
   - `skrl/agents/{torch,jax,warp}` contains the main single-agent algorithms.
   - Torch has the widest algorithm coverage: A2C, AMP, CEM, DDPG, DDQN, DQN, PPO, Q-learning, RPO, SAC, SARSA, TD3, TRPO, plus recurrent variants for some methods.
   - JAX and Warp expose a smaller but parallel set of core algorithms, reflecting backend maturity and scope.

4. **Multi-agent subsystem**
   - `skrl/multi_agents/{torch,jax}` adds coordinated training for multiple agents.
   - The main algorithms are **IPPO** and **MAPPO**, which sit beside the single-agent APIs rather than replacing them.
   - This is the key boundary for environments that expose multiple controlled entities or shared/partitioned scopes.

5. **Environment integration layer**
   - `skrl/envs/wrappers` and `skrl/envs/loaders` are the adaptation boundary between the library and external simulators.
   - Supported integrations include **Gym**, **Gymnasium**, **PettingZoo**, **ManiSkill**, **Isaac Lab**, and **MuJoCo Playground**.
   - Wrappers normalize observations/actions/dones/infos into backend-specific tensor formats; loaders handle environment construction and configuration, especially for Isaac Lab and Playground.

6. **Model subsystem**
   - `skrl/models/{torch,jax,warp}` provides backend-specific policy/value model classes.
   - The library distinguishes common action-distribution styles: deterministic, Gaussian, categorical, multicategorical, multivariate Gaussian, and tabular models.
   - These models are the learnable interface consumed by agents; they are not tied to a single environment type.

7. **Resources: shared training components**
   - `skrl/resources` contains reusable training utilities that algorithms plug into:
     - **noises** for exploration,
     - **preprocessors** such as running standardization,
     - **schedulers** such as KL-adaptive control,
     - **optimizers** where backend-specific implementations are needed.
   - This keeps algorithm code focused on learning logic while cross-cutting concerns remain reusable.

8. **Memory subsystem**
   - `skrl/memories/{torch,jax,warp}` implements experience storage, with a random/replay-style memory being the primary reusable component.
   - Memory is the bridge between online environment rollout and gradient updates, especially for off-policy algorithms like DDPG, TD3, SAC, and DQN variants.

9. **Training orchestration**
   - `skrl/trainers/{torch,jax,warp}` contains the execution controllers: sequential, parallel, and step-based trainers depending on backend.
   - Trainers own the rollout/update schedule, coordinate agent calls, and mediate interactions with environments and memories.
   - This is the main boundary for “how the system runs” versus “what the algorithm does.”

10. **Utility layer**
    - `skrl/utils` provides glue code: distributed launching, model instantiation helpers, spaces handling, postprocessing, tensorboard support, huggingface integration, and a small Warp framework utility layer.
    - `runner` and `model_instantiators` are especially important because they convert high-level configuration into runnable backend objects.

11. **Examples as integration references**
    - `examples/` is organized by environment family: Gym, Gymnasium, Isaac Lab, ManiSkill, Playground, Shimmy, and real-world robot setups.
    - The examples show the architecture in practice: an environment adapter, a chosen backend, an agent, and a trainer bound together for a specific task.

12. **Testing and quality gates**
    - `tests/` mirrors the library structure by backend and subsystem, which is a strong sign of the intended architecture boundaries.
    - GitHub Actions run separate test matrices for **torch**, **jax**, and **warp**, plus pre-commit checks, reinforcing backend isolation and contract stability.

13. **Documentation and packaging**
    - `docs/` is a full Sphinx documentation site with API pages organized by subsystem, plus runnable snippets.
    - The repository is packaged as a Python distribution via `pyproject.toml`, with PyPI publishing and Read the Docs integration; these are delivery concerns, not runtime dependencies.

14. **Key architectural takeaway**
    - The repo is a **backend-agnostic RL framework with backend-specific implementations**.
    - The main diagram should show shared conceptual layers—environments, trainers, agents, models, memories, and resources—replicated across Torch/JAX/Warp, with wrappers/loaders as the adapter boundary to external simulators and examples/tests/docs as supporting surfaces.

Main entry points: [`tests`](https://github.com/toni-sm/skrl/tree/develop/tests) (Tests), [`skrl/envs/wrappers`](https://github.com/toni-sm/skrl/tree/develop/skrl/envs/wrappers) (Env wrappers), [`examples`](https://github.com/toni-sm/skrl/tree/develop/examples) (Examples), [`skrl/agents/torch`](https://github.com/toni-sm/skrl/tree/develop/skrl/agents/torch) (Torch agents)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core RL"]
  node_multi_agents["Multi-agents<br/>coordinated algorithms"]
  node_resources["Resources<br/>shared components"]
end

subgraph group_backend["Backends"]
  node_trainers_torch["Torch trainers<br/>execution controller"]
  node_trainers_jax["JAX trainers<br/>execution controller"]
  node_trainers_warp["Warp trainers<br/>execution controller"]
  node_agents_torch["Torch agents<br/>single-agent algorithms"]
  node_agents_jax["JAX agents<br/>single-agent algorithms"]
  node_agents_warp["Warp agents<br/>single-agent algorithms"]
  node_models["Models<br/>policy/value nets"]
  node_memories[("Memories<br/>experience storage")]
end

subgraph group_integration["Integration"]
  node_env_wrappers["Env wrappers<br/>adapter layer"]
  node_env_loaders["Env loaders<br/>constructor layer"]
  node_examples["Examples"]
end

subgraph group_support["Support"]
  node_runner_utils["Runner utils<br/>launch glue"]
  node_model_instantiators["Model instantiators<br/>factory helpers"]
  node_spaces_utils["Spaces utils<br/>space helpers"]
  node_docs["Docs<br/>documentation site"]
  node_tests["Tests<br/>verification suite"]
end

node_env_wrappers -->|"torch env API"| node_trainers_torch
node_env_wrappers -->|"jax env API"| node_trainers_jax
node_env_wrappers -->|"warp env API"| node_trainers_warp
node_env_loaders -->|"builds"| node_env_wrappers
node_trainers_torch -->|"drives"| node_agents_torch
node_trainers_jax -->|"drives"| node_agents_jax
node_trainers_warp -->|"drives"| node_agents_warp
node_agents_torch -->|"uses"| node_models
node_agents_jax -->|"uses"| node_models
node_agents_warp -->|"uses"| node_models
node_agents_torch -->|"stores experience"| node_memories
node_agents_jax -->|"stores experience"| node_memories
node_agents_warp -->|"stores experience"| node_memories
node_multi_agents -->|"uses"| node_models
node_multi_agents -->|"stores experience"| node_memories
node_resources -->|"supports"| node_agents_torch
node_resources -->|"supports"| node_agents_jax
node_resources -->|"supports"| node_agents_warp
node_runner_utils -->|"launches"| node_trainers_torch
node_runner_utils -->|"launches"| node_trainers_jax
node_runner_utils -->|"launches"| node_trainers_warp
node_model_instantiators -->|"constructs"| node_models
node_spaces_utils -->|"adapts spaces"| node_env_wrappers
node_examples -->|"demonstrates"| node_env_wrappers
node_examples -->|"demonstrates"| node_trainers_torch
node_examples -->|"demonstrates"| node_trainers_jax
node_examples -->|"demonstrates"| node_trainers_warp
node_docs -->|"documents"| node_examples
node_tests -->|"verifies"| node_agents_torch
node_tests -->|"verifies"| node_agents_jax
node_tests -->|"verifies"| node_agents_warp
node_tests -->|"verifies"| node_trainers_torch
node_tests -->|"verifies"| node_trainers_jax
node_tests -->|"verifies"| node_trainers_warp
node_tests -->|"verifies"| node_env_wrappers

click node_env_wrappers "https://github.com/toni-sm/skrl/tree/develop/skrl/envs/wrappers"
click node_env_loaders "https://github.com/toni-sm/skrl/tree/develop/skrl/envs/loaders"
click node_trainers_torch "https://github.com/toni-sm/skrl/tree/develop/skrl/trainers/torch"
click node_trainers_jax "https://github.com/toni-sm/skrl/tree/develop/skrl/trainers/jax"
click node_trainers_warp "https://github.com/toni-sm/skrl/tree/develop/skrl/trainers/warp"
click node_agents_torch "https://github.com/toni-sm/skrl/tree/develop/skrl/agents/torch"
click node_agents_jax "https://github.com/toni-sm/skrl/tree/develop/skrl/agents/jax"
click node_agents_warp "https://github.com/toni-sm/skrl/tree/develop/skrl/agents/warp"
click node_multi_agents "https://github.com/toni-sm/skrl/tree/develop/skrl/multi_agents"
click node_models "https://github.com/toni-sm/skrl/tree/develop/skrl/models"
click node_memories "https://github.com/toni-sm/skrl/tree/develop/skrl/memories"
click node_resources "https://github.com/toni-sm/skrl/tree/develop/skrl/resources"
click node_runner_utils "https://github.com/toni-sm/skrl/tree/develop/skrl/utils/runner"
click node_model_instantiators "https://github.com/toni-sm/skrl/tree/develop/skrl/utils/model_instantiators"
click node_spaces_utils "https://github.com/toni-sm/skrl/tree/develop/skrl/utils/spaces"
click node_examples "https://github.com/toni-sm/skrl/tree/develop/examples"
click node_docs "https://github.com/toni-sm/skrl/tree/develop/docs"
click node_tests "https://github.com/toni-sm/skrl/tree/develop/tests"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_multi_agents,node_resources toneBlue
class node_trainers_torch,node_trainers_jax,node_trainers_warp,node_agents_torch,node_agents_jax,node_agents_warp,node_models,node_memories toneAmber
class node_env_wrappers,node_env_loaders,node_examples toneMint
class node_runner_utils,node_model_instantiators,node_spaces_utils,node_docs,node_tests toneRose
```

## Components

### Core RL

Main runtime and learning subsystems

- [Multi-agents](https://github.com/toni-sm/skrl/tree/develop/skrl/multi_agents): coordinated algorithms · IPPO and MAPPO for multi-entity training · `skrl/multi_agents`
- [Resources](https://github.com/toni-sm/skrl/tree/develop/skrl/resources): shared components · Exploration noise, preprocessing, schedulers, and backend-specific optimizers · `skrl/resources`

### Backends

Backend-specific implementations replicated across Torch, JAX, and Warp

- [Torch trainers](https://github.com/toni-sm/skrl/tree/develop/skrl/trainers/torch): execution controller · Sequential, parallel, and step-based training loops for PyTorch · `skrl/trainers/torch`
- [JAX trainers](https://github.com/toni-sm/skrl/tree/develop/skrl/trainers/jax): execution controller · Sequential and step-based training loops for JAX · `skrl/trainers/jax`
- [Warp trainers](https://github.com/toni-sm/skrl/tree/develop/skrl/trainers/warp): execution controller · Sequential training loop for Warp · `skrl/trainers/warp`
- [Torch agents](https://github.com/toni-sm/skrl/tree/develop/skrl/agents/torch): single-agent algorithms · Broad algorithm set including PPO, SAC, TD3, DQN, TRPO, and recurrent variants · `skrl/agents/torch`
- [JAX agents](https://github.com/toni-sm/skrl/tree/develop/skrl/agents/jax): single-agent algorithms · Core single-agent algorithms ported to JAX · `skrl/agents/jax`
- [Warp agents](https://github.com/toni-sm/skrl/tree/develop/skrl/agents/warp): single-agent algorithms · Warp implementations of the main policy-gradient and off-policy agents · `skrl/agents/warp`
- [Models](https://github.com/toni-sm/skrl/tree/develop/skrl/models): policy/value nets · Backend-specific model families for deterministic, Gaussian, categorical, multicategorical, multivariate Gaussian, and tabular policies · `skrl/models`
- [Memories](https://github.com/toni-sm/skrl/tree/develop/skrl/memories): experience storage · Replay and random memory implementations bridging rollout and updates · `skrl/memories`

### Integration

Environment adapters and example entrypoints

- [Env wrappers](https://github.com/toni-sm/skrl/tree/develop/skrl/envs/wrappers): adapter layer · Normalizes external simulators into backend-ready environment interfaces · `skrl/envs/wrappers`
- [Env loaders](https://github.com/toni-sm/skrl/tree/develop/skrl/envs/loaders): constructor layer · Builds configured environments for simulator-specific integrations · `skrl/envs/loaders`
- [Examples](https://github.com/toni-sm/skrl/tree/develop/examples): integration examples · Task-oriented runnable references spanning Gym, Gymnasium, Isaac Lab, ManiSkill, Playground, Shimmy, and real-world setups · `examples`

### Support

Reusable utilities, docs, and quality gates

- [Runner utils](https://github.com/toni-sm/skrl/tree/develop/skrl/utils/runner): launch glue · Configuration-to-runtime helpers for starting backend training jobs · `skrl/utils/runner`
- [Model instantiators](https://github.com/toni-sm/skrl/tree/develop/skrl/utils/model_instantiators): factory helpers · Builds backend-specific model objects from configuration · `skrl/utils/model_instantiators`
- [Spaces utils](https://github.com/toni-sm/skrl/tree/develop/skrl/utils/spaces): space helpers · Handles action and observation space translation across backends · `skrl/utils/spaces`
- [Docs](https://github.com/toni-sm/skrl/tree/develop/docs): documentation site · Sphinx API and usage documentation · `docs`
- [Tests](https://github.com/toni-sm/skrl/tree/develop/tests): verification suite · Backend-separated tests for agents, env wrappers, trainers, multi-agents, utilities, and configs · `tests`

## Connections

- Env wrappers → Torch trainers: torch env API · Produces environment interfaces consumed by Torch training loops
- Env wrappers → JAX trainers: jax env API · Produces environment interfaces consumed by JAX training loops
- Env wrappers → Warp trainers: warp env API · Produces environment interfaces consumed by Warp training loops
- Env loaders → Env wrappers: builds · Constructs supported simulator environments before wrapping them
- Torch trainers → Torch agents: drives · Coordinates rollout and update cycles for Torch agents
- JAX trainers → JAX agents: drives · Coordinates rollout and update cycles for JAX agents
- Warp trainers → Warp agents: drives · Coordinates rollout and update cycles for Warp agents
- Torch agents → Models: uses · Consumes Torch models as policy/value approximators
- JAX agents → Models: uses · Consumes JAX models as policy/value approximators
- Warp agents → Models: uses · Consumes Warp models as policy/value approximators
- Torch agents → Memories: stores experience · Uses replay or random memory for batched/off-policy updates
- JAX agents → Memories: stores experience · Uses replay or random memory for batched/off-policy updates
- Warp agents → Memories: stores experience · Uses replay or random memory for batched/off-policy updates
- Multi-agents → Models: uses · Shares the same model interface for coordinated policies
- Multi-agents → Memories: stores experience · Buffers multi-agent rollouts for coordinated updates
- Resources → Torch agents: supports · Provides noise, preprocessing, and schedule utilities used by algorithms
- Resources → JAX agents: supports · Provides noise, preprocessing, and schedule utilities used by algorithms
- Resources → Warp agents: supports · Provides noise, preprocessing, and schedule utilities used by algorithms
- Runner utils → Torch trainers: launches · Turns configuration into runnable Torch training jobs
- Runner utils → JAX trainers: launches · Turns configuration into runnable JAX training jobs
- Runner utils → Warp trainers: launches · Turns configuration into runnable Warp training jobs
- Model instantiators → Models: constructs · Builds backend-specific model instances from config
- Spaces utils → Env wrappers: adapts spaces · Helps normalize observation and action spaces for wrappers
- Examples → Env wrappers: demonstrates · Shows environment adaptation in runnable tasks
- Examples → Torch trainers: demonstrates · Shows Torch execution patterns in practice
- Examples → JAX trainers: demonstrates · Shows JAX execution patterns in practice
- Examples → Warp trainers: demonstrates · Shows Warp execution patterns in practice
- Docs → Examples: documents · Explains usage through API pages and snippets
- Tests → Torch agents: verifies · Covers Torch agent contracts and algorithm behavior
- Tests → JAX agents: verifies · Covers JAX agent contracts and algorithm behavior
- Tests → Warp agents: verifies · Covers Warp agent contracts and algorithm behavior
- Tests → Torch trainers: verifies · Covers Torch training loop behavior
- Tests → JAX trainers: verifies · Covers JAX training loop behavior
- Tests → Warp trainers: verifies · Covers Warp training loop behavior
- Tests → Env wrappers: verifies · Covers adapter behavior across supported simulators
