refactor: 统一物理后端 contract 收敛 Phase 1 (#888) - #892
Merged
TATP-233 merged 2 commits intoAug 4, 2026
Merged
Conversation
Phase 1 of the #882 roadmap: converge the unified physics backend contract and establish the owner boundary for a future unisim package extraction (boundary only, no separate package). - decouple manager runtime from the env layer: ManagedEnvState is now owned by the manager layer, removing the runtime's reverse dependency on NpEnvState - trim SimBackend public surface: demote apply_body_linear_velocity_delta to adapter-private (no external callers), neutralize training/MuJoCo/ spawn-manager wording in the shared contract, remove unreachable MemorySpace.DEVICE branches - keep placement as a pure buffer attribute; fail-closed profile guards remain in place - migrate manip_loco diagnostic scripts to the public SimBackend API (no more backend private member access) - mechanize the owner boundary in tools/backend_isolation.py: * physics-layer import audit: base/backend/** must not import hydra, omegaconf, unilab.envs/training/algos/manager/ipc; allowed dependencies are an explicit documented allowlist * private-access audit now covers manager/, training/ and scripts/ in addition to envs/, dr/ and np_env.py * sibling runtime audit covers every file in each backend package, with two documented cold-path exceptions pending relocation - add tests/base/test_backend_conformance.py: factory-only construction assertion, parametrized legacy and typed construct/bind/step/reset sequences through the public contract, fail-closed conformance for backends without typed entry points Refs #888, #882
11 tasks
…physics-contract-convergence
6 tasks
12 tasks
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
执行 #888(#882 Roadmap Phase 1):收敛统一物理后端 contract,建立未来可提取为独立
unisimpackage 的 owner 边界(只整理边界,不创建独立 package)。contract 收敛
NpEnvState的反向依赖:新增 manager 层ManagedEnvState(镜像 NpEnvState 字段,归属 manager 层),manager/runtime.py不再 importnp_env;SimBackend公共 surface:apply_body_linear_velocity_delta无外部调用方,下沉为 mujoco/motrix adapter 私有方法;normalize_play_render_mode错误消息不再引用training.play_render_mode;get_motion_body_ids去掉 "MuJoCo-style";BackendTerrainSpawnData去掉 spawn-manager 措辞;ExecutionProfile下不可达的MemorySpace.DEVICE死分支(batch.py/mutation.py);placement 保持纯 buffer 属性,各 backend 的 fail-closed profile 守卫保留;run_playback(env, ...)经调查三个实现深度依赖 env wrapper(cfg/playback model/physics-state getter),保守保留签名,docstring 标注为已知边界(列入后续 issue)。owner 边界机械化(
tools/backend_isolation.py)src/unilab/base/backend/**禁止 importhydra/omegaconf/unilab.envs/unilab.training/unilab.algos/unilab.manager/unilab.ipc(运行期与 TYPE_CHECKING 同样禁止);允许依赖进入带注释的 allowlist(dr.types/base.scene/terrains/dtype_config/base.base(TYPE_CHECKING-only)/visualization),每项注明 unisim 提取待决策;envs/、dr/、np_env.py扩展到manager/、training/、scripts/;visitor 精化(getattr 别名追踪、scripts 冷路径公开名带 fallback 探测放行、runtime 层保持严格);两个 manip_loco 诊断脚本全部迁移到公开SimBackendAPI(IK 脚本行为实测逐位等价);backend.py/batch.py扩展到包内全部文件;两个既有 sibling 冷路径依赖(drake→mujoco.playback、mjwarp→mujoco.xml)进入文档化例外,迁移留给后续 issue。conformance suite(新
tests/base/test_backend_conformance.py)src/,四个 backend 类无绕过create_backend的直接实例化);create_backend→step→set_state→ state read(mujoco 全过、motrix 实跑通过、drake 不可用 skip、mjwarp slow 车道);bind_task_io→read_state_batch→bind_mutation_plan+reset_batch→step_batch;motrix/drake 断言干净抛NotImplementedError(fail-closed 即 conformant);audit_backend_isolation集成断言。Acceptance Criteria 对照
unisim的单向依赖结构;本 PR 不创建独立 package。Validation
make test-all中无关测试):tests/base、manager、training、tools、config、envs/locomotion/g1、scripts、dr、utils 共 1123 passed / 0 failed(23 skipped 为 motrix/drake 不可用与 slow 车道 deselect);ruff check src/ scripts/ tests/通过;mypy src/unilab267 文件零 issue;audit_backend_isolation真实仓库直跑:ok=True,0 violations(runtime_modules=19, contract_files=126);make test-all未完整运行(用户明确指示本任务序列只跑核心测试)。留给后续 issue(代码注释已标注)
scene_visual_model_file/scene_artifacts_dir提升为SimBackendcontract 成员后,收紧 scripts probe 规则;drake→mujoco.playback、mjwarp→mujoco.xml两个冷路径共享工具迁移到 backend-neutral 位置;dr.types、dtype_config、visualization等)的 unisim 提取决策;run_playback的 env 依赖重设计(playback contract 归位)。ADR 关联(契约改动必备)
平台/后端行为说明
Refs #888, #882, #705