Skip to content

perf: move MotrixSim write compiler onto native write plans - #60

Merged
wlgys8 merged 1 commit into
mainfrom
perf/native-write-plan
Sep 20, 2026
Merged

wlgys8 merged 1 commit into
mainfrom
perf/native-write-plan

Conversation

@wlgys8

@wlgys8 wlgys8 commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

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.execute call.

Supersedes #45 (same work, second-generation implementation rebased onto current main).

MotrixSim backend

  • Migrate the compiler onto the batched compile_write FFI plan; reset/FK behavior is baked into the plan at compile time via SceneModel.compile_write(reset=, forward_kinematic=)
  • Upgrade motrixsim to the official PyPI 0.10.1 release (was 0.10.1.dev124285 from the internal index); the internal motphys-dev index entry is dropped from pyproject.toml since release versions are published on PyPI
  • Split the fused MocapPoseWrite (N,B,7) contract into separate position/rotation writes, both compiled to native BodyPosition/BodyRotation; _MultiTargetOp removed; four envs migrated
  • JointPositionWrite/JointVelocityWrite compile to native BodyJointPosition/BodyJointVelocity joint-name sources
  • Add neutral JointQuaternionWrite (xyzw, normalized on write) and JointAngularVelocityWrite from core/motphys-articulated-body#2106 (MR !1755); migrate peg-insert off the multi-DoF patch path

Core (backend-neutral)

  • Rename MocapPositionWrite/MocapRotationWriteKinematicBodyPositionWrite/KinematicBodyRotationWrite: "mocap" is an MJCF/MuJoCo asset concept and must not leak into the backend-neutral write vocabulary

Testing

  • motrix_env_core + motrix_env_motrixsim test suites pass (56 tests)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Low severity

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 native compile_write plan; drop DofPositionWrite/DofVelocityWrite.
  • Rename MocapPositionWrite/MocapRotationWrite intent to neutral KinematicBodyPositionWrite/KinematicBodyRotationWrite, split fused pose writes, and add JointQuaternionWrite/JointAngularVelocityWrite; migrate 5 envs.
  • Upgrade motrixsim to PyPI 0.10.1, dropping the internal motphys-dev index.
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.

Comment thread motrix_env_core/tests/test_sim_write_dispatch.py Outdated
Comment thread motrix_env_motrixsim/src/motrix_env_motrixsim/runtime.py
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.
@wlgys8
wlgys8 force-pushed the perf/native-write-plan branch from 1d8dcae to 475fed2 Compare September 19, 2026 10:48
@wlgys8
wlgys8 merged commit dd2eafe into main Sep 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants