File size: 1,770 Bytes
819919b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Fix 100 seed-0 episodes per task for the three-task source pool."""

import argparse
import json
from pathlib import Path

from inspect_and_manifest import select_manifest, summarize, write_json


TASKS = {
    "coffee_preparation_d0": ("source_episodes.json", (68662, 67762)),
    "pick_place_d0": ("broad_pick_place_d0_episodes.json", (67611, 66711)),
    "kitchen_d0": ("multi_kitchen_d0_episodes.json", None),
}


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--raw-root", type=Path, required=True)
    parser.add_argument("--output-dir", type=Path, required=True)
    args = parser.parse_args()

    combined = {"seed": 0, "episodes_per_task": 100, "sequence_length": 10, "tasks": {}}
    for task, (filename, expected) in TASKS.items():
        raw = args.raw_root / "core" / f"{task}.hdf5"
        summary = summarize(raw)
        manifest = select_manifest(summary, f"core/{task}", 100, 0, 10)
        counts = (
            sum(row["timesteps"] for row in manifest["episodes"]),
            manifest["valid_sequence_anchors"],
        )
        if expected is not None and counts != expected:
            raise RuntimeError(f"{task}: expected {expected}, got {counts}")
        manifest["raw_file"] = {"path": str(raw), "bytes": summary["bytes"], "sha256": summary["sha256"]}
        manifest["raw_timesteps"] = counts[0]
        write_json(args.output_dir / filename, manifest)
        combined["tasks"][task] = {"manifest": filename, "raw_timesteps": counts[0], "complete_windows": counts[1]}
    write_json(args.output_dir / "multi_source_manifest.json", combined)
    print(json.dumps(combined, indent=2, sort_keys=True))
    print("MULTI_SOURCE_MANIFESTS_OK")


if __name__ == "__main__":
    main()