# ccrprepo/amp_mjlab architecture

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

- Interactive diagram: https://gitdiagram.com/ccrprepo/amp_mjlab
- Repository: https://github.com/ccrprepo/amp_mjlab

## Overview

AMP_mjlab trains a unified G1 locomotion-and-recovery policy using mjlab environments and rsl_rl’s AMP/PPO stack. The main workflow configures the task, gathers simulated experience, updates the policy, and supports checkpoint playback and ONNX export. Separate velocity-task configuration and shared rsl_rl capabilities remain visible as supporting branches. Source excerpts are partial; links between unsampled components are included only where the README or SOURCE INDEX documents them.

Main entry points: [`rsl_rl/algorithms/amp_ppo.py`](https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/algorithms/amp_ppo.py) (AMP PPO), [`src/tasks/amp_loco/amp_env_cfg.py`](https://github.com/ccrprepo/amp_mjlab/blob/main/src/tasks/amp_loco/amp_env_cfg.py) (AMP task config), [`scripts/train.py`](https://github.com/ccrprepo/amp_mjlab/blob/main/scripts/train.py) (Train entry), [`src/tasks/amp_loco/config/g1/env_cfgs.py`](https://github.com/ccrprepo/amp_mjlab/blob/main/src/tasks/amp_loco/config/g1/env_cfgs.py) (G1 AMP config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_task["Simulation tasks"]
  node_amp_task["AMP task config<br/>[amp_env_cfg.py]"]
  node_g1_amp["G1 AMP config<br/>[env_cfgs.py]"]
  node_amp_mdp["AMP task logic"]
  node_velocity_config["Velocity task config"]
  node_velocity_mdp["Velocity task logic"]
end

subgraph group_learning["RL learning"]
  node_amp_ppo["AMP PPO<br/>[amp_ppo.py]"]
  node_ppo["PPO<br/>[ppo.py]"]
  node_actor_critic["Actor critic<br/>[actor_critic.py]"]
  node_discriminator["Style discriminator<br/>[discriminator.py]"]
  node_rnd["Intrinsic reward<br/>[rnd.py]"]
  node_normalizer["Observation normalization<br/>[normalizer.py]"]
  node_rollout[("Rollout storage<br/>[rollout_storage.py]")]
end

subgraph group_runtime["Training and playback"]
  node_train_cli["Train entry<br/>[train.py]"]
  node_play_cli["Playback entry<br/>[play.py]"]
  node_task_runner["AMP runner adapter<br/>[runner.py]"]
  node_amp_runner["AMP on-policy runner"]
end

subgraph group_support["Motion and observation"]
  node_motion_loader["AMP motion loader<br/>[motion_loader.py]"]
  node_ampmotion_loader["Task motion loader"]
  node_obs_patch["Observation history patch"]
end

node_engineer(("Operator"))
node_policy_artifact["ONNX policy"]

node_engineer -->|"starts training"| node_train_cli
node_engineer -->|"starts playback"| node_play_cli
node_train_cli -->|"selects task"| node_amp_task
node_g1_amp -->|"customizes"| node_amp_task
node_amp_task -->|"configures terms"| node_amp_mdp
node_velocity_config -->|"configures terms"| node_velocity_mdp
node_amp_task -->|"uses history ordering"| node_obs_patch
node_velocity_config -->|"uses history ordering"| node_obs_patch
node_g1_amp -.->|"selects runner"| node_task_runner
node_task_runner -->|"delegates to"| node_amp_runner
node_amp_runner -->|"configures algorithm"| node_amp_ppo
node_amp_ppo -->|"records transitions"| node_rollout
node_amp_ppo -.->|"uses discriminator"| node_discriminator
node_ppo -->|"records transitions"| node_rollout
node_amp_ppo -.->|"supports intrinsic reward"| node_rnd
node_ppo -.->|"supports intrinsic reward"| node_rnd
node_ampmotion_loader -.->|"motion integration"| node_motion_loader
node_play_cli -->|"exports ONNX"| node_policy_artifact
node_train_cli -->|"exports ONNX"| node_policy_artifact

click node_train_cli "https://github.com/ccrprepo/amp_mjlab/blob/main/scripts/train.py"
click node_play_cli "https://github.com/ccrprepo/amp_mjlab/blob/main/scripts/play.py"
click node_amp_task "https://github.com/ccrprepo/amp_mjlab/blob/main/src/tasks/amp_loco/amp_env_cfg.py"
click node_g1_amp "https://github.com/ccrprepo/amp_mjlab/blob/main/src/tasks/amp_loco/config/g1/env_cfgs.py"
click node_amp_mdp "https://github.com/ccrprepo/amp_mjlab/tree/main/src/tasks/amp_loco/mdp"
click node_velocity_config "https://github.com/ccrprepo/amp_mjlab/blob/main/src/tasks/velocity/velocity_env_cfg.py"
click node_velocity_mdp "https://github.com/ccrprepo/amp_mjlab/tree/main/src/tasks/velocity/mdp"
click node_task_runner "https://github.com/ccrprepo/amp_mjlab/blob/main/src/tasks/amp_loco/rl/runner.py"
click node_amp_runner "https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/runners/amp_on_policy_runner.py"
click node_amp_ppo "https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/algorithms/amp_ppo.py"
click node_ppo "https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/algorithms/ppo.py"
click node_actor_critic "https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/modules/actor_critic.py"
click node_discriminator "https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/modules/discriminator.py"
click node_rnd "https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/modules/rnd.py"
click node_normalizer "https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/modules/normalizer.py"
click node_rollout "https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/storage/rollout_storage.py"
click node_motion_loader "https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/utils/motion_loader.py"
click node_ampmotion_loader "https://github.com/ccrprepo/amp_mjlab/blob/main/src/tasks/amp_loco/ampmotion_loader.py"
click node_obs_patch "https://github.com/ccrprepo/amp_mjlab/blob/main/mjlab_patch/mjlab/managers/observation_manager.py"

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_amp_task,node_g1_amp,node_amp_mdp,node_velocity_config,node_velocity_mdp toneBlue
class node_amp_ppo,node_ppo,node_actor_critic,node_discriminator,node_rnd,node_normalizer,node_rollout toneAmber
class node_train_cli,node_play_cli,node_task_runner,node_amp_runner toneMint
class node_motion_loader,node_ampmotion_loader,node_obs_patch toneRose
class node_engineer,node_policy_artifact toneIndigo
```

## Components

### Simulation tasks

- [AMP task config](https://github.com/ccrprepo/amp_mjlab/blob/main/src/tasks/amp_loco/amp_env_cfg.py): `src/tasks/amp_loco/amp_env_cfg.py`
- [G1 AMP config](https://github.com/ccrprepo/amp_mjlab/blob/main/src/tasks/amp_loco/config/g1/env_cfgs.py): `src/tasks/amp_loco/config/g1/env_cfgs.py`
- [AMP task logic](https://github.com/ccrprepo/amp_mjlab/tree/main/src/tasks/amp_loco/mdp): `src/tasks/amp_loco/mdp`
- [Velocity task config](https://github.com/ccrprepo/amp_mjlab/blob/main/src/tasks/velocity/velocity_env_cfg.py): `src/tasks/velocity/velocity_env_cfg.py`
- [Velocity task logic](https://github.com/ccrprepo/amp_mjlab/tree/main/src/tasks/velocity/mdp): `src/tasks/velocity/mdp`

### RL learning

- [AMP PPO](https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/algorithms/amp_ppo.py): `rsl_rl/algorithms/amp_ppo.py`
- [PPO](https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/algorithms/ppo.py): `rsl_rl/algorithms/ppo.py`
- [Actor critic](https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/modules/actor_critic.py): `rsl_rl/modules/actor_critic.py`
- [Style discriminator](https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/modules/discriminator.py): `rsl_rl/modules/discriminator.py`
- [Intrinsic reward](https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/modules/rnd.py): `rsl_rl/modules/rnd.py`
- [Observation normalization](https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/modules/normalizer.py): `rsl_rl/modules/normalizer.py`
- [Rollout storage](https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/storage/rollout_storage.py): `rsl_rl/storage/rollout_storage.py`

### Training and playback

- [Train entry](https://github.com/ccrprepo/amp_mjlab/blob/main/scripts/train.py): `scripts/train.py`
- [Playback entry](https://github.com/ccrprepo/amp_mjlab/blob/main/scripts/play.py): `scripts/play.py`
- [AMP runner adapter](https://github.com/ccrprepo/amp_mjlab/blob/main/src/tasks/amp_loco/rl/runner.py): `src/tasks/amp_loco/rl/runner.py`
- [AMP on-policy runner](https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/runners/amp_on_policy_runner.py): `rsl_rl/runners/amp_on_policy_runner.py`

### Motion and observation

- [AMP motion loader](https://github.com/ccrprepo/amp_mjlab/blob/main/rsl_rl/utils/motion_loader.py): `rsl_rl/utils/motion_loader.py`
- [Task motion loader](https://github.com/ccrprepo/amp_mjlab/blob/main/src/tasks/amp_loco/ampmotion_loader.py): `src/tasks/amp_loco/ampmotion_loader.py`
- [Observation history patch](https://github.com/ccrprepo/amp_mjlab/blob/main/mjlab_patch/mjlab/managers/observation_manager.py): `mjlab_patch/mjlab/managers/observation_manager.py`

### Other components

- **Operator**
- **ONNX policy**

## Connections

- Operator → Train entry: starts training
- Operator → Playback entry: starts playback
- Train entry → AMP task config: selects task
- G1 AMP config → AMP task config: customizes (evidence: `src/tasks/amp_loco/config/g1/env_cfgs.py`)
- AMP task config → AMP task logic: configures terms (evidence: `src/tasks/amp_loco/amp_env_cfg.py`)
- Velocity task config → Velocity task logic: configures terms (evidence: `src/tasks/velocity/velocity_env_cfg.py`)
- AMP task config → Observation history patch: uses history ordering (evidence: `src/tasks/amp_loco/amp_env_cfg.py`)
- Velocity task config → Observation history patch: uses history ordering (evidence: `src/tasks/velocity/velocity_env_cfg.py`)
- G1 AMP config → AMP runner adapter: selects runner
- AMP runner adapter → AMP on-policy runner: delegates to (evidence: `src/tasks/amp_loco/rl/runner.py`)
- AMP on-policy runner → AMP PPO: configures algorithm (evidence: `rsl_rl/runners/amp_on_policy_runner.py`)
- AMP PPO → Rollout storage: records transitions (evidence: `rsl_rl/algorithms/amp_ppo.py`)
- AMP PPO → Style discriminator: uses discriminator
- PPO → Rollout storage: records transitions (evidence: `rsl_rl/algorithms/ppo.py`)
- AMP PPO → Intrinsic reward: supports intrinsic reward (evidence: `rsl_rl/algorithms/amp_ppo.py`)
- PPO → Intrinsic reward: supports intrinsic reward (evidence: `rsl_rl/algorithms/ppo.py`)
- Task motion loader → AMP motion loader: motion integration
- Playback entry → ONNX policy: exports ONNX
- Train entry → ONNX policy: exports ONNX
