Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

## Validation

- [ ] `uv run pytest -q`
- [ ] `python -m pytest -q`
- [ ] `prek run --all-files`
- [ ] CI checks pass on the target branch
- [ ] Documentation updated (if applicable)
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: uv python install 3.10

- name: Install workspace and test dependencies
run: uv sync --all-packages --all-groups --all-extras
run: sh install.sh --all

- name: Run tests
run: uv run pytest -q --disable-warnings --maxfail=1
run: .venv/bin/python -m pytest -q --disable-warnings --maxfail=1
38 changes: 20 additions & 18 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,22 @@ Python 方法,由 manager 运行时契约定义(`wiki/design/manager/runtime

项目使用 UV 管理依赖,Python 版本要求 3.10.\*。可用的依赖组与 extras 见 `pyproject.toml`

完整安装(含全部 package、依赖组与 extras):
完整开发环境(全部 package、依赖组与 extras`--gpu rocm` 切换 AMD wheel):

```bash
uv sync --all-packages --all-groups --all-extras
sh install.sh --all
```

按框架安装
运行环境(无开发工具链;GPU 厂商自动探测,`--rslrl` 换后端)

```bash
uv sync --all-packages --extra skrl-jax # SKRL JAX backend
uv sync --all-packages --extra skrl-torch # SKRL PyTorch backend
uv sync --all-packages --extra rslrl # RSLRL(PyTorch)
sh install.sh
```

避免裸 `uv run` / `uv sync``cuda`/`rocm` extras 声明为互斥,裸命令会解析到默认 fork(PyPI torch)
并重装环境。运行命令先 `source .venv/bin/activate`,之后直接 `python` / `pytest`(下文示例即此写法),
或对单条命令使用 `uv run --no-sync`。依赖变更(`pyproject.toml` / `uv.lock`)后重新执行对应 install 命令。

## 常用命令

train/play/view CLI 由 [Hydra](https://hydra.cc/) 驱动,参数使用 `key=value` 语法(不是 `--flag`)。可用选项见
Expand All @@ -128,72 +130,72 @@ train/play/view CLI 由 [Hydra](https://hydra.cc/) 驱动,参数使用 `key=va
SKRL(默认):

```bash
uv run scripts/train.py task=cartpole/skrl.ppo
python scripts/train.py task=cartpole/skrl.ppo
```

RSLRL:

```bash
uv run scripts/train.py task=cartpole/rslrl.ppo
python scripts/train.py task=cartpole/rslrl.ppo
```

直接覆写框架运行时设置和类型化 RL 参数:

```bash
uv run scripts/train.py task=cartpole/skrl.ppo num_envs=64 algo.agent.learning_rate=1e-3
uv run scripts/train.py task=cartpole/skrl.ppo logging.interval=20 checkpoint.interval=100
python scripts/train.py task=cartpole/skrl.ppo num_envs=64 algo.agent.learning_rate=1e-3
python scripts/train.py task=cartpole/skrl.ppo logging.interval=20 checkpoint.interval=100
```

### 环境可视化

不训练只查看环境:

```bash
uv run scripts/view.py env=cartpole
python scripts/view.py env=cartpole
```

查看内置机器人(不创建 RL 环境):

```bash
uv run scripts/view.py robot=g1-29dof
python scripts/view.py robot=g1-29dof
```

### 评估

```bash
uv run scripts/play.py env=cartpole
python scripts/play.py env=cartpole
```

指定 policy 文件:

```bash
uv run scripts/play.py env=cartpole policy=<path/to/best.[pickle/pt]>
python scripts/play.py env=cartpole policy=<path/to/best.[pickle/pt]>
```

### ONNX 导出

```bash
uv run scripts/export_onnx.py run_dir=<run-dir> output=/tmp/policy.onnx
python scripts/export_onnx.py run_dir=<run-dir> output=/tmp/policy.onnx
```

### 渲染

训练时开启可视化:

```bash
uv run scripts/train.py task=cartpole/skrl.ppo render=true
python scripts/train.py task=cartpole/skrl.ppo render=true
```

### TensorBoard

```bash
uv run tensorboard --logdir runs/{env-name}
tensorboard --logdir runs/{env-name}
```

### 测试

```bash
uv run pytest
python -m pytest
```

## 架构要点
Expand Down
36 changes: 17 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ git lfs pull
Create the complete development environment from the repository root:

```bash
uv sync --all-packages --all-groups --all-extras
sh install.sh --all # --gpu rocm switches to the AMD wheels
```

Optional training backends can be installed separately when a full environment
is unnecessary:

```bash
uv sync --all-packages --extra skrl-torch
uv sync --all-packages --extra skrl-jax # Linux only
uv sync --all-packages --extra rslrl
```
A runtime-only environment without the dev toolchain is available via `sh install.sh`: it
auto-detects the GPU vendor (NVIDIA/AMD) for the torch wheels and `--rslrl`
selects the RSLRL backend. On Windows, run `install.ps1` in PowerShell. Avoid bare
`uv sync` / `uv run`: the `cuda`/`rocm` extras are declared conflicting, so a bare
command resolves the default fork (PyPI torch) and reinstalls the environment. Run
commands from the activated environment (`source .venv/bin/activate`); the examples
below assume it is active, or pass `--no-sync` to one-off `uv run` calls.

The workspace contains nine packages. Package-local changes should use the
smallest required extra; changes involving the simulator, built-in assets, or
Expand Down Expand Up @@ -168,15 +167,15 @@ branch unless the change specifically requires them.
Run the full test suite before opening a pull request:

```bash
uv run pytest -q
python -m pytest -q
```

For an iteration on one package, run its tests directly, then run the full
suite before requesting review:

```bash
uv run pytest motrix_env_core/tests -q
uv run pytest motrix_deploy/tests motrix_deploy_mujoco/tests -q
python -m pytest motrix_env_core/tests -q
python -m pytest motrix_deploy/tests motrix_deploy_mujoco/tests -q
```

Run the repository's formatting, license-header, and lint hooks:
Expand All @@ -190,17 +189,16 @@ prek run --all-files
The hooks run Copywrite, Ruff, and dprint. For individual checks, use:

```bash
uv run ruff check .
uv run ruff format --check .
uv run mypy
ruff check .
ruff format --check .
mypy
```

When changing documentation, install the `docs` extra and build with warnings
treated as errors:
When changing documentation, build with warnings treated as errors (`sh install.sh --all`
or a runtime install with `--docs` provides the required docs toolchain):

```bash
uv sync --all-packages --extra docs
uv run sphinx-build -W -b html docs/source docs/build/html
sphinx-build -W -b html docs/source docs/build/html
```

The public CI runs the complete workspace test command on Linux for both
Expand Down
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ _Microduck locomotion policies trained with MotrixLab, rendered in MotrixRender
<div align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="docs/source/_static/images/architecture-dark.svg">
<img src="docs/source/_static/images/architecture-light.svg" alt="MotrixLab architecture: define an environment once, train it with SKRL, RSL-RL or FastSAC on thousands of parallel MotrixSim environments, then deploy the same policy artifact to MuJoCo or Unitree hardware" width="720">
<img src="docs/source/_static/images/architecture-light.svg" alt="MotrixLab architecture: define an environment once, train it with SKRL, RSL-RL or FastSAC on thousands of parallel MotrixSim environments running on NVIDIA CUDA or AMD ROCm GPUs, then deploy the same policy artifact to MuJoCo or Unitree hardware" width="100%">
</picture>
</div>

Expand All @@ -60,6 +60,7 @@ _Microduck locomotion policies trained with MotrixLab, rendered in MotrixRender
| [uv](https://docs.astral.sh/uv/) | Python project and dependency manager — [installation guide](https://docs.astral.sh/uv/getting-started/installation/) |
| [Git LFS](https://git-lfs.com) | Robot meshes, motion data, and videos are tracked by LFS |
| OS | Linux x86_64 or Windows x86_64; the JAX training backend is Linux-only |
| GPU | NVIDIA (CUDA) or AMD (ROCm) — the matching wheels are selected automatically by `sh install.sh` |

### 1. Clone the repository

Expand All @@ -71,16 +72,29 @@ git lfs pull

### 2. Install dependencies

Linux:

```bash
uv sync --all-packages
sh install.sh
```
Comment thread
wlgys8 marked this conversation as resolved.

This installs all workspace packages together with **PyTorch**, the default training backend used by the built-in FastSAC. Third-party frameworks such as SKRL and RSLRL are optional extras.
Windows (PowerShell):

```powershell
.\install.ps1
# if blocked by the execution policy:
powershell -ExecutionPolicy Bypass -File install.ps1
```

This auto-detects your GPU vendor (NVIDIA → CUDA, AMD → ROCm) and installs all workspace packages with the matching PyTorch wheels. Use `--gpu cuda|rocm` to override detection and `--skrl-jax` / `--rslrl` to add training backends — see `sh install.sh --help`.

### 3. Train your first policy

Activate the installed environment (Windows PowerShell: `.venv\Scripts\Activate.ps1`):

```bash
uv run scripts/train.py task=microduck-walk-flat/motrix.fastsac play=true
source .venv/bin/activate
python scripts/train.py task=microduck-walk-flat/motrix.fastsac play=true
```

While training, the built-in dashboard shows live run progress, episode statistics, throughput, rewards, and system health:
Expand All @@ -92,7 +106,7 @@ While training, the built-in dashboard shows live run progress, episode statisti
Training runs thousands of parallel environment instances; when it finishes, the trained policy is loaded and played in the viewer automatically. Checkpoints and TensorBoard logs are saved under `runs/microduck-walk-flat/`; watch the curves with:

```bash
uv run tensorboard --logdir runs/microduck-walk-flat
tensorboard --logdir runs/microduck-walk-flat
```

Training finishes in minutes: mean return and episode length typically converge after about 4,000 iterations:
Expand All @@ -106,7 +120,7 @@ Training finishes in minutes: mean return and episode length typically converge
Replay the latest trained policy without retraining (for example, after stopping training early with Ctrl+C):

```bash
uv run scripts/play.py env=microduck-walk-flat
python scripts/play.py env=microduck-walk-flat
```

A trained microduck policy replayed in the viewer:
Expand All @@ -124,7 +138,7 @@ MotrixLab ships 50+ built-in simulation environments spanning basic control, qua
| <img src="docs/source/_static/images/poster/g1-wbt-dance.jpg" alt="g1-wbt-dance" width="240"> | Whole-body tracking (WBT) | `g1-wbt-dance` · `k1-wbt-freekick` · `g1-29dof-wbt-largebox` |

```bash
uv run scripts/view.py env=go2-walk-rough
python scripts/view.py env=go2-walk-rough
```

See the [full environment gallery](https://motrixlab.readthedocs.io/en/latest/user_guide/envs/index.html) for all registered environments and their supported training algorithms.
Expand All @@ -144,7 +158,7 @@ Seven reusable robot models are registered out of the box and can be combined in
| <img src="docs/source/_static/images/robots/microduck.png" alt="microduck" width="180"> | `microduck` | Humanoid | 14 |

```bash
uv run scripts/view.py robot=go2
python scripts/view.py robot=go2
```

See [Supported Robots](https://motrixlab.readthedocs.io/en/latest/user_guide/robots.html) for configuration details and how to add your own model.
Expand Down
30 changes: 22 additions & 8 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ _使用 MotrixLab 训练的 microduck 行走策略,由 MotrixRender 实时渲
<div align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="docs/source/_static/images/architecture-dark.svg">
<img src="docs/source/_static/images/architecture-light.svg" alt="MotrixLab 架构:环境只需定义一次,即可用 SKRL、RSL-RL 或 FastSAC 在数千个并行 MotrixSim 环境上训练,同一策略产物可部署到 MuJoCo 或 Unitree 硬件" width="720">
<img src="docs/source/_static/images/architecture-light.svg" alt="MotrixLab 架构:环境只需定义一次,即可用 SKRL、RSL-RL 或 FastSAC 在数千个并行 MotrixSim 环境上训练(支持 NVIDIA CUDA 与 AMD ROCm GPU),同一策略产物可部署到 MuJoCo 或 Unitree 硬件" width="100%">
</picture>
</div>

Expand All @@ -60,6 +60,7 @@ _使用 MotrixLab 训练的 microduck 行走策略,由 MotrixRender 实时渲
| [uv](https://docs.astral.sh/uv/) | Python 项目与依赖管理工具 — [安装指南](https://docs.astral.sh/uv/getting-started/installation/) |
| [Git LFS](https://git-lfs.com) | 机器人网格、运动数据与视频由 LFS 管理 |
| 操作系统 | Linux x86_64 或 Windows x86_64;JAX 训练后端仅支持 Linux |
| GPU | NVIDIA(CUDA)或 AMD(ROCm)——`sh install.sh` 自动选择对应 wheel |

### 1. 克隆仓库

Expand All @@ -71,16 +72,29 @@ git lfs pull

### 2. 安装依赖

Linux:

```bash
uv sync --all-packages
sh install.sh
```
Comment thread
wlgys8 marked this conversation as resolved.

该命令会安装全部 workspace package,以及内置 FastSAC 所需的默认训练后端 **PyTorch**。SKRL、RSLRL 等第三方训练框架为可选 extras。
Windows(PowerShell):

```powershell
.\install.ps1
# 若提示执行策略受限:
powershell -ExecutionPolicy Bypass -File install.ps1
```

脚本会自动探测 GPU 厂商(NVIDIA → CUDA,AMD → ROCm),安装全部 workspace package 及对应的 PyTorch wheel。可用 `--gpu cuda|rocm` 显式指定 GPU,`--skrl-jax` / `--rslrl` 追加训练后端——详见 `sh install.sh --help`。

### 3. 训练第一个策略

先激活安装好的环境(Windows PowerShell:`.venv\Scripts\Activate.ps1`):

```bash
uv run scripts/train.py task=microduck-walk-flat/motrix.fastsac play=true
source .venv/bin/activate
python scripts/train.py task=microduck-walk-flat/motrix.fastsac play=true
```

训练过程中,内置面板会实时显示运行进度、回合统计、吞吐、奖励与系统健康状态:
Expand All @@ -92,7 +106,7 @@ uv run scripts/train.py task=microduck-walk-flat/motrix.fastsac play=true
训练会启动数千个并行环境实例;训练结束后会自动加载策略并在查看器中回放。checkpoint 与 TensorBoard 日志保存在 `runs/microduck-walk-flat/` 目录下,通过以下命令查看训练曲线:

```bash
uv run tensorboard --logdir runs/microduck-walk-flat
tensorboard --logdir runs/microduck-walk-flat
```

microduck 的训练数分钟内即可完成:平均回报与回合长度通常在约 4,000 次迭代后收敛:
Expand All @@ -106,7 +120,7 @@ microduck 的训练数分钟内即可完成:平均回报与回合长度通常
无需重新训练即可回放最近一次训练得到的策略(例如提前 Ctrl+C 中断训练之后):

```bash
uv run scripts/play.py env=microduck-walk-flat
python scripts/play.py env=microduck-walk-flat
```

训练好的 microduck 策略在查看器中的回放效果:
Expand All @@ -124,7 +138,7 @@ MotrixLab 内置 50+ 个仿真环境,覆盖基础控制、四足、人形、
| <img src="docs/source/_static/images/poster/g1-wbt-dance.jpg" alt="g1-wbt-dance" width="240"> | 全身动作跟踪(WBT) | `g1-wbt-dance` · `k1-wbt-freekick` · `g1-29dof-wbt-largebox` |

```bash
uv run scripts/view.py env=go2-walk-rough
python scripts/view.py env=go2-walk-rough
```

完整环境列表与各环境支持的训练算法见[环境总览](https://motrixlab.readthedocs.io/zh-cn/latest/user_guide/envs/index.html)。
Expand All @@ -144,7 +158,7 @@ uv run scripts/view.py env=go2-walk-rough
| <img src="docs/source/_static/images/robots/microduck.png" alt="microduck" width="180"> | `microduck` | 人形机器人 | 14 |

```bash
uv run scripts/view.py robot=go2
python scripts/view.py robot=go2
```

机器人配置细节与自定义新模型的方法见[支持的机器人](https://motrixlab.readthedocs.io/zh-cn/latest/user_guide/robots.html)。
Expand Down
4 changes: 4 additions & 0 deletions configs/task/microduck-walk-flat/motrix.fastsac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ algo:
agent:
alpha_init: 0.01
target_entropy_ratio: -0.1
batch_size: 2048
num_updates: 4
trainer:
async_options:
utd_mode: strict
Loading
Loading