Datasets:
Upload verified LIBERO-CF64k files
Browse files- contexts.jsonl +0 -0
- dataset.py +178 -0
contexts.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
dataset.py
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Read and verify the common CF64k download using NumPy and the standard library."""
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
from collections import Counter
|
| 5 |
+
import hashlib
|
| 6 |
+
import io
|
| 7 |
+
import json
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
import tarfile
|
| 10 |
+
|
| 11 |
+
import numpy as np
|
| 12 |
+
|
| 13 |
+
VIEWS = ("observation.images.agentview_rgb", "observation.images.eye_in_hand_rgb")
|
| 14 |
+
SAMPLE_FIELDS = (*VIEWS, "future_actions", "observation.state", "frame_index", "timestamp")
|
| 15 |
+
CONTEXT_FIELDS = ("simulator_state",)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def digest(path):
|
| 19 |
+
with path.open("rb") as handle:
|
| 20 |
+
return hashlib.file_digest(handle, "sha256").hexdigest()
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def validate_npz(data, *, context):
|
| 24 |
+
with np.load(io.BytesIO(data), allow_pickle=False) as payload:
|
| 25 |
+
fields = CONTEXT_FIELDS if context else SAMPLE_FIELDS
|
| 26 |
+
if set(payload.files) != set(fields) or len(payload.files) != len(fields):
|
| 27 |
+
raise ValueError("Unexpected public NPZ fields")
|
| 28 |
+
for field in fields:
|
| 29 |
+
array = payload[field]
|
| 30 |
+
if array.dtype.hasobject or not np.isfinite(array).all():
|
| 31 |
+
raise ValueError("Nonfinite or object public array")
|
| 32 |
+
if context:
|
| 33 |
+
state = payload["simulator_state"]
|
| 34 |
+
if state.ndim != 1 or state.size < 2 or state.dtype != np.float64:
|
| 35 |
+
raise ValueError("Invalid boundary physics state")
|
| 36 |
+
return {"state_length": state.size}
|
| 37 |
+
shapes = {**{key: ((129, 128, 128, 3), np.uint8) for key in VIEWS},
|
| 38 |
+
"future_actions": ((128, 7), np.float32),
|
| 39 |
+
"observation.state": ((129, 8), np.float32),
|
| 40 |
+
"frame_index": ((129,), np.int64), "timestamp": ((129,), np.float64)}
|
| 41 |
+
for key, (shape, dtype) in shapes.items():
|
| 42 |
+
if payload[key].shape != shape or payload[key].dtype != dtype:
|
| 43 |
+
raise ValueError(f"Invalid public array: {key}")
|
| 44 |
+
if not np.array_equal(payload["frame_index"], np.arange(129)) or not np.array_equal(
|
| 45 |
+
payload["timestamp"], np.arange(129) / 20.0
|
| 46 |
+
):
|
| 47 |
+
raise ValueError("Invalid public control clock")
|
| 48 |
+
boundary = hashlib.sha256()
|
| 49 |
+
for key in (*VIEWS, "observation.state"):
|
| 50 |
+
boundary.update(payload[key][0].tobytes())
|
| 51 |
+
return {"boundary_sha256": boundary.hexdigest()}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class Dataset:
|
| 55 |
+
def __init__(self, root):
|
| 56 |
+
self.root = Path(root)
|
| 57 |
+
self.metadata = json.loads((self.root / "dataset.json").read_text())
|
| 58 |
+
if set(self.metadata) != {"samples", "contexts", "parent_trajectories", "split",
|
| 59 |
+
"control_frequency_hz", "duration_seconds", "frames", "actions",
|
| 60 |
+
"views", "perturbations", "tasks", "indices"}:
|
| 61 |
+
raise ValueError("Unexpected dataset metadata fields")
|
| 62 |
+
for key, value in {"samples": 64000, "contexts": 10000, "split": "train",
|
| 63 |
+
"control_frequency_hz": 20, "duration_seconds": 6.4,
|
| 64 |
+
"frames": 129, "actions": 128, "views": list(VIEWS)}.items():
|
| 65 |
+
if self.metadata[key] != value:
|
| 66 |
+
raise ValueError(f"Incorrect dataset contract: {key}")
|
| 67 |
+
for name in ("samples.jsonl", "contexts.jsonl", "shards.json"):
|
| 68 |
+
if digest(self.root / name) != self.metadata["indices"][name]:
|
| 69 |
+
raise ValueError("Index checksum mismatch")
|
| 70 |
+
read_rows = lambda name: [json.loads(line) for line in (self.root / name).read_text().splitlines()]
|
| 71 |
+
self.samples = read_rows("samples.jsonl")
|
| 72 |
+
self.contexts = read_rows("contexts.jsonl")
|
| 73 |
+
self.shards = json.loads((self.root / "shards.json").read_text())
|
| 74 |
+
self.entries = {}
|
| 75 |
+
for kind, rows, count, fields in (
|
| 76 |
+
("samples", self.samples, 64000, {"sample_id", "context_id", "task_id", "perturbation"}),
|
| 77 |
+
("contexts", self.contexts, 10000, {"context_id", "task_id", "parent_id", "state_length"}),
|
| 78 |
+
):
|
| 79 |
+
id_key = "sample_id" if kind == "samples" else "context_id"
|
| 80 |
+
if [row[id_key] for row in rows] != list(range(count)):
|
| 81 |
+
raise ValueError("Incomplete or duplicate membership")
|
| 82 |
+
for row in rows:
|
| 83 |
+
if set(row) != fields | {"path", "shard", "sha256", "bytes"}:
|
| 84 |
+
raise ValueError("Unexpected public index fields")
|
| 85 |
+
if row["path"] != f"{kind}/{row[id_key]:05d}.npz":
|
| 86 |
+
raise ValueError("Invalid member path")
|
| 87 |
+
if row["shard"] != f"shards/{kind}-{row[id_key] // 512:05d}.tar":
|
| 88 |
+
raise ValueError("Invalid shard assignment")
|
| 89 |
+
self.entries[row["path"]] = row
|
| 90 |
+
if Counter(row["task_id"] for row in self.samples) != Counter({i: 6400 for i in range(10)}):
|
| 91 |
+
raise ValueError("Invalid task composition")
|
| 92 |
+
if set(row["parent_id"] for row in self.contexts) != set(range(self.metadata["parent_trajectories"])):
|
| 93 |
+
raise ValueError("Invalid parent groups")
|
| 94 |
+
for row in self.samples:
|
| 95 |
+
if type(row["context_id"]) is not int or not 0 <= row["context_id"] < 10000:
|
| 96 |
+
raise ValueError("Invalid context reference")
|
| 97 |
+
context = self.contexts[row["context_id"]]
|
| 98 |
+
if row["task_id"] != context["task_id"]:
|
| 99 |
+
raise ValueError("Sample/context task mismatch")
|
| 100 |
+
if dict(Counter(row["perturbation"] for row in self.samples)) != self.metadata["perturbations"]:
|
| 101 |
+
raise ValueError("Perturbation counts disagree")
|
| 102 |
+
if [row["task_id"] for row in self.metadata["tasks"]] != list(range(10)):
|
| 103 |
+
raise ValueError("Invalid task table")
|
| 104 |
+
for task in self.metadata["tasks"]:
|
| 105 |
+
if set(task) != {"task_id", "prompt", "samples", "simulator_state_length"} or task["samples"] != 6400:
|
| 106 |
+
raise ValueError("Invalid task metadata")
|
| 107 |
+
expected_shards = {row["shard"] for row in self.entries.values()}
|
| 108 |
+
if len(self.shards) != len(expected_shards) or {row["path"] for row in self.shards} != expected_shards:
|
| 109 |
+
raise ValueError("Missing or duplicate shard index")
|
| 110 |
+
|
| 111 |
+
def read(self, sample_id):
|
| 112 |
+
"""Read one lossless sequence without extracting a tar to disk."""
|
| 113 |
+
row = self.samples[sample_id]
|
| 114 |
+
return row, self._read_member(row)
|
| 115 |
+
|
| 116 |
+
def read_context(self, context_id):
|
| 117 |
+
row = self.contexts[context_id]
|
| 118 |
+
return row, self._read_member(row)
|
| 119 |
+
|
| 120 |
+
def _read_member(self, row):
|
| 121 |
+
with tarfile.open(self.root / row["shard"]) as archive:
|
| 122 |
+
member = archive.getmember(row["path"])
|
| 123 |
+
if not member.isfile() or member.size != row["bytes"]:
|
| 124 |
+
raise ValueError("Invalid member")
|
| 125 |
+
with archive.extractfile(member) as handle:
|
| 126 |
+
data = handle.read()
|
| 127 |
+
if hashlib.sha256(data).hexdigest() != row["sha256"]:
|
| 128 |
+
raise ValueError("Member checksum mismatch")
|
| 129 |
+
validate_npz(data, context="sample_id" not in row)
|
| 130 |
+
with np.load(io.BytesIO(data), allow_pickle=False) as payload:
|
| 131 |
+
return {key: payload[key] for key in payload.files}
|
| 132 |
+
|
| 133 |
+
def verify(self):
|
| 134 |
+
seen, boundaries = set(), {}
|
| 135 |
+
layouts = {task["task_id"]: task["simulator_state_length"] for task in self.metadata["tasks"]}
|
| 136 |
+
for index, shard in enumerate(self.shards):
|
| 137 |
+
path = self.root / shard["path"]
|
| 138 |
+
if path.stat().st_size != shard["bytes"] or digest(path) != shard["sha256"]:
|
| 139 |
+
raise ValueError("Archive checksum mismatch")
|
| 140 |
+
count = 0
|
| 141 |
+
with tarfile.open(path, "r|") as archive:
|
| 142 |
+
for member in archive:
|
| 143 |
+
if not member.isfile() or member.name not in self.entries or member.name in seen:
|
| 144 |
+
raise ValueError("Unexpected or duplicate member")
|
| 145 |
+
row = self.entries[member.name]
|
| 146 |
+
if row["shard"] != shard["path"] or member.size != row["bytes"]:
|
| 147 |
+
raise ValueError("Wrong member placement or size")
|
| 148 |
+
with archive.extractfile(member) as handle:
|
| 149 |
+
data = handle.read()
|
| 150 |
+
if hashlib.sha256(data).hexdigest() != row["sha256"]:
|
| 151 |
+
raise ValueError("Member checksum mismatch")
|
| 152 |
+
detail = validate_npz(data, context="sample_id" not in row)
|
| 153 |
+
if "sample_id" in row:
|
| 154 |
+
boundary = detail["boundary_sha256"]
|
| 155 |
+
if boundaries.setdefault(row["context_id"], boundary) != boundary:
|
| 156 |
+
raise ValueError("Inconsistent branch boundary")
|
| 157 |
+
elif detail["state_length"] != row["state_length"] or row["state_length"] != layouts[row["task_id"]]:
|
| 158 |
+
raise ValueError("Wrong physics layout")
|
| 159 |
+
seen.add(member.name)
|
| 160 |
+
count += 1
|
| 161 |
+
if count != shard["members"]:
|
| 162 |
+
raise ValueError("Wrong archive member count")
|
| 163 |
+
print(json.dumps({"verified_shards": index + 1, "verified_members": len(seen)}), flush=True)
|
| 164 |
+
if seen != self.entries.keys() or set(boundaries) != set(range(10000)):
|
| 165 |
+
raise ValueError("Incomplete downloaded data")
|
| 166 |
+
return {"status": "verified", "samples": len(self.samples), "contexts": len(self.contexts),
|
| 167 |
+
"shards": len(self.shards), "dataset_sha256": digest(self.root / "dataset.json")}
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
if __name__ == "__main__":
|
| 171 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 172 |
+
parser.add_argument("root", type=Path)
|
| 173 |
+
parser.add_argument("--receipt", type=Path)
|
| 174 |
+
args = parser.parse_args()
|
| 175 |
+
report = Dataset(args.root).verify()
|
| 176 |
+
if args.receipt:
|
| 177 |
+
args.receipt.write_text(json.dumps(report, indent=2) + "\n")
|
| 178 |
+
print(json.dumps(report), flush=True)
|