perf: move MotrixSim write compiler onto native write plans - #60
Conversation
c5cd1c0 to
1d8dcae
Compare
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It is a broad refactor of the write vocabulary and reset lifecycle that swaps to a new native FFI (compile_write/mtx_write.*) whose behavior and quaternion conventions cannot be verified in this environment, warranting human review.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
This PR migrates the MotrixSim backend's declarative write path onto batched native write programs. Every compiled write set now becomes a single SceneModel.compile_write(...) plan whose reset and forward‑kinematics behavior are baked in at compile time, and execution collapses to one native_program.execute FFI call. It also upgrades motrixsim from the internal dev build to the official PyPI 0.10.1, renames the backend‑neutral Mocap*Write vocabulary to KinematicBody*Write, splits the fused mocap pose write into separate position/rotation writes, and adds neutral JointQuaternionWrite/JointAngularVelocityWrite for ball joints (used to move peg‑insert off the multi‑DoF path). It fits into the framework's backend‑neutral core / simulator‑backend split by keeping the neutral write declarations while replacing the MotrixSim‑specific numpy scatter ops with native plans.
Changes:
- Replace numpy-scatter write ops (
_DofChannelOp,_MultiTargetOp,_CtrlOp, reset patch ops) with a single nativecompile_writeplan; dropDofPositionWrite/DofVelocityWrite. - Rename
MocapPositionWrite/MocapRotationWriteintent to neutralKinematicBodyPositionWrite/KinematicBodyRotationWrite, split fused pose writes, and addJointQuaternionWrite/JointAngularVelocityWrite; migrate 5 envs. - Upgrade
motrixsimto PyPI0.10.1, dropping the internalmotphys-devindex.
| File | Description |
|---|---|
motrix_env_core/src/motrix_env_core/sim/write.py |
Removes Dof writes, renames mocap writes to kinematic-body, adds ball-joint writes + abstract hooks. |
motrix_env_core/src/motrix_env_core/sim/__init__.py |
Drops DofPositionWrite/DofVelocityWrite from re-exports and __all__. |
motrix_env_motrixsim/src/motrix_env_motrixsim/write_compiler.py |
Rewrites compiler onto native compile_write plans; adds ball-joint/single-DoF/mocap validation. |
motrix_env_motrixsim/src/motrix_env_motrixsim/runtime.py |
Drops masked_rows arg from compiler construction (leaves _masked_rows unused). |
motrix_envs/.../shadow_hand_np.py, anymal_c_np.py, manipulator_np.py, bounce_ball_np.py |
Split mocap pose writes into separate position/rotation kinematic-body writes. |
motrix_envs/.../rm65_insert_peg/insert_peg_np.py |
Moves peg off multi-DoF free-joint writes onto per-quantity slide/ball joint writes. |
motrix_env_motrixsim/pyproject.toml, pyproject.toml, uv.lock |
Upgrade motrixsim to PyPI 0.10.1; drop internal index. |
motrix_env_motrixsim/tests/*, motrix_env_core/tests/* |
Rework write-compiler/backend/dispatch tests; delete _MultiTargetOp test. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Migrate the MotrixSim write path onto batched native write programs:
every declarative write compiles into a single plan and execution is
one native_program.execute call.
- migrate the compiler onto the batched compile_write FFI plan and
upgrade motrixsim to 0.10.1.dev124285, whose WriteProgram.execute no
longer takes forward_kinematic: reset/FK behavior is baked into the
plan via SceneModel.compile_write(reset=, forward_kinematic=)
- split the fused MocapPoseWrite (N,B,7) contract into
MocapPositionWrite (N,B,3) + MocapRotationWrite (N,B,4), both compiled
to native BodyPosition/BodyRotation (bit-identical to mocap.set_pose);
_MultiTargetOp removed; four envs migrated
- JointPositionWrite/JointVelocityWrite compile to native
BodyJointPosition/BodyJointVelocity joint-name sources
- adopt the new ball joint sources from
core/motphys-articulated-body#2106 (MR !1755): add neutral
JointQuaternionWrite (xyzw, normalized on write) and
JointAngularVelocityWrite; migrate peg-insert off the multi-DoF
BodyJointPositionWrite("free_peg") fusion
- remove DofPositionWrite/DofVelocityWrite (zero users) and the legacy
Python pipeline they propped up: _DofChannelOp, _ResetPatchOp,
_DofComponentPatchOp, _execute_reset, and the masked_rows callback;
body-joint writes on multi-DoF bodies now fail loudly pointing at the
per-quantity writes; native plan reset also clears per-instance
overrides not covered by the plan
- _MotrixSimWriteProgram reduces to env_ids validation plus one native
execute
Full suite: 885 passed, 4 skipped.
1d8dcae to
475fed2
Compare

Summary
Migrate the MotrixSim write path onto batched native write programs: every declarative write compiles into a single native plan and execution is one
native_program.executecall.Supersedes #45 (same work, second-generation implementation rebased onto current main).
MotrixSim backend
compile_writeFFI plan; reset/FK behavior is baked into the plan at compile time viaSceneModel.compile_write(reset=, forward_kinematic=)motrixsimto the official PyPI0.10.1release (was0.10.1.dev124285from the internal index); the internalmotphys-devindex entry is dropped frompyproject.tomlsince release versions are published on PyPIMocapPoseWrite (N,B,7)contract into separate position/rotation writes, both compiled to nativeBodyPosition/BodyRotation;_MultiTargetOpremoved; four envs migratedJointPositionWrite/JointVelocityWritecompile to nativeBodyJointPosition/BodyJointVelocityjoint-name sourcesJointQuaternionWrite(xyzw, normalized on write) andJointAngularVelocityWritefrom core/motphys-articulated-body#2106 (MR !1755); migrate peg-insert off the multi-DoF patch pathCore (backend-neutral)
MocapPositionWrite/MocapRotationWrite→KinematicBodyPositionWrite/KinematicBodyRotationWrite: "mocap" is an MJCF/MuJoCo asset concept and must not leak into the backend-neutral write vocabularyTesting
motrix_env_core+motrix_env_motrixsimtest suites pass (56 tests)