File size: 2,365 Bytes
6f003f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python
"""Validate Task 0 baseline episode identity and completeness."""

from __future__ import annotations

import argparse
import json
import sys
from pathlib import Path

SCRIPT_DIR = Path(__file__).resolve().parent
if str(SCRIPT_DIR) not in sys.path:
    sys.path.insert(0, str(SCRIPT_DIR))

from task0_baseline_common import (  # noqa: E402
    expected_keys,
    load_config,
    load_episode_records,
    parse_int_spec,
    protocol_hash,
    require_project_path,
    validate_key_set,
)


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--input-dir", type=Path, required=True)
    parser.add_argument(
        "--config",
        type=Path,
        default=Path("configs/baseline/libero10_task0_pi05_sft_formal.yaml"),
    )
    parser.add_argument("--expected-seeds", default=None)
    parser.add_argument("--expected-trials", default=None)
    parser.add_argument("--allow-incomplete", action="store_true")
    args = parser.parse_args()

    root = require_project_path(args.input_dir, label="result directory")
    cfg = load_config(args.config)
    cfg_hash = protocol_hash(cfg)
    seeds = parse_int_spec(args.expected_seeds, label="seeds") if args.expected_seeds else [int(seed) for seed in cfg.policy_seeds]
    trials = parse_int_spec(args.expected_trials, label="trial ids") if args.expected_trials else [int(trial) for trial in cfg.trial_ids]
    records = load_episode_records(root, expected_protocol_hash=cfg_hash)
    report = validate_key_set(records, expected_keys(seeds, trials))
    report["error_count"] = sum(record["status"] == "error" for record in records)
    report["completed_count"] = sum(record["status"] == "completed" for record in records)
    report["protocol_sha256"] = cfg_hash
    report["video_paths_non_null"] = sum(record["video_path"] is not None for record in records)
    print(json.dumps(report, ensure_ascii=False, indent=2, sort_keys=True))

    valid = (
        report["missing"] == []
        and report["unexpected"] == []
        and report["duplicates"] == []
        and report["error_count"] == 0
        and report["video_paths_non_null"] == 0
        and report["observed_count"] == report["expected_count"]
    )
    if not args.allow_incomplete and not valid:
        return 1
    return 0


if __name__ == "__main__":
    raise SystemExit(main())