Repository navigation
fix(entity): resolve authored site tracking - #2678
Conversation
TATP-233
left a comment
There was a problem hiding this comment.
结论
一处需要在合并前补上;其余部分我在 PR 代码(48725430)上独立验证通过。
合并前要补:报错只覆盖挂在 world body 上的静态 site
resolve_authored_site_frames 只在 site 属于 world 时比较各 variant 的框架,其它 site 直接跳过。但 EntityData 发布所有 site 用的是同一个冷路径读到的 canonical 本地框架(_publish_site_states 的 frames.pos / frames.quat),动态 site 也是如此;而 unilabsim/unisim#592 放开的是所有 site 的 site_pos / site_quat。所以动态 site 的本地框架在 variant 间不同时,#2675 的问题原样保留。
实测(本 PR 加 unisim#592 fc81ac08,两个只在动态 site tip 的 pos 上不同的 variant,4 个 env 各一半,tests/fixtures/site_frames.xml 改两行):
tip 的世界坐标 |
|
|---|---|
| env 0/1(variant 0),期望 | (0.52, -0.03, 1.3) |
| env 2/3(variant 1),按独立编译的模型应为 | (0.46, 0.05, 1.2) |
| env 2/3,实际发布 | (0.52, -0.03, 1.3) |
差 10 cm,构建不报错。
建议
- 去掉
scene.py:172的 world 限定,对所有 site 比较body_name、pos、quat(含site_bodyid在 variant 间变化的情况),报错信息里的 "world-owned static site frames" 改成 "site frames"。理由和现在写的一样:get_ray_site_frames只暴露一个 canonical 本地框架。 validate_fixed_variant_site_frames只在fixed_variant_plan存在时运行,scene.entity_variant路径没有校验。这条我没有单独复现,请确认该路径是否会走到_publish_site_states。- 测试补一条:动态 site 的本地框架在 variant 间不同时应当报错。
FlashDexRetarget 不受影响:它的机器人在各 variant 间相同,站点框架一致。
验证通过的部分
tests/base/test_entity_site_state.py、test_mjwarp_site_state.py、test_fixed_model_variants.py共 30 个通过,分别搭配 unisim-core 2.9.0 和 unisim#592fc81ac08(RTX 4090,mujoco 4.0.1,mujoco-warp 4.0.1)。- #2675 的静态 site 复现现在报
ValueError: Fixed variants must keep world-owned static site frames identical ... variant 1 (...) changes static site 'marker' (site_pos),variant、源文件、site 和字段都在信息里。 - 冷编译一个真实 H2R 场景(TACO
seq_121,91 个网格)需要 0.07 s,提前解析父 body 的启动开销可以忽略。
复现脚本:动态 site 的本地框架在 variant 间不同
在仓库根目录运行,PYTHONPATH=src:<unisim#592>/src:
import pathlib, tempfile, numpy as np, mujoco
from unilab.base.backend_factory import create_backend
from unilab.base.entity import EntityCfg, EntityScene, SceneTensorReadSpec
from unilab.base.scene import SceneCfg
from unisim.dr.types import FixedVariantLayout, FixedVariantPlan, ModelSourceDescriptor
source = pathlib.Path("tests/fixtures/site_frames.xml").read_text()
sites = ("palm", "elbow", "tip")
with tempfile.TemporaryDirectory() as tmp:
tmp = pathlib.Path(tmp)
(tmp / "v0.xml").write_text(source)
(tmp / "v1.xml").write_text(source.replace('<site name="tip" pos="0.02 -0.03 0.2"', '<site name="tip" pos="-0.04 0.05 0.1"'))
truth = {}
for k in ("v0", "v1"):
m = mujoco.MjModel.from_xml_path(str(tmp / f"{k}.xml")); d = mujoco.MjData(m); mujoco.mj_kinematics(m, d)
truth[k] = np.round(d.site_xpos[m.site("tip").id], 3).tolist()
print("raw MuJoCo tip world pose at qpos0:", truth)
cfg = SceneCfg(model_file=str(tmp / "v0.xml"), fixed_variant_plan=FixedVariantPlan(assignment=np.array([0, 0, 1, 1], dtype=np.int32),
variants=(ModelSourceDescriptor(str(tmp / "v0.xml")), ModelSourceDescriptor(str(tmp / "v1.xml"))), layout=FixedVariantLayout.SAME_LAYOUT),
entities={"robot": EntityCfg(root_body_name="base", body_names=("base",), site_names=sites)})
try:
backend = create_backend("mjwarp", cfg, 4, 0.01, body_state_required=True, tracked_body_names=None, mjwarp_nconmax=32, mjwarp_njmax=64)
except Exception as e:
print(f"FAIL CLOSED: {type(e).__name__}: {str(e)[:260]}"); raise SystemExit(0)
scene = EntityScene.from_scene_cfg(cfg, backend, device="cuda")
scene.compile_tensor_reads("cuda", (SceneTensorReadSpec(entity="robot", site_names=sites),)).refresh()
tip = scene["robot"].data.site_pos_w[:, 2].cpu().numpy().astype(float)
print("published tip pos per env:", np.round(tip, 3).tolist(), "| envs 2/3 should be", truth["v1"])输出:
raw MuJoCo tip world pose at qpos0: {'v0': [0.52, -0.03, 1.3], 'v1': [0.46, 0.05, 1.2]}
published tip pos per env: [[0.52, -0.03, 1.3], [0.52, -0.03, 1.3], [0.52, -0.03, 1.3], [0.52, -0.03, 1.3]] | envs 2/3 should be [0.46, 0.05, 1.2]
| canonical = resolved[0] | ||
| for variant_index, frames in enumerate(resolved[1:], start=1): | ||
| for reference, candidate in zip(canonical, frames, strict=True): | ||
| if reference.body_name != "world" and candidate.body_name != "world": |
There was a problem hiding this comment.
这个限定让动态 site 的框架差异被跳过,但 _publish_site_states 对动态 site 同样只用 get_ray_site_frames 返回的 canonical 本地框架,而 unisim#592 放开的是所有 site 的 site_pos / site_quat。实测动态 site tip 的 pos 在 variant 间不同时,variant 1 的 env 发布的是 variant 0 的框架((0.52, -0.03, 1.3),应为 (0.46, 0.05, 1.2)),构建不报错。建议去掉 world 限定,对所有 site 比较 body_name / pos / quat,报错信息同步改成 "site frames"。详见审查正文。
There was a problem hiding this comment.
已在 95878833 修复:
- 去掉 world 限定,对所有 site 比较
body_name/pos/quat,动态 site 的本地框架差异也会 fail closed。 - 确认
entity_variant同样进入_publish_site_states,已为该路径加入 authored-source 预校验。 - 新增动态
tip与 physical-entity variant 回归;搭配 UniSimfc81ac08运行时 3 项均通过。
最终本地 make test-all:3041 passed, 42 skipped, 1 xfailed;MJWarp CUDA 4 项通过,Sphinx 构建通过。
Summary
site_namesdeclaration to all named bodies; unresolved sources retain the documented full-tracking fallback.site_bodyid,site_pos, orsite_quat. The error names the variant, site, and changed fields instead of publishing one canonical pose to every environment.create_backendrepro path, dynamic site mismatches, physical-entity variants, selective tracking scope, and MJWarp acceptance; update the bilingual env contract and changelog.Linked Work
mainValidation
make test-allpassed on the final local head before this PR was created or updatedCommands actually run:
Remote CI route:
main: CI run 47033459458 and Docs run 47033459627 are running on95878833. Sphinx, ruff, mypy, pyright, benchmark-smoke, and RL checks have passed; application/core/environment checks remain pending.Impact
mujocoandmjwarp; other backends are unchangedsite_names; downstream tasks that do avoid unrelated body tracking. Scene and physical-entity fixed variants with incompatible site frames now fail explicitly instead of returning incorrect posesArtifacts
make test-allbenchmark smoke only; no performance claimChecklist