# mandizhao/dexmachina architecture

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

- Interactive diagram: https://gitdiagram.com/mandizhao/dexmachina
- Repository: https://github.com/mandizhao/dexmachina

## Overview

#### Purpose and Entry Points
DexMachina is a Python research stack for functional retargeting of bimanual human manipulation demonstrations to multiple dexterous robot hands, followed by simulation-based RL training and evaluation. Primary executable entry points are retargeting scripts, RL training/evaluation scripts, and shell examples: `dexmachina/retargeting/parallel_retarget.py`, `dexmachina/rl/train_rl_games.py`, `dexmachina/rl/eval_rl_games.py`, and `examples/train_rl.sh`.

#### Asset and Embodiment Layer
The repository is asset-heavy: it packages URDFs, collision/visual meshes, and per-hand retarget configuration for supported robot embodiments (Ability, Allegro, Dex3, DexRobot, Inspire, Schunk, XHand) plus MANO human hands. These assets form the kinematic and physical interface consumed by processing, retargeting, and simulation.
- `dexmachina/assets/allegro_hand/allegro_hand_right_6dof.urdf`
- `dexmachina/assets/xhand/retarget_config.yaml`
- `dexmachina/assets/mano_hand/right/mano.urdf`

#### Demonstration-to-Retargeting Pipeline
ARCTIC manipulation trajectories are stored as processed NumPy sequences. Retargeting code processes source demonstrations, maps contacts, and produces target-hand motion representations. Repository snapshots include both intermediate retargeter vectors (`.npy`) and final parameterized trajectories (`.pt`), establishing a file-based pipeline boundary rather than a service API.
- Input demonstrations: `dexmachina/assets/arctic/processed/s01/box_use_01.npy`
- Pipeline modules: `dexmachina/retargeting/process_arctic.py`, `dexmachina/retargeting/map_contacts.py`, `dexmachina/retargeting/parallel_retarget.py`
- Outputs: `dexmachina/assets/retargeted/allegro_hand/s01/box_use_01_vector_para.pt`

#### Simulation Environment Construction
The environment subsystem defines the control loop used for imitation/manipulation training: base environment lifecycle, hand/object construction, contacts, randomization, curriculum, rewards, and demonstration ingestion. Hand-specific Python configurations bridge generic environment construction to the packaged URDF assets; object support includes articulated ARCTIC objects and a plane.
- Core environment: `dexmachina/envs/base_env.py`, `dexmachina/envs/constructors.py`, `dexmachina/envs/maniptrans_curr.py`
- Physics/task boundaries: `dexmachina/envs/contacts.py`, `dexmachina/envs/object.py`, `dexmachina/envs/robot.py`
- Embodiment configs: `dexmachina/envs/hand_cfgs/allegro.py`, `dexmachina/envs/hand_cfgs/dex3.py`

#### Training and Runtime Integration
RL is integrated through a wrapper around a custom `rl_games` fork, with PPO configuration and separate train/evaluation drivers. The simulation runtime depends on a custom Genesis fork; PyTorch is the primary tensor/runtime dependency. Training additionally expects Gymnasium and may use Ray, Weights & Biases, and visualization/geometry libraries, but no deployed external service is required by the repository structure.
- `dexmachina/rl/rl_games_wrapper.py`
- `dexmachina/rl/configs/rl_games_ppo_cfg.yaml`
- `dexmachina/rl/train_rl_games.py`

#### Hand Onboarding and Model Transformation
`hand_proc` is the extension boundary for adding or adapting robot hands. It inspects raw URDFs, adds wrist degrees of freedom, supports minimal retargeting, and tunes gains. Generated/edited URDFs and matching `retarget_config.yaml` files then feed the normal asset and environment paths.
- `dexmachina/hand_proc/inspect_raw_urdf.py`
- `dexmachina/hand_proc/add_wrist_dof.py`
- `dexmachina/hand_proc/minimal_retarget.py`

#### Evaluation Outputs
Evaluation utilities compute pose/alignment metrics and aggregate grouped experiment results. Existing group configuration and persisted AUC statistics indicate offline, artifact-based reporting over training/retargeting runs.
- `dexmachina/eval/compute_add.py`
- `dexmachina/eval/group_results.py`
- `dexmachina/eval/group_cfgs/dexmachina_main.yaml`

Main entry points: [`dexmachina/retargeting/parallel_retarget.py`](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/retargeting/parallel_retarget.py) (Parallel retargeting), [`dexmachina/envs/base_env.py`](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/envs/base_env.py) (Base environment), [`dexmachina/assets/allegro_hand/allegro_hand_right_6dof.urdf`](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/assets/allegro_hand/allegro_hand_right_6dof.urdf) (Robot hand assets), [`dexmachina/retargeting/process_arctic.py`](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/retargeting/process_arctic.py) (ARCTIC processing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_assets["Assets &amp; Embodiments"]
  node_robot_assets["Robot hand assets<br/>URDFs, meshes &amp; configs"]
  node_xhand_retarget_config["Hand retarget config<br/>YAML config"]
  node_mano_assets["MANO hand model<br/>human hand URDF<br/>[mano.urdf]"]
  node_arctic_demos["ARCTIC demonstrations<br/>processed NumPy trajectories<br/>[box_use_01.npy]"]
end

subgraph group_retargeting["Retargeting Pipeline"]
  node_process_arctic["ARCTIC processing<br/>trajectory processing<br/>[process_arctic.py]"]
  node_contact_mapping["Contact mapping<br/>retargeting stage<br/>[map_contacts.py]"]
  node_parallel_retarget["Parallel retargeting<br/>pipeline entry point"]
  node_retargeted_trajectories["Retargeted trajectories<br/>parameterized .pt artifacts"]
end

subgraph group_simulation["Simulation Environment"]
  node_base_environment["Base environment<br/>environment lifecycle<br/>[base_env.py]"]
  node_environment_construction["Environment construction<br/>task assembly<br/>[constructors.py]"]
  node_physics_components["Robot, object &amp; contacts<br/>physics/task boundary<br/>[contacts.py]"]
  node_curriculum_task["Manipulation curriculum<br/>task &amp; rewards<br/>[maniptrans_curr.py]"]
  node_hand_environment_configs["Hand environment configs<br/>embodiment bridge<br/>[allegro.py]"]
  node_genesis_runtime{{"Custom Genesis fork<br/>simulation runtime"}}
end

subgraph group_rl["RL Training &amp; Evaluation"]
  node_rl_games_wrapper["RL Games wrapper<br/>RL integration"]
  node_ppo_config["PPO configuration<br/>RL config"]
  node_training_driver["RL training<br/>training entry point<br/>[train_rl_games.py]"]
  node_evaluation_driver["RL evaluation<br/>evaluation entry point<br/>[eval_rl_games.py]"]
  node_offline_metrics["Offline metrics &amp; grouping<br/>artifact reporting<br/>[compute_add.py]"]
end

subgraph group_onboarding["Hand Onboarding"]
  node_hand_processing["Hand processing<br/>URDF adaptation tools<br/>[add_wrist_dof.py]"]
end

node_hand_processing -->|"generates or edits"| node_robot_assets
node_hand_processing -->|"creates matching config"| node_xhand_retarget_config
node_mano_assets -->|"human kinematics"| node_process_arctic
node_arctic_demos -->|"source sequences"| node_process_arctic
node_process_arctic -->|"processed poses"| node_contact_mapping
node_contact_mapping -->|"contact targets"| node_parallel_retarget
node_robot_assets -->|"target embodiment"| node_parallel_retarget
node_xhand_retarget_config -->|"mapping parameters"| node_parallel_retarget
node_parallel_retarget -->|"writes .pt trajectories"| node_retargeted_trajectories
node_robot_assets -->|"URDF embodiment"| node_hand_environment_configs
node_hand_environment_configs -->|"hand specification"| node_environment_construction
node_environment_construction -->|"assembles"| node_physics_components
node_physics_components -->|"simulation entities"| node_base_environment
node_retargeted_trajectories -->|"demonstration ingestion"| node_base_environment
node_base_environment -->|"task lifecycle"| node_curriculum_task
node_genesis_runtime -->|"physics backend"| node_base_environment
node_curriculum_task -->|"observations and rewards"| node_rl_games_wrapper
node_ppo_config -->|"PPO settings"| node_training_driver
node_training_driver -->|"runs training"| node_rl_games_wrapper
node_evaluation_driver -->|"runs policy evaluation"| node_rl_games_wrapper
node_evaluation_driver -->|"evaluation artifacts"| node_offline_metrics

click node_robot_assets "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/assets/allegro_hand/allegro_hand_right_6dof.urdf"
click node_xhand_retarget_config "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/assets/xhand/retarget_config.yaml"
click node_mano_assets "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/assets/mano_hand/right/mano.urdf"
click node_arctic_demos "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/assets/arctic/processed/s01/box_use_01.npy"
click node_process_arctic "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/retargeting/process_arctic.py"
click node_contact_mapping "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/retargeting/map_contacts.py"
click node_parallel_retarget "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/retargeting/parallel_retarget.py"
click node_retargeted_trajectories "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/assets/retargeted/allegro_hand/s01/box_use_01_vector_para.pt"
click node_hand_processing "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/hand_proc/add_wrist_dof.py"
click node_base_environment "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/envs/base_env.py"
click node_environment_construction "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/envs/constructors.py"
click node_physics_components "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/envs/contacts.py"
click node_curriculum_task "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/envs/maniptrans_curr.py"
click node_hand_environment_configs "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/envs/hand_cfgs/allegro.py"
click node_rl_games_wrapper "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/rl/rl_games_wrapper.py"
click node_ppo_config "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/rl/configs/rl_games_ppo_cfg.yaml"
click node_training_driver "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/rl/train_rl_games.py"
click node_evaluation_driver "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/rl/eval_rl_games.py"
click node_offline_metrics "https://github.com/mandizhao/dexmachina/blob/main/dexmachina/eval/compute_add.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_robot_assets,node_xhand_retarget_config,node_mano_assets,node_arctic_demos toneBlue
class node_process_arctic,node_contact_mapping,node_parallel_retarget,node_retargeted_trajectories toneAmber
class node_base_environment,node_environment_construction,node_physics_components,node_curriculum_task,node_hand_environment_configs,node_genesis_runtime toneMint
class node_rl_games_wrapper,node_ppo_config,node_training_driver,node_evaluation_driver,node_offline_metrics toneRose
class node_hand_processing toneIndigo
```

## Components

### Assets & Embodiments

Robot, MANO, and ARCTIC data assets.

- [Robot hand assets](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/assets/allegro_hand/allegro_hand_right_6dof.urdf): URDFs, meshes & configs · Supported hand embodiments and their retarget settings. · `dexmachina/assets/allegro_hand/allegro_hand_right_6dof.urdf`
- [Hand retarget config](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/assets/xhand/retarget_config.yaml): YAML config · Per-hand mapping parameters accompany embodiment assets. · `dexmachina/assets/xhand/retarget_config.yaml`
- [MANO hand model](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/assets/mano_hand/right/mano.urdf): human hand URDF · `dexmachina/assets/mano_hand/right/mano.urdf`
- [ARCTIC demonstrations](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/assets/arctic/processed/s01/box_use_01.npy): processed NumPy trajectories · `dexmachina/assets/arctic/processed/s01/box_use_01.npy`

### Retargeting Pipeline

File-based conversion of human demonstrations to robot trajectories.

- [ARCTIC processing](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/retargeting/process_arctic.py): trajectory processing · `dexmachina/retargeting/process_arctic.py`
- [Contact mapping](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/retargeting/map_contacts.py): retargeting stage · `dexmachina/retargeting/map_contacts.py`
- [Parallel retargeting](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/retargeting/parallel_retarget.py): pipeline entry point · Produces target-hand motion representations. · `dexmachina/retargeting/parallel_retarget.py`
- [Retargeted trajectories](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/assets/retargeted/allegro_hand/s01/box_use_01_vector_para.pt): parameterized .pt artifacts · File boundary between retargeting and simulation. · `dexmachina/assets/retargeted/allegro_hand/s01/box_use_01_vector_para.pt`

### Simulation Environment

Genesis-backed manipulation task construction and control.

- [Base environment](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/envs/base_env.py): environment lifecycle · Owns task lifecycle, control loop, and demonstration ingestion. · `dexmachina/envs/base_env.py`
- [Environment construction](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/envs/constructors.py): task assembly · Builds hands, objects, and simulation components. · `dexmachina/envs/constructors.py`
- [Robot, object & contacts](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/envs/contacts.py): physics/task boundary · Encapsulates hand/object construction and contact handling. · `dexmachina/envs/contacts.py`
- [Manipulation curriculum](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/envs/maniptrans_curr.py): task & rewards · Applies randomization, curriculum, and reward logic. · `dexmachina/envs/maniptrans_curr.py`
- [Hand environment configs](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/envs/hand_cfgs/allegro.py): embodiment bridge · Connects generic tasks to hand-specific assets. · `dexmachina/envs/hand_cfgs/allegro.py`
- **Custom Genesis fork**: simulation runtime

### RL Training & Evaluation

PPO runtime, experiment execution, and offline reporting.

- [RL Games wrapper](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/rl/rl_games_wrapper.py): RL integration · Bridges vectorized environments to the custom RL runtime. · `dexmachina/rl/rl_games_wrapper.py`
- [PPO configuration](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/rl/configs/rl_games_ppo_cfg.yaml): RL config · `dexmachina/rl/configs/rl_games_ppo_cfg.yaml`
- [RL training](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/rl/train_rl_games.py): training entry point · `dexmachina/rl/train_rl_games.py`
- [RL evaluation](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/rl/eval_rl_games.py): evaluation entry point · `dexmachina/rl/eval_rl_games.py`
- [Offline metrics & grouping](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/eval/compute_add.py): artifact reporting · Computes alignment metrics and aggregates experiment results. · `dexmachina/eval/compute_add.py`

### Hand Onboarding

URDF transformation path for new embodiments.

- [Hand processing](https://github.com/mandizhao/dexmachina/blob/main/dexmachina/hand_proc/add_wrist_dof.py): URDF adaptation tools · Inspects hands, adds wrist DOFs, and supports minimal retargeting. · `dexmachina/hand_proc/add_wrist_dof.py`

## Connections

- Hand processing → Robot hand assets: generates or edits
- Hand processing → Hand retarget config: creates matching config
- MANO hand model → ARCTIC processing: human kinematics
- ARCTIC demonstrations → ARCTIC processing: source sequences
- ARCTIC processing → Contact mapping: processed poses
- Contact mapping → Parallel retargeting: contact targets
- Robot hand assets → Parallel retargeting: target embodiment
- Hand retarget config → Parallel retargeting: mapping parameters
- Parallel retargeting → Retargeted trajectories: writes .pt trajectories
- Robot hand assets → Hand environment configs: URDF embodiment
- Hand environment configs → Environment construction: hand specification
- Environment construction → Robot, object & contacts: assembles
- Robot, object & contacts → Base environment: simulation entities
- Retargeted trajectories → Base environment: demonstration ingestion
- Base environment → Manipulation curriculum: task lifecycle
- Custom Genesis fork → Base environment: physics backend
- Manipulation curriculum → RL Games wrapper: observations and rewards
- PPO configuration → RL training: PPO settings
- RL training → RL Games wrapper: runs training
- RL evaluation → RL Games wrapper: runs policy evaluation
- RL evaluation → Offline metrics & grouping: evaluation artifacts
