#!/usr/bin/env python3 """Print a compact status table for parallel Bench2Drive workers.""" import argparse import json from pathlib import Path RETRYABLE_STATUSES = { "Started", "Failed - Simulation crashed", "Failed - Agent crashed", } def load_json(path): try: with open(path, encoding="utf-8") as file_handle: return json.load(file_handle) except (OSError, json.JSONDecodeError): return None def retry_state_path(result_file): worker_label = result_file.stem.removeprefix("bench2drive220_") return result_file.parent / f"retry_state_{worker_label}.json" def worker_status(result_file): data = load_json(result_file) if not isinstance(data, dict): return f"{result_file.stem:<52} waiting for a valid checkpoint" checkpoint = data.get("_checkpoint", {}) progress = checkpoint.get("progress", ["?", "?"]) records = checkpoint.get("records", []) completed = progress[0] if len(progress) == 2 else "?" total = progress[1] if len(progress) == 2 else "?" current = next( ( record for record in records if isinstance(record, dict) and record.get("status") in RETRYABLE_STATUSES ), None, ) last_record = records[-1] if records and isinstance(records[-1], dict) else {} display_record = current or last_record route_id = display_record.get("route_id", "-") status = display_record.get("status", "-") skipped = sum( 1 for record in records if isinstance(record, dict) and record.get("status") == "Failed - Retry limit exceeded" ) retries = 0 retry_data = load_json(retry_state_path(result_file)) if current and isinstance(retry_data, dict): route_state = retry_data.get("routes", {}).get(route_id, {}) retries = route_state.get("retries", 0) return ( f"{result_file.stem:<52} " f"progress={completed}/{total} entry={data.get('entry_status', '-'):<8} " f"route={route_id:<28} retries={retries} skipped={skipped} status={status}" ) def main(): parser = argparse.ArgumentParser() parser.add_argument("result_root", type=Path) args = parser.parse_args() result_files = sorted(args.result_root.glob("bench2drive220_worker_*.json")) print(f"Bench2Drive results: {args.result_root}") if not result_files: print("Waiting for worker checkpoints...") return for result_file in result_files: print(worker_status(result_file)) if __name__ == "__main__": main()