diff --git a/.gitattributes b/.gitattributes index 7929c85..91148a6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12,3 +12,4 @@ *.npz filter=lfs diff=lfs merge=lfs -text docs/source/_static/data/performance/*.json filter=lfs diff=lfs merge=lfs -text docs/source/_static/images/performance/*.svg filter=lfs diff=lfs merge=lfs -text +*.gif filter=lfs diff=lfs merge=lfs -text diff --git a/AGENTS.md b/AGENTS.md index 1e2a289..c9973e3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -9,7 +9,7 @@ MotrixLab 是构建在 MotrixSim 仿真后端之上的强化学习框架,提 ## Workspace 结构 -项目使用 UV workspace,包含十个 package: +项目使用 UV workspace,包含九个 package: - `motrix_env_core`:backend 无关的环境框架(不依赖任何 simulator) - `motrix_env_motrixsim`:MotrixSim 仿真后端(SimBackend、scene compiler、renderer、torch frontend) @@ -96,7 +96,7 @@ Python 方法,由 manager 运行时契约定义(`wiki/design/manager/runtime ### 版本与依赖一致性 -- 所有 workspace package(见上文 Workspace 结构,共十个)的 `pyproject.toml` 中 `version` 字段必须保持一致。 +- 所有 workspace package(见上文 Workspace 结构,共九个)的 `pyproject.toml` 中 `version` 字段必须保持一致。 - MotrixSim 相关依赖版本必须在使用该依赖的 workspace package 之间保持一致。 - 关键第三方依赖使用精确版本锁定(`===`);新增或升级依赖时同步更新 `uv.lock`。 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1a216f3..bf24d77 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,7 +38,7 @@ uv sync --all-packages --extra skrl-jax # Linux only uv sync --all-packages --extra rslrl ``` -The workspace contains ten packages. Package-local changes should use the +The workspace contains nine packages. Package-local changes should use the smallest required extra; changes involving the simulator, built-in assets, or training integrations should be tested with the corresponding package and extra enabled. @@ -267,6 +267,6 @@ fork](https://docs.github.com/en/pull-requests/how-tos/create-pull-requests/crea and [secure use of GitHub Actions](https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions). All source files should retain the Apache-2.0 SPDX header used by this -repository. Keep the ten workspace package versions synchronized when making a +repository. Keep the nine workspace package versions synchronized when making a release, and update `THIRD_PARTY_NOTICES.md` whenever a dependency or bundled asset changes. diff --git a/README.md b/README.md index 6d61a27..fda0ef2 100644 --- a/README.md +++ b/README.md @@ -1,154 +1,173 @@ **Language**: [English](README.md) | [简体中文](README.zh-CN.md) +
+
+_Microduck locomotion policies trained with MotrixLab, rendered in MotrixRender — [watch the HD video](https://github.com/user-attachments/assets/4bcf3122-f135-44cb-a966-d2d8e84479da)._
-`MotrixLab` is a reinforcement learning framework based on the [MotrixSim](https://github.com/Motphys/motrixsim-docs) simulation engine, designed specifically for robot simulation and training. This project provides a complete reinforcement learning development platform that integrates multiple simulation environments and training frameworks.
+**📖 Documentation**: [简体中文](https://motrixlab.readthedocs.io/zh-cn/stable/) | [English](https://motrixlab.readthedocs.io/en/stable/)
-## Project Overview
+
+
+
+
+
| Quadruped velocity tracking | `go2-walk-flat` · `go2-walk-rough` · `go1-walk-rough` · `anymalc-walk-flat` |
+|
| Humanoid velocity tracking | `g1-walk-flat` · `k1-walk-rough` · `dex-evt-walk-flat` · `microduck-walk-flat` |
+|
| Whole-body tracking (WBT) | `g1-wbt-dance` · `k1-wbt-freekick` · `g1-29dof-wbt-largebox` |
```bash
-uv run scripts/view.py robot=g1-29dof
+uv run scripts/view.py env=go2-walk-rough
```
-Available built-in robot names are `dex-evt`, `g1-29dof`, `go1`, `go2`, and `k1`.
-
-### Model Training
-
-Train the default Cartpole SKRL task:
-
-```bash
-uv run scripts/train.py task=cartpole/skrl.ppo
-```
+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.
-Train with RSLRL framework:
+## 🤖 Built-in Robot Models
-```bash
-uv run scripts/train.py task=cartpole/rslrl.ppo
-```
+Seven reusable robot models are registered out of the box and can be combined into any scene or task:
-Override runtime settings and algorithm parameters directly through Hydra:
+| Screenshot | Registry name | Type | DoF |
+| --- | --- | --- | --- |
+|
| `anymal_c` | Quadruped | 12 |
+|
| `dex-evt` | Humanoid | 23 |
+|
| `g1-29dof` | Humanoid | 29 |
+|
| `go1` | Quadruped | 12 |
+|
| `go2` | Quadruped | 12 |
+|
| `k1` | Humanoid | 22 |
+|
| `microduck` | Humanoid | 14 |
```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
+uv run scripts/view.py robot=go2
```
-Training results are saved in the `runs/{env-name}/` directory.
+See [Supported Robots](https://motrixlab.readthedocs.io/en/latest/user_guide/robots.html) for configuration details and how to add your own model.
-View training data through TensorBoard:
+## 🏗️ What's Inside
-```bash
-uv run tensorboard --logdir runs/{env-name}
-```
+MotrixLab is a [uv](https://docs.astral.sh/uv/) workspace of nine packages:
-### Model Inference
+| Package | PyPI name | Description |
+| --- | --- | --- |
+| **motrix_deploy** | `motrix-deploy` | Framework-independent artifact, backend, policy, control-loop, registry, and CLI |
+| **motrix_deploy_mujoco** | `motrix-deploy-mujoco` | MuJoCo deployment backend plugin |
+| **motrix_deploy_unitree** | `motrix-deploy-unitree` | Unitree SDK2 DDS hardware backend plugin |
+| **motrix_deploy_tasks** | `motrix-deploy-tasks` | Concrete versioned deployment tasks and executable bootstrap |
+| **motrix_env_core** | `motrix-env-core` | Environment base classes, configuration, registry, scene construction, NumPy runtime, and rendering. It contains no built-in tasks or robot assets |
+| **motrix_env_motrixsim** | `motrix-env-motrixsim` | Live MotrixSim backend, renderer, and torch frontend |
+| **motrix_env_mujoco** | `motrix-env-mujoco` | Compile-only MuJoCo scene backend |
+| **motrix_envs** | `motrix-envs` | Built-in environments, models, data, and environment-to-deployment-profile compilers |
+| **motrix_rl** | `motrix-rl` | RL-framework integration built against `motrix-env-core`, with SKRL, RSLRL, and FastSAC support |
-```bash
-uv run scripts/play.py env=cartpole
-```
+## 🤝 Contributing
-For more usage methods, please refer to the [User Documentation](https://motrixlab.readthedocs.io)
+Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for the development environment setup, branch and commit conventions, and the configured checks (`prek`, `ruff`, `dprint`, `mypy`).
## 📬 Contact
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 46aac42..72db638 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -1,154 +1,173 @@
**语言**: [English](README.md) | [简体中文](README.zh-CN.md)
+
+
+_使用 MotrixLab 训练的 microduck 行走策略,由 MotrixRender 实时渲染 — [观看高清视频](https://github.com/user-attachments/assets/4bcf3122-f135-44cb-a966-d2d8e84479da)。_
-`MotrixLab` 是一个基于 [MotrixSim](https://github.com/Motphys/motrixsim-docs) 仿真引擎的强化学习框架,专为机器人仿真和训练设计。该项目提供了一个完整的强化学习开发平台,集成了多种仿真环境和训练框架。
+**📖 用户文档**: [简体中文](https://motrixlab.readthedocs.io/zh-cn/stable/) | [English](https://motrixlab.readthedocs.io/en/stable/)
-## 项目概述
+
+
+
+
+
| 四足速度跟踪 | `go2-walk-flat` · `go2-walk-rough` · `go1-walk-rough` · `anymalc-walk-flat` |
+|
| 人形速度跟踪 | `g1-walk-flat` · `k1-walk-rough` · `dex-evt-walk-flat` · `microduck-walk-flat` |
+|
| 全身动作跟踪(WBT) | `g1-wbt-dance` · `k1-wbt-freekick` · `g1-29dof-wbt-largebox` |
```bash
-uv run scripts/view.py robot=g1-29dof
+uv run scripts/view.py env=go2-walk-rough
```
-可用的内置机器人名称包括 `dex-evt`、`g1-29dof`、`go1`、`go2` 和 `k1`。
-
-### 训练模型
-
-使用默认的 Cartpole SKRL 任务训练:
-
-```bash
-uv run scripts/train.py task=cartpole/skrl.ppo
-```
+完整环境列表与各环境支持的训练算法见[环境总览](https://motrixlab.readthedocs.io/zh-cn/latest/user_guide/envs/index.html)。
-使用 RSLRL 框架训练:
+## 🤖 内置机器人模型
-```bash
-uv run scripts/train.py task=cartpole/rslrl.ppo
-```
+通过 robot registry 内置 7 个可复用机器人模型,可与任意场景和任务组合:
-通过 Hydra 直接覆盖运行参数和算法参数:
+| 截图 | Registry 名称 | 类型 | 自由度 |
+| --- | --- | --- | --- |
+|
| `anymal_c` | 四足机器人 | 12 |
+|
| `dex-evt` | 人形机器人 | 23 |
+|
| `g1-29dof` | 人形机器人 | 29 |
+|
| `go1` | 四足机器人 | 12 |
+|
| `go2` | 四足机器人 | 12 |
+|
| `k1` | 人形机器人 | 22 |
+|
| `microduck` | 人形机器人 | 14 |
```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
+uv run scripts/view.py robot=go2
```
-训练结果会保存在 `runs/{env-name}/` 目录下。
+机器人配置细节与自定义新模型的方法见[支持的机器人](https://motrixlab.readthedocs.io/zh-cn/latest/user_guide/robots.html)。
-通过 TensorBoard 查看训练数据:
+## 🏗️ 项目组成
-```bash
-uv run tensorboard --logdir runs/{env-name}
-```
+MotrixLab 是一个由九个 package 组成的 [uv](https://docs.astral.sh/uv/) workspace:
-### 模型推理
+| Package | PyPI 名称 | 说明 |
+| --- | --- | --- |
+| **motrix_deploy** | `motrix-deploy` | 独立于训练框架的 artifact、backend、policy、控制循环、registry 与 CLI |
+| **motrix_deploy_mujoco** | `motrix-deploy-mujoco` | MuJoCo 部署 backend plugin |
+| **motrix_deploy_unitree** | `motrix-deploy-unitree` | Unitree SDK2 DDS 硬件 backend plugin |
+| **motrix_deploy_tasks** | `motrix-deploy-tasks` | 具体的带版本部署任务实现与可执行入口 bootstrap |
+| **motrix_env_core** | `motrix-env-core` | 环境基类、配置、registry、场景构建、NumPy runtime 与渲染能力,不包含任何内置任务和机器人资产 |
+| **motrix_env_motrixsim** | `motrix-env-motrixsim` | MotrixSim 实时仿真 backend、renderer 与 torch frontend |
+| **motrix_env_mujoco** | `motrix-env-mujoco` | 仅负责编译场景的 MuJoCo backend |
+| **motrix_envs** | `motrix-envs` | 内置环境、模型、数据及环境到部署 profile 的编译实现 |
+| **motrix_rl** | `motrix-rl` | 基于 `motrix-env-core` 的 RL 框架集成,支持 SKRL、RSLRL 和 FastSAC |
-```bash
-uv run scripts/play.py env=cartpole
-```
+## 🤝 参与贡献
-更多使用方式请参考[用户文档](https://motrixlab.readthedocs.io)
+欢迎参与贡献!开发环境搭建、分支与提交规范、以及仓库配置的检查工具(`prek`、`ruff`、`dprint`、`mypy`)请参见 [CONTRIBUTING.md](CONTRIBUTING.md)。
## 📬 联系方式
diff --git a/docs/source/_static/images/architecture-dark.svg b/docs/source/_static/images/architecture-dark.svg
new file mode 100644
index 0000000..85612d1
--- /dev/null
+++ b/docs/source/_static/images/architecture-dark.svg
@@ -0,0 +1,114 @@
+
diff --git a/docs/source/_static/images/architecture-light.svg b/docs/source/_static/images/architecture-light.svg
new file mode 100644
index 0000000..9aea7c8
--- /dev/null
+++ b/docs/source/_static/images/architecture-light.svg
@@ -0,0 +1,114 @@
+
diff --git a/docs/source/_static/images/microduck-training-curves.png b/docs/source/_static/images/microduck-training-curves.png
new file mode 100644
index 0000000..b682d49
--- /dev/null
+++ b/docs/source/_static/images/microduck-training-curves.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:10d117976d6a131a416d8ac34610ea0278996262bc1adf88cba5e52d755fe999
+size 72359
diff --git a/docs/source/_static/images/microduck-walk.gif b/docs/source/_static/images/microduck-walk.gif
new file mode 100644
index 0000000..57e171c
--- /dev/null
+++ b/docs/source/_static/images/microduck-walk.gif
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:ce7ac578ac164229e669e7351ca87bebf3935a68993ebec280191a912e6d230d
+size 5759289
diff --git a/docs/source/_static/images/train-console.png b/docs/source/_static/images/train-console.png
new file mode 100644
index 0000000..bd2eb87
--- /dev/null
+++ b/docs/source/_static/images/train-console.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:74d03422c67b62e68002e34ff3a0b8844fd82fcd4e8fb62f23d40cdc3abf4ae1
+size 39922
diff --git a/docs/source/_static/videos/microduck-walk.mp4 b/docs/source/_static/videos/microduck-walk.mp4
new file mode 100644
index 0000000..0cb248d
--- /dev/null
+++ b/docs/source/_static/videos/microduck-walk.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:e38fff19a52577c8f437e9c4d389c50fcec0be77eb125a432e2923aef35c2bb6
+size 1585145
diff --git a/motrix_rl/pyproject.toml b/motrix_rl/pyproject.toml
index 8480a3c..0e1b75a 100644
--- a/motrix_rl/pyproject.toml
+++ b/motrix_rl/pyproject.toml
@@ -21,13 +21,13 @@ dependencies = [
"numpy>=1.26",
"omegaconf>=2.3,<2.4",
"nvidia-ml-py>=13.610.43",
+ # Default training backend; also required by scripts/view.py. Resolved
+ # from the pytorch-cu128 index via the workspace root tool.uv.sources.
+ "torch==2.7.0",
]
[project.optional-dependencies]
-onnx = [
- "onnx==1.20.1",
- "onnxruntime==1.23.2",
-]
+onnx = ["onnx==1.20.1", "onnxruntime==1.23.2"]
skrl-jax = [
"skrl>=2.1,<2.2; sys_platform == 'linux'",
"jax[cuda12]==0.4.34; sys_platform == 'linux'",
diff --git a/scripts/view.py b/scripts/view.py
index 1eaa837..053ea7f 100644
--- a/scripts/view.py
+++ b/scripts/view.py
@@ -2,12 +2,12 @@
# SPDX-License-Identifier: Apache-2.0
import time
+from typing import TYPE_CHECKING
import gymnasium as gym
import hydra
import motrixsim as mtx
import numpy as np
-import torch
from motrixsim.render import RenderApp, RenderClosedError, RenderSettings
from omegaconf import DictConfig
@@ -19,11 +19,13 @@
from motrix_env_core.config.scene import RobotCfg, SystemCameraCfg
from motrix_env_core.renderer import RenderConfig, create_renderer
from motrix_env_motrixsim.compiler import build_scene_model
-from motrix_env_motrixsim.torch_env import TorchEnv
from motrix_envs.config.scene import StandardSceneCfg, StandardSceneObjsCfg
from motrix_rl.cli import to_typed_config
from motrix_rl.config import ViewConfig
+if TYPE_CHECKING:
+ from motrix_env_motrixsim.torch_env import TorchEnv
+
DEFAULT_ENV_NAME = "cartpole"
ROBOT_VIEW_FPS = 60
@@ -137,7 +139,9 @@ def _run_robot(robot_cfg: RobotCfg, sim: str | None = None) -> None:
raise ValueError(f"Unsupported robot view sim {backend!r}; expected 'motrixsim' or 'mujoco'")
-def _run_torch(env: TorchEnv):
+def _run_torch(env: "TorchEnv"):
+ import torch
+
renderer = create_renderer(env, RenderConfig())
env.init_state()
env_dt = env.cfg.ctrl_dt
@@ -157,6 +161,13 @@ def _run_torch(env: TorchEnv):
time.sleep(sleep_dt)
+def _torch_frontend_missing(env_name: str) -> ModuleNotFoundError:
+ return ModuleNotFoundError(
+ f"Environment '{env_name}' uses the torch frontend, but PyTorch is not installed; install torch "
+ f"(for example `uv sync --all-packages`) or view a NumPy-frontend environment such as '{DEFAULT_ENV_NAME}'"
+ )
+
+
def run(cfg: ViewConfig) -> None:
if cfg.env is not None and cfg.robot is not None:
raise ValueError("env and robot are mutually exclusive; set only one")
@@ -167,11 +178,27 @@ def run(cfg: ViewConfig) -> None:
_run_robot(registry.make_robot_config(cfg.robot), cfg.sim)
return
- env = registry.make(cfg.env or DEFAULT_ENV_NAME, num_envs=cfg.num_envs)
+ env_name = cfg.env or DEFAULT_ENV_NAME
+ try:
+ env = registry.make(env_name, num_envs=cfg.num_envs)
+ except ModuleNotFoundError as exc:
+ # Torch-frontend environments import torch when their factory resolves the env class.
+ if exc.name == "torch":
+ raise _torch_frontend_missing(env_name) from exc
+ raise
if isinstance(env, ArrayEnv):
_run_np(env)
- elif isinstance(env, TorchEnv):
+ return
+
+ try:
+ from motrix_env_motrixsim.torch_env import TorchEnv
+ except ModuleNotFoundError as exc:
+ if exc.name == "torch":
+ raise _torch_frontend_missing(env_name) from exc
+ raise
+
+ if isinstance(env, TorchEnv):
_run_torch(env)
else:
raise TypeError(f"Unsupported environment type '{type(env).__name__}'.")
diff --git a/uv.lock b/uv.lock
index 8809e2b..5847447 100644
--- a/uv.lock
+++ b/uv.lock
@@ -1094,6 +1094,8 @@ dependencies = [
{ name = "omegaconf" },
{ name = "python-abc" },
{ name = "rich" },
+ { name = "torch", version = "2.7.0", source = { registry = "https://pypi.org/simple" }, marker = "sys_platform != 'linux' and sys_platform != 'win32'" },
+ { name = "torch", version = "2.7.0+cu128", source = { registry = "https://download.pytorch.org/whl/cu128" }, marker = "sys_platform == 'linux' or sys_platform == 'win32'" },
]
[package.optional-dependencies]
@@ -1154,6 +1156,8 @@ requires-dist = [
{ name = "skrl", marker = "sys_platform == 'linux' and extra == 'skrl-jax'", specifier = ">=2.1,<2.2" },
{ name = "skrl", marker = "extra == 'skrl-torch'", specifier = ">=2.1,<2.2" },
{ name = "tensorflow", marker = "sys_platform == 'linux' and extra == 'skrl-jax'", specifier = "==2.20.0" },
+ { name = "torch", marker = "sys_platform != 'linux' and sys_platform != 'win32'", specifier = "==2.7.0" },
+ { name = "torch", marker = "sys_platform == 'linux' or sys_platform == 'win32'", specifier = "==2.7.0", index = "https://download.pytorch.org/whl/cu128" },
{ name = "torch", marker = "(sys_platform == 'linux' and extra == 'rslrl') or (sys_platform == 'win32' and extra == 'rslrl')", specifier = "==2.7.0", index = "https://download.pytorch.org/whl/cu128" },
{ name = "torch", marker = "(sys_platform == 'linux' and extra == 'skrl-torch') or (sys_platform == 'win32' and extra == 'skrl-torch')", specifier = "==2.7.0", index = "https://download.pytorch.org/whl/cu128" },
{ name = "torch", marker = "sys_platform != 'linux' and sys_platform != 'win32' and extra == 'rslrl'", specifier = "==2.7.0" },