File size: 2,584 Bytes
314ecfb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #!/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()
|