fix: validate composed MJCF with MotrixSim
This commit is contained in:
parent
dd7312d3dd
commit
5923049af6
@ -1022,11 +1022,17 @@ def run_simulator_validation(config: PlatformConfig, store: PlatformStore, task:
|
||||
root / "motrix_scene.json",
|
||||
root / "motrix_import.json",
|
||||
root / "scene.json",
|
||||
root / "scene.xml",
|
||||
root / "mjcf" / "scene.xml",
|
||||
root / "mujoco" / "scene.xml",
|
||||
root / "simulator_assets" / "rm65_table_pick_place.xml",
|
||||
root / "motrixsim" / "motrix_import.json",
|
||||
root / "motrixsim" / "scene.json",
|
||||
*root.glob("*motrix*.json"),
|
||||
*root.glob("motrixsim/*.json"),
|
||||
*root.glob("*.xml"),
|
||||
*root.glob("mjcf/*.xml"),
|
||||
*root.glob("mujoco/*.xml"),
|
||||
*root.glob("simulator_assets/*.xml"),
|
||||
]
|
||||
report["simulators"]["motrixsim"] = _validate_motrixsim_asset(candidates, level=level)
|
||||
@ -1037,6 +1043,14 @@ def run_simulator_validation(config: PlatformConfig, store: PlatformStore, task:
|
||||
path.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
||||
store.add_artifact(task_id=task["id"], name="validation_report.json", path=path, kind="json")
|
||||
_task_progress(store, task, 95, "生成报告", "仿真校验报告已生成")
|
||||
if level == "runtime_required" and not report["ok"]:
|
||||
failures = []
|
||||
for simulator, result in report["simulators"].items():
|
||||
if result.get("ok"):
|
||||
continue
|
||||
runtime = result.get("runtime") or {}
|
||||
failures.append(f"{simulator}: {runtime.get('error') or result.get('error') or runtime.get('status') or 'validation failed'}")
|
||||
raise RuntimeError("runtime_required 仿真校验未通过;" + "; ".join(failures))
|
||||
return {"ok": report["ok"], "report_path": str(path), "report": report}
|
||||
|
||||
|
||||
@ -3018,10 +3032,13 @@ def _validate_mujoco_asset(candidates: list[Path], *, level: str) -> dict[str, A
|
||||
|
||||
def _validate_motrixsim_asset(candidates: list[Path], *, level: str) -> dict[str, Any]:
|
||||
descriptor = _validate_sim_asset(candidates, required_suffix=".json")
|
||||
runtime_scene = next((path for path in candidates if path.is_file() and path.suffix.lower() == ".xml"), None)
|
||||
if level == "smoke":
|
||||
if not descriptor["ok"] and runtime_scene is not None:
|
||||
descriptor = _validate_sim_asset([runtime_scene], required_suffix=".xml")
|
||||
descriptor["artifact_kind"] = "mjcf"
|
||||
descriptor["level_effective"] = "smoke"
|
||||
return descriptor
|
||||
runtime_scene = next((path for path in candidates if path.is_file() and path.suffix.lower() == ".xml"), None)
|
||||
if runtime_scene is None:
|
||||
return {
|
||||
"ok": False,
|
||||
|
||||
@ -513,8 +513,8 @@ def test_runtime_required_validation_steps_mujoco_and_motrixsim(tmp_path: Path)
|
||||
package = tmp_path / "runtime-scene"
|
||||
simulator_assets = package / "simulator_assets"
|
||||
simulator_assets.mkdir(parents=True)
|
||||
(package / "scene.json").write_text('{"schema":"motrixsim.scene.v1"}\n', encoding="utf-8")
|
||||
(simulator_assets / "scene.xml").write_text(
|
||||
runtime_scene = simulator_assets / "scene.xml"
|
||||
runtime_scene.write_text(
|
||||
'<mujoco model="runtime-validation"><option timestep="0.002"/><worldbody><geom type="plane" size="1 1 .1"/><body pos="0 0 .2"><freejoint/><geom type="sphere" size=".03" mass=".1"/></body></worldbody></mujoco>\n',
|
||||
encoding="utf-8",
|
||||
)
|
||||
@ -524,7 +524,7 @@ def test_runtime_required_validation_steps_mujoco_and_motrixsim(tmp_path: Path)
|
||||
"/api/tasks",
|
||||
json={
|
||||
"type": "simulator_validation",
|
||||
"params": {"scene_path": str(package), "simulators": ["mujoco", "motrixsim"], "level": "runtime_required"},
|
||||
"params": {"scene_path": str(runtime_scene), "simulators": ["mujoco", "motrixsim"], "level": "runtime_required"},
|
||||
},
|
||||
).json()
|
||||
for _ in range(80):
|
||||
@ -539,6 +539,27 @@ def test_runtime_required_validation_steps_mujoco_and_motrixsim(tmp_path: Path)
|
||||
assert simulators["motrixsim"]["runtime"]["steps"] == 8
|
||||
|
||||
|
||||
def test_runtime_required_validation_fails_task_when_runtime_artifact_is_missing(tmp_path: Path) -> None:
|
||||
package = tmp_path / "missing-runtime-scene"
|
||||
package.mkdir()
|
||||
config = PlatformConfig(app_root=ROOT, workspace_dir=tmp_path / "workspace", allowed_path_roots=(tmp_path,))
|
||||
with TestClient(create_app(config)) as client:
|
||||
created = client.post(
|
||||
"/api/tasks",
|
||||
json={
|
||||
"type": "simulator_validation",
|
||||
"params": {"scene_path": str(package), "simulators": ["motrixsim"], "level": "runtime_required"},
|
||||
},
|
||||
).json()
|
||||
for _ in range(80):
|
||||
task = client.get(f"/api/tasks/{created['id']}").json()
|
||||
if task["status"] in {"succeeded", "failed"}:
|
||||
break
|
||||
__import__("time").sleep(0.1)
|
||||
assert task["status"] == "failed"
|
||||
assert "runtime_required" in task["error"]
|
||||
|
||||
|
||||
def test_production_artifact_index_includes_viewer_dataset_and_model_outputs(tmp_path: Path) -> None:
|
||||
store = PlatformStore(tmp_path / "state.db")
|
||||
run_dir = tmp_path / "run"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user