Repository navigation
feat(entity): publish mjlab-aligned site pose and velocity on EntityData - #2674
Merged
Merged
Conversation
EntityData gains site_pos_w, site_quat_w (wxyz), site_lin_vel_w, and site_ang_vel_w for entities that declare site_names: (num_envs, num_sites, 3|4) in the declared site order, world frame, linear velocity at the site origin. The public SimBackend has no site-state read, so the scene tensor read plan transfers each owning body's tracked link state (link-origin velocity on MuJoCo and MJWarp) through the local frame from SimBackend.get_ray_site_frames: p_site = p_body + R(q_body) @ site_pos q_site = q_body * site_quat v_site = v_body + w_body x (p_site - p_body) w_site = w_body The per-entity carrier is written in place every phase, so masked-autoreset CUDA graph capture records fixed addresses. Before a read plan is compiled the carrier is zero-valued for ObservationManager's construction-time shape probe; afterwards an unrefreshed phase fails closed. Entities without sites return empty tensors, static world-owned sites keep a constant frame, and SceneTensorReadSpec.site_names / SceneTensorReadPlan.site_tensor_view expose the phase view. Declaring site_names keeps the full named-body tracking request on MuJoCo and MJWarp because owning bodies resolve only after backend materialization; an explicit SceneCfg.tracked_body_names that omits one fails closed at read-plan compilation. Closes #2673
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
EntityDatapublishes mjlab-aligned site state for entities that declaresite_names:site_pos_w,site_quat_w(wxyz),site_lin_vel_w,site_ang_vel_w, each(num_envs, num_sites, 3|4)in the declared site order, world frame, linear velocity taken at the site origin. Entities without sites return(num_envs, 0, ...); sites owned by the static world body keep a constant pose and zero velocity.SimBackendhas no site-state read (onlyget_site_ids,get_site_jacobian_w,get_ray_site_frames), so the scene tensor read plan derives every site from its owning body's tracked link state and the local frame fromSimBackend.get_ray_site_frames. Tracked body velocity is the link-origin velocity on both MuJoCo and MJWarp (mjOBJ_XBODYframe sensors), so the rigid transfer is exact and final-state fresh on both backends:p_site = p_body + R(q_body) @ site_pos,q_site = q_body * site_quat,v_site = v_body + w_body x (p_site - p_body),w_site = w_body.This is the same recipe downstream
RobotView._sites()repeats per task; it now lives in the owner layer. No unisim change.SceneTensorReadSpec.site_namesrequests the publish,SceneTensorReadPlan.site_tensor_view()returns the phase view,EntityData.site_frames(device)exposes the cold local frames (EntitySiteFrames), and Manager environments publish every declared site automatically. Owning bodies join the packed packet even when they are not inEntityCfg.body_names.data.site_pos_wduringObservationManager's construction-time shape probe (the same pre-bind convention as the motion-trackingbind_read_phaseterms); after compilation an unrefreshed phase fails closed.site_nameskeeps the full named-body tracking request on MuJoCo and MJWarp (owning bodies resolve only after backend materialization, so the derived selection cannot know them). An explicitSceneCfg.tracked_body_namesthat omits an owning body fails closed at read-plan compilation and names the body. A site request also opts that plan out of the pose-only host body blocks, because sites need velocities.get_ray_site_frameskeep constructing with declaredsite_names; readingsite_*_wthen raisesNotImplementedError.Linked Work
mainSimBackendmethods.site_pos/site_quatas identical across variants, so the canonical frame is exact for every world.get_ray_site_framesis reused for its "detached site-to-body transform" contract; a dedicated name would be a unisim API decision and is not needed for correctness.Validation
make test-allpassed on the final local head before this PR was created (df3bf3eb)Commands actually run (worktree synced with
uv sync --extra mujoco --extra mjwarpplusunilab-pull-assets --robot all; RTX 4090, CUDA 13.0 torch, mujoco 4.0.1, unisim-core 2.9.0):Measured parity (max abs error, declared tolerance 1e-5):
mj_kinematics+mj_comPos/mj_comVel+mj_objectVelocity(SITE)contact_*_tipvs raw MuJoCo (downstream scenario)contact_*_tipvs "body pose + local offset" hand calculationDownstream scenario (issue acceptance): a local script reproduced FlashDexRetarget's
robot_spec()—assets/robot/sharpa/right.xmlwith the native sites frombimanual.xmlinjected by body (28 bodies, 35 sites including the fivecontact_right_*_tipsites onright_*_DP) — on the CPU MuJoCo backend with random joint state, and comparedEntityData.site_*_wagainst raw MuJoCo and against the task-side body-pose-plus-offset recipe. The asset is private to that repo, so the check is a one-off script rather than an in-tree test; the in-tree fixturetests/fixtures/site_frames.xmlcovers the same shape (COM offset from the link origin, non-trivial local rotations, static sites).Pre-existing and unrelated:
tests/base/test_mjwarp_backend.py(slow, not part ofmake test-all) has 6 failures onmainatdb6cceebfrom removed 1.x NumPy APIs (set_state,get_body_pos_w); this PR does not touch it.Remote CI route:
main: all applicable current-head remote checks passed ondf3bf3eb.Impact
mujocoandmjwarp(both validated); other backends are unchanged and fail closed on site readssite_names, existing reads are unchanged; the only cost is for tasks that opt intosite_names(all named bodies stay tracked, and the plan carries the owning bodies' four velocity/pose sensors)Artifacts
make test-allbenchmark smoke only (35/35 modules, 36/36 scripts)Checklist
Unreleased / Added, env contract page en + zh_CN,SceneCfgdocstring)