Upload strict640x480-v2/code/merge_clean_strict_lpd.py with huggingface_hub
Browse files
strict640x480-v2/code/merge_clean_strict_lpd.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Merge only freshly completed LPD HDF5 trajectories into a new 100-demo corpus."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
import h5py
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def main() -> None:
|
| 12 |
+
parser = argparse.ArgumentParser()
|
| 13 |
+
parser.add_argument("--input", action="append", type=Path, required=True)
|
| 14 |
+
parser.add_argument("--output", type=Path, required=True)
|
| 15 |
+
args = parser.parse_args()
|
| 16 |
+
if args.output.exists():
|
| 17 |
+
raise FileExistsError(args.output)
|
| 18 |
+
|
| 19 |
+
selected: list[tuple[Path, str]] = []
|
| 20 |
+
for root in args.input:
|
| 21 |
+
for path in sorted(root.rglob("worker_*.h5")):
|
| 22 |
+
with h5py.File(path, "r") as source:
|
| 23 |
+
selected.extend((path, key) for key in sorted(k for k in source if k.startswith("traj_")))
|
| 24 |
+
if len(selected) != 100:
|
| 25 |
+
raise AssertionError(f"exactly 100 fresh trajectories required, found {len(selected)}")
|
| 26 |
+
|
| 27 |
+
args.output.mkdir(parents=True)
|
| 28 |
+
provenance: list[dict[str, str]] = []
|
| 29 |
+
for shard_index in range(4):
|
| 30 |
+
target = args.output / f"worker_{shard_index:02d}.h5"
|
| 31 |
+
with h5py.File(target, "w") as destination:
|
| 32 |
+
for local_index, (source_path, source_key) in enumerate(selected[shard_index * 25:(shard_index + 1) * 25]):
|
| 33 |
+
output_key = f"traj_{local_index:05d}"
|
| 34 |
+
with h5py.File(source_path, "r") as source:
|
| 35 |
+
destination.copy(source[source_key], output_key)
|
| 36 |
+
provenance.append({"output": f"{target.name}:{output_key}", "source": f"{source_path}:{source_key}"})
|
| 37 |
+
(args.output / "manifest.json").write_text(json.dumps({
|
| 38 |
+
"task": "long_pipeline_delivery", "protocol": "strict640x480_v2",
|
| 39 |
+
"episodes": 100, "source_policy": "fresh clean rebuild only", "provenance": provenance,
|
| 40 |
+
}, indent=2) + "\n", encoding="utf-8")
|
| 41 |
+
print("MERGED_CLEAN_STRICT_LPD_100")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
main()
|