hynky commited on
Commit
f88eef7
·
verified ·
1 Parent(s): 795dc44

Add synchronized robot perception states

Browse files

Adds a separate `robot_states` configuration for the 50 RoboInter/DROID and 25 RoboCOIN/Galaxea benchmark episodes.

The sidecar preserves named source-native joint, EEF, and gripper channels; pins all upstream revisions; includes SHA-256 provenance and a reproducible builder; and intentionally leaves HomER video-only.

Validation: 75/75 state IDs match the default benchmark, 30,494 synchronized frames pass frame-count/channel-length checks, and the compressed sidecar is 1.5 MB.

README.md CHANGED
@@ -23,6 +23,10 @@ configs:
23
  data_files:
24
  - split: train
25
  path: data/annotations.parquet
 
 
 
 
26
  ---
27
 
28
  # WGO-Bench: What's Going On Benchmark
@@ -44,6 +48,7 @@ Each row contains one video episode, a high-level task instruction, and gold sub
44
  | Source families | 3 |
45
  | Format | Parquet |
46
  | Video storage | MP4 bytes embedded in each row |
 
47
 
48
  ## Sources
49
 
@@ -55,6 +60,8 @@ Each row contains one video episode, a high-level task instruction, and gold sub
55
 
56
  ## Schema
57
 
 
 
58
  | Column | Type | Description |
59
  | --- | --- | --- |
60
  | `id` | string | Stable episode identifier. |
@@ -63,6 +70,30 @@ Each row contains one video episode, a high-level task instruction, and gold sub
63
  | `segments` | list | Gold `{start_sec, end_sec, subtask}` annotations. |
64
  | `metadata` | string | JSON metadata with source-specific fields. |
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  ## Quick Start
67
 
68
  ```python
@@ -75,6 +106,22 @@ print(example["instruction"])
75
  print(example["segments"])
76
  ```
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  To use the parquet directly:
79
 
80
  ```python
@@ -83,6 +130,23 @@ import pandas as pd
83
  df = pd.read_parquet("hf://datasets/macrodata/WGO-Bench/data/annotations.parquet")
84
  ```
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  ## Annotation Policy
87
 
88
  Segments are intended to describe completed manipulation events, not every small pose adjustment. A new segment should generally correspond to a visible state change such as picking up, placing, opening, closing, moving, pouring, wiping, cutting, or transferring an object.
 
23
  data_files:
24
  - split: train
25
  path: data/annotations.parquet
26
+ - config_name: robot_states
27
+ data_files:
28
+ - split: train
29
+ path: robot_states/perception_states.parquet
30
  ---
31
 
32
  # WGO-Bench: What's Going On Benchmark
 
48
  | Source families | 3 |
49
  | Format | Parquet |
50
  | Video storage | MP4 bytes embedded in each row |
51
+ | Robot-state coverage | 75 robotic episodes; HomER is video-only |
52
 
53
  ## Sources
54
 
 
60
 
61
  ## Schema
62
 
63
+ ### `default`
64
+
65
  | Column | Type | Description |
66
  | --- | --- | --- |
67
  | `id` | string | Stable episode identifier. |
 
70
  | `segments` | list | Gold `{start_sec, end_sec, subtask}` annotations. |
71
  | `metadata` | string | JSON metadata with source-specific fields. |
72
 
73
+ ### `robot_states`
74
+
75
+ The optional `robot_states` configuration contains synchronized proprioception
76
+ for the 50 RoboInter/DROID and 25 RoboCOIN/Galaxea episodes. HomER has no robot
77
+ telemetry and is intentionally absent rather than filled with synthetic zeros.
78
+
79
+ | Column | Type | Description |
80
+ | --- | --- | --- |
81
+ | `bench_id` | string | Stable episode identifier matching `id` in `default`. |
82
+ | `robot_family` | string | `droid` or `galaxea`. |
83
+ | `source_dataset` | string | Official upstream dataset repository. |
84
+ | `source_revision` | string | Immutable upstream Git revision. |
85
+ | `source_episode_index` | integer | Episode index in the upstream dataset. |
86
+ | `fps` | float | State sampling rate. |
87
+ | `num_frames` | integer | Number of synchronized state/video frames. |
88
+ | `frame_index` | list | Ordered frame indices. |
89
+ | `timestamp_sec` | list | Ordered timestamps in seconds. |
90
+ | `primary_channel` | string | Main source-native proprioception column. |
91
+ | `channels` | list | Named state channels with semantic value names and per-frame values. |
92
+
93
+ DROID retains EEF position, rotation, and gripper state. Galaxea retains
94
+ bilateral arm joints and grippers plus its available EEF- and gripper-derived
95
+ channels. Actions are not included.
96
+
97
  ## Quick Start
98
 
99
  ```python
 
106
  print(example["segments"])
107
  ```
108
 
109
+ Load robot states separately and join them on `id == bench_id`:
110
+
111
+ ```python
112
+ from datasets import load_dataset
113
+
114
+ episodes = load_dataset("macrodata/WGO-Bench", "default", split="train")
115
+ robot_states = load_dataset("macrodata/WGO-Bench", "robot_states", split="train")
116
+
117
+ state_by_id = {row["bench_id"]: row for row in robot_states}
118
+ episode = next(row for row in episodes if row["id"] in state_by_id)
119
+ state = state_by_id[episode["id"]]
120
+
121
+ print(state["primary_channel"])
122
+ print(state["channels"][0]["value_names"])
123
+ ```
124
+
125
  To use the parquet directly:
126
 
127
  ```python
 
130
  df = pd.read_parquet("hf://datasets/macrodata/WGO-Bench/data/annotations.parquet")
131
  ```
132
 
133
+ ## Rebuilding Robot States
134
+
135
+ `scripts/perception_sources.lock.json` pins both annotation maps and all 26
136
+ upstream robot-dataset revisions. Rebuild the sidecar without downloading the
137
+ embedded benchmark videos:
138
+
139
+ ```bash
140
+ python scripts/perception_states.py robot_states/perception_states.parquet
141
+ ```
142
+
143
+ Requirements are Python 3.11+, `huggingface_hub`, and `pyarrow`. The exporter
144
+ validates episode coverage, frame counts, channel widths, and timestamp order,
145
+ then writes a SHA-256 provenance file next to the Parquet. Hugging Face caches
146
+ all source files; pass `--cache-dir` to use a shared cache. The DROID state data
147
+ comes from one roughly 241 MB upstream tar archive, while the generated
148
+ Zstandard-compressed sidecar is roughly 1.5 MB.
149
+
150
  ## Annotation Policy
151
 
152
  Segments are intended to describe completed manipulation events, not every small pose adjustment. A new segment should generally correspond to a visible state change such as picking up, placing, opening, closing, moving, pouring, wiping, cutting, or transferring an object.
robot_states/perception_states.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:979135afc50e826fef887e7ed4c30ed15bbc08e6ae17ebbb18fa8b48032d933e
3
+ size 1609505
robot_states/perception_states.parquet.provenance.json ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "schema_version": 1,
3
+ "artifact": "perception_states.parquet",
4
+ "sha256": "979135afc50e826fef887e7ed4c30ed15bbc08e6ae17ebbb18fa8b48032d933e",
5
+ "episodes": 75,
6
+ "bench_ids": [
7
+ "galaxea_002",
8
+ "galaxea_007",
9
+ "galaxea_009",
10
+ "galaxea_011",
11
+ "galaxea_013",
12
+ "galaxea_028",
13
+ "galaxea_033",
14
+ "galaxea_037",
15
+ "galaxea_039",
16
+ "galaxea_041",
17
+ "galaxea_043",
18
+ "galaxea_045",
19
+ "galaxea_047",
20
+ "galaxea_049",
21
+ "galaxea_050",
22
+ "galaxea_052",
23
+ "galaxea_058",
24
+ "galaxea_060",
25
+ "galaxea_062",
26
+ "galaxea_065",
27
+ "galaxea_067",
28
+ "galaxea_069",
29
+ "galaxea_071",
30
+ "galaxea_073",
31
+ "galaxea_075",
32
+ "robointer_droid_000001",
33
+ "robointer_droid_000002",
34
+ "robointer_droid_000003",
35
+ "robointer_droid_000004",
36
+ "robointer_droid_000005",
37
+ "robointer_droid_000006",
38
+ "robointer_droid_000007",
39
+ "robointer_droid_000008",
40
+ "robointer_droid_000009",
41
+ "robointer_droid_000010",
42
+ "robointer_droid_000011",
43
+ "robointer_droid_000012",
44
+ "robointer_droid_000013",
45
+ "robointer_droid_000014",
46
+ "robointer_droid_000015",
47
+ "robointer_droid_000016",
48
+ "robointer_droid_000017",
49
+ "robointer_droid_000019",
50
+ "robointer_droid_000021",
51
+ "robointer_droid_000022",
52
+ "robointer_droid_000023",
53
+ "robointer_droid_000024",
54
+ "robointer_droid_000025",
55
+ "robointer_droid_000027",
56
+ "robointer_droid_000028",
57
+ "robointer_droid_000029",
58
+ "robointer_droid_000030",
59
+ "robointer_droid_000032",
60
+ "robointer_droid_000033",
61
+ "robointer_droid_000034",
62
+ "robointer_droid_000035",
63
+ "robointer_droid_000036",
64
+ "robointer_droid_000037",
65
+ "robointer_droid_000038",
66
+ "robointer_droid_000039",
67
+ "robointer_droid_000042",
68
+ "robointer_droid_000043",
69
+ "robointer_droid_000044",
70
+ "robointer_droid_000045",
71
+ "robointer_droid_000046",
72
+ "robointer_droid_000047",
73
+ "robointer_droid_000050",
74
+ "robointer_droid_000055",
75
+ "robointer_droid_000056",
76
+ "robointer_droid_000057",
77
+ "robointer_droid_000058",
78
+ "robointer_droid_000059",
79
+ "robointer_droid_000060",
80
+ "robointer_droid_000061",
81
+ "robointer_droid_000062"
82
+ ],
83
+ "source_lock": "perception_sources.lock.json",
84
+ "source_lock_sha256": "0a7da2033dc2007207c9dc77e5e36172ec01fe2ed2a286501b48e169ce6dce8b",
85
+ "video_only_episodes": 25
86
+ }
scripts/perception_sources.lock.json ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "schema_version": 1,
3
+ "coverage": {
4
+ "benchmark_episodes": 100,
5
+ "robot_episodes": 75,
6
+ "video_only_episodes": 25,
7
+ "video_only_subset": "HomER"
8
+ },
9
+ "annotation_sources": {
10
+ "droid": {
11
+ "repo_id": "macrodata/robointer-droid-50-subtask-annotations",
12
+ "revision": "39342b5e3a7603748d97fbfe25aa0e54e6b45326",
13
+ "parquet_path": "data/annotations.parquet"
14
+ },
15
+ "galaxea": {
16
+ "repo_id": "macrodata/robocoin-galaxea-head-25-subtask-annotations",
17
+ "revision": "e974f9bd6c6cb46289fd54586c10385f43f0ec6e",
18
+ "parquet_path": "data/annotations.parquet"
19
+ }
20
+ },
21
+ "upstream_revisions": {
22
+ "InternRobotics/RoboInter-Data": "0208b79c34eca4d214cdb5d07f5ae0f7cc634340",
23
+ "RoboCOIN/Galaxea_R1_Lite_change_baai_into_brain": "98393798142b2b99a386d9bbc8ca9a6a8cdd5d5c",
24
+ "RoboCOIN/Galaxea_R1_Lite_classify_object_four": "1b8fbd8d24b9ca70476b2945e8bd61b8a3ab2ad2",
25
+ "RoboCOIN/Galaxea_R1_Lite_classify_object_green_tablecloth": "e99edefc3df9f0864d1cadc81af60e916b8dcf74",
26
+ "RoboCOIN/Galaxea_R1_Lite_classify_object_six": "ffcb9eba5977763d6bc0ddfca6f99e4213d42ad4",
27
+ "RoboCOIN/Galaxea_R1_Lite_classify_object_three": "cd40bb70b6d943c644f643fbe9fabefedee24e69",
28
+ "RoboCOIN/Galaxea_R1_Lite_mix_color_small_test_tube": "03649ca80d0349b7369f0ed2b3c225eb3959d35d",
29
+ "RoboCOIN/Galaxea_R1_Lite_mix_red_blue_left_large_test_tube": "6257a59fc9b74059295460f8c00cba3d21bcfe74",
30
+ "RoboCOIN/Galaxea_R1_Lite_mix_red_yellow_large_test_tube": "a7eae049447f13ecf936305460feabb120b033bb",
31
+ "RoboCOIN/Galaxea_R1_Lite_mix_red_yellow_left_large_test_tube": "f32383071e90569802df0ac52de690d4908c4e64",
32
+ "RoboCOIN/Galaxea_R1_Lite_mix_red_yellow_right": "696a2d3a867ccc3a7cef7eb0d12924b8737ee297",
33
+ "RoboCOIN/Galaxea_R1_Lite_move_mouse": "cc841d0478cb2b95ea41396b93b17310f74d341c",
34
+ "RoboCOIN/Galaxea_R1_Lite_pour_liquid_mrable_bar_counter": "879dcddeccf12315577791bfff24f585eb2efdda",
35
+ "RoboCOIN/Galaxea_R1_Lite_pour_powder_marble_bar_counter": "e76ae5ae555f30b2cf79e4fec049c1101ec81c14",
36
+ "RoboCOIN/Galaxea_R1_Lite_pour_solid": "5e856053cd65e3c383cbb3c96a4ace230399073b",
37
+ "RoboCOIN/Galaxea_R1_Lite_pour_solid_marble_bar_counter": "28958bd97ad782a850d3282b3a7535ce9809fbed",
38
+ "RoboCOIN/Galaxea_R1_Lite_pour_water_black_tablecloth": "e67c5774c4b961393ade0769ec8072e7cab76f8d",
39
+ "RoboCOIN/Galaxea_R1_Lite_storage_object_brown_bowl": "d518e4efd84024e20a8108ec40ab668c47e6b277",
40
+ "RoboCOIN/Galaxea_R1_Lite_storage_object_brown_plate": "4acca05909f7d52845c0569bf699b77de30b820a",
41
+ "RoboCOIN/Galaxea_R1_Lite_storage_object_dish": "39525f063a9b1b158f8b7152be76b3d6cad1935d",
42
+ "RoboCOIN/Galaxea_R1_Lite_storage_object_gray_plate": "88bd99242337b756f1ebb9ccb4d363731abf8576",
43
+ "RoboCOIN/Galaxea_R1_Lite_storage_object_pink_bowl": "eaad5ed3a6087907d2d64495b437ff7911314b51",
44
+ "RoboCOIN/Galaxea_R1_Lite_storage_object_white_box": "817a191f19f6c9bdc64f620869d10b7343f240d0",
45
+ "RoboCOIN/Galaxea_R1_Lite_storage_object_yellow_basket": "d12c143bf81dd56a535ef5e2483c50712463cae5",
46
+ "RoboCOIN/Galaxea_R1_Lite_toggle_drawer_red": "bd2fb11362203299f0b95aa07e33975e3141cd04",
47
+ "RoboCOIN/Galaxea_R1_Lite_toggle_drawer_yellow": "1676795e4c0bb4ce786243a6711a1b3dc4f7346f"
48
+ }
49
+ }
scripts/perception_states.py ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import hashlib
5
+ import io
6
+ import json
7
+ import tarfile
8
+ from pathlib import Path
9
+ from typing import Any, Iterable
10
+
11
+ import pyarrow as pa
12
+ import pyarrow.parquet as pq
13
+ from huggingface_hub import hf_hub_download
14
+
15
+
16
+ LOCK_PATH = Path(__file__).with_name("perception_sources.lock.json")
17
+ PRIMARY_STATE_COLUMNS = ("observation.state", "state")
18
+
19
+
20
+ def load_source_lock(path: Path = LOCK_PATH) -> dict[str, Any]:
21
+ lock = json.loads(path.read_text(encoding="utf-8"))
22
+ if lock.get("schema_version") != 1:
23
+ raise ValueError(f"Unsupported perception-source lock schema: {lock.get('schema_version')!r}")
24
+ return lock
25
+
26
+
27
+ def discover_robot_episodes(lock: dict[str, Any], cache_dir: Path | None = None) -> list[dict[str, Any]]:
28
+ episodes: list[dict[str, Any]] = []
29
+ for source_name, source in lock["annotation_sources"].items():
30
+ parquet_path = _download(
31
+ source["repo_id"], source["revision"], source["parquet_path"], cache_dir
32
+ )
33
+ for row in pq.read_table(parquet_path).to_pylist():
34
+ if source_name == "droid":
35
+ repo_id = row["source_dataset"]
36
+ episode_index = int(row["episode_index"])
37
+ episodes.append(
38
+ {
39
+ "bench_id": row["bench_id"],
40
+ "robot_family": "droid",
41
+ "repo_id": repo_id,
42
+ "revision": lock["upstream_revisions"][repo_id],
43
+ "episode_index": episode_index,
44
+ "fps": float(row["fps"]),
45
+ "expected_num_frames": int(row["num_frames"]),
46
+ "source_subset": row["source_subset"],
47
+ "data_path": f"{row['source_subset']}/data/chunk-000.tar",
48
+ "tar_member": f"chunk-000/episode_{episode_index:06d}.parquet",
49
+ "info_path": f"{row['source_subset']}/meta/info.json",
50
+ }
51
+ )
52
+ elif source_name == "galaxea":
53
+ repo_id = row["source_dataset"]
54
+ episode_index = int(row["source_episode_index"])
55
+ episodes.append(
56
+ {
57
+ "bench_id": row["bench_id"],
58
+ "robot_family": "galaxea",
59
+ "repo_id": repo_id,
60
+ "revision": lock["upstream_revisions"][repo_id],
61
+ "episode_index": episode_index,
62
+ "fps": float(row["fps"]),
63
+ "expected_num_frames": int(row["num_frames"]),
64
+ "data_path": f"data/chunk-000/episode_{episode_index:06d}.parquet",
65
+ "info_path": "meta/info.json",
66
+ }
67
+ )
68
+ else:
69
+ raise ValueError(f"Unknown annotation source {source_name!r}")
70
+
71
+ episodes.sort(key=lambda item: item["bench_id"])
72
+ bench_ids = [item["bench_id"] for item in episodes]
73
+ if len(bench_ids) != len(set(bench_ids)):
74
+ raise ValueError("Duplicate bench_id in robotic source mappings")
75
+ expected = int(lock["coverage"]["robot_episodes"])
76
+ if len(episodes) != expected:
77
+ raise ValueError(f"Expected {expected} robotic episodes, found {len(episodes)}")
78
+ return episodes
79
+
80
+
81
+ def normalize_episode(
82
+ table: pa.Table,
83
+ episode: dict[str, Any],
84
+ feature_info: dict[str, Any],
85
+ ) -> dict[str, Any]:
86
+ columns = set(table.column_names)
87
+ primary = next((name for name in PRIMARY_STATE_COLUMNS if name in columns), None)
88
+ if primary is None:
89
+ raise ValueError(f"{episode['bench_id']} has no supported proprioception column")
90
+ if "frame_index" not in columns or "timestamp" not in columns:
91
+ raise ValueError(f"{episode['bench_id']} is missing frame_index or timestamp")
92
+
93
+ frame_index = [int(_scalar(value)) for value in table["frame_index"].to_pylist()]
94
+ timestamps = [float(_scalar(value)) for value in table["timestamp"].to_pylist()]
95
+ if frame_index != sorted(frame_index) or timestamps != sorted(timestamps):
96
+ raise ValueError(f"{episode['bench_id']} state rows are not ordered")
97
+ if len(frame_index) != episode["expected_num_frames"]:
98
+ raise ValueError(
99
+ f"{episode['bench_id']} expected {episode['expected_num_frames']} frames, "
100
+ f"found {len(frame_index)} state rows"
101
+ )
102
+
103
+ channel_names = [primary]
104
+ channel_names.extend(
105
+ sorted(name for name in columns if name.endswith("_state") and name != primary)
106
+ )
107
+ channels = []
108
+ for name in channel_names:
109
+ values = [_vector(value) for value in table[name].to_pylist()]
110
+ names = list((feature_info.get(name) or {}).get("names") or [])
111
+ width = len(values[0]) if values else 0
112
+ if any(len(value) != width for value in values):
113
+ raise ValueError(f"{episode['bench_id']} channel {name!r} changes width")
114
+ if names and len(names) != width:
115
+ raise ValueError(f"{episode['bench_id']} channel {name!r} names do not match width")
116
+ if not names:
117
+ names = [f"value_{index}" for index in range(width)]
118
+ channels.append({"name": name, "value_names": names, "values": values})
119
+
120
+ return {
121
+ "bench_id": episode["bench_id"],
122
+ "robot_family": episode["robot_family"],
123
+ "source_dataset": episode["repo_id"],
124
+ "source_revision": episode["revision"],
125
+ "source_episode_index": episode["episode_index"],
126
+ "fps": episode["fps"],
127
+ "num_frames": len(frame_index),
128
+ "frame_index": frame_index,
129
+ "timestamp_sec": timestamps,
130
+ "primary_channel": primary,
131
+ "channels": channels,
132
+ }
133
+
134
+
135
+ def export_perception_states(
136
+ output_path: Path,
137
+ *,
138
+ lock_path: Path = LOCK_PATH,
139
+ cache_dir: Path | None = None,
140
+ bench_ids: Iterable[str] | None = None,
141
+ ) -> dict[str, Any]:
142
+ lock = load_source_lock(lock_path)
143
+ episodes = discover_robot_episodes(lock, cache_dir)
144
+ selected = set(bench_ids or [])
145
+ if selected:
146
+ known = {episode["bench_id"] for episode in episodes}
147
+ unknown = selected - known
148
+ if unknown:
149
+ raise ValueError(f"Unknown robotic bench IDs: {sorted(unknown)}")
150
+ episodes = [episode for episode in episodes if episode["bench_id"] in selected]
151
+
152
+ rows = []
153
+ for episode in episodes:
154
+ table, feature_info = _load_episode(episode, cache_dir)
155
+ rows.append(normalize_episode(table, episode, feature_info))
156
+
157
+ output_path.parent.mkdir(parents=True, exist_ok=True)
158
+ table = pa.Table.from_pylist(rows, schema=perception_schema())
159
+ pq.write_table(table, output_path, compression="zstd")
160
+ digest = hashlib.sha256(output_path.read_bytes()).hexdigest()
161
+ provenance = {
162
+ "schema_version": 1,
163
+ "artifact": output_path.name,
164
+ "sha256": digest,
165
+ "episodes": len(rows),
166
+ "bench_ids": [row["bench_id"] for row in rows],
167
+ "source_lock": lock_path.name,
168
+ "source_lock_sha256": hashlib.sha256(lock_path.read_bytes()).hexdigest(),
169
+ "video_only_episodes": lock["coverage"]["video_only_episodes"],
170
+ }
171
+ provenance_path = output_path.with_suffix(output_path.suffix + ".provenance.json")
172
+ provenance_path.write_text(json.dumps(provenance, indent=2) + "\n", encoding="utf-8")
173
+ return provenance
174
+
175
+
176
+ def perception_schema() -> pa.Schema:
177
+ return pa.schema(
178
+ [
179
+ ("bench_id", pa.string()),
180
+ ("robot_family", pa.string()),
181
+ ("source_dataset", pa.string()),
182
+ ("source_revision", pa.string()),
183
+ ("source_episode_index", pa.int64()),
184
+ ("fps", pa.float64()),
185
+ ("num_frames", pa.int64()),
186
+ ("frame_index", pa.list_(pa.int64())),
187
+ ("timestamp_sec", pa.list_(pa.float64())),
188
+ ("primary_channel", pa.string()),
189
+ (
190
+ "channels",
191
+ pa.list_(
192
+ pa.struct(
193
+ [
194
+ ("name", pa.string()),
195
+ ("value_names", pa.list_(pa.string())),
196
+ ("values", pa.list_(pa.list_(pa.float64()))),
197
+ ]
198
+ )
199
+ ),
200
+ ),
201
+ ]
202
+ )
203
+
204
+
205
+ def _load_episode(episode: dict[str, Any], cache_dir: Path | None) -> tuple[pa.Table, dict[str, Any]]:
206
+ info_path = _download(
207
+ episode["repo_id"], episode["revision"], episode["info_path"], cache_dir
208
+ )
209
+ feature_info = json.loads(info_path.read_text(encoding="utf-8")).get("features", {})
210
+ data_path = _download(
211
+ episode["repo_id"], episode["revision"], episode["data_path"], cache_dir
212
+ )
213
+ if episode.get("tar_member"):
214
+ with tarfile.open(data_path) as archive:
215
+ member = archive.extractfile(episode["tar_member"])
216
+ if member is None:
217
+ raise FileNotFoundError(episode["tar_member"])
218
+ table = pq.read_table(io.BytesIO(member.read()))
219
+ else:
220
+ table = pq.read_table(data_path)
221
+ return table, feature_info
222
+
223
+
224
+ def _download(repo_id: str, revision: str, filename: str, cache_dir: Path | None) -> Path:
225
+ return Path(
226
+ hf_hub_download(
227
+ repo_id=repo_id,
228
+ repo_type="dataset",
229
+ revision=revision,
230
+ filename=filename,
231
+ cache_dir=str(cache_dir) if cache_dir else None,
232
+ )
233
+ )
234
+
235
+
236
+ def _scalar(value: Any) -> Any:
237
+ if isinstance(value, (list, tuple)):
238
+ if len(value) != 1:
239
+ raise ValueError(f"Expected a scalar or one-element sequence, got {value!r}")
240
+ return value[0]
241
+ return value
242
+
243
+
244
+ def _vector(value: Any) -> list[float]:
245
+ if value is None:
246
+ return []
247
+ if not isinstance(value, (list, tuple)):
248
+ value = [value]
249
+ return [float(item) for item in value]
250
+
251
+
252
+ def main() -> None:
253
+ parser = argparse.ArgumentParser(
254
+ description="Export pinned proprioception sidecars for WGO-Bench robotic episodes."
255
+ )
256
+ parser.add_argument("output", type=Path)
257
+ parser.add_argument("--lock", type=Path, default=LOCK_PATH)
258
+ parser.add_argument("--cache-dir", type=Path)
259
+ parser.add_argument("--bench-id", action="append", default=[])
260
+ args = parser.parse_args()
261
+ result = export_perception_states(
262
+ args.output,
263
+ lock_path=args.lock,
264
+ cache_dir=args.cache_dir,
265
+ bench_ids=args.bench_id,
266
+ )
267
+ print(json.dumps(result, indent=2))
268
+
269
+
270
+ if __name__ == "__main__":
271
+ main()