Skip to content

perf: migrate MotrixSim writes to batched compile_write FFI plan - #45

Closed
wlgys8 wants to merge 1 commit into
mainfrom
perf/write-compiler-ffi-plan
Closed

wlgys8 wants to merge 1 commit into
mainfrom
perf/write-compiler-ffi-plan

Conversation

@wlgys8

@wlgys8 wlgys8 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Closes #20

Summary

  • upgrade motrixsim to 0.10.1.dev123565, whose compile_write supports compile-time reset and forward_kinematic flags
  • semantic writes (ctrl targets, body pose/velocities, kp/damping/mass/com/friction overrides, mocap poses) compile into one native WritePlan; each execute scatters in a single FFI call, applies the native reset first when compiled with reset=True, and refreshes kinematics at most once
  • mocap pose declarations expand into per-body interleaved BodyPosition/BodyRotation fields; buffer(name) synthesizes the neutral (N, B, 7) layout as one zero-copy slice, so consumers are unchanged
  • dof-channel writes keep the numpy scatter path but land through the explicit set_dof_pos/set_dof_vel setters: SceneData property projections are read-only copies, so in-place patches never reached the sim state
  • keep compile-time conflict detection for dof and ctrl targets with the existing error messages; native duplicate-channel rejection covers the override fields
  • drop _MultiTargetOp (unused after the migration) and the post-reset op branch (all remaining numpy ops fold into the reset state)

Test plan

  • full workspace suite: 871 passed
  • prek run clean on changed files
  • smoke: cartpole skrl training, shadow-hand / go2 / stewart / manipulator envs step loops

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/write-compiler-ffi-plan branch from 09b6b93 to c5cd1c0 Compare September 19, 2026 08:34
@wlgys8

wlgys8 commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

Superseded: this work was rebased onto the newer native write plan implementation; continuing in the new PR from perf/native-write-plan.

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.

perf: migrate MotrixSim write compiler to batched compile_write FFI plan

1 participant