#!/usr/bin/env python3 """Run the L80 30 m/s policy-3 Unreal trace for Linux 92.""" from __future__ import annotations import csv import json import re import subprocess import time from collections import Counter from pathlib import Path ROOT = Path(__file__).resolve().parents[4] HOST = Path("/home/jahni/VFHost") HOST_PLUGIN_SAVED = HOST / "Plugins/VoxelForge/Saved/Linux/l92" HOST_SAVED = HOST / "Saved/Linux/l92" EDITOR = Path("/home/jahni/UnrealEngine/Engine/Binaries/Linux/UnrealEditor-Cmd") OUT = ROOT / "Saved/Linux/l92/movement/unreal" SPAWN_M = (19.166015625, -14.2001953125, -753.3740234375) SPEED_CM_S = 3000.0 MOVE_START_S = 6.0 MOVE_DURATION_S = 12.0 DWELL_S = 5.0 EXIT_S = MOVE_START_S + MOVE_DURATION_S + DWELL_S ORPHAN_KEYS = {(47, -2, -99), (47, -2, -100), (47, -2, -101), (47, -2, -102)} def read_events(path: Path) -> list[dict]: events = [] if path.is_file(): for line in path.read_text(encoding="utf-8", errors="replace").splitlines(): if line.startswith("{"): try: events.append(json.loads(line)) except json.JSONDecodeError: pass return events def main() -> int: if not EDITOR.is_file(): raise SystemExit(f"missing Unreal commandlet executable: {EDITOR}") OUT.mkdir(parents=True, exist_ok=True) label = "fast-L80" trace, abslog, stdout = (OUT / f"{label}.trace.jsonl", OUT / f"{label}.log", OUT / f"{label}.stdout.log") output = HOST_PLUGIN_SAVED / "output" / label userdir = HOST_SAVED / "user" / label zendata = HOST_SAVED / "zen" / label ddc = HOST_SAVED / "DDC" for directory in (output, userdir, zendata, ddc): directory.mkdir(parents=True, exist_ok=True) trace.unlink(missing_ok=True) spawn_cm = ",".join(f"{value * 100.0:.3f}" for value in SPAWN_M) command = [ str(EDITOR), str(HOST / "VFHost.uproject"), "-nullrhi", "-unattended", "-nop4", "-nosplash", "-NoSound", "-corelimit=12", "-NoZenAutoLaunch", "-notraceserver", "-nocrashreports", "-DisablePlugins=AndroidFileServer", "-ddc=NoZenLocalFallback", f"-userdir={userdir}", f"-ZenDataPath={zendata}", f"-LocalDataCachePath={ddc}", "-run=VoxelForgeExplore", "-seed=0", "-archetype=TunnelNetwork", "-slot=0", "-modes=export", "-gameconfig=1", "-coreworldtest=1", "-ownerfourstrateplan=1", "-corevoxelsizecm=25", "-coreislandtest=0", "-corefallbacktest=0", "-coreofftest=0", "-coreplantest=0", "-settingsref=/Game/VoxelForge/DA_Settings.DA_Settings", "-corehybridmesher=0", f"-out={output}", "-voxel.StreamingCoarseFirst=1", "-voxel.StreamingDynamicNearReserve=1", "-voxel.StreamingLegacyPendingResultCap=0", "-voxel.CoreRegionConcurrentAdmission=1", "-voxel.StreamingResultBacklogCap=256", "-voxel.StreamingReadyQueueDepth=8", "-voxel.StreamingBackgroundWorkerCap=1", "-voxel.CoreColumnCacheDirectMapped=0", "-voxel.CoreMCGradientMemoization=1", "-voxel.StreamingCollisionLookahead=1", "-voxel.StreamingStartupApplyBoost=1", "-voxel.TestMove=1", f"-voxel.TestMoveSpeedCmPerSecond={SPEED_CM_S:.1f}", f"-voxel.TestMoveStartSeconds={MOVE_START_S:.1f}", f"-voxel.TestMoveDurationSeconds={MOVE_DURATION_S:.1f}", f"-voxel.TestExitSeconds={EXIT_S:.1f}", "-voxel.TestMoveDirection=1,0,0", "-voxel.StreamingSchedulerPolicy=3", "-voxel.TestExitOnSteady=0", "-coreworldstreamtrace=1", f"-voxel.StartupTraceSpawnCm={spawn_cm}", "-voxel.StartupTraceUntilEndPlay=1", "-voxel.StartupTraceThroughCrossing=1", "-voxel.StartupTraceMaxTiles=16384", f"-voxel.StartupTraceFile={trace}", f"-abslog={abslog}", ] started = time.monotonic() with stdout.open("w", encoding="utf-8") as stream: result = subprocess.run(["taskset", "-c", "0-11", "timeout", "1740s", *command], cwd=ROOT, stdout=stream, stderr=subprocess.STDOUT, check=False, timeout=1740) events = read_events(trace) samples = [e for e in events if e.get("type") == "streaming_sample"] move = [e for e in samples if float(e.get("speed_cm_s", 0.0)) >= 50.0] stop = next((e for e in events if e.get("type") == "streaming_test_move_stopped"), None) stop_t = float(stop.get("t_s", 0.0)) if stop else ( float(move[0].get("t_s", 0.0)) + MOVE_DURATION_S if move else float("inf")) dwell = [e for e in samples if float(e.get("t_s", 0.0)) >= stop_t and float(e.get("speed_cm_s", 0.0)) < 50.0] rows = [] for event in samples: desired = event.get("desired_by_lod", [0] * 9) resident = event.get("resident_by_lod", [0] * 9) covered = event.get("covered_by_lod", resident) far_desired = sum(desired[3:]) far_covered = sum(covered[3:]) near_desired = sum(desired[:3]) near_resident = sum(resident[:3]) rows.append({ "t_s": event.get("t_s"), "speed_cm_s": event.get("speed_cm_s"), "far_desired": far_desired, "far_covered": far_covered, "far_hole_pct": round(100.0 * (far_desired - far_covered) / max(1, far_desired), 3), "near_desired": near_desired, "near_resident": near_resident, "near_ready_pct": round(100.0 * near_resident / max(1, near_desired), 3), }) moving_holes = [row["far_hole_pct"] for row in rows if float(row["speed_cm_s"] or 0.0) >= 50.0] moving_near = [row["near_ready_pct"] for row in rows if float(row["speed_cm_s"] or 0.0) >= 50.0] dwell_rows = [row for row in rows if float(row["t_s"] or 0.0) >= stop_t and float(row["speed_cm_s"] or 0.0) < 50.0] orphan = Counter() for event in events: key = event.get("tile", event.get("key")) if key is not None and tuple(key) in ORPHAN_KEYS: orphan[(tuple(key), event.get("type"))] += 1 stdout_text = stdout.read_text(encoding="utf-8", errors="replace") core_failure = re.search(r"\[VoxelForgeCoreWorldTest\] failed: ([^\r\n]+)", stdout_text) core_pass = "[VoxelForgeCoreWorldTest] pass complete=1" in stdout_text result_row = { "label": label, "policy": "L80", "policy_id": 3, "speed_cm_s": SPEED_CM_S, "exit_code": result.returncode, "wall_s": round(time.monotonic() - started, 3), "sample_count": len(samples), "moving_samples": len(move), "dwell_samples": len(dwell), "core_world_test_pass": core_pass, "core_world_test_failure": core_failure.group(1) if core_failure else None, "far_holes_moving_mean_pct": round(sum(moving_holes) / max(1, len(moving_holes)), 3), "near_ready_moving_mean_pct": round(sum(moving_near) / max(1, len(moving_near)), 3), "far_holes_dwell_last_pct": dwell_rows[-1]["far_hole_pct"] if dwell_rows else None, "near_ready_dwell_last_pct": dwell_rows[-1]["near_ready_pct"] if dwell_rows else None, "move_stopped_t_s": stop_t if stop else None, "orphan_key_events": {f"{key}:{event_type}": count for (key, event_type), count in sorted(orphan.items())}, "trace": str(trace.relative_to(ROOT)), "abslog": str(abslog.relative_to(ROOT)), "stdout": str(stdout.relative_to(ROOT)), } (OUT / "summary.json").write_text(json.dumps(result_row, indent=2) + "\n", encoding="utf-8") if rows: with (OUT / "samples.csv").open("w", newline="", encoding="utf-8") as stream: writer = csv.DictWriter(stream, fieldnames=list(rows[0])) writer.writeheader() writer.writerows(rows) print("[L92FastMove] " + json.dumps(result_row, sort_keys=True), flush=True) if result.returncode != 0 or not core_pass or len(move) < 40 or len(dwell) < 16: return 1 return 0 if __name__ == "__main__": raise SystemExit(main())