Implementation:Haosulab ManiSkill MP Solutions Pattern
Appearance
| Field | Value |
|---|---|
| Implementation Name | MP Solutions Pattern |
| Type | Pattern Doc |
| Domain | Motion_Planning |
| Source File | mani_skill/examples/motionplanning/panda/run.py (L13-76)
|
| Date | 2026-02-15 |
| Repository | Haosulab/ManiSkill |
Overview
The MP Solutions Pattern implements the solver-selection registry for the motion planning demo generation pipeline. It defines the MP_SOLUTIONS dictionary that maps environment IDs to their corresponding solver functions, and provides the command-line interface and main execution loop for generating trajectories.
Description
The pattern consists of three components:
- Registry dictionary (
MP_SOLUTIONS): A Python dict mapping string environment IDs to callable solver functions imported frommani_skill.examples.motionplanning.panda.solutions.
- Argument parser (
parse_args): Defines all CLI parameters for controlling trajectory generation.
- Main execution loop (
_main): Creates the environment, wraps it withRecordEpisode, and iterates through trajectory generation, calling the selected solver for each episode.
Usage
# Generate 10 PickCube trajectories with video recording
python -m mani_skill.examples.motionplanning.panda.run -e PickCube-v1 -n 10 --save-video
# Generate 50 successful StackCube trajectories using 4 processes
python -m mani_skill.examples.motionplanning.panda.run -e StackCube-v1 -n 50 --only-count-success --num-procs 4
# Generate with ray-traced rendering
python -m mani_skill.examples.motionplanning.panda.run -e PegInsertionSide-v1 -n 20 --shader rt
Code Reference
MP_SOLUTIONS Registry
from mani_skill.examples.motionplanning.panda.solutions import (
solvePushCube, solvePickCube, solveStackCube, solvePegInsertionSide,
solvePlugCharger, solvePullCubeTool, solveLiftPegUpright, solvePullCube,
solveDrawTriangle, solveDrawSVG, solvePlaceSphere, solveStackPyramid,
)
MP_SOLUTIONS = {
"DrawTriangle-v1": solveDrawTriangle,
"PickCube-v1": solvePickCube,
"StackCube-v1": solveStackCube,
"PegInsertionSide-v1": solvePegInsertionSide,
"PlugCharger-v1": solvePlugCharger,
"PlaceSphere-v1": solvePlaceSphere,
"PushCube-v1": solvePushCube,
"PullCubeTool-v1": solvePullCubeTool,
"LiftPegUpright-v1": solveLiftPegUpright,
"PullCube-v1": solvePullCube,
"DrawSVG-v1": solveDrawSVG,
"StackPyramid-v1": solveStackPyramid,
}
CLI Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
-e / --env-id |
str | PickCube-v1 |
Environment to solve. Must be a key in MP_SOLUTIONS.
|
-n / --num-traj |
int | 10 |
Number of trajectories to generate. |
--only-count-success |
flag | False |
Only save and count successful trajectories. |
-o / --obs-mode |
str | none |
Observation mode (observations can be replayed later). |
-b / --sim-backend |
str | auto |
Simulation backend: auto, cpu, or gpu.
|
--render-mode |
str | rgb_array |
Render mode: sensors or rgb_array.
|
--record-dir |
str | demos |
Directory for recorded trajectory output. |
--num-procs |
int | 1 |
Number of parallel CPU processes. |
--save-video |
flag | False |
Whether to save video files. |
--vis |
flag | False |
Open a GUI to visualize the solution live. |
--shader |
str | default |
Shader for rendering: default, rt, or rt-fast.
|
--traj-name |
str | (timestamp) | Name for the trajectory .h5 file.
|
Execution Loop (L44-125)
def _main(args, proc_id: int = 0, start_seed: int = 0) -> str:
env_id = args.env_id
env = gym.make(
env_id,
obs_mode=args.obs_mode,
control_mode="pd_joint_pos",
render_mode=args.render_mode,
sensor_configs=dict(shader_pack=args.shader),
human_render_camera_configs=dict(shader_pack=args.shader),
viewer_camera_configs=dict(shader_pack=args.shader),
sim_backend=args.sim_backend,
)
if env_id not in MP_SOLUTIONS:
raise RuntimeError(
f"No already written motion planning solutions for {env_id}. "
f"Available options are {list(MP_SOLUTIONS.keys())}"
)
# ... wraps env with RecordEpisode, then loops calling solve(env, seed=seed) ...
I/O Contract
| Direction | Data | Format |
|---|---|---|
| Input | Environment ID | String key in MP_SOLUTIONS
|
| Input | CLI arguments | Parsed via argparse
|
| Output | Trajectory file | {record_dir}/{env_id}/motionplanning/{traj_name}.h5
|
| Output | Metadata file | {record_dir}/{env_id}/motionplanning/{traj_name}.json
|
| Output | Video files (optional) | {record_dir}/{env_id}/motionplanning/{video_id}.mp4
|
| Return | H5 file path | str (returned by _main)
|
Usage Examples
# Programmatic usage (not typical; usually invoked via CLI)
from mani_skill.examples.motionplanning.panda.run import _main, parse_args
import sys
sys.argv = ["run.py", "-e", "PickCube-v1", "-n", "5", "--record-dir", "my_demos"]
args = parse_args()
output_path = _main(args, proc_id=0, start_seed=0)
print(f"Trajectories saved to: {output_path}")
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment