Publish verified compact target-aware graph loader v3.0.7
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- README.md +117 -20
- ROOT_MANIFEST_V307.json +0 -0
- SCHEMA.md +20 -9
- V307_UPLOAD_ALLOWLIST.json +593 -0
- gwam_active13_gwam_training_v3_20260801/AGENT_HANDOFF_COMPACT_V305.md +3 -0
- gwam_active13_gwam_training_v3_20260801/AGENT_HANDOFF_COMPACT_V306.md +3 -0
- gwam_active13_gwam_training_v3_20260801/AGENT_HANDOFF_COMPACT_V307.md +19 -0
- gwam_active13_gwam_training_v3_20260801/DATASET_SUMMARY.json +44 -0
- gwam_active13_gwam_training_v3_20260801/GUIDE_GNN_AND_GWAM_TRAINING.md +86 -0
- gwam_active13_gwam_training_v3_20260801/PACKAGE_MANIFEST.json +410 -0
- gwam_active13_gwam_training_v3_20260801/README.md +415 -0
- gwam_active13_gwam_training_v3_20260801/SCHEMA.md +81 -0
- gwam_active13_gwam_training_v3_20260801/TRAINING_EPISODES.jsonl +0 -0
- gwam_active13_gwam_training_v3_20260801/V306_TIMESTAMP_DEFECT_AUDIT.json +12 -0
- gwam_active13_gwam_training_v3_20260801/V307_COMPLETE_DATA_READINESS_RECEIPT.md +15 -0
- gwam_active13_gwam_training_v3_20260801/V307_MIGRATION.md +15 -0
- gwam_active13_gwam_training_v3_20260801/VALIDATION_RECEIPT.json +145 -0
- gwam_active13_gwam_training_v3_20260801/WINDOW_LEGALITY_INDEX_V307.jsonl +0 -0
- gwam_active13_gwam_training_v3_20260801/WINDOW_LEGALITY_SUMMARY_V307.json +16 -0
- gwam_active13_gwam_training_v3_20260801/examples/buffered_compact_target_aware_eval.py +171 -0
- gwam_active13_gwam_training_v3_20260801/examples/compact_gwam_conditioning_cpu.py +14 -0
- gwam_active13_gwam_training_v3_20260801/examples/download_compact_example.py +44 -0
- gwam_active13_gwam_training_v3_20260801/examples/download_training_closure.py +175 -0
- gwam_active13_gwam_training_v3_20260801/examples/gnn_loss_dry_run.py +23 -0
- gwam_active13_gwam_training_v3_20260801/examples/inspect_compact_frame.py +18 -0
- gwam_active13_gwam_training_v3_20260801/examples/model_neutral_graph_examples.py +93 -0
- gwam_active13_gwam_training_v3_20260801/examples/pair_graph_rgb.py +10 -0
- gwam_active13_gwam_training_v3_20260801/examples/robocasa_live_compact_eval.py +74 -0
- gwam_active13_gwam_training_v3_20260801/loader/__init__.py +2 -0
- gwam_active13_gwam_training_v3_20260801/loader/compact_collate.py +271 -0
- gwam_active13_gwam_training_v3_20260801/loader/compact_contract.py +836 -0
- gwam_active13_gwam_training_v3_20260801/loader/compact_target_aware_gwam_training_dataset.py +286 -0
- gwam_active13_gwam_training_v3_20260801/loader/direct_compact_source.py +1584 -0
- gwam_active13_gwam_training_v3_20260801/loader/gwam_conditioning.py +42 -0
- gwam_active13_gwam_training_v3_20260801/loader/online_compact_adapter.py +516 -0
- gwam_active13_gwam_training_v3_20260801/loader/per_frame.py +51 -0
- gwam_active13_gwam_training_v3_20260801/loader/relation_geometry.py +179 -0
- gwam_active13_gwam_training_v3_20260801/loader/rgb_pairing.py +64 -0
- gwam_active13_gwam_training_v3_20260801/loader/robocasa_live_compact.py +154 -0
- gwam_active13_gwam_training_v3_20260801/loader/robocasa_mujoco_compact.py +259 -0
- gwam_active13_gwam_training_v3_20260801/loader/sealed_model_regression.py +150 -0
- gwam_active13_gwam_training_v3_20260801/loader/temporal_precision.py +83 -0
- gwam_active13_gwam_training_v3_20260801/loader/variable_n.py +71 -0
- gwam_active13_gwam_training_v3_20260801/model_v2_0_4/README.md +20 -0
- gwam_active13_gwam_training_v3_20260801/model_v2_0_4/__init__.py +46 -0
- gwam_active13_gwam_training_v3_20260801/model_v2_0_4/batch.py +544 -0
- gwam_active13_gwam_training_v3_20260801/model_v2_0_4/config.py +157 -0
- gwam_active13_gwam_training_v3_20260801/model_v2_0_4/controls.py +168 -0
- gwam_active13_gwam_training_v3_20260801/model_v2_0_4/geometry.py +339 -0
- gwam_active13_gwam_training_v3_20260801/model_v2_0_4/interventions.py +338 -0
README.md
CHANGED
|
@@ -18,22 +18,47 @@ tags:
|
|
| 18 |
pretty_name: GWAM_Data
|
| 19 |
---
|
| 20 |
|
| 21 |
-
# GWAM_Data — verified 10-task compact target-aware graph v3.0.
|
| 22 |
|
| 23 |
-
This upload tree is the
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
## Cold bootstrap
|
| 26 |
|
| 27 |
-
Install `huggingface_hub` and the `hf` CLI, then retrieve this v3.0.
|
| 28 |
|
| 29 |
~~~bash
|
| 30 |
python -m pip install huggingface_hub
|
| 31 |
-
hf download ChangChrisLiu/GWAM_Data --repo-type dataset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
~~~
|
| 33 |
|
| 34 |
## Start here: run the dataloader to get the correct compact graph
|
| 35 |
|
| 36 |
-
**AI/coding agents:** start with the exact [agent handoff](
|
| 37 |
|
| 38 |
Download stored graph ZIP + target receipt (+ OpenDrawer C2)
|
| 39 |
→ run DirectCompactGWAMDatasetV3
|
|
@@ -71,15 +96,15 @@ The model-neutral examples/download_training_closure.py helper verifies every so
|
|
| 71 |
The full 2,699-source-ZIP closure is 20,339,307,035 bytes (20.339 GB, 18.942 GiB), plus receipts, package files, Hub cache, and filesystem overhead.
|
| 72 |
|
| 73 |
~~~bash
|
| 74 |
-
python -m pip install -r
|
| 75 |
# Bootstrap package/index, then plan two rows without downloading source closure.
|
| 76 |
-
python
|
| 77 |
-
python
|
| 78 |
# Two-row real closure, then task-filtered example:
|
| 79 |
-
python
|
| 80 |
-
python
|
| 81 |
# Full approved closure (2,699 episodes): warn about storage before running.
|
| 82 |
-
python
|
| 83 |
~~~
|
| 84 |
|
| 85 |
### Direct model-neutral construction
|
|
@@ -87,7 +112,7 @@ python gwam_active13_gwam_training_v3_20260731/examples/download_training_closur
|
|
| 87 |
From the directory containing `GWAM_training_closure` after the cold bootstrap:
|
| 88 |
|
| 89 |
~~~bash
|
| 90 |
-
cd ./GWAM_training_closure/
|
| 91 |
export PYTHONPATH="$PWD${PYTHONPATH:+:$PYTHONPATH}"
|
| 92 |
~~~
|
| 93 |
|
|
@@ -110,7 +135,29 @@ frame0 = select_frame(example, 0)
|
|
| 110 |
print(example.packet, example.action, example.targets, example.provenance)
|
| 111 |
~~~
|
| 112 |
|
| 113 |
-
For OpenDrawer,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
### Returned fields, storage, and batching
|
| 116 |
|
|
@@ -183,11 +230,11 @@ The adapter packs active nodes with flatnonzero(node_valid), builds an old-to-ne
|
|
| 183 |
The approved outer-train corpus contains **2,699 episodes** and **702,094 L=8/H=8 windows**, covering **79.7% of the ten-task source population**. Immutable source ZIPs plus authenticated target receipts (and OpenDrawer C2 when selected) are read by the strict compact loader as variable-N graph history, logged actions, and targets; `encode_compact_to_k16` produces `K=16` tokens of width 384 for the sealed GWAM conditioning seam. Target-to-loss heads and optimizer authorization are separate gates; no optimizer is bundled or run.
|
| 184 |
|
| 185 |
```bash
|
| 186 |
-
python
|
| 187 |
-
--revision gwam-compact-target-v3.0.
|
| 188 |
-
PYTHONPATH=./GWAM_compact_example/
|
| 189 |
python \
|
| 190 |
-
./GWAM_compact_example/
|
| 191 |
--root ./GWAM_compact_example
|
| 192 |
```
|
| 193 |
|
|
@@ -211,6 +258,33 @@ graph_off = seam(latent, k16, mode="off")
|
|
| 211 |
graph_on = seam(latent, k16, mode="on")
|
| 212 |
```
|
| 213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
### Actual-rollout validation by online extraction
|
| 215 |
|
| 216 |
No held-out offline validation package is required. RoboCasa live MuJoCo state and three synchronized RGB streams are read by `RoboCasaMuJoCoCompactReaderV3`; an authenticated reset capability is required; one compact graph/frame is appended to `CompactOnlineHistoryBufferV3` for L=8, then encoded to K=16. Only `env.step(action)` advances the simulator, and future graph/RGB frames are never model inputs.
|
|
@@ -218,18 +292,41 @@ No held-out offline validation package is required. RoboCasa live MuJoCo state a
|
|
| 218 |
```bash
|
| 219 |
CUDA_VISIBLE_DEVICES=0 MUJOCO_GL=egl PYOPENGL_PLATFORM=egl PYTHONPATH=. \
|
| 220 |
python \
|
| 221 |
-
|
| 222 |
--task PickPlaceCabinetToCounter --split target --steps 8 \
|
| 223 |
--output live_summary.json --rgb-npy live_rgb.npy
|
| 224 |
|
| 225 |
CUDA_VISIBLE_DEVICES=0 MUJOCO_GL=egl PYOPENGL_PLATFORM=egl PYTHONPATH=. \
|
| 226 |
python \
|
| 227 |
-
|
| 228 |
--task OpenDrawer --split target --steps 8 \
|
| 229 |
--c2-receipt gwam_active13_c2_v2_0_5_20260731/C2_CAPABILITY_RECEIPT.json \
|
| 230 |
--output open_drawer_live_summary.json
|
| 231 |
```
|
| 232 |
|
| 233 |
-
The live contract is one physical graph with three camera records (RGB is a separate side channel), variable `N<=256`, optional non-authoritative 46-D convenience values, `K=16`, and no SAM2, CLIP, public masks, velocity, or qvel. Use the [current compact README](
|
| 234 |
|
| 235 |
Immutable dependency bindings are the outer-train manifest SHA256 `8e33045badf338ca7f0b802b689dc74765e392014df6b9c3f8f0413d4f9b44f3` and OpenDrawer C2 index SHA256 `e7fec3656d6e479a16698f1a96aafb8b6562e99a344d568de4b58e79f76aad26`. Source ZIPs, sidecars, and RGB remain immutable and separate. Historical/older root documentation is preserved verbatim in [`docs/README_PRE_V305_ARCHIVE_20260731.md`](docs/README_PRE_V305_ARCHIVE_20260731.md).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
pretty_name: GWAM_Data
|
| 19 |
---
|
| 20 |
|
| 21 |
+
# GWAM_Data — verified 10-task compact target-aware graph v3.0.7
|
| 22 |
|
| 23 |
+
This upload tree is the verified local v3.0.7 compact dataset/interface successor and its offline-training/live-rollout-validation workflow. It is an additive docs/code/support release over the same immutable 10-task Active-13 source lineage—not a new graph corpus, not complete Active-13 coverage, and publication does not authorize training. The v3.0.6 tag and prefix remain byte-immutable historical evidence; the intended new immutable tag is `gwam-compact-target-v3.0.7-20260801`.
|
| 24 |
+
|
| 25 |
+
## Frozen v3.0.7 release evidence
|
| 26 |
+
|
| 27 |
+
The exhaustive production-loader gate is **PASS** over all **2,699 episodes**, **742,579 frames**, and **702,094 legal `L=8,H=8` windows**, with zero load errors, missing artifacts, or hash mismatches. The exact copied gate bytes are included under `gwam_v307_release_receipts_20260801/`:
|
| 28 |
+
|
| 29 |
+
| Evidence | SHA-256 |
|
| 30 |
+
|---|---|
|
| 31 |
+
| `EXHAUSTIVE_GATE_V307_SUMMARY.json` | `50fcb04f9c21d84efd4ef4a8da2b6a04d4f60a5d7bababce3047fc240629a7bf` |
|
| 32 |
+
| `EXHAUSTIVE_GATE_V307_INDEX.json` | `73d647fbcadab7df8139445c2701f7a8e1a6bc6126a4e3bf97cdb56892f6336e` |
|
| 33 |
+
| `EXHAUSTIVE_GATE_V307_PROGRESS.jsonl` | `f62cc5f79c4065e35978f7dad1ba4e83b51a020309db07191c185551fed40e4d` |
|
| 34 |
+
| v3.0.7 `PACKAGE_MANIFEST.json` | `ce640f15cf0f8a29b4afddc7bf7662fbb4c392c3c1a970252b5342f7e5dc36e3` |
|
| 35 |
+
| `TRAINING_EPISODES.jsonl` | `f54a19de57bb3bd281b119f581762b132ded38cd298b3f7955c1de1217232b00` |
|
| 36 |
+
| outer-train manifest | `8e33045badf338ca7f0b802b689dc74765e392014df6b9c3f8f0413d4f9b44f3` |
|
| 37 |
+
| OpenDrawer C2 episode index | `e7fec3656d6e479a16698f1a96aafb8b6562e99a344d568de4b58e79f76aad26` |
|
| 38 |
+
|
| 39 |
+
Scope is exactly ten verified tasks and excludes `TurnOffStove`, `TurnOnMicrowave`, and `TurnOnSinkFaucet`. The release inherits all 2,699 source ZIPs and target receipts plus 409 OpenDrawer C2 receipts from the unchanged parent; it adds a new package namespace, receipts, and standalone compatibility examples. It never overwrites an inherited prefix.
|
| 40 |
|
| 41 |
## Cold bootstrap
|
| 42 |
|
| 43 |
+
Install `huggingface_hub` and the `hf` CLI, then retrieve this v3.0.7 package before running any examples:
|
| 44 |
|
| 45 |
~~~bash
|
| 46 |
python -m pip install huggingface_hub
|
| 47 |
+
hf download ChangChrisLiu/GWAM_Data --repo-type dataset \
|
| 48 |
+
--revision gwam-compact-target-v3.0.7-20260801 \
|
| 49 |
+
--include 'README.md' --include 'SCHEMA.md' \
|
| 50 |
+
--include 'gwam_active13_gwam_training_v3_20260801/*' \
|
| 51 |
+
--include 'gwam_v307_release_receipts_20260801/*' \
|
| 52 |
+
--include 'gwam_v307_gnn_training_examples_20260802/*' \
|
| 53 |
+
--include 'gwam_active13_target_physical_v2_0_1_20260731/census/OUTER_TRAIN_MANIFEST.jsonl' \
|
| 54 |
+
--include 'gwam_active13_c2_v2_0_5_20260731/C2_CAPABILITY_RECEIPT.json' \
|
| 55 |
+
--include 'gwam_active13_c2_v2_0_5_20260731/C2_EPISODE_INDEX.jsonl' \
|
| 56 |
+
--include 'docs/assets/*' --local-dir ./GWAM_training_closure
|
| 57 |
~~~
|
| 58 |
|
| 59 |
## Start here: run the dataloader to get the correct compact graph
|
| 60 |
|
| 61 |
+
**AI/coding agents:** start with the exact [agent handoff](gwam_active13_gwam_training_v3_20260801/AGENT_HANDOFF_COMPACT_V307.md), then retrieve its linked README/SCHEMA/GUIDE/source details.
|
| 62 |
|
| 63 |
Download stored graph ZIP + target receipt (+ OpenDrawer C2)
|
| 64 |
→ run DirectCompactGWAMDatasetV3
|
|
|
|
| 96 |
The full 2,699-source-ZIP closure is 20,339,307,035 bytes (20.339 GB, 18.942 GiB), plus receipts, package files, Hub cache, and filesystem overhead.
|
| 97 |
|
| 98 |
~~~bash
|
| 99 |
+
python -m pip install -r gwam_active13_gwam_training_v3_20260801/requirements.txt
|
| 100 |
# Bootstrap package/index, then plan two rows without downloading source closure.
|
| 101 |
+
python gwam_active13_gwam_training_v3_20260801/examples/download_compact_example.py --revision gwam-compact-target-v3.0.7-20260801 --root ./GWAM_training_closure --row 0
|
| 102 |
+
python gwam_active13_gwam_training_v3_20260801/examples/download_training_closure.py --root ./GWAM_training_closure --limit 2 --dry-run
|
| 103 |
# Two-row real closure, then task-filtered example:
|
| 104 |
+
python gwam_active13_gwam_training_v3_20260801/examples/download_training_closure.py --root ./GWAM_training_closure --limit 2 --workers 2
|
| 105 |
+
python gwam_active13_gwam_training_v3_20260801/examples/download_training_closure.py --root ./GWAM_training_closure --task OpenDrawer --limit 2 --workers 2
|
| 106 |
# Full approved closure (2,699 episodes): warn about storage before running.
|
| 107 |
+
python gwam_active13_gwam_training_v3_20260801/examples/download_training_closure.py --root ./GWAM_training_closure --workers 4
|
| 108 |
~~~
|
| 109 |
|
| 110 |
### Direct model-neutral construction
|
|
|
|
| 112 |
From the directory containing `GWAM_training_closure` after the cold bootstrap:
|
| 113 |
|
| 114 |
~~~bash
|
| 115 |
+
cd ./GWAM_training_closure/gwam_active13_gwam_training_v3_20260801
|
| 116 |
export PYTHONPATH="$PWD${PYTHONPATH:+:$PYTHONPATH}"
|
| 117 |
~~~
|
| 118 |
|
|
|
|
| 135 |
print(example.packet, example.action, example.targets, example.provenance)
|
| 136 |
~~~
|
| 137 |
|
| 138 |
+
For OpenDrawer, download the exact ZIP, target receipt, and indexed C2 receipt named by the selected row, then use the same production loader with the C2 join. Missing or mismatched C2 fails closed:
|
| 139 |
+
|
| 140 |
+
~~~python
|
| 141 |
+
import json
|
| 142 |
+
|
| 143 |
+
rows = [json.loads(line) for line in (PACKAGE_ROOT / "TRAINING_EPISODES.jsonl").read_text().splitlines() if line]
|
| 144 |
+
drawer_row = next(row for row in rows if row["task"] == "OpenDrawer")
|
| 145 |
+
dataset_with_c2 = DirectCompactGWAMDatasetV3(
|
| 146 |
+
root,
|
| 147 |
+
outer_manifest_path=outer,
|
| 148 |
+
outer_manifest_sha256="8e33045badf338ca7f0b802b689dc74765e392014df6b9c3f8f0413d4f9b44f3",
|
| 149 |
+
c2_root=root / "gwam_active13_c2_v2_0_5_20260731",
|
| 150 |
+
c2_index_path=root / "gwam_active13_c2_v2_0_5_20260731/C2_EPISODE_INDEX.jsonl",
|
| 151 |
+
c2_index_sha256="e7fec3656d6e479a16698f1a96aafb8b6562e99a344d568de4b58e79f76aad26",
|
| 152 |
+
)
|
| 153 |
+
drawer_episode_index = next(
|
| 154 |
+
i for i in range(dataset_with_c2.episode_count)
|
| 155 |
+
if dataset_with_c2.episode_metadata(i)["episode_key"] == drawer_row["episode_key"]
|
| 156 |
+
)
|
| 157 |
+
drawer_example = dataset_with_c2.load_episode_window(drawer_episode_index, 0)
|
| 158 |
+
drawer_example.validate()
|
| 159 |
+
assert drawer_example.provenance.c2_receipt_sha256[0]
|
| 160 |
+
~~~
|
| 161 |
|
| 162 |
### Returned fields, storage, and batching
|
| 163 |
|
|
|
|
| 230 |
The approved outer-train corpus contains **2,699 episodes** and **702,094 L=8/H=8 windows**, covering **79.7% of the ten-task source population**. Immutable source ZIPs plus authenticated target receipts (and OpenDrawer C2 when selected) are read by the strict compact loader as variable-N graph history, logged actions, and targets; `encode_compact_to_k16` produces `K=16` tokens of width 384 for the sealed GWAM conditioning seam. Target-to-loss heads and optimizer authorization are separate gates; no optimizer is bundled or run.
|
| 231 |
|
| 232 |
```bash
|
| 233 |
+
python gwam_active13_gwam_training_v3_20260801/examples/download_compact_example.py \
|
| 234 |
+
--revision gwam-compact-target-v3.0.7-20260801 --root ./GWAM_compact_example --row 0
|
| 235 |
+
PYTHONPATH=./GWAM_compact_example/gwam_active13_gwam_training_v3_20260801 \
|
| 236 |
python \
|
| 237 |
+
./GWAM_compact_example/gwam_active13_gwam_training_v3_20260801/examples/compact_gwam_conditioning_cpu.py \
|
| 238 |
--root ./GWAM_compact_example
|
| 239 |
```
|
| 240 |
|
|
|
|
| 258 |
graph_on = seam(latent, k16, mode="on")
|
| 259 |
```
|
| 260 |
|
| 261 |
+
### Standalone GNN compatibility examples
|
| 262 |
+
|
| 263 |
+
`gwam_v307_gnn_training_examples_20260802/` is a path-portable, external compatibility example for the unchanged 54.357M-parameter `candidate_correct_target` model. It is outside the fingerprinted package manifest; the package itself contains no optimizer. Its schedule replays all 2,699 metadata rows, assigns whole source groups to **fit/tune/audit = 652/88/88 groups and 2,271/213/215 episodes**, and draws the five compatibility rows only from the 597,168 fit windows. The five rows are a boundary sample, not evidence of convergence, effectiveness, throughput, or readiness.
|
| 264 |
+
|
| 265 |
+
The adapter preserves one graph per frame, three camera-evidence records per node, variable `N`, authoritative typed masks, `future_action[B,8,12]`, and `K16[B,16,384]`. The output/loss binding is:
|
| 266 |
+
|
| 267 |
+
| Model output | Bound label | Mask | Compatibility loss |
|
| 268 |
+
|---|---|---|---|
|
| 269 |
+
| current position | `current_position` | current pose/node | masked Smooth-L1 |
|
| 270 |
+
| current rotation 6-D | quaternion XYZW | current pose/node | SO(3) geodesic |
|
| 271 |
+
| current articulation | `current_articulation_q` | articulation/node | masked Smooth-L1 |
|
| 272 |
+
| current visibility | camera visibility | record/node | masked BCE logits |
|
| 273 |
+
| current visible geometry | 3 cameras × 7 geometry | record and target-visible | masked Smooth-L1 |
|
| 274 |
+
| current pair occupancy | `current_contact` | pair/contact | masked BCE logits |
|
| 275 |
+
| current structural route | ordered-route relation | structural/route | masked cross-entropy |
|
| 276 |
+
| future position | `future_position_delta` | future pose/node | masked Smooth-L1 |
|
| 277 |
+
| future rotation | `future_rotation_log` | future pose/node | masked Smooth-L1 |
|
| 278 |
+
| future articulation | `future_articulation_delta` | articulation/node | masked Smooth-L1 |
|
| 279 |
+
| future visibility | future camera visibility | record/node | masked BCE logits |
|
| 280 |
+
| future visible geometry | future 3 × 7 geometry | record and target-visible | masked Smooth-L1 |
|
| 281 |
+
| future pair occupancy | `future_contact_occupancy` | future pair | masked BCE logits |
|
| 282 |
+
| future pair event | `future_contact_event_id` | event/pair | masked cross-entropy |
|
| 283 |
+
|
| 284 |
+
**Schedule warning:** `compatibility_all_supported_heads_v1` calls `compose_codec_loss` directly. It bypasses `compose_training_loss`, so five compatibility updates are **not** signed protocol updates 1–5 and do not exercise the current-codec-through-update-512 / future-term-at-update-513 phase boundary. That boundary remains separate, unexecuted training governance.
|
| 285 |
+
|
| 286 |
+
The portable CPU-only verification command is documented in the folder README and binds `V307_TRAINER_ROOT`, `V307_PACKAGE_ROOT`, `V307_DATA_ROOT`, `V307_OUTER_MANIFEST`, and `V307_C2_INDEX`. The live launcher remains locked to the named lab RTX 5090/SM120, BF16, CUDA 13.0, cuDNN 91900, deterministic, TF32-off environment. This release closure neither invokes that launcher nor constructs its optimizer.
|
| 287 |
+
|
| 288 |
### Actual-rollout validation by online extraction
|
| 289 |
|
| 290 |
No held-out offline validation package is required. RoboCasa live MuJoCo state and three synchronized RGB streams are read by `RoboCasaMuJoCoCompactReaderV3`; an authenticated reset capability is required; one compact graph/frame is appended to `CompactOnlineHistoryBufferV3` for L=8, then encoded to K=16. Only `env.step(action)` advances the simulator, and future graph/RGB frames are never model inputs.
|
|
|
|
| 292 |
```bash
|
| 293 |
CUDA_VISIBLE_DEVICES=0 MUJOCO_GL=egl PYOPENGL_PLATFORM=egl PYTHONPATH=. \
|
| 294 |
python \
|
| 295 |
+
gwam_active13_gwam_training_v3_20260801/examples/robocasa_live_compact_eval.py \
|
| 296 |
--task PickPlaceCabinetToCounter --split target --steps 8 \
|
| 297 |
--output live_summary.json --rgb-npy live_rgb.npy
|
| 298 |
|
| 299 |
CUDA_VISIBLE_DEVICES=0 MUJOCO_GL=egl PYOPENGL_PLATFORM=egl PYTHONPATH=. \
|
| 300 |
python \
|
| 301 |
+
gwam_active13_gwam_training_v3_20260801/examples/robocasa_live_compact_eval.py \
|
| 302 |
--task OpenDrawer --split target --steps 8 \
|
| 303 |
--c2-receipt gwam_active13_c2_v2_0_5_20260731/C2_CAPABILITY_RECEIPT.json \
|
| 304 |
--output open_drawer_live_summary.json
|
| 305 |
```
|
| 306 |
|
| 307 |
+
The live contract is one physical graph with three camera records (RGB is a separate side channel), variable `N<=256`, optional non-authoritative 46-D convenience values, `K=16`, and no SAM2, CLIP, public masks, velocity, or qvel. Use the [current compact README](gwam_active13_gwam_training_v3_20260801/README.md), [schema](gwam_active13_gwam_training_v3_20260801/SCHEMA.md), [guide](gwam_active13_gwam_training_v3_20260801/GUIDE_GNN_AND_GWAM_TRAINING.md), [direct loader](gwam_active13_gwam_training_v3_20260801/loader/compact_target_aware_gwam_training_dataset.py), and [live example](gwam_active13_gwam_training_v3_20260801/examples/robocasa_live_compact_eval.py).
|
| 308 |
|
| 309 |
Immutable dependency bindings are the outer-train manifest SHA256 `8e33045badf338ca7f0b802b689dc74765e392014df6b9c3f8f0413d4f9b44f3` and OpenDrawer C2 index SHA256 `e7fec3656d6e479a16698f1a96aafb8b6562e99a344d568de4b58e79f76aad26`. Source ZIPs, sidecars, and RGB remain immutable and separate. Historical/older root documentation is preserved verbatim in [`docs/README_PRE_V305_ARCHIVE_20260731.md`](docs/README_PRE_V305_ARCHIVE_20260731.md).
|
| 310 |
+
|
| 311 |
+
## Release verification and bounded-sample boundary
|
| 312 |
+
|
| 313 |
+
Before publication, validate the package manifest, acyclic root manifest, exact finite allowlist, copied exhaustive receipts, 90 package tests, and 85 non-live trainer tests. After an authorized additive CAS publication creates the new tag, verify it only from a fresh directory:
|
| 314 |
+
|
| 315 |
+
~~~bash
|
| 316 |
+
# Local release tree; these commands perform no Hub mutation.
|
| 317 |
+
python agent_workspace/gwam_gnn_restart_20260730/gwam_training_package_20260731/upload_tree/scripts/validate_root_manifest_v307.py
|
| 318 |
+
python agent_workspace/gwam_gnn_restart_20260730/publication_preparation/build_v307_final_allowlist.py \
|
| 319 |
+
--upload-tree agent_workspace/gwam_gnn_restart_20260730/gwam_training_package_20260731/upload_tree
|
| 320 |
+
|
| 321 |
+
# Fresh immutable-tag verification; use an absent/empty dedicated directory.
|
| 322 |
+
python agent_workspace/gwam_gnn_restart_20260730/publication_preparation/verify_v307_fresh_remote.py \
|
| 323 |
+
--repo ChangChrisLiu/GWAM_Data \
|
| 324 |
+
--tag gwam-compact-target-v3.0.7-20260801 \
|
| 325 |
+
--staged-tree agent_workspace/gwam_gnn_restart_20260730/gwam_training_package_20260731/upload_tree \
|
| 326 |
+
--source-root data/gwam_compact_v307_local \
|
| 327 |
+
--fresh-dir /tmp/GWAM_V307_FRESH_DETACHED \
|
| 328 |
+
--publication-receipt /path/to/V307_ADDITIVE_PUBLICATION_RECEIPT.json \
|
| 329 |
+
--output /path/to/V307_FRESH_REMOTE_VERIFICATION_RECEIPT.json
|
| 330 |
+
~~~
|
| 331 |
+
|
| 332 |
+
The external five-step sample is authorized only after the additive publication receipt and the detached fresh-tag verification receipt bind the same immutable commit and every other runner preflight passes. This local release-tree closure does not publish, tag, initialize an optimizer, run CUDA, execute a training step, or create a checkpoint.
|
ROOT_MANIFEST_V307.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
SCHEMA.md
CHANGED
|
@@ -1,14 +1,23 @@
|
|
| 1 |
# GWAM_Data schema
|
| 2 |
|
| 3 |
-
## Current model-facing contract: compact target-aware v3.0.
|
| 4 |
|
| 5 |
The normative current training/evaluation schema is:
|
| 6 |
|
| 7 |
-
- `
|
| 8 |
-
- `
|
| 9 |
-
- immutable revision `gwam-compact-target-v3.0.
|
| 10 |
|
| 11 |
-
Compact v3 uses one variable-N physical graph, typed node/edge/action/target tensors, a convenience 46-D node view, 12-D `METRIC12` edge geometry, L=8 history, H=8 action/future horizon, and K=16 graph tokens. It excludes SAM-derived features, type-text embeddings, masks, linear/angular velocity, and qvel. RGB remains external and synchronizes through `source_tier/task/episode_id/source_frame` plus the fixed three-camera order.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
In a collated batch, edge_index endpoints are row-local. Pair edge_index with edge_batch, or add edge_batch * N before flattening [B,N] nodes.
|
| 14 |
|
|
@@ -410,9 +419,11 @@ Original RGB/video is **not** stored in canonical graph ZIPs. Optional joint gra
|
|
| 410 |
|
| 411 |
For online evaluation, use the v2 atomic `extract_velocity_free_target_aware_current_graph()` API. Internally it calls `RealtimeGWAMGraphExtractor.extract_final_graph()` to construct the source-compatible 342-D physical/visual graph, immediately removes the seven velocity columns, sets model-facing `x[N,335]`, and appends only a complete pre-action task/reset target-slot set to produce `x_target_aware[N,337]` before returning. Raw `extract_final_graph()` output is source/audit-only; `extract_current_graph()` remains Phase-1/debug only.
|
| 412 |
<!-- END ACTIVE13_DIRECT_GWAM_TRAINING_V2 -->
|
| 413 |
-
##
|
| 414 |
|
| 415 |
-
See `
|
| 416 |
GraphPacket-Slim runtime, live graph/RGB synchronization, offline RGB join manifest,
|
| 417 |
-
and K=16 token conditioning contract.
|
| 418 |
-
|
|
|
|
|
|
|
|
|
| 1 |
# GWAM_Data schema
|
| 2 |
|
| 3 |
+
## Current model-facing contract: compact target-aware v3.0.7
|
| 4 |
|
| 5 |
The normative current training/evaluation schema is:
|
| 6 |
|
| 7 |
+
- `gwam_active13_gwam_training_v3_20260801/SCHEMA.md`
|
| 8 |
+
- `gwam_active13_gwam_training_v3_20260801/README.md`
|
| 9 |
+
- immutable revision `gwam-compact-target-v3.0.7-20260801`
|
| 10 |
|
| 11 |
+
Compact v3.0.7 uses one variable-N physical graph, typed node/edge/action/target tensors and masks, a non-authoritative convenience 46-D node view, 12-D `METRIC12` edge geometry, L=8 history, H=8 action/future horizon, and K=16 graph tokens. It excludes SAM-derived features, type-text embeddings, public segmentation masks, linear/angular velocity, and qvel. RGB remains external and synchronizes through `source_tier/task/episode_id/source_frame` plus the fixed three-camera order.
|
| 12 |
+
|
| 13 |
+
The finite release-support namespaces are:
|
| 14 |
+
|
| 15 |
+
- `gwam_v307_release_receipts_20260801/`: exact exhaustive summary/index/progress bytes, ordinary and OpenDrawer production-loader witnesses, parent-source inventory, and the acyclic release-verification receipt;
|
| 16 |
+
- `gwam_v307_gnn_training_examples_20260802/`: the exact path-portable standalone compatibility-example tree, including its CPU tests and separately gated RTX 5090 launcher;
|
| 17 |
+
- `ROOT_MANIFEST_V307.json`: every non-allowlist local release-tree file and byte hash;
|
| 18 |
+
- `V307_UPLOAD_ALLOWLIST.json`: the last-built finite publication set. It hashes the root manifest and every upload-authorized file while excluding its own digest.
|
| 19 |
+
|
| 20 |
+
Authority is acyclic: protected package/C2 manifests and copied gate bytes precede the representative and release receipts; the root manifest binds all non-allowlist files; the final allowlist binds the root manifest. Neither a directory prefix nor recursive enumeration is upload authority.
|
| 21 |
|
| 22 |
In a collated batch, edge_index endpoints are row-local. Pair edge_index with edge_batch, or add edge_batch * N before flattening [B,N] nodes.
|
| 23 |
|
|
|
|
| 419 |
|
| 420 |
For online evaluation, use the v2 atomic `extract_velocity_free_target_aware_current_graph()` API. Internally it calls `RealtimeGWAMGraphExtractor.extract_final_graph()` to construct the source-compatible 342-D physical/visual graph, immediately removes the seven velocity columns, sets model-facing `x[N,335]`, and appends only a complete pre-action task/reset target-slot set to produce `x_target_aware[N,337]` before returning. Raw `extract_final_graph()` output is source/audit-only; `extract_current_graph()` remains Phase-1/debug only.
|
| 421 |
<!-- END ACTIVE13_DIRECT_GWAM_TRAINING_V2 -->
|
| 422 |
+
## Compact v3.0.7 additive release namespace
|
| 423 |
|
| 424 |
+
See `gwam_active13_gwam_training_v3_20260801/SCHEMA.md` for the additive variable-N
|
| 425 |
GraphPacket-Slim runtime, live graph/RGB synchronization, offline RGB join manifest,
|
| 426 |
+
and K=16 token conditioning contract. Canonical source ZIPs, target/C2 receipts,
|
| 427 |
+
the v3.0.6 prefix/tag, and prior v1/v2 prefixes remain unchanged. Local closure does
|
| 428 |
+
not itself publish, tag, authorize training, construct an optimizer, or create a
|
| 429 |
+
checkpoint.
|
V307_UPLOAD_ALLOWLIST.json
ADDED
|
@@ -0,0 +1,593 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"allowed_files": [
|
| 3 |
+
{
|
| 4 |
+
"path": "README.md",
|
| 5 |
+
"sha256": "9d1e29b870c425b596862dc2146e252045e189b60a03e160428dbff55ce0d7dd",
|
| 6 |
+
"size": 21787
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"path": "ROOT_MANIFEST_V307.json",
|
| 10 |
+
"sha256": "74e693c0f4b521881498bc612b15b38da7204c207c789141bb155c48312381bc",
|
| 11 |
+
"size": 147381
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"path": "SCHEMA.md",
|
| 15 |
+
"sha256": "ca6a8f2e1e8c0f014f3e1b0e172c0790fa00a5bc3db3dbf930f8276c888adc56",
|
| 16 |
+
"size": 23405
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"path": "V307_UPLOAD_ALLOWLIST.json",
|
| 20 |
+
"self_excluded": true,
|
| 21 |
+
"sha256": null,
|
| 22 |
+
"size": null
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"path": "gwam_active13_gwam_training_v3_20260801/AGENT_HANDOFF_COMPACT_V305.md",
|
| 26 |
+
"sha256": "489afa2660395946c04a4811c5279b3f3ac354b16c945c32eb61072f054a4509",
|
| 27 |
+
"size": 251
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"path": "gwam_active13_gwam_training_v3_20260801/AGENT_HANDOFF_COMPACT_V306.md",
|
| 31 |
+
"sha256": "0b6d5de9a206e6e6fc0656ba23390bf39f0b5829bbefbcf5cda7e1c11a146661",
|
| 32 |
+
"size": 384
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"path": "gwam_active13_gwam_training_v3_20260801/AGENT_HANDOFF_COMPACT_V307.md",
|
| 36 |
+
"sha256": "51cc5ffefc8f71e4e15ab0732e7aca4e2d4cbab947f9fd97ccba3b3360fc71be",
|
| 37 |
+
"size": 1713
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"path": "gwam_active13_gwam_training_v3_20260801/DATASET_SUMMARY.json",
|
| 41 |
+
"sha256": "02b81ad2b7acca727fdda672eba4e0e63852d01b8547cf5da244f971b745c74e",
|
| 42 |
+
"size": 2328
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"path": "gwam_active13_gwam_training_v3_20260801/GUIDE_GNN_AND_GWAM_TRAINING.md",
|
| 46 |
+
"sha256": "79c8349b85484997675e760900eafbd00c91926e3b45b585a7d83213071e4bd1",
|
| 47 |
+
"size": 6504
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"path": "gwam_active13_gwam_training_v3_20260801/PACKAGE_MANIFEST.json",
|
| 51 |
+
"sha256": "ce640f15cf0f8a29b4afddc7bf7662fbb4c392c3c1a970252b5342f7e5dc36e3",
|
| 52 |
+
"size": 13240
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"path": "gwam_active13_gwam_training_v3_20260801/README.md",
|
| 56 |
+
"sha256": "41ef335a3e2220bbc2a415d7965272a91769c0a529c95e0c21f26c826bb2ad59",
|
| 57 |
+
"size": 28025
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
"path": "gwam_active13_gwam_training_v3_20260801/SCHEMA.md",
|
| 61 |
+
"sha256": "fabd4625301549bfb830cae166984751c3660aa180444ff8f010e70345678f04",
|
| 62 |
+
"size": 7708
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"path": "gwam_active13_gwam_training_v3_20260801/TRAINING_EPISODES.jsonl",
|
| 66 |
+
"sha256": "f54a19de57bb3bd281b119f581762b132ded38cd298b3f7955c1de1217232b00",
|
| 67 |
+
"size": 3092602
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
"path": "gwam_active13_gwam_training_v3_20260801/V306_TIMESTAMP_DEFECT_AUDIT.json",
|
| 71 |
+
"sha256": "929e89080b2f1aa4f2ceb7fa69abd1f7760e45946ff4deff1111fc04c85abd51",
|
| 72 |
+
"size": 870
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"path": "gwam_active13_gwam_training_v3_20260801/V307_COMPLETE_DATA_READINESS_RECEIPT.md",
|
| 76 |
+
"sha256": "704d5551586b143d4826140125ac69df8fb5727398f1f78f2dd55803e71b8b65",
|
| 77 |
+
"size": 1277
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"path": "gwam_active13_gwam_training_v3_20260801/V307_MIGRATION.md",
|
| 81 |
+
"sha256": "46d680e617581e781a242c4aa33f85068079a787e15fca60600e6603a4fb7e3b",
|
| 82 |
+
"size": 1483
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"path": "gwam_active13_gwam_training_v3_20260801/VALIDATION_RECEIPT.json",
|
| 86 |
+
"sha256": "daf74d00c07b4e5a7784ef28b8810dc71fc682b48e2cf9e539c51838c02c59ce",
|
| 87 |
+
"size": 5265
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"path": "gwam_active13_gwam_training_v3_20260801/WINDOW_LEGALITY_INDEX_V307.jsonl",
|
| 91 |
+
"sha256": "0bf97bf9cb33e5584429c74cbb40177931223e8d3d7fe52307cc112f37f4afb9",
|
| 92 |
+
"size": 914744
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"path": "gwam_active13_gwam_training_v3_20260801/WINDOW_LEGALITY_SUMMARY_V307.json",
|
| 96 |
+
"sha256": "64f69549544731deb8cbc441293229a3cc73f2695488ec35c97b077a97d540b2",
|
| 97 |
+
"size": 370
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
"path": "gwam_active13_gwam_training_v3_20260801/examples/buffered_compact_target_aware_eval.py",
|
| 101 |
+
"sha256": "2204ae49ba69b368f7bec84c41e20b7a0f691dcf1b5eee9415e90bdf1101f08d",
|
| 102 |
+
"size": 6455
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"path": "gwam_active13_gwam_training_v3_20260801/examples/compact_gwam_conditioning_cpu.py",
|
| 106 |
+
"sha256": "85589f28fb088736bec5395d9b217b9a6a61ecd202ab100098beb4bd59b57aa7",
|
| 107 |
+
"size": 1666
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
"path": "gwam_active13_gwam_training_v3_20260801/examples/download_compact_example.py",
|
| 111 |
+
"sha256": "b5849020c2e7446f342ae2ad12548d74a5573552264b73b124447ee70722b0b7",
|
| 112 |
+
"size": 4116
|
| 113 |
+
},
|
| 114 |
+
{
|
| 115 |
+
"path": "gwam_active13_gwam_training_v3_20260801/examples/download_training_closure.py",
|
| 116 |
+
"sha256": "6efe67a487a9eedea7339e5b9a75728b5092130eb300b014cd9a215a6bd13a37",
|
| 117 |
+
"size": 9194
|
| 118 |
+
},
|
| 119 |
+
{
|
| 120 |
+
"path": "gwam_active13_gwam_training_v3_20260801/examples/gnn_loss_dry_run.py",
|
| 121 |
+
"sha256": "47edf3ca18d7eb75e1a94cc845bff96961e2468aa75892a955d1d4f25210743d",
|
| 122 |
+
"size": 2089
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"path": "gwam_active13_gwam_training_v3_20260801/examples/inspect_compact_frame.py",
|
| 126 |
+
"sha256": "e07c993cb45323746d5a1c6c95348083558ea9e2a1905f49040d235530d6c425",
|
| 127 |
+
"size": 1828
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"path": "gwam_active13_gwam_training_v3_20260801/examples/model_neutral_graph_examples.py",
|
| 131 |
+
"sha256": "7edf8d786f18c9892ebe8a5f883dbb4bf6153c98b188acbfeeda4f7fd041e665",
|
| 132 |
+
"size": 4633
|
| 133 |
+
},
|
| 134 |
+
{
|
| 135 |
+
"path": "gwam_active13_gwam_training_v3_20260801/examples/pair_graph_rgb.py",
|
| 136 |
+
"sha256": "68ca9fe605770e992f96b35df833a01f59a2b87bb7aeb42dac71362106a0aabf",
|
| 137 |
+
"size": 1063
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"path": "gwam_active13_gwam_training_v3_20260801/examples/robocasa_live_compact_eval.py",
|
| 141 |
+
"sha256": "d218eee665c2e95023d06723620adcb2ea4527cb819431aa9ff6796625698ff8",
|
| 142 |
+
"size": 6046
|
| 143 |
+
},
|
| 144 |
+
{
|
| 145 |
+
"path": "gwam_active13_gwam_training_v3_20260801/loader/__init__.py",
|
| 146 |
+
"sha256": "c9d606abb807f2534f08ef12d1f41b0338178dea3ae695515a234e6091d2efb9",
|
| 147 |
+
"size": 66
|
| 148 |
+
},
|
| 149 |
+
{
|
| 150 |
+
"path": "gwam_active13_gwam_training_v3_20260801/loader/compact_collate.py",
|
| 151 |
+
"sha256": "a7f26da9e08fcc636bcaddb7ff1fccbdfab709ae2aca1bdf9d27c90ddff2e951",
|
| 152 |
+
"size": 14278
|
| 153 |
+
},
|
| 154 |
+
{
|
| 155 |
+
"path": "gwam_active13_gwam_training_v3_20260801/loader/compact_contract.py",
|
| 156 |
+
"sha256": "8a406232d4453ab805c9c42b2bc45ac4e4ee43babcaaa5e34a13e51aab26ef6a",
|
| 157 |
+
"size": 40354
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
"path": "gwam_active13_gwam_training_v3_20260801/loader/compact_target_aware_gwam_training_dataset.py",
|
| 161 |
+
"sha256": "ee98b34222617451ffc90baaef0b39ab1ebed782b08a063976aed8143753997a",
|
| 162 |
+
"size": 13357
|
| 163 |
+
},
|
| 164 |
+
{
|
| 165 |
+
"path": "gwam_active13_gwam_training_v3_20260801/loader/direct_compact_source.py",
|
| 166 |
+
"sha256": "fd3d66eda92f9cff2dde3ca16ee27d2ef76bcb1f95ac90ca921a13012e90a537",
|
| 167 |
+
"size": 72628
|
| 168 |
+
},
|
| 169 |
+
{
|
| 170 |
+
"path": "gwam_active13_gwam_training_v3_20260801/loader/gwam_conditioning.py",
|
| 171 |
+
"sha256": "4413de27a20aa9110a6b918171e0e5cf2382d50fe3a4628497e669f82b1947c8",
|
| 172 |
+
"size": 2557
|
| 173 |
+
},
|
| 174 |
+
{
|
| 175 |
+
"path": "gwam_active13_gwam_training_v3_20260801/loader/online_compact_adapter.py",
|
| 176 |
+
"sha256": "527ed60bbc7c9b26d9988cc4d3b2c6a7a82c96e28c5c596be744fff113dfa1a5",
|
| 177 |
+
"size": 23418
|
| 178 |
+
},
|
| 179 |
+
{
|
| 180 |
+
"path": "gwam_active13_gwam_training_v3_20260801/loader/per_frame.py",
|
| 181 |
+
"sha256": "a0d4364953021be7bd3f20cffc6b96c371445e2347ceac1c8f3df6a8394a2891",
|
| 182 |
+
"size": 2481
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"path": "gwam_active13_gwam_training_v3_20260801/loader/relation_geometry.py",
|
| 186 |
+
"sha256": "f5e0dd38ff99003ba45249b02d8f26376a74063ead7d9fd988751fe28ba42672",
|
| 187 |
+
"size": 7804
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"path": "gwam_active13_gwam_training_v3_20260801/loader/rgb_pairing.py",
|
| 191 |
+
"sha256": "78b5763efdf18075028ea05b5f07736a8142ba92e6b07d3471749d8343ea5dcf",
|
| 192 |
+
"size": 3312
|
| 193 |
+
},
|
| 194 |
+
{
|
| 195 |
+
"path": "gwam_active13_gwam_training_v3_20260801/loader/robocasa_live_compact.py",
|
| 196 |
+
"sha256": "2b3882d5573ac5090ee0ce861b3543f27751b0d8ee19d66ac93de85dc760423a",
|
| 197 |
+
"size": 8949
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
"path": "gwam_active13_gwam_training_v3_20260801/loader/robocasa_mujoco_compact.py",
|
| 201 |
+
"sha256": "06ef4d0160bac10b0c8293967fcb398d2bdcd5990265876a4db3cce3c2dc7bfe",
|
| 202 |
+
"size": 17149
|
| 203 |
+
},
|
| 204 |
+
{
|
| 205 |
+
"path": "gwam_active13_gwam_training_v3_20260801/loader/sealed_model_regression.py",
|
| 206 |
+
"sha256": "b86051078508c6313f13f29500b9c406816925b50b67242d8a8497de345fc1ed",
|
| 207 |
+
"size": 6374
|
| 208 |
+
},
|
| 209 |
+
{
|
| 210 |
+
"path": "gwam_active13_gwam_training_v3_20260801/loader/temporal_precision.py",
|
| 211 |
+
"sha256": "55e0dc1152c36ae133195b2de386164259b5705c1da3f7cee8d2989c24d93fb7",
|
| 212 |
+
"size": 4164
|
| 213 |
+
},
|
| 214 |
+
{
|
| 215 |
+
"path": "gwam_active13_gwam_training_v3_20260801/loader/variable_n.py",
|
| 216 |
+
"sha256": "47906f8c0d66914e6583a7a8d97820e5ef16f273e39098bf5d0d285554322607",
|
| 217 |
+
"size": 6570
|
| 218 |
+
},
|
| 219 |
+
{
|
| 220 |
+
"path": "gwam_active13_gwam_training_v3_20260801/model_v2_0_4/README.md",
|
| 221 |
+
"sha256": "7c24425eca9d4979a15163c60ffa5099292b97338c05b54dc735687f777fd241",
|
| 222 |
+
"size": 1359
|
| 223 |
+
},
|
| 224 |
+
{
|
| 225 |
+
"path": "gwam_active13_gwam_training_v3_20260801/model_v2_0_4/__init__.py",
|
| 226 |
+
"sha256": "9eca17536370c8b9ec07d37f338d8a518222ac2afdca598607dcc60fe18f165c",
|
| 227 |
+
"size": 1431
|
| 228 |
+
},
|
| 229 |
+
{
|
| 230 |
+
"path": "gwam_active13_gwam_training_v3_20260801/model_v2_0_4/batch.py",
|
| 231 |
+
"sha256": "05bdf7fe3e521d2f62b5da7375649c89cc2f4aa0979e381fa85537891a38ab8a",
|
| 232 |
+
"size": 22756
|
| 233 |
+
},
|
| 234 |
+
{
|
| 235 |
+
"path": "gwam_active13_gwam_training_v3_20260801/model_v2_0_4/config.py",
|
| 236 |
+
"sha256": "3f47c1e0a8b15606d3172fd05c1d042d75737d248b5a622028bf93ef4526ac35",
|
| 237 |
+
"size": 4982
|
| 238 |
+
},
|
| 239 |
+
{
|
| 240 |
+
"path": "gwam_active13_gwam_training_v3_20260801/model_v2_0_4/controls.py",
|
| 241 |
+
"sha256": "aa35ea0a756c124a8d42254b72fbcbb4b5383e8e9e7290a1026fd14cbec41af9",
|
| 242 |
+
"size": 5887
|
| 243 |
+
},
|
| 244 |
+
{
|
| 245 |
+
"path": "gwam_active13_gwam_training_v3_20260801/model_v2_0_4/geometry.py",
|
| 246 |
+
"sha256": "f238045ce24ceed53cc8c411280244a060fffd42a0cbb74960ac03a49ea14f68",
|
| 247 |
+
"size": 14046
|
| 248 |
+
},
|
| 249 |
+
{
|
| 250 |
+
"path": "gwam_active13_gwam_training_v3_20260801/model_v2_0_4/interventions.py",
|
| 251 |
+
"sha256": "aaabf4a371ee40d65a6a6757443bb2feffc0c1196d32f50f0c95b0f14c50d9ef",
|
| 252 |
+
"size": 13552
|
| 253 |
+
},
|
| 254 |
+
{
|
| 255 |
+
"path": "gwam_active13_gwam_training_v3_20260801/model_v2_0_4/ledger.py",
|
| 256 |
+
"sha256": "e720e50826c2d4403e1b3fdd4cd915bf991d4ee79d31bd54ad684e137ad3bdb8",
|
| 257 |
+
"size": 12266
|
| 258 |
+
},
|
| 259 |
+
{
|
| 260 |
+
"path": "gwam_active13_gwam_training_v3_20260801/model_v2_0_4/loader.py",
|
| 261 |
+
"sha256": "3b125b66264ce61a2c36d27b489bc4055bf27d3af88f3963e3ef0c0d2b5b391c",
|
| 262 |
+
"size": 17774
|
| 263 |
+
},
|
| 264 |
+
{
|
| 265 |
+
"path": "gwam_active13_gwam_training_v3_20260801/model_v2_0_4/losses.py",
|
| 266 |
+
"sha256": "1892325f5f4458154fa7a519d2a8f58e9ab9b9bf28b014eba25dc3a6186e72c6",
|
| 267 |
+
"size": 13132
|
| 268 |
+
},
|
| 269 |
+
{
|
| 270 |
+
"path": "gwam_active13_gwam_training_v3_20260801/model_v2_0_4/metrics.py",
|
| 271 |
+
"sha256": "5ffed0ba116f9468a76ee9a91070ade1c64b23f787ec3b357168c92cfcd2f3d6",
|
| 272 |
+
"size": 39730
|
| 273 |
+
},
|
| 274 |
+
{
|
| 275 |
+
"path": "gwam_active13_gwam_training_v3_20260801/model_v2_0_4/model.py",
|
| 276 |
+
"sha256": "aa4d8dc39ed68f1b4e5658d6c2c908eb31cb4b7f4aca8622b3942d66dc03fa35",
|
| 277 |
+
"size": 48157
|
| 278 |
+
},
|
| 279 |
+
{
|
| 280 |
+
"path": "gwam_active13_gwam_training_v3_20260801/model_v2_0_4/persistence.py",
|
| 281 |
+
"sha256": "bdbd6306ad224c356a222d3eeaefbe4ce37ec7faaff7fcaaafc0bb827993edda",
|
| 282 |
+
"size": 11945
|
| 283 |
+
},
|
| 284 |
+
{
|
| 285 |
+
"path": "gwam_active13_gwam_training_v3_20260801/model_v2_0_4/receipts.py",
|
| 286 |
+
"sha256": "34426445729fe37ee9d2592b4c045402b62b3de36f1ce7e253356bc74564a1ca",
|
| 287 |
+
"size": 2145
|
| 288 |
+
},
|
| 289 |
+
{
|
| 290 |
+
"path": "gwam_active13_gwam_training_v3_20260801/model_v2_0_4/train_only.py",
|
| 291 |
+
"sha256": "4a96dd3adf1beed9b7a6287d858c44c5f81b4efb81642f70f3e42791070fbffc",
|
| 292 |
+
"size": 17200
|
| 293 |
+
},
|
| 294 |
+
{
|
| 295 |
+
"path": "gwam_active13_gwam_training_v3_20260801/requirements-dev.txt",
|
| 296 |
+
"sha256": "b2dfb119398ce53f30ca7436b0fc0331c791fd367d3328ce0bf510eaee000160",
|
| 297 |
+
"size": 85
|
| 298 |
+
},
|
| 299 |
+
{
|
| 300 |
+
"path": "gwam_active13_gwam_training_v3_20260801/requirements.txt",
|
| 301 |
+
"sha256": "7002f96dddac37c0b5cd9f4bcffea1492c1890aaabf7f69ee0a1ba56c411ef25",
|
| 302 |
+
"size": 45
|
| 303 |
+
},
|
| 304 |
+
{
|
| 305 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/conftest.py",
|
| 306 |
+
"sha256": "9485b82a17588da81555610b8a2b14a9d460b0c1aeaa8a4bccbfd5618095424d",
|
| 307 |
+
"size": 188
|
| 308 |
+
},
|
| 309 |
+
{
|
| 310 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/helpers.py",
|
| 311 |
+
"sha256": "6fac0a9b3c138032f421152661ab394b121bc3744fa44f49fc2a856b3d13819b",
|
| 312 |
+
"size": 10772
|
| 313 |
+
},
|
| 314 |
+
{
|
| 315 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_collate_and_model_regression.py",
|
| 316 |
+
"sha256": "c55d6d2e408bf724a95fc437d46889328ceb0aaba73c6748d231e76caad5914e",
|
| 317 |
+
"size": 3336
|
| 318 |
+
},
|
| 319 |
+
{
|
| 320 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_compact_contract.py",
|
| 321 |
+
"sha256": "a652d4c54f30be61961f56b41cb55917da63c0e7025f373effcd2726748f6f98",
|
| 322 |
+
"size": 8254
|
| 323 |
+
},
|
| 324 |
+
{
|
| 325 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_direct_source_no_access.py",
|
| 326 |
+
"sha256": "9fa9fbfad9c7a005f75d09c23503eb0acb73207f012f5fd5a1de4b7b1177e689",
|
| 327 |
+
"size": 15433
|
| 328 |
+
},
|
| 329 |
+
{
|
| 330 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_download_training_closure.py",
|
| 331 |
+
"sha256": "a573046e27006a9020d39215cd253cf45aaaecd8d74524dc5fcb9495de070c34",
|
| 332 |
+
"size": 4690
|
| 333 |
+
},
|
| 334 |
+
{
|
| 335 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_exhaustive_gate_v307.py",
|
| 336 |
+
"sha256": "73c01c890751b9368f591e54a85c374f38316d6c03ec37dbfafdd8668dc67832",
|
| 337 |
+
"size": 6463
|
| 338 |
+
},
|
| 339 |
+
{
|
| 340 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_hf_ready_finalization.py",
|
| 341 |
+
"sha256": "e9d86a36dc474f6cb5483bf300a05af632d31c9b13330d292a1906663bba057e",
|
| 342 |
+
"size": 5048
|
| 343 |
+
},
|
| 344 |
+
{
|
| 345 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_model_neutral_examples.py",
|
| 346 |
+
"sha256": "98edd84c1fe61d790805ca11ebbbf56b9fb4937d87236394cb3600b2ccaac5d7",
|
| 347 |
+
"size": 1142
|
| 348 |
+
},
|
| 349 |
+
{
|
| 350 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_online_buffer.py",
|
| 351 |
+
"sha256": "ad6185c0651ca0461ac3f87fb2ac793e98a211b6af3d58615a86dcf3545c03f1",
|
| 352 |
+
"size": 8783
|
| 353 |
+
},
|
| 354 |
+
{
|
| 355 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_package_governance.py",
|
| 356 |
+
"sha256": "664789afbb410672a0c6794fb4bc7c828acd07735104520d6441463f34af4da1",
|
| 357 |
+
"size": 6090
|
| 358 |
+
},
|
| 359 |
+
{
|
| 360 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_real_reader_contract.py",
|
| 361 |
+
"sha256": "b8cda674eddd99c002ebef7ee3fb5280c0fd379f616a81c13722ca28688e1b21",
|
| 362 |
+
"size": 7128
|
| 363 |
+
},
|
| 364 |
+
{
|
| 365 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_real_train_artifacts.py",
|
| 366 |
+
"sha256": "b14d4600e65e2c1cf3dae2c6a373900dd7cc9085d62c89097626ec841382edc5",
|
| 367 |
+
"size": 7108
|
| 368 |
+
},
|
| 369 |
+
{
|
| 370 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_relation_geometry.py",
|
| 371 |
+
"sha256": "05a1c6dcf32b5b49816c1b5109351497f0cc42bb45289201a642be0350152e1b",
|
| 372 |
+
"size": 2578
|
| 373 |
+
},
|
| 374 |
+
{
|
| 375 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_usage_guide.py",
|
| 376 |
+
"sha256": "558d7bf8f7851179fe121be6953ca799eadbf0aee7f10012ae91c143d0b33e40",
|
| 377 |
+
"size": 618
|
| 378 |
+
},
|
| 379 |
+
{
|
| 380 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_v305_adversarial_contract.py",
|
| 381 |
+
"sha256": "1eca95ed94b95878f4faf53c1d1d708c06e5e70603e885814abe4118ca8e8fd4",
|
| 382 |
+
"size": 8697
|
| 383 |
+
},
|
| 384 |
+
{
|
| 385 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_v307_cache_surgical_fix.py",
|
| 386 |
+
"sha256": "c519598e367c28533e79a121751d2321a8acf94217640a1c98ad5834a010dca9",
|
| 387 |
+
"size": 11883
|
| 388 |
+
},
|
| 389 |
+
{
|
| 390 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tests/test_v307_readiness.py",
|
| 391 |
+
"sha256": "b70a606a853d0f3ee20faac4b9d2c9b836ed948d21a2436a1a0d5d298b61e241",
|
| 392 |
+
"size": 2141
|
| 393 |
+
},
|
| 394 |
+
{
|
| 395 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tools/build_manifest.py",
|
| 396 |
+
"sha256": "c177dbf07dab519117ae265f815f05966a71818360d7fefe628a233e9d30ee03",
|
| 397 |
+
"size": 973
|
| 398 |
+
},
|
| 399 |
+
{
|
| 400 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tools/build_upload_allowlist.py",
|
| 401 |
+
"sha256": "2898b7e3889441fb07020fafe1bf720bc80607c87cd254db143fcaafa012ba19",
|
| 402 |
+
"size": 2676
|
| 403 |
+
},
|
| 404 |
+
{
|
| 405 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tools/census_window_legality_v307.py",
|
| 406 |
+
"sha256": "f555d77c4dd1e851f538744652cce2ff5141024384ff90355a4131fe15521d2a",
|
| 407 |
+
"size": 3552
|
| 408 |
+
},
|
| 409 |
+
{
|
| 410 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tools/compile_gate.py",
|
| 411 |
+
"sha256": "8b9fc0f22d50db6043146dabe0b638b9320400aff7891e634ea6801a07119dad",
|
| 412 |
+
"size": 481
|
| 413 |
+
},
|
| 414 |
+
{
|
| 415 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tools/exhaustive_gate_v307.py",
|
| 416 |
+
"sha256": "15c5922a037053e1383912709851f29578c14e06ec07119aa0348cdd1e7bb7d6",
|
| 417 |
+
"size": 7936
|
| 418 |
+
},
|
| 419 |
+
{
|
| 420 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tools/validate_manifest.py",
|
| 421 |
+
"sha256": "2386482b4bf90d1ce302af043a45cc1cb487d2574dac9d1ceda5ed2a8a6a3ad9",
|
| 422 |
+
"size": 871
|
| 423 |
+
},
|
| 424 |
+
{
|
| 425 |
+
"path": "gwam_active13_gwam_training_v3_20260801/tools/validate_upload_allowlist.py",
|
| 426 |
+
"sha256": "36c2a21fbe203b6b558b7451f0cfb514759ba3f4a78c4e16419f466a3b1705f4",
|
| 427 |
+
"size": 1913
|
| 428 |
+
},
|
| 429 |
+
{
|
| 430 |
+
"path": "gwam_v307_gnn_training_examples_20260802/README.md",
|
| 431 |
+
"sha256": "df933e7517c744729bb576ff42434395c6437db98740b9f00ec9495af9a6a599",
|
| 432 |
+
"size": 10210
|
| 433 |
+
},
|
| 434 |
+
{
|
| 435 |
+
"path": "gwam_v307_gnn_training_examples_20260802/__init__.py",
|
| 436 |
+
"sha256": "ccbc25a2860e05741b23a03c8359021baafe278be1a50a886745a02e1c7320a8",
|
| 437 |
+
"size": 235
|
| 438 |
+
},
|
| 439 |
+
{
|
| 440 |
+
"path": "gwam_v307_gnn_training_examples_20260802/action_recurrence_probe.py",
|
| 441 |
+
"sha256": "a3ec3082de816991db039af2170808cdc0aa9d691a6c5b62ef16a8763cd666a4",
|
| 442 |
+
"size": 11355
|
| 443 |
+
},
|
| 444 |
+
{
|
| 445 |
+
"path": "gwam_v307_gnn_training_examples_20260802/geometry_authority.py",
|
| 446 |
+
"sha256": "321596e787ab0fe876c56bf17efcdaf0bae7a71d27bb35e66239e4c68c798517",
|
| 447 |
+
"size": 13555
|
| 448 |
+
},
|
| 449 |
+
{
|
| 450 |
+
"path": "gwam_v307_gnn_training_examples_20260802/launch_rtx5090_wdg.sh",
|
| 451 |
+
"sha256": "f97200a645a7843764ce5d69de69b173fbf61fb2e5a489f9b265e96a4b339e72",
|
| 452 |
+
"size": 2107
|
| 453 |
+
},
|
| 454 |
+
{
|
| 455 |
+
"path": "gwam_v307_gnn_training_examples_20260802/requirements-train.txt",
|
| 456 |
+
"sha256": "75ed6041b21b7a16aec57e7411273af320fbe1a1079bc3b37028be4c52a5a903",
|
| 457 |
+
"size": 102
|
| 458 |
+
},
|
| 459 |
+
{
|
| 460 |
+
"path": "gwam_v307_gnn_training_examples_20260802/run_v307_five_step_cuda_smoke.py",
|
| 461 |
+
"sha256": "ebced5347518685f900dab0d5a52ebec4e105f7f9a81a14308a6833d4a08f8be",
|
| 462 |
+
"size": 97616
|
| 463 |
+
},
|
| 464 |
+
{
|
| 465 |
+
"path": "gwam_v307_gnn_training_examples_20260802/tests/test_v307_action_boundaries.py",
|
| 466 |
+
"sha256": "ce77b9c4ef80208a1beb635f764f300a439a00bca31014e96e7481ff9252aa8b",
|
| 467 |
+
"size": 9719
|
| 468 |
+
},
|
| 469 |
+
{
|
| 470 |
+
"path": "gwam_v307_gnn_training_examples_20260802/tests/test_v307_adapter.py",
|
| 471 |
+
"sha256": "6f33e66d9162cc9d4c1f9d203f569074cc210f2de7286381e736bad021455946",
|
| 472 |
+
"size": 10624
|
| 473 |
+
},
|
| 474 |
+
{
|
| 475 |
+
"path": "gwam_v307_gnn_training_examples_20260802/tests/test_v307_cuda_smoke.py",
|
| 476 |
+
"sha256": "65f9187d0604452829aef3681c192a770a76712417b4d227400e20da20fa6a64",
|
| 477 |
+
"size": 2195
|
| 478 |
+
},
|
| 479 |
+
{
|
| 480 |
+
"path": "gwam_v307_gnn_training_examples_20260802/tests/test_v307_fit_action_stats.py",
|
| 481 |
+
"sha256": "9cc8a835e5e22f0ae25b83256e400b24d8a8d1a5d4a7349e5c2e65d8fd25c483",
|
| 482 |
+
"size": 5674
|
| 483 |
+
},
|
| 484 |
+
{
|
| 485 |
+
"path": "gwam_v307_gnn_training_examples_20260802/tests/test_v307_geometry_guard_binding.py",
|
| 486 |
+
"sha256": "bdbe3f82e8240e9ad23bc284866bb80943db8a6f169dda6fab8dbe1a12544c12",
|
| 487 |
+
"size": 13262
|
| 488 |
+
},
|
| 489 |
+
{
|
| 490 |
+
"path": "gwam_v307_gnn_training_examples_20260802/tests/test_v307_loss_binding.py",
|
| 491 |
+
"sha256": "e0d41b3be8dbb9b66c14fae7bb2c0596a8d9c7e3edbdd764bb5909856af0b75d",
|
| 492 |
+
"size": 9343
|
| 493 |
+
},
|
| 494 |
+
{
|
| 495 |
+
"path": "gwam_v307_gnn_training_examples_20260802/tests/test_v307_release_binding.py",
|
| 496 |
+
"sha256": "d61140203c3ae97eea2a499d90b5184a008999f0f8b276bd4020adc8c0991730",
|
| 497 |
+
"size": 18901
|
| 498 |
+
},
|
| 499 |
+
{
|
| 500 |
+
"path": "gwam_v307_gnn_training_examples_20260802/tests/test_v307_run_receipt.py",
|
| 501 |
+
"sha256": "249c786ce345f42a98e522ff5b91f3a9948f5df23bdfde3ad9e1c86d64b365fc",
|
| 502 |
+
"size": 26251
|
| 503 |
+
},
|
| 504 |
+
{
|
| 505 |
+
"path": "gwam_v307_gnn_training_examples_20260802/tests/test_v307_schedule_firewall.py",
|
| 506 |
+
"sha256": "c787072b99dadeff026894776c05b8d30d001164f74f628dfaad8c033ab084a7",
|
| 507 |
+
"size": 8327
|
| 508 |
+
},
|
| 509 |
+
{
|
| 510 |
+
"path": "gwam_v307_gnn_training_examples_20260802/trainer_contract.py",
|
| 511 |
+
"sha256": "b492e20836655a999fec7a522f7b76cd374372ba2d28b8e2f401fa17b490a1d3",
|
| 512 |
+
"size": 20012
|
| 513 |
+
},
|
| 514 |
+
{
|
| 515 |
+
"path": "gwam_v307_gnn_training_examples_20260802/v307_adapter.py",
|
| 516 |
+
"sha256": "1424cf841e1e4a3eff3d3b97a3eddc69607f6e975432368d48a57ee7e6998ee1",
|
| 517 |
+
"size": 19670
|
| 518 |
+
},
|
| 519 |
+
{
|
| 520 |
+
"path": "gwam_v307_gnn_training_examples_20260802/v307_loss_binding.py",
|
| 521 |
+
"sha256": "1625d7f65af1bf01e428861e48ff33f472741754b4d34d4934910200e6964459",
|
| 522 |
+
"size": 11112
|
| 523 |
+
},
|
| 524 |
+
{
|
| 525 |
+
"path": "gwam_v307_gnn_training_examples_20260802/v307_run_io.py",
|
| 526 |
+
"sha256": "fd5873d04f0a6b425b15c4bcdd7bc5988e00494b761e553a4834912e8709742e",
|
| 527 |
+
"size": 15002
|
| 528 |
+
},
|
| 529 |
+
{
|
| 530 |
+
"path": "gwam_v307_gnn_training_examples_20260802/v307_schedule.py",
|
| 531 |
+
"sha256": "4d19db8f0547224bfaa19709e16c81df8b15361173f4ea27d7980b3679dd60ce",
|
| 532 |
+
"size": 29054
|
| 533 |
+
},
|
| 534 |
+
{
|
| 535 |
+
"path": "gwam_v307_release_receipts_20260801/EXHAUSTIVE_GATE_V307_INDEX.json",
|
| 536 |
+
"sha256": "73d647fbcadab7df8139445c2701f7a8e1a6bc6126a4e3bf97cdb56892f6336e",
|
| 537 |
+
"size": 4746358
|
| 538 |
+
},
|
| 539 |
+
{
|
| 540 |
+
"path": "gwam_v307_release_receipts_20260801/EXHAUSTIVE_GATE_V307_PROGRESS.jsonl",
|
| 541 |
+
"sha256": "f62cc5f79c4065e35978f7dad1ba4e83b51a020309db07191c185551fed40e4d",
|
| 542 |
+
"size": 4187521
|
| 543 |
+
},
|
| 544 |
+
{
|
| 545 |
+
"path": "gwam_v307_release_receipts_20260801/EXHAUSTIVE_GATE_V307_SUMMARY.json",
|
| 546 |
+
"sha256": "50fcb04f9c21d84efd4ef4a8da2b6a04d4f60a5d7bababce3047fc240629a7bf",
|
| 547 |
+
"size": 1648
|
| 548 |
+
},
|
| 549 |
+
{
|
| 550 |
+
"path": "gwam_v307_release_receipts_20260801/V307_PRODUCTION_LOADER_OPENDRAWER_RECEIPT.json",
|
| 551 |
+
"sha256": "05d352d42b1b6133680377f02f5d1ef4a27275d21162e45c932ef29b6537b550",
|
| 552 |
+
"size": 81500
|
| 553 |
+
},
|
| 554 |
+
{
|
| 555 |
+
"path": "gwam_v307_release_receipts_20260801/V307_PRODUCTION_LOADER_ORDINARY_RECEIPT.json",
|
| 556 |
+
"sha256": "a8430dfe255cb687ca5d042b600d48430f64dd60074e8905d5217a0dfe394971",
|
| 557 |
+
"size": 81678
|
| 558 |
+
},
|
| 559 |
+
{
|
| 560 |
+
"path": "gwam_v307_release_receipts_20260801/V307_RELEASE_VERIFICATION_RECEIPT.json",
|
| 561 |
+
"sha256": "be0caa362bf8e85064f2a1c26b33fb715fa7583e41371342b40dddaed865c769",
|
| 562 |
+
"size": 5990
|
| 563 |
+
},
|
| 564 |
+
{
|
| 565 |
+
"path": "gwam_v307_release_receipts_20260801/V307_REMOTE_PARENT_SOURCE_INVENTORY_20260801.json",
|
| 566 |
+
"sha256": "05e1d52d030e30c835f8acef3ee463075b159d13e9183aa3d7f67e3b767246f8",
|
| 567 |
+
"size": 915
|
| 568 |
+
}
|
| 569 |
+
],
|
| 570 |
+
"authority": "Finite file enumeration only. No prefix, glob, or recursive directory is upload authority. The allowlist excludes its own digest to avoid a self-hash cycle.",
|
| 571 |
+
"denied_prefixes": [
|
| 572 |
+
"gwam_v12_sparse_v2/",
|
| 573 |
+
"gwam_active13_target_physical_v2_0_1_20260731/",
|
| 574 |
+
"gwam_active13_c2_v2_0_5_20260731/",
|
| 575 |
+
"gwam_active13_gwam_training_v3_20260731/",
|
| 576 |
+
"data/",
|
| 577 |
+
".cache/",
|
| 578 |
+
"tmp/"
|
| 579 |
+
],
|
| 580 |
+
"explicit_sets": {
|
| 581 |
+
"package_files_including_manifest": 81,
|
| 582 |
+
"release_receipts": 7,
|
| 583 |
+
"root_files": 3,
|
| 584 |
+
"trainer_files": 21
|
| 585 |
+
},
|
| 586 |
+
"file_count_excluding_self": 112,
|
| 587 |
+
"package_manifest_sha256": "ce640f15cf0f8a29b4afddc7bf7662fbb4c392c3c1a970252b5342f7e5dc36e3",
|
| 588 |
+
"revision": "gwam-compact-target-v3.0.7-20260801",
|
| 589 |
+
"root_manifest_sha256": "74e693c0f4b521881498bc612b15b38da7204c207c789141bb155c48312381bc",
|
| 590 |
+
"schema": "gwam.v3.0.7.upload_allowlist.v1",
|
| 591 |
+
"self_path": "V307_UPLOAD_ALLOWLIST.json",
|
| 592 |
+
"total_bytes_excluding_self": 14325070
|
| 593 |
+
}
|
gwam_active13_gwam_training_v3_20260801/AGENT_HANDOFF_COMPACT_V305.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Historical redirect: v3.0.5
|
| 2 |
+
|
| 3 |
+
This filename is retained only for immutable compatibility. Use [`AGENT_HANDOFF_COMPACT_V307.md`](AGENT_HANDOFF_COMPACT_V307.md) for the current v3.0.7 package; prior v3.0.5 material is archived outside the live prefix.
|
gwam_active13_gwam_training_v3_20260801/AGENT_HANDOFF_COMPACT_V306.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Historical redirect: v3.0.6
|
| 2 |
+
|
| 3 |
+
This filename is retained only for immutable compatibility. The current package is v3.0.7 at `gwam-compact-target-v3.0.7-20260801`; use [`AGENT_HANDOFF_COMPACT_V307.md`](AGENT_HANDOFF_COMPACT_V307.md), `V307_MIGRATION.md`, and the current README/SCHEMA. The original v3.0.6 handoff is preserved outside `upload_tree` in `v306_package_archive_20260801`.
|
gwam_active13_gwam_training_v3_20260801/AGENT_HANDOFF_COMPACT_V307.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Agent handoff — compact target-aware v3.0.7
|
| 2 |
+
|
| 3 |
+
Start with this package and `V307_MIGRATION.md`. The authoritative storage remains the 2,699 train-only source graph ZIPs, target receipts, and 409 OpenDrawer C2 receipts. v3.0.7 does not publish a pre-materialized compact tensor corpus: construct authenticated `CompactExampleV3` objects through `DirectCompactGWAMDatasetV3`.
|
| 4 |
+
|
| 5 |
+
Use `episode_cache_size=1` for worker-local authenticated reuse or `0` for uncached comparison. The cache key binds episode identity, source ZIP SHA, target SHA, C2 SHA, and receipt-byte digests; cache state is cleared on pickle/fork. `load_window` remains compatible.
|
| 6 |
+
|
| 7 |
+
```python
|
| 8 |
+
from loader.compact_target_aware_gwam_training_dataset import DirectCompactGWAMDatasetV3
|
| 9 |
+
dataset = DirectCompactGWAMDatasetV3(root, outer_manifest_path=outer, outer_manifest_sha256=OUTER_SHA,
|
| 10 |
+
c2_root=c2.parent, c2_index_path=c2, c2_index_sha256=C2_SHA, episode_cache_size=1)
|
| 11 |
+
example = dataset[307]
|
| 12 |
+
example.validate()
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
Run `tools/census_window_legality_v307.py` for the cheap 2,699-episode legality gate and `tools/exhaustive_gate_v307.py` for the full production-loader gate. Both are CPU-only and fail closed. No validation/test trajectories, training, optimizer, checkpoint, source mutation, or HF upload is authorized by this handoff.
|
| 16 |
+
|
| 17 |
+
The authoritative index contains **702,094** legal starts. K16 is optional and not claimed as run by this data-readiness gate; forbidden modalities remain excluded. Agents must **do not guess** at missing fields: retrieve and validate the linked source, schema, and receipt bytes.
|
| 18 |
+
|
| 19 |
+
The typed example exposes singular `example.action` and label-only `example.targets`; do not invent a plural action attribute.
|
gwam_active13_gwam_training_v3_20260801/DATASET_SUMMARY.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"artifact_type": "GWAMVerified10TaskDirectCompactTargetAwareBoundarySummary",
|
| 3 |
+
"version": "3.0.7",
|
| 4 |
+
"intended_revision": "gwam-compact-target-v3.0.7-20260801",
|
| 5 |
+
"correction_sha256": "b259a4d72b5650bd14dd7edf47e2e62fd64d78e0b7473fdb3fd3ec561ab5b8c1",
|
| 6 |
+
"prior_data_first_correction_sha256": "fe39e38029832fd97590f5a5646deeeae1cb8237efd80a71822ff719fc177efb",
|
| 7 |
+
"status": "LOCALLY_VALIDATED_PUBLICATION_RELEASE_TRAINING_NOT_AUTHORIZED",
|
| 8 |
+
"index_sha256": "f54a19de57bb3bd281b119f581762b132ded38cd298b3f7955c1de1217232b00",
|
| 9 |
+
"task_count": 10,
|
| 10 |
+
"included_tasks_scope": "verified_outer_train_subset",
|
| 11 |
+
"excluded_unverified_tasks": ["TurnOffStove", "TurnOnMicrowave", "TurnOnSinkFaucet"],
|
| 12 |
+
"complete_active13_coverage_claimed": false,
|
| 13 |
+
"episode_count": 2699,
|
| 14 |
+
"window_count_L8_H8_stride1": 702094,
|
| 15 |
+
"history_length": 8,
|
| 16 |
+
"horizon": 8,
|
| 17 |
+
"canonical_storage_node_capacity": 256,
|
| 18 |
+
"runtime_node_cardinality": "N_active",
|
| 19 |
+
"batch_node_cardinality": "max_N_active_in_batch",
|
| 20 |
+
"runtime_pair_cardinality": "N_active*(N_active-1)/2",
|
| 21 |
+
"runtime_ordered_route_cardinality": "N_active*(N_active-1)",
|
| 22 |
+
"single_graph_target_aware": true,
|
| 23 |
+
"convenience_projection_authoritative": false,
|
| 24 |
+
"convenience_physical_family_view_dim": 44,
|
| 25 |
+
"convenience_target_aware_dim": 46,
|
| 26 |
+
"convenience_visibility_duplicated": false,
|
| 27 |
+
"robot_target_contact_is_separate_derived_view": true,
|
| 28 |
+
"active_relation_ids": [0, 1, 2, 3, 4, 5],
|
| 29 |
+
"pose_xyz_frame": "canonical_world_metres",
|
| 30 |
+
"robot_target_contact_source": "typed_relation_4_edges_plus_robot_family_plus_target_bits",
|
| 31 |
+
"robot_target_contact_validity": "valid_node_target_frames_are_valid_negative_when_relation4_is_empty",
|
| 32 |
+
"holds_relation_registered": false,
|
| 33 |
+
"normal_path_decoded_member_count": 5,
|
| 34 |
+
"outer_train_only": true,
|
| 35 |
+
"sealed_model_modified": false,
|
| 36 |
+
"current_sealed_model_tokens": 16,
|
| 37 |
+
"pending_architecture_spec_token_ablation": [32, 64],
|
| 38 |
+
"pending_target_to_loss_binding": true,
|
| 39 |
+
"canonical_sources_mutated": false,
|
| 40 |
+
"published": false,
|
| 41 |
+
"window_legality_status": "PASS_702094_LOADABLE_ZERO_REJECTED",
|
| 42 |
+
"historical_v306_diagnostic": {"loadable_windows": 652495, "rejected_windows": 49599, "affected_episodes": 614, "first_rejected_start": 308},
|
| 43 |
+
"storage_truth": "authenticated source ZIPs plus target/C2 receipts; no pre-materialized compact tensor corpus"
|
| 44 |
+
}
|
gwam_active13_gwam_training_v3_20260801/GUIDE_GNN_AND_GWAM_TRAINING.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GNN and GWAM usage guide (v3.0.7)
|
| 2 |
+
|
| 3 |
+
Use `AGENT_HANDOFF_COMPACT_V307.md` and the authenticated `DirectCompactGWAMDatasetV3` cache (`episode_cache_size=1` by default). No pre-materialized compact tensor corpus is claimed; source ZIPs and sidecars remain the storage truth.
|
| 4 |
+
|
| 5 |
+
This package publishes a lazy, typed derived interface successor over a verified 10-task subset of the immutable Active-13 source lineage: 2,699 outer-train episodes and 702,094 legal `L=8,H=8` windows. It intentionally excludes `TurnOffStove`, `TurnOnMicrowave`, and `TurnOnSinkFaucet`; their actionable component/task-state contracts are not verified, so this package does not claim complete 13-task coverage. Use the immutable revision `gwam-compact-target-v3.0.7-20260801` and download the complete closure with `examples/download_compact_example.py`. OpenDrawer additionally requires the content-addressed capability receipt `gwam_active13_c2_v2_0_5_20260731/C2_CAPABILITY_RECEIPT.json` and the C2 index/episode receipt joins; the outer manifest and C2 index are pinned by the hashes in `README.md`.
|
| 6 |
+
|
| 7 |
+
The normal path excludes SAM2, CLIP, dense/stored masks, velocity/qvel, and the historical rich 337-D wrapper. The source ZIP is immutable; the loader decodes only the five declared physical/action/view members and uses C2 for articulation.
|
| 8 |
+
|
| 9 |
+
## Data to typed graph
|
| 10 |
+
|
| 11 |
+
Each frame is one canonical physical graph with typed relation edges. Three camera records enrich that same graph as `[N,3,8]` evidence; RGB remains three separate streams in the order right, left, eye-in-hand. Offline joins use `(task, episode_key, source_frame)`; live capture requires the same simulator state marker before and after graph/RGB capture. Segmentation IDs are reduced immediately inside the concrete live extractor and never cross the public packet boundary.
|
| 12 |
+
|
| 13 |
+
Authoritative tensors use fixed dtypes and validity masks: node pose `[B,8,N,7]` float32, articulation `[B,8,N,1]`, views `[B,8,N,3,8]`, stable int16 `slot_id`, typed relation endpoints/batch/time, relation payload `[E,12]`, target bits/validity, and derived robot-target contact `[B,8,N]`. Active `N` varies; collation pads to batch-local max-N with `slot_id=-1`. Family IDs are categorical embeddings/one-hot, never continuous scalars. Relation 4 is physical contact. With strict observed frames, an empty relation-4 set is a valid negative; robot-target contact is recomputed from contact edges, robot identity, and target bits. The optional 46-D convenience projection is inspection-only and never the training input.
|
| 14 |
+
|
| 15 |
+
## Causal window and GNN recipe
|
| 16 |
+
|
| 17 |
+
For start `s`, inputs are history `s..s+7` with anchor `s+7`; logged actions are `anchor..anchor+7`, where action `t` drives `t→t+1`; labels are `anchor+1..anchor+8`. No future graph or RGB enters the input.
|
| 18 |
+
|
| 19 |
+
```python
|
| 20 |
+
dataset = DirectCompactGWAMDatasetV3(root, outer_manifest_path=manifest,
|
| 21 |
+
outer_manifest_sha256=OUTER_SHA, c2_root=c2_root, c2_index_path=c2_index,
|
| 22 |
+
c2_index_sha256=C2_SHA)
|
| 23 |
+
batch = collate_compact_examples_v3((dataset[0],))
|
| 24 |
+
tokens = encode_compact_to_k16(dataset[0]) # [1,16,384], CPU audit seam
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
The intended field-aware encoder uses categorical family/static/target encoders, typed metric message passing, temporal/action conditioning, and masked target heads. The target/loss ledger is: pose XYZ and quaternion-safe rotation (`target_pose_valid`), C2 articulation (`target_articulation_valid`), pair contact occupancy/events (`target_pair_valid`), structural relations (`current_structural_valid`), and view visibility/geometry (`target_view_record_valid`), with every term masked by its corresponding validity. Report natural-risk and rare-event strata separately; do not infer performance from event prevalence.
|
| 28 |
+
|
| 29 |
+
`examples/gnn_loss_dry_run.py` performs a real-row CPU forward/binding dry-run without backward or optimizer. It reports K16 and finite binding losses while explicitly marking full target heads external where the sealed audit model does not expose a complete train-loss API.
|
| 30 |
+
|
| 31 |
+
## GWAM integration contract
|
| 32 |
+
|
| 33 |
+
Three RGB branches stay camera-specific through image encoding/fusion. The single compact graph history becomes exactly K=16 tokens `[B,16,384]` and is injected after/around multiview fusion through `ZeroGatedGWAMConditionerV3`; never make three graphs by pairing one graph with each camera. At zero gate, output is bit-identical to the baseline. The available seam is a CPU reference, not a complete trained video WAM.
|
| 34 |
+
|
| 35 |
+
```python
|
| 36 |
+
shared_latent = gwam.encode_rgb(rgb_right, rgb_left, rgb_wrist)
|
| 37 |
+
graph_tokens = encode_compact_to_k16(example)
|
| 38 |
+
fused = conditioner(shared_latent, graph_tokens, mode="on")
|
| 39 |
+
pred = video_action_delta_heads(fused)
|
| 40 |
+
loss = masked_video_loss(pred, labels) + masked_graph_loss(graph_heads, targets)
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
Required matched controls are graph-off, correct, shuffled, stale/cross-episode, with identical seeds/windows. This release contains no optimizer run, checkpoint, or performance claim.
|
| 44 |
+
|
| 45 |
+
## Live RoboCasa
|
| 46 |
+
|
| 47 |
+
The local validation environment was `/home/chris/anaconda3/envs/robocasa`; public users supply their own RoboCasa environment. A typical live command is:
|
| 48 |
+
|
| 49 |
+
```bash
|
| 50 |
+
CUDA_VISIBLE_DEVICES=0 MUJOCO_GL=egl PYOPENGL_PLATFORM=egl \
|
| 51 |
+
PYTHONPATH=. python examples/robocasa_live_compact_eval.py \
|
| 52 |
+
--task PickPlaceCabinetToCounter --split target --steps 8 \
|
| 53 |
+
--output live_summary.json --rgb-npy live_rgb.npy
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
The reader requires reset-bound target authority, uses internal immediate segmentation reduction, emits no raster, and materializes an eight-frame rolling packet from logged actions. OpenDrawer additionally requires its exact C2 receipt and reset-derived fixture-joint binding; no caller-supplied offline map is accepted by the live path.
|
| 57 |
+
|
| 58 |
+
## Alignment diagrams
|
| 59 |
+
|
| 60 |
+
```mermaid
|
| 61 |
+
flowchart LR
|
| 62 |
+
Z[immutable ZIP + receipts] --> P[typed CompactGraphPacketV3]
|
| 63 |
+
P --> G[typed GNN] --> H[masked target heads]
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
```mermaid
|
| 67 |
+
flowchart LR
|
| 68 |
+
R1[RGB right] --> F[multiview fusion]
|
| 69 |
+
R2[RGB left] --> F
|
| 70 |
+
R3[RGB wrist] --> F
|
| 71 |
+
P[one graph history] --> K[K=16 x 384]
|
| 72 |
+
F --> W[ZeroGated GWAM seam]
|
| 73 |
+
K --> W
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
```mermaid
|
| 77 |
+
timeline
|
| 78 |
+
s : history frame 0
|
| 79 |
+
s+7 : anchor; action prefix begins
|
| 80 |
+
s+8 : target 1
|
| 81 |
+
s+15 : target 8
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
## Status and dependencies
|
| 85 |
+
|
| 86 |
+
Data/interface correctness is locally validated; training remains unauthorized in this release. Existing v2 artifacts remain immutable. Minimal CPU dependencies are listed in `requirements.txt`. The guide is an integration contract, not evidence that a complete video WAM was trained.
|
gwam_active13_gwam_training_v3_20260801/PACKAGE_MANIFEST.json
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"file_count": 80,
|
| 3 |
+
"files": [
|
| 4 |
+
{
|
| 5 |
+
"path": "AGENT_HANDOFF_COMPACT_V305.md",
|
| 6 |
+
"sha256": "489afa2660395946c04a4811c5279b3f3ac354b16c945c32eb61072f054a4509",
|
| 7 |
+
"size": 251
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"path": "AGENT_HANDOFF_COMPACT_V306.md",
|
| 11 |
+
"sha256": "0b6d5de9a206e6e6fc0656ba23390bf39f0b5829bbefbcf5cda7e1c11a146661",
|
| 12 |
+
"size": 384
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"path": "AGENT_HANDOFF_COMPACT_V307.md",
|
| 16 |
+
"sha256": "51cc5ffefc8f71e4e15ab0732e7aca4e2d4cbab947f9fd97ccba3b3360fc71be",
|
| 17 |
+
"size": 1713
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"path": "DATASET_SUMMARY.json",
|
| 21 |
+
"sha256": "02b81ad2b7acca727fdda672eba4e0e63852d01b8547cf5da244f971b745c74e",
|
| 22 |
+
"size": 2328
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"path": "GUIDE_GNN_AND_GWAM_TRAINING.md",
|
| 26 |
+
"sha256": "79c8349b85484997675e760900eafbd00c91926e3b45b585a7d83213071e4bd1",
|
| 27 |
+
"size": 6504
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"path": "README.md",
|
| 31 |
+
"sha256": "41ef335a3e2220bbc2a415d7965272a91769c0a529c95e0c21f26c826bb2ad59",
|
| 32 |
+
"size": 28025
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"path": "SCHEMA.md",
|
| 36 |
+
"sha256": "fabd4625301549bfb830cae166984751c3660aa180444ff8f010e70345678f04",
|
| 37 |
+
"size": 7708
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"path": "TRAINING_EPISODES.jsonl",
|
| 41 |
+
"sha256": "f54a19de57bb3bd281b119f581762b132ded38cd298b3f7955c1de1217232b00",
|
| 42 |
+
"size": 3092602
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"path": "V306_TIMESTAMP_DEFECT_AUDIT.json",
|
| 46 |
+
"sha256": "929e89080b2f1aa4f2ceb7fa69abd1f7760e45946ff4deff1111fc04c85abd51",
|
| 47 |
+
"size": 870
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"path": "V307_COMPLETE_DATA_READINESS_RECEIPT.md",
|
| 51 |
+
"sha256": "704d5551586b143d4826140125ac69df8fb5727398f1f78f2dd55803e71b8b65",
|
| 52 |
+
"size": 1277
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"path": "V307_MIGRATION.md",
|
| 56 |
+
"sha256": "46d680e617581e781a242c4aa33f85068079a787e15fca60600e6603a4fb7e3b",
|
| 57 |
+
"size": 1483
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
"path": "VALIDATION_RECEIPT.json",
|
| 61 |
+
"sha256": "daf74d00c07b4e5a7784ef28b8810dc71fc682b48e2cf9e539c51838c02c59ce",
|
| 62 |
+
"size": 5265
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"path": "WINDOW_LEGALITY_INDEX_V307.jsonl",
|
| 66 |
+
"sha256": "0bf97bf9cb33e5584429c74cbb40177931223e8d3d7fe52307cc112f37f4afb9",
|
| 67 |
+
"size": 914744
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
"path": "WINDOW_LEGALITY_SUMMARY_V307.json",
|
| 71 |
+
"sha256": "64f69549544731deb8cbc441293229a3cc73f2695488ec35c97b077a97d540b2",
|
| 72 |
+
"size": 370
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"path": "examples/buffered_compact_target_aware_eval.py",
|
| 76 |
+
"sha256": "2204ae49ba69b368f7bec84c41e20b7a0f691dcf1b5eee9415e90bdf1101f08d",
|
| 77 |
+
"size": 6455
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"path": "examples/compact_gwam_conditioning_cpu.py",
|
| 81 |
+
"sha256": "85589f28fb088736bec5395d9b217b9a6a61ecd202ab100098beb4bd59b57aa7",
|
| 82 |
+
"size": 1666
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"path": "examples/download_compact_example.py",
|
| 86 |
+
"sha256": "b5849020c2e7446f342ae2ad12548d74a5573552264b73b124447ee70722b0b7",
|
| 87 |
+
"size": 4116
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"path": "examples/download_training_closure.py",
|
| 91 |
+
"sha256": "6efe67a487a9eedea7339e5b9a75728b5092130eb300b014cd9a215a6bd13a37",
|
| 92 |
+
"size": 9194
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"path": "examples/gnn_loss_dry_run.py",
|
| 96 |
+
"sha256": "47edf3ca18d7eb75e1a94cc845bff96961e2468aa75892a955d1d4f25210743d",
|
| 97 |
+
"size": 2089
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
"path": "examples/inspect_compact_frame.py",
|
| 101 |
+
"sha256": "e07c993cb45323746d5a1c6c95348083558ea9e2a1905f49040d235530d6c425",
|
| 102 |
+
"size": 1828
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"path": "examples/model_neutral_graph_examples.py",
|
| 106 |
+
"sha256": "7edf8d786f18c9892ebe8a5f883dbb4bf6153c98b188acbfeeda4f7fd041e665",
|
| 107 |
+
"size": 4633
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
"path": "examples/pair_graph_rgb.py",
|
| 111 |
+
"sha256": "68ca9fe605770e992f96b35df833a01f59a2b87bb7aeb42dac71362106a0aabf",
|
| 112 |
+
"size": 1063
|
| 113 |
+
},
|
| 114 |
+
{
|
| 115 |
+
"path": "examples/robocasa_live_compact_eval.py",
|
| 116 |
+
"sha256": "d218eee665c2e95023d06723620adcb2ea4527cb819431aa9ff6796625698ff8",
|
| 117 |
+
"size": 6046
|
| 118 |
+
},
|
| 119 |
+
{
|
| 120 |
+
"path": "loader/__init__.py",
|
| 121 |
+
"sha256": "c9d606abb807f2534f08ef12d1f41b0338178dea3ae695515a234e6091d2efb9",
|
| 122 |
+
"size": 66
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"path": "loader/compact_collate.py",
|
| 126 |
+
"sha256": "a7f26da9e08fcc636bcaddb7ff1fccbdfab709ae2aca1bdf9d27c90ddff2e951",
|
| 127 |
+
"size": 14278
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"path": "loader/compact_contract.py",
|
| 131 |
+
"sha256": "8a406232d4453ab805c9c42b2bc45ac4e4ee43babcaaa5e34a13e51aab26ef6a",
|
| 132 |
+
"size": 40354
|
| 133 |
+
},
|
| 134 |
+
{
|
| 135 |
+
"path": "loader/compact_target_aware_gwam_training_dataset.py",
|
| 136 |
+
"sha256": "ee98b34222617451ffc90baaef0b39ab1ebed782b08a063976aed8143753997a",
|
| 137 |
+
"size": 13357
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"path": "loader/direct_compact_source.py",
|
| 141 |
+
"sha256": "fd3d66eda92f9cff2dde3ca16ee27d2ef76bcb1f95ac90ca921a13012e90a537",
|
| 142 |
+
"size": 72628
|
| 143 |
+
},
|
| 144 |
+
{
|
| 145 |
+
"path": "loader/gwam_conditioning.py",
|
| 146 |
+
"sha256": "4413de27a20aa9110a6b918171e0e5cf2382d50fe3a4628497e669f82b1947c8",
|
| 147 |
+
"size": 2557
|
| 148 |
+
},
|
| 149 |
+
{
|
| 150 |
+
"path": "loader/online_compact_adapter.py",
|
| 151 |
+
"sha256": "527ed60bbc7c9b26d9988cc4d3b2c6a7a82c96e28c5c596be744fff113dfa1a5",
|
| 152 |
+
"size": 23418
|
| 153 |
+
},
|
| 154 |
+
{
|
| 155 |
+
"path": "loader/per_frame.py",
|
| 156 |
+
"sha256": "a0d4364953021be7bd3f20cffc6b96c371445e2347ceac1c8f3df6a8394a2891",
|
| 157 |
+
"size": 2481
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
"path": "loader/relation_geometry.py",
|
| 161 |
+
"sha256": "f5e0dd38ff99003ba45249b02d8f26376a74063ead7d9fd988751fe28ba42672",
|
| 162 |
+
"size": 7804
|
| 163 |
+
},
|
| 164 |
+
{
|
| 165 |
+
"path": "loader/rgb_pairing.py",
|
| 166 |
+
"sha256": "78b5763efdf18075028ea05b5f07736a8142ba92e6b07d3471749d8343ea5dcf",
|
| 167 |
+
"size": 3312
|
| 168 |
+
},
|
| 169 |
+
{
|
| 170 |
+
"path": "loader/robocasa_live_compact.py",
|
| 171 |
+
"sha256": "2b3882d5573ac5090ee0ce861b3543f27751b0d8ee19d66ac93de85dc760423a",
|
| 172 |
+
"size": 8949
|
| 173 |
+
},
|
| 174 |
+
{
|
| 175 |
+
"path": "loader/robocasa_mujoco_compact.py",
|
| 176 |
+
"sha256": "06ef4d0160bac10b0c8293967fcb398d2bdcd5990265876a4db3cce3c2dc7bfe",
|
| 177 |
+
"size": 17149
|
| 178 |
+
},
|
| 179 |
+
{
|
| 180 |
+
"path": "loader/sealed_model_regression.py",
|
| 181 |
+
"sha256": "b86051078508c6313f13f29500b9c406816925b50b67242d8a8497de345fc1ed",
|
| 182 |
+
"size": 6374
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"path": "loader/temporal_precision.py",
|
| 186 |
+
"sha256": "55e0dc1152c36ae133195b2de386164259b5705c1da3f7cee8d2989c24d93fb7",
|
| 187 |
+
"size": 4164
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"path": "loader/variable_n.py",
|
| 191 |
+
"sha256": "47906f8c0d66914e6583a7a8d97820e5ef16f273e39098bf5d0d285554322607",
|
| 192 |
+
"size": 6570
|
| 193 |
+
},
|
| 194 |
+
{
|
| 195 |
+
"path": "model_v2_0_4/README.md",
|
| 196 |
+
"sha256": "7c24425eca9d4979a15163c60ffa5099292b97338c05b54dc735687f777fd241",
|
| 197 |
+
"size": 1359
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
"path": "model_v2_0_4/__init__.py",
|
| 201 |
+
"sha256": "9eca17536370c8b9ec07d37f338d8a518222ac2afdca598607dcc60fe18f165c",
|
| 202 |
+
"size": 1431
|
| 203 |
+
},
|
| 204 |
+
{
|
| 205 |
+
"path": "model_v2_0_4/batch.py",
|
| 206 |
+
"sha256": "05bdf7fe3e521d2f62b5da7375649c89cc2f4aa0979e381fa85537891a38ab8a",
|
| 207 |
+
"size": 22756
|
| 208 |
+
},
|
| 209 |
+
{
|
| 210 |
+
"path": "model_v2_0_4/config.py",
|
| 211 |
+
"sha256": "3f47c1e0a8b15606d3172fd05c1d042d75737d248b5a622028bf93ef4526ac35",
|
| 212 |
+
"size": 4982
|
| 213 |
+
},
|
| 214 |
+
{
|
| 215 |
+
"path": "model_v2_0_4/controls.py",
|
| 216 |
+
"sha256": "aa35ea0a756c124a8d42254b72fbcbb4b5383e8e9e7290a1026fd14cbec41af9",
|
| 217 |
+
"size": 5887
|
| 218 |
+
},
|
| 219 |
+
{
|
| 220 |
+
"path": "model_v2_0_4/geometry.py",
|
| 221 |
+
"sha256": "f238045ce24ceed53cc8c411280244a060fffd42a0cbb74960ac03a49ea14f68",
|
| 222 |
+
"size": 14046
|
| 223 |
+
},
|
| 224 |
+
{
|
| 225 |
+
"path": "model_v2_0_4/interventions.py",
|
| 226 |
+
"sha256": "aaabf4a371ee40d65a6a6757443bb2feffc0c1196d32f50f0c95b0f14c50d9ef",
|
| 227 |
+
"size": 13552
|
| 228 |
+
},
|
| 229 |
+
{
|
| 230 |
+
"path": "model_v2_0_4/ledger.py",
|
| 231 |
+
"sha256": "e720e50826c2d4403e1b3fdd4cd915bf991d4ee79d31bd54ad684e137ad3bdb8",
|
| 232 |
+
"size": 12266
|
| 233 |
+
},
|
| 234 |
+
{
|
| 235 |
+
"path": "model_v2_0_4/loader.py",
|
| 236 |
+
"sha256": "3b125b66264ce61a2c36d27b489bc4055bf27d3af88f3963e3ef0c0d2b5b391c",
|
| 237 |
+
"size": 17774
|
| 238 |
+
},
|
| 239 |
+
{
|
| 240 |
+
"path": "model_v2_0_4/losses.py",
|
| 241 |
+
"sha256": "1892325f5f4458154fa7a519d2a8f58e9ab9b9bf28b014eba25dc3a6186e72c6",
|
| 242 |
+
"size": 13132
|
| 243 |
+
},
|
| 244 |
+
{
|
| 245 |
+
"path": "model_v2_0_4/metrics.py",
|
| 246 |
+
"sha256": "5ffed0ba116f9468a76ee9a91070ade1c64b23f787ec3b357168c92cfcd2f3d6",
|
| 247 |
+
"size": 39730
|
| 248 |
+
},
|
| 249 |
+
{
|
| 250 |
+
"path": "model_v2_0_4/model.py",
|
| 251 |
+
"sha256": "aa4d8dc39ed68f1b4e5658d6c2c908eb31cb4b7f4aca8622b3942d66dc03fa35",
|
| 252 |
+
"size": 48157
|
| 253 |
+
},
|
| 254 |
+
{
|
| 255 |
+
"path": "model_v2_0_4/persistence.py",
|
| 256 |
+
"sha256": "bdbd6306ad224c356a222d3eeaefbe4ce37ec7faaff7fcaaafc0bb827993edda",
|
| 257 |
+
"size": 11945
|
| 258 |
+
},
|
| 259 |
+
{
|
| 260 |
+
"path": "model_v2_0_4/receipts.py",
|
| 261 |
+
"sha256": "34426445729fe37ee9d2592b4c045402b62b3de36f1ce7e253356bc74564a1ca",
|
| 262 |
+
"size": 2145
|
| 263 |
+
},
|
| 264 |
+
{
|
| 265 |
+
"path": "model_v2_0_4/train_only.py",
|
| 266 |
+
"sha256": "4a96dd3adf1beed9b7a6287d858c44c5f81b4efb81642f70f3e42791070fbffc",
|
| 267 |
+
"size": 17200
|
| 268 |
+
},
|
| 269 |
+
{
|
| 270 |
+
"path": "requirements-dev.txt",
|
| 271 |
+
"sha256": "b2dfb119398ce53f30ca7436b0fc0331c791fd367d3328ce0bf510eaee000160",
|
| 272 |
+
"size": 85
|
| 273 |
+
},
|
| 274 |
+
{
|
| 275 |
+
"path": "requirements.txt",
|
| 276 |
+
"sha256": "7002f96dddac37c0b5cd9f4bcffea1492c1890aaabf7f69ee0a1ba56c411ef25",
|
| 277 |
+
"size": 45
|
| 278 |
+
},
|
| 279 |
+
{
|
| 280 |
+
"path": "tests/conftest.py",
|
| 281 |
+
"sha256": "9485b82a17588da81555610b8a2b14a9d460b0c1aeaa8a4bccbfd5618095424d",
|
| 282 |
+
"size": 188
|
| 283 |
+
},
|
| 284 |
+
{
|
| 285 |
+
"path": "tests/helpers.py",
|
| 286 |
+
"sha256": "6fac0a9b3c138032f421152661ab394b121bc3744fa44f49fc2a856b3d13819b",
|
| 287 |
+
"size": 10772
|
| 288 |
+
},
|
| 289 |
+
{
|
| 290 |
+
"path": "tests/test_collate_and_model_regression.py",
|
| 291 |
+
"sha256": "c55d6d2e408bf724a95fc437d46889328ceb0aaba73c6748d231e76caad5914e",
|
| 292 |
+
"size": 3336
|
| 293 |
+
},
|
| 294 |
+
{
|
| 295 |
+
"path": "tests/test_compact_contract.py",
|
| 296 |
+
"sha256": "a652d4c54f30be61961f56b41cb55917da63c0e7025f373effcd2726748f6f98",
|
| 297 |
+
"size": 8254
|
| 298 |
+
},
|
| 299 |
+
{
|
| 300 |
+
"path": "tests/test_direct_source_no_access.py",
|
| 301 |
+
"sha256": "9fa9fbfad9c7a005f75d09c23503eb0acb73207f012f5fd5a1de4b7b1177e689",
|
| 302 |
+
"size": 15433
|
| 303 |
+
},
|
| 304 |
+
{
|
| 305 |
+
"path": "tests/test_download_training_closure.py",
|
| 306 |
+
"sha256": "a573046e27006a9020d39215cd253cf45aaaecd8d74524dc5fcb9495de070c34",
|
| 307 |
+
"size": 4690
|
| 308 |
+
},
|
| 309 |
+
{
|
| 310 |
+
"path": "tests/test_exhaustive_gate_v307.py",
|
| 311 |
+
"sha256": "73c01c890751b9368f591e54a85c374f38316d6c03ec37dbfafdd8668dc67832",
|
| 312 |
+
"size": 6463
|
| 313 |
+
},
|
| 314 |
+
{
|
| 315 |
+
"path": "tests/test_hf_ready_finalization.py",
|
| 316 |
+
"sha256": "e9d86a36dc474f6cb5483bf300a05af632d31c9b13330d292a1906663bba057e",
|
| 317 |
+
"size": 5048
|
| 318 |
+
},
|
| 319 |
+
{
|
| 320 |
+
"path": "tests/test_model_neutral_examples.py",
|
| 321 |
+
"sha256": "98edd84c1fe61d790805ca11ebbbf56b9fb4937d87236394cb3600b2ccaac5d7",
|
| 322 |
+
"size": 1142
|
| 323 |
+
},
|
| 324 |
+
{
|
| 325 |
+
"path": "tests/test_online_buffer.py",
|
| 326 |
+
"sha256": "ad6185c0651ca0461ac3f87fb2ac793e98a211b6af3d58615a86dcf3545c03f1",
|
| 327 |
+
"size": 8783
|
| 328 |
+
},
|
| 329 |
+
{
|
| 330 |
+
"path": "tests/test_package_governance.py",
|
| 331 |
+
"sha256": "664789afbb410672a0c6794fb4bc7c828acd07735104520d6441463f34af4da1",
|
| 332 |
+
"size": 6090
|
| 333 |
+
},
|
| 334 |
+
{
|
| 335 |
+
"path": "tests/test_real_reader_contract.py",
|
| 336 |
+
"sha256": "b8cda674eddd99c002ebef7ee3fb5280c0fd379f616a81c13722ca28688e1b21",
|
| 337 |
+
"size": 7128
|
| 338 |
+
},
|
| 339 |
+
{
|
| 340 |
+
"path": "tests/test_real_train_artifacts.py",
|
| 341 |
+
"sha256": "b14d4600e65e2c1cf3dae2c6a373900dd7cc9085d62c89097626ec841382edc5",
|
| 342 |
+
"size": 7108
|
| 343 |
+
},
|
| 344 |
+
{
|
| 345 |
+
"path": "tests/test_relation_geometry.py",
|
| 346 |
+
"sha256": "05a1c6dcf32b5b49816c1b5109351497f0cc42bb45289201a642be0350152e1b",
|
| 347 |
+
"size": 2578
|
| 348 |
+
},
|
| 349 |
+
{
|
| 350 |
+
"path": "tests/test_usage_guide.py",
|
| 351 |
+
"sha256": "558d7bf8f7851179fe121be6953ca799eadbf0aee7f10012ae91c143d0b33e40",
|
| 352 |
+
"size": 618
|
| 353 |
+
},
|
| 354 |
+
{
|
| 355 |
+
"path": "tests/test_v305_adversarial_contract.py",
|
| 356 |
+
"sha256": "1eca95ed94b95878f4faf53c1d1d708c06e5e70603e885814abe4118ca8e8fd4",
|
| 357 |
+
"size": 8697
|
| 358 |
+
},
|
| 359 |
+
{
|
| 360 |
+
"path": "tests/test_v307_cache_surgical_fix.py",
|
| 361 |
+
"sha256": "c519598e367c28533e79a121751d2321a8acf94217640a1c98ad5834a010dca9",
|
| 362 |
+
"size": 11883
|
| 363 |
+
},
|
| 364 |
+
{
|
| 365 |
+
"path": "tests/test_v307_readiness.py",
|
| 366 |
+
"sha256": "b70a606a853d0f3ee20faac4b9d2c9b836ed948d21a2436a1a0d5d298b61e241",
|
| 367 |
+
"size": 2141
|
| 368 |
+
},
|
| 369 |
+
{
|
| 370 |
+
"path": "tools/build_manifest.py",
|
| 371 |
+
"sha256": "c177dbf07dab519117ae265f815f05966a71818360d7fefe628a233e9d30ee03",
|
| 372 |
+
"size": 973
|
| 373 |
+
},
|
| 374 |
+
{
|
| 375 |
+
"path": "tools/build_upload_allowlist.py",
|
| 376 |
+
"sha256": "2898b7e3889441fb07020fafe1bf720bc80607c87cd254db143fcaafa012ba19",
|
| 377 |
+
"size": 2676
|
| 378 |
+
},
|
| 379 |
+
{
|
| 380 |
+
"path": "tools/census_window_legality_v307.py",
|
| 381 |
+
"sha256": "f555d77c4dd1e851f538744652cce2ff5141024384ff90355a4131fe15521d2a",
|
| 382 |
+
"size": 3552
|
| 383 |
+
},
|
| 384 |
+
{
|
| 385 |
+
"path": "tools/compile_gate.py",
|
| 386 |
+
"sha256": "8b9fc0f22d50db6043146dabe0b638b9320400aff7891e634ea6801a07119dad",
|
| 387 |
+
"size": 481
|
| 388 |
+
},
|
| 389 |
+
{
|
| 390 |
+
"path": "tools/exhaustive_gate_v307.py",
|
| 391 |
+
"sha256": "15c5922a037053e1383912709851f29578c14e06ec07119aa0348cdd1e7bb7d6",
|
| 392 |
+
"size": 7936
|
| 393 |
+
},
|
| 394 |
+
{
|
| 395 |
+
"path": "tools/validate_manifest.py",
|
| 396 |
+
"sha256": "2386482b4bf90d1ce302af043a45cc1cb487d2574dac9d1ceda5ed2a8a6a3ad9",
|
| 397 |
+
"size": 871
|
| 398 |
+
},
|
| 399 |
+
{
|
| 400 |
+
"path": "tools/validate_upload_allowlist.py",
|
| 401 |
+
"sha256": "36c2a21fbe203b6b558b7451f0cfb514759ba3f4a78c4e16419f466a3b1705f4",
|
| 402 |
+
"size": 1913
|
| 403 |
+
}
|
| 404 |
+
],
|
| 405 |
+
"prefix": "gwam_active13_gwam_training_v3_20260801",
|
| 406 |
+
"revision": "gwam-compact-target-v3.0.7-20260801",
|
| 407 |
+
"schema": "gwam.v3.0.7.package_manifest.v1",
|
| 408 |
+
"upload_performed": false,
|
| 409 |
+
"version": "3.0.7"
|
| 410 |
+
}
|
gwam_active13_gwam_training_v3_20260801/README.md
ADDED
|
@@ -0,0 +1,415 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Verified 10-task outer-train compact target-aware graph v3.0.7
|
| 2 |
+
|
| 3 |
+
This additive successor is `gwam-compact-target-v3.0.7-20260801`. It uses the shared precision-aware temporal contract, authenticated worker-local episode cache, and exhaustive legality artifacts. v3.0.6 remains immutable historical evidence; no source ZIP, target receipt, or C2 byte changed.
|
| 4 |
+
|
| 5 |
+
Student-facing execution guide: [`GUIDE_GNN_AND_GWAM_TRAINING.md`](GUIDE_GNN_AND_GWAM_TRAINING.md).
|
| 6 |
+
|
| 7 |
+
Status: **locally validated 10-task data/interface publication release; not train-ready and training remains unauthorized pending the separately governed target-to-loss binding**.
|
| 8 |
+
|
| 9 |
+
Cold bootstrap from a clean directory: install `huggingface_hub` and the `hf` CLI, then run `hf download ChangChrisLiu/GWAM_Data --repo-type dataset --revision gwam-compact-target-v3.0.7-20260801 --include 'gwam_active13_gwam_training_v3_20260801/*' --include 'gwam_active13_c2_v2_0_5_20260731/C2_CAPABILITY_RECEIPT.json' --include 'gwam_active13_c2_v2_0_5_20260731/C2_EPISODE_INDEX.jsonl' --include 'docs/assets/*' --local-dir ./GWAM_training_closure`.
|
| 10 |
+
|
| 11 |
+
This compact package intentionally contains 2,699 resolved outer-train episodes from 10 tasks. `TurnOffStove`, `TurnOnMicrowave`, and `TurnOnSinkFaucet` are excluded because their actionable component/task-state contracts are not verified in the compact representation. The broader immutable Active-13 source release remains separate and unchanged; this prefix must not be described as complete 13-task coverage.
|
| 12 |
+
|
| 13 |
+
This README prioritizes the current v3.0.7 compact workflow. It is an additive docs/interface safety successor over the same verified 10-task source bytes; no graph corpus changed. Historical v3.0.5 root-release material is preserved verbatim in [`../docs/README_PRE_V305_ARCHIVE_20260731.md`](../docs/README_PRE_V305_ARCHIVE_20260731.md).
|
| 14 |
+
|
| 15 |
+
This tree replaces the rejected strip-after-rich-loader draft. The normal path reads the five required physical/action/view members directly and joins independently content-addressed target, C2 articulation, and geometry receipts. It never delegates to a rich dataset, visual feature backend, or rich collator. Canonical ZIPs and all v1/v2/model artifacts remain immutable. Intended revision: `gwam-compact-target-v3.0.7-20260801`.
|
| 16 |
+
|
| 17 |
+
The legacy 337-D rich vector is deprecated and is not a compact training input.
|
| 18 |
+
|
| 19 |
+
## Start here: run the dataloader to get the correct compact graph
|
| 20 |
+
|
| 21 |
+
**AI/coding agents:** start with the exact [agent handoff](AGENT_HANDOFF_COMPACT_V307.md), then retrieve the linked README/SCHEMA/GUIDE/source details.
|
| 22 |
+
|
| 23 |
+
Download stored graph ZIP + target receipt (+ OpenDrawer C2)
|
| 24 |
+
→ run DirectCompactGWAMDatasetV3
|
| 25 |
+
→ receive CompactExampleV3 with the correct typed compact graph
|
| 26 |
+
→ feed it to any GNN/world model, or optionally encode K16 for GWAM.
|
| 27 |
+
|
| 28 |
+
Students do not need offline RoboCasa, raw simulator replay, SAM2, CLIP, public masks, qvel/velocity, or their own graph conversion. Source ZIPs contain stored graph observations; the verified loader performs the strict compact projection at load time. No newly materialized compact per-frame corpus is claimed.
|
| 29 |
+
|
| 30 |
+

|
| 31 |
+

|
| 32 |
+

|
| 33 |
+

|
| 34 |
+

|
| 35 |
+

|
| 36 |
+
|
| 37 |
+
Students can use the typed packet immediately; the following sections add GWAM-specific and actual-rollout details.
|
| 38 |
+
|
| 39 |
+
### Authenticated episode cache (v3.0.7)
|
| 40 |
+
|
| 41 |
+
`DirectCompactSourceV3.open_episode` returns an opaque, immutable, PID-owned authenticated handle. Its frozen episode arrays, target/C2 receipt snapshots, source-access trace, descriptor authority, and projection-contract ID are retained for overlapping windows; the handle rejects pickle and cannot cross a worker or fork. `DirectCompactGWAMDatasetV3` keeps this cache worker-local and lazily reinitializes it after a PID change or unpickle. Cache admission is deterministic LRU with both `episode_cache_max_entries` and `episode_cache_max_bytes`; an oversized handle is served but not admitted. `cache_info()` and `clear_episode_cache()` expose only counters/metadata. A cache hit is looked up from the complete descriptor-derived key before target/C2 receipt reads, so a changed source or sidecar fails authentication on the next miss. No archive file descriptors, mutable arrays, or raw member payloads escape the handle. The documented worst-case retained memory is `worker_count * episode_cache_max_bytes` (plus batch memory); configure both bounds explicitly for production workers.
|
| 42 |
+
|
| 43 |
+
### Exact inputs and joins
|
| 44 |
+
|
| 45 |
+
| Download | Required use |
|
| 46 |
+
|---|---|
|
| 47 |
+
| This v3 package prefix and TRAINING_EPISODES.jsonl | loader code, index, schema, tests |
|
| 48 |
+
| gwam_active13_target_physical_v2_0_1_20260731/census/OUTER_TRAIN_MANIFEST.jsonl | required outer-train join; SHA256 8e33045badf338ca7f0b802b689dc74765e392014df6b9c3f8f0413d4f9b44f3 |
|
| 49 |
+
| canonical episode ZIP named by the index row | stored graph observations |
|
| 50 |
+
| row target receipt | authenticated target identity/binding, not every future label |
|
| 51 |
+
| gwam_active13_c2_v2_0_5_20260731/C2_EPISODE_INDEX.jsonl and selected receipt | OpenDrawer only; index SHA256 e7fec3656d6e479a16698f1a96aafb8b6562e99a344d568de4b58e79f76aad26 |
|
| 52 |
+
| external RGB videos | optional, only for an RGB-consuming model |
|
| 53 |
+
|
| 54 |
+
The stable RGB join identity is (source_tier, task, episode_id, graph/frames.jsonl::source_frame). The loader does not replay RoboCasa or construct new segmentation. Source ZIPs store graph observations; strict projection happens at load time.
|
| 55 |
+
|
| 56 |
+
### Full training-closure downloader
|
| 57 |
+
|
| 58 |
+
The model-neutral closure helper is examples/download_training_closure.py. It is resumable/cache-aware, verifies every source ZIP size/SHA, target receipt SHA, the outer manifest SHA, and OpenDrawer C2 index/receipt SHAs, and writes TRAINING_CLOSURE_RECEIPT.json. It never extracts, rewrites, trains, or uploads.
|
| 59 |
+
|
| 60 |
+
The full 2,699-source-ZIP closure is 20,339,307,035 bytes (20.339 GB, 18.942 GiB), plus receipts, package files, Hub cache, and filesystem overhead.
|
| 61 |
+
|
| 62 |
+
~~~bash
|
| 63 |
+
python -m pip install -r requirements.txt
|
| 64 |
+
# Bootstrap the immutable package/index and make a two-row plan first.
|
| 65 |
+
python examples/download_compact_example.py --revision gwam-compact-target-v3.0.7-20260801 --root ./GWAM_training_closure --row 0
|
| 66 |
+
python examples/download_training_closure.py --root ./GWAM_training_closure --limit 2 --dry-run
|
| 67 |
+
python examples/download_training_closure.py --root ./GWAM_training_closure --limit 2 --workers 2
|
| 68 |
+
python examples/download_training_closure.py --root ./GWAM_training_closure --task OpenDrawer --limit 2 --workers 2
|
| 69 |
+
# Full approved closure: 2,699 episodes; warn before allocating the required storage.
|
| 70 |
+
python examples/download_training_closure.py --root ./GWAM_training_closure --workers 4
|
| 71 |
+
~~~
|
| 72 |
+
|
| 73 |
+
Use the immutable revision default; add --revision gwam-compact-target-v3.0.7-20260801 only when making the binding explicit. The dry run requires a bootstrapped package index and writes a plan without Hub mutation. The full command is intentionally not run by the package tests.
|
| 74 |
+
|
| 75 |
+
### Model-neutral loader API
|
| 76 |
+
|
| 77 |
+
From the directory containing `GWAM_training_closure` after the cold bootstrap:
|
| 78 |
+
|
| 79 |
+
~~~bash
|
| 80 |
+
cd ./GWAM_training_closure/gwam_active13_gwam_training_v3_20260801
|
| 81 |
+
export PYTHONPATH="$PWD${PYTHONPATH:+:$PYTHONPATH}"
|
| 82 |
+
~~~
|
| 83 |
+
|
| 84 |
+
from loader.compact_target_aware_gwam_training_dataset import DirectCompactGWAMDatasetV3
|
| 85 |
+
from loader.per_frame import select_frame
|
| 86 |
+
|
| 87 |
+
from pathlib import Path
|
| 88 |
+
import sys
|
| 89 |
+
PACKAGE_ROOT = Path.cwd().resolve()
|
| 90 |
+
sys.path.insert(0, str(PACKAGE_ROOT))
|
| 91 |
+
root = PACKAGE_ROOT.parent
|
| 92 |
+
outer_manifest = root / "gwam_active13_target_physical_v2_0_1_20260731/census/OUTER_TRAIN_MANIFEST.jsonl"
|
| 93 |
+
dataset = DirectCompactGWAMDatasetV3(
|
| 94 |
+
root, outer_manifest_path=outer_manifest,
|
| 95 |
+
outer_manifest_sha256="8e33045badf338ca7f0b802b689dc74765e392014df6b9c3f8f0413d4f9b44f3",
|
| 96 |
+
)
|
| 97 |
+
example = dataset[0]
|
| 98 |
+
print(example.packet, example.action, example.targets, example.provenance)
|
| 99 |
+
frame0 = select_frame(example, 0)
|
| 100 |
+
|
| 101 |
+
For an OpenDrawer row, pass c2_root, c2_index_path, and the exact C2 index SHA shown above. Any missing or mismatched receipt fails closed. A standalone GNN consumes the typed packet/history directly; PyTorch Geometric conversion is optional and must remap active-node edges with the provided slot IDs. No PyG dependency is required by the core loader.
|
| 102 |
+
|
| 103 |
+
### Complete returned-field table
|
| 104 |
+
|
| 105 |
+
| Field | Shape / dtype | Validity and meaning |
|
| 106 |
+
|---|---|---|
|
| 107 |
+
| node_valid | [B,8,N] bool | active node per observed frame |
|
| 108 |
+
| slot_id | [B,N] int16 | original 0..255 storage identity; -1 only batch padding |
|
| 109 |
+
| family_id / family_valid | [B,N] int64 / bool | canonical family and static validity |
|
| 110 |
+
| static_flags / static_flags_valid | [B,N,2] bool / bool | immutable static flags |
|
| 111 |
+
| pose / pose_valid | [B,8,N,7] float32 / bool | xyz metres + quaternion XYZW |
|
| 112 |
+
| articulation_q / articulation_valid | [B,8,N,1] float32 / bool | C2 q; invalid values positive zero |
|
| 113 |
+
| view_evidence / view_record_valid | [B,8,N,3,8] float32 / bool | 3 ordered camera records |
|
| 114 |
+
| edge_index / edge_time | [2,E] int64 / [E] int16 | packed endpoints and observed time |
|
| 115 |
+
| edge_relation_id | [E] uint8 | IDs 0..5 |
|
| 116 |
+
| edge_payload / edge_payload_valid | [E,12] float32 / bool | METRIC12 and per-coordinate validity |
|
| 117 |
+
| is_task_target / task_target_valid | [B,N] bool / bool | exact target truth table below |
|
| 118 |
+
| robot_target_contact / valid | [B,8,N] bool / bool | derived contact view from relation-4 edges |
|
| 119 |
+
| current_robot_target_contact / valid | [B,N] bool / bool | target-side current-frame view in targets |
|
| 120 |
+
| future_action | float32[B,8,12] | opaque logged prefix action coordinates |
|
| 121 |
+
| future_action_valid | bool[B,8] | action validity mask |
|
| 122 |
+
| action_timestamp_s | float64[B,8] | logged action timestamps |
|
| 123 |
+
| action_timestamp_valid | bool[B,8] | timestamp validity mask |
|
| 124 |
+
| targets | target schema, see SCHEMA | future labels plus masks; never input |
|
| 125 |
+
| provenance | typed receipt fields | source, split, hashes, derivation binding |
|
| 126 |
+
|
| 127 |
+
Runtime storage is 256 slots; packed N is the active count and batch padding is batch-local max N. In a collated batch, edge_index endpoints are row-local: pair edge_index with edge_batch, or add edge_batch * N before flattening [B,N] nodes. The non-authoritative values46 convenience projection is never a model-facing requirement.
|
| 128 |
+
|
| 129 |
+
### Exact relation, geometry, and target semantics
|
| 130 |
+
|
| 131 |
+
| ID | Relation | Semantics |
|
| 132 |
+
|---:|---|---|
|
| 133 |
+
| 0 | part_of | structural component membership; inverse 1 |
|
| 134 |
+
| 1 | has_part | inverse of 0 |
|
| 135 |
+
| 2 | controls | actuator/control controls articulated component; inverse 3 |
|
| 136 |
+
| 3 | controlled_by | inverse of 2 |
|
| 137 |
+
| 4 | contact | symmetric physical touch only |
|
| 138 |
+
| 5 | geometry_near | nearest-eight geometry relation |
|
| 139 |
+
|
| 140 |
+
METRIC12 is [sender−receiver dx, dy, dz, distance, eight distance-RBF values]. Contact never infers grasp or ownership. A fully observed frame with zero contact edges is a valid negative.
|
| 141 |
+
|
| 142 |
+
| is_task_target | task_target_valid | State |
|
| 143 |
+
|---:|---:|---|
|
| 144 |
+
| 0 | 0 | unknown |
|
| 145 |
+
| 0 | 1 | known non-target |
|
| 146 |
+
| 1 | 1 | known target |
|
| 147 |
+
| 1 | 0 | invalid; fail closed |
|
| 148 |
+
|
| 149 |
+
### Model-neutral tensor and world-model examples
|
| 150 |
+
|
| 151 |
+
The tested examples/model_neutral_graph_examples.py returns a standalone tensor dictionary with active-node packing and edge remapping:
|
| 152 |
+
|
| 153 |
+
~~~python
|
| 154 |
+
from examples.model_neutral_graph_examples import standalone_tensor_dict, world_model_inputs
|
| 155 |
+
values = standalone_tensor_dict(example, time_index=0)
|
| 156 |
+
print(values["x_pose"].shape, values["edge_index"].shape, values["slot_id"].shape)
|
| 157 |
+
wm_inputs = world_model_inputs(example)
|
| 158 |
+
assert wm_inputs["graph_history"] is example.packet
|
| 159 |
+
assert wm_inputs["future_targets_labels_only"] is example.targets
|
| 160 |
+
~~~
|
| 161 |
+
|
| 162 |
+
Its optional PyTorch Geometric adapter performs the same active-node map and endpoint remap without requiring PyG for core loading:
|
| 163 |
+
|
| 164 |
+
~~~python
|
| 165 |
+
from examples.model_neutral_graph_examples import to_pyg_data
|
| 166 |
+
data = to_pyg_data(example, time_index=0) # requires optional torch_geometric
|
| 167 |
+
assert data.edge_index.shape[0] == 2
|
| 168 |
+
~~~
|
| 169 |
+
|
| 170 |
+
Keep slot IDs, masks, target validity, actions, targets, and provenance when caching or converting. The generic world-model path consumes graph history plus logged actions; future target tensors are labels-only. The optional K16 path is GWAM-specific.
|
| 171 |
+
|
| 172 |
+
**Mask warning:** validity masks are authoritative semantics. Dropping or replacing them converts unknown/padding/invalid states into apparent negatives or values and changes the contract.
|
| 173 |
+
|
| 174 |
+

|
| 175 |
+

|
| 176 |
+

|
| 177 |
+

|
| 178 |
+
|
| 179 |
+
### A. Offline GWAM training over most of the data
|
| 180 |
+
|
| 181 |
+
The approved compact outer-train corpus contains **2,699 episodes** and **702,094 L=8/H=8 windows**, covering **79.7% of the ten-task source population**. The immutable ZIP plus authenticated target receipt (and OpenDrawer C2 when selected) is read by the strict compact loader as variable-N graph history, logged actions, and targets; `encode_compact_to_k16` emits `K=16` tokens of width 384 for the sealed GWAM conditioning seam. Target-to-loss heads and optimizer authorization are separate gates; this package does not bundle or run an optimizer.
|
| 182 |
+
|
| 183 |
+
```bash
|
| 184 |
+
python examples/download_compact_example.py \
|
| 185 |
+
--revision gwam-compact-target-v3.0.7-20260801 --root ./GWAM_compact_example --row 0
|
| 186 |
+
PYTHONPATH=./GWAM_compact_example/gwam_active13_gwam_training_v3_20260801 \
|
| 187 |
+
python \
|
| 188 |
+
./GWAM_compact_example/gwam_active13_gwam_training_v3_20260801/examples/compact_gwam_conditioning_cpu.py \
|
| 189 |
+
--root ./GWAM_compact_example
|
| 190 |
+
```
|
| 191 |
+
|
| 192 |
+
```python
|
| 193 |
+
from pathlib import Path
|
| 194 |
+
import torch
|
| 195 |
+
from loader.compact_target_aware_gwam_training_dataset import DirectCompactGWAMDatasetV3
|
| 196 |
+
from loader.gwam_conditioning import encode_compact_to_k16, ZeroGatedGWAMConditionerV3
|
| 197 |
+
|
| 198 |
+
root = Path("./GWAM_compact_example")
|
| 199 |
+
outer_manifest = root / "gwam_active13_target_physical_v2_0_1_20260731/census/OUTER_TRAIN_MANIFEST.jsonl"
|
| 200 |
+
ds = DirectCompactGWAMDatasetV3(root, outer_manifest_path=outer_manifest,
|
| 201 |
+
outer_manifest_sha256="8e33045badf338ca7f0b802b689dc74765e392014df6b9c3f8f0413d4f9b44f3")
|
| 202 |
+
example = ds[0]
|
| 203 |
+
k16 = encode_compact_to_k16(example) # [1,16,384]
|
| 204 |
+
latent = torch.zeros(1, 8, 384)
|
| 205 |
+
seam = ZeroGatedGWAMConditionerV3()
|
| 206 |
+
graph_off = seam(latent, k16, mode="off")
|
| 207 |
+
graph_on = seam(latent, k16, mode="on")
|
| 208 |
+
```
|
| 209 |
+
|
| 210 |
+
### B. Validate by extracting graphs during actual rollouts
|
| 211 |
+
|
| 212 |
+
There is no required held-out offline validation package. During an actual RoboCasa rollout, `RoboCasaMuJoCoCompactReaderV3` reads live MuJoCo state and three synchronized RGB streams, authenticates the reset capability, emits one compact graph/frame, and `CompactOnlineHistoryBufferV3` materializes L=8 before K=16 encoding. Only `env.step(action)` advances the simulator; future graph/RGB frames are never inputs.
|
| 213 |
+
|
| 214 |
+
```bash
|
| 215 |
+
CUDA_VISIBLE_DEVICES=0 MUJOCO_GL=egl PYOPENGL_PLATFORM=egl PYTHONPATH=. \
|
| 216 |
+
python \
|
| 217 |
+
examples/robocasa_live_compact_eval.py \
|
| 218 |
+
--task PickPlaceCabinetToCounter --split target --steps 8 \
|
| 219 |
+
--output live_summary.json --rgb-npy live_rgb.npy
|
| 220 |
+
|
| 221 |
+
CUDA_VISIBLE_DEVICES=0 MUJOCO_GL=egl PYOPENGL_PLATFORM=egl PYTHONPATH=. \
|
| 222 |
+
python \
|
| 223 |
+
examples/robocasa_live_compact_eval.py --task OpenDrawer --split target --steps 8 \
|
| 224 |
+
--c2-receipt gwam_active13_c2_v2_0_5_20260731/C2_CAPABILITY_RECEIPT.json \
|
| 225 |
+
--output open_drawer_live_summary.json
|
| 226 |
+
```
|
| 227 |
+
|
| 228 |
+
The live contract is one graph with three camera records (RGB is a separate side channel), variable `N<=256`, optional non-authoritative 46-D convenience values, `K=16`, and no SAM2, CLIP, public masks, velocity, or qvel. See [`GUIDE_GNN_AND_GWAM_TRAINING.md`](GUIDE_GNN_AND_GWAM_TRAINING.md), [`examples/robocasa_live_compact_eval.py`](examples/robocasa_live_compact_eval.py), and [`loader/compact_target_aware_gwam_training_dataset.py`](loader/compact_target_aware_gwam_training_dataset.py).
|
| 229 |
+
|
| 230 |
+
This is a **10-task compact view over Active-13 source lineage**, not complete Active-13 coverage. Immutable source ZIPs, target receipts, the outer-train manifest (`8e33045badf338ca7f0b802b689dc74765e392014df6b9c3f8f0413d4f9b44f3`), and the C2 index (`e7fec3656d6e479a16698f1a96aafb8b6562e99a344d568de4b58e79f76aad26`) remain separately bound.
|
| 231 |
+
|
| 232 |
+
## One target-aware graph
|
| 233 |
+
|
| 234 |
+
There is one typed physical graph. `is_task_target` and `task_target_valid` are node fields in that graph; there is no parallel non-target graph. The authoritative input is `CompactGraphPacketV3`, not a flat feature matrix.
|
| 235 |
+
|
| 236 |
+
At runtime, inactive 256-slot storage padding is removed with an ascending-storage-slot lossless pack. `slot_id` retains the original storage identity. Every node tensor, relation endpoint, target bit, pair ledger, ordered route, label, and output index uses the same local remap. A batch pads only to that batch's largest `N_active`, using `slot_id=-1` plus validity masks for padding.
|
| 237 |
+
|
| 238 |
+
Pose-valid node xyz is always explicit in metres in the canonical world frame. `METRIC12` retains relative sender-minus-receiver `dx,dy,dz`; this is geometry, not a spatial-containment relation.
|
| 239 |
+
|
| 240 |
+
The optional `ConvenienceNodeProjectionV3.values46` is non-authoritative:
|
| 241 |
+
|
| 242 |
+
```text
|
| 243 |
+
2 static flags
|
| 244 |
+
7 xyz + quaternion XYZW
|
| 245 |
+
1 C2-audited articulation q
|
| 246 |
+
10 family one-hot
|
| 247 |
+
24 3 ordered cameras x [visible,cx,cy,area,xmin,ymin,xmax,ymax]
|
| 248 |
+
--
|
| 249 |
+
44 values-only physical/family/view prefix (visibility appears once)
|
| 250 |
+
2 is_task_target + task_target_valid
|
| 251 |
+
--
|
| 252 |
+
46 target-aware convenience values
|
| 253 |
+
```
|
| 254 |
+
|
| 255 |
+
`robot_target_contact[B,8,N]` and `robot_target_contact_valid[B,8,N]` remain separate derived views, recomputed from authoritative contact edges. They are never appended to the canonical node feature. There is one target-aware graph; no parallel 44/46 graph product and no model-facing API accepts `values46`.
|
| 256 |
+
|
| 257 |
+
## Direct offline boundary
|
| 258 |
+
|
| 259 |
+
`DirectCompactSourceV3` requires a frozen outer-train descriptor, exact ZIP hash/size, canonical v2.0.1 target receipt bytes, and—only for `OpenDrawer`—the exact C2 sidecar bytes. It decodes only:
|
| 260 |
+
|
| 261 |
+
- `graph_static.json`
|
| 262 |
+
- `node_state.npz`, immediately projecting active/family/static/pose columns
|
| 263 |
+
- `view_evidence.npz`
|
| 264 |
+
- `frames.jsonl`
|
| 265 |
+
- `dynamic_edges.jsonl`
|
| 266 |
+
|
| 267 |
+
The learned-visual and dense-mask members are untouched on the normal path. If an explicit integrity map is supplied, they are read only as opaque bytes and hashed; they are never decoded. Raw source q, simulator-rate state, and every derived-motion channel are neither returned nor validated as model dependencies. Articulation is exclusively C2 `q_model` plus validity; non-articulated tasks are masked positive zero.
|
| 268 |
+
|
| 269 |
+
The map-style facade is `DirectCompactGWAMDatasetV3`. Construction always requires the exact outer-manifest path/hash. The exact C2 index/root is required only when an `OpenDrawer` sample is selected; other tasks load without opening C2. The bundled 2,699-row index enumerates 702,094 `L=8,H=8` outer-train windows but is not, by itself, a train authority.
|
| 270 |
+
|
| 271 |
+
## Relations
|
| 272 |
+
|
| 273 |
+
The active profile contains exactly IDs 0..5 and `METRIC12 = [sender-receiver xyz, distance, 8 distance RBFs]`:
|
| 274 |
+
|
| 275 |
+
- `0 part_of`, with `1 has_part` inverse;
|
| 276 |
+
- `2 controls`, meaning a control or actuator controls an articulated component, with `3 controlled_by` inverse;
|
| 277 |
+
- `4 contact`, symmetric physical touch only. Contact is touch, not grasp or ownership evidence;
|
| 278 |
+
- `5 geometry_near`, nearest eight senders per receiver.
|
| 279 |
+
|
| 280 |
+
`holds/held_by` is not inferred or emitted. It requires a separately source-backed and signed relation profile.
|
| 281 |
+
|
| 282 |
+
The derived `robot_target_contact` view is recomputed from valid relation-4 contact edges, robot-family identity, and target bits. Inverse message edges cannot double-count it. For strict observed frames, an empty relation-4 edge set is a valid negative; unknown target identity remains invalid, not negative. A global phase indicator is computed on demand from the view and is not stored.
|
| 283 |
+
|
| 284 |
+
## Online boundary
|
| 285 |
+
|
| 286 |
+
`CompactOnlineHistoryBufferV3` accepts exactly eight timestamped compact physical frames, aligned logged actions, and an authenticated target capability whose canonical receipt binds the reset nonce, graph-static inventory, resolver/registry hashes, original slots, target bits, and static relations. Missing, altered, stale-reset, or inventory-disagreeing capability bytes fail closed. The adapter does not claim one-frame parity and cannot forge a train-only example.
|
| 287 |
+
|
| 288 |
+
## Open gates
|
| 289 |
+
|
| 290 |
+
- The sealed v2.0.4 K=16 model remains the current architecture boundary and was not edited. K=32/K=64 are future capacity ablations only; no token change is authorized here.
|
| 291 |
+
- A complete target-to-loss binding remains separately required.
|
| 292 |
+
- Full train authorization remains separate: it requires the signed target-to-loss binding and final training protocol. Publication of this validated data/interface package does not authorize optimizer construction.
|
| 293 |
+
|
| 294 |
+
No optimizer step, checkpoint, or training run was used to create this release. The publication operation adds only the documented compact/C2 prefixes and root documentation; canonical source ZIPs and historical tags remain unchanged.
|
| 295 |
+
|
| 296 |
+
## Hugging Face release
|
| 297 |
+
|
| 298 |
+
This prefix is a lazy derived view over immutable source ZIPs and content-addressed sidecars. Exact local gate results—including the current full suite, real offline frame loading, real live RoboCasa L=8 capture, three-video RGB decoding, and K=16 encoding—are recorded in [`VALIDATION_RECEIPT.json`](VALIDATION_RECEIPT.json).
|
| 299 |
+
|
| 300 |
+
### Download/install
|
| 301 |
+
|
| 302 |
+
Install `numpy`, `torch`, and `huggingface_hub` (`opencv-python` is optional for RGB decoding). The tested public path is:
|
| 303 |
+
|
| 304 |
+
```bash
|
| 305 |
+
python examples/download_compact_example.py \
|
| 306 |
+
--revision gwam-compact-target-v3.0.7-20260801 \
|
| 307 |
+
--root ./compact_example_download --row 0
|
| 308 |
+
|
| 309 |
+
PYTHONPATH=./compact_example_download/gwam_active13_gwam_training_v3_20260801 \
|
| 310 |
+
python ./compact_example_download/gwam_active13_gwam_training_v3_20260801/examples/inspect_compact_frame.py \
|
| 311 |
+
--root ./compact_example_download --index 0
|
| 312 |
+
```
|
| 313 |
+
|
| 314 |
+
### Download one real compact example
|
| 315 |
+
|
| 316 |
+
The following downloads the complete v3 loader/docs prefix plus exactly one
|
| 317 |
+
canonical ZIP, its target receipt, and the immutable outer-train manifest. For
|
| 318 |
+
OpenDrawer it additionally fetches the C2 index and the selected episode receipt
|
| 319 |
+
under the assumed `gwam_active13_c2_v2_0_5_20260731/` prefix:
|
| 320 |
+
|
| 321 |
+
```bash
|
| 322 |
+
python examples/download_compact_example.py --root ./compact_example_download --row 0
|
| 323 |
+
python examples/inspect_compact_frame.py \
|
| 324 |
+
--root ./compact_example_download \
|
| 325 |
+
--outer-manifest ./compact_example_download/gwam_active13_target_physical_v2_0_1_20260731/census/OUTER_TRAIN_MANIFEST.jsonl
|
| 326 |
+
python examples/compact_gwam_conditioning_cpu.py --root ./compact_example_download
|
| 327 |
+
```
|
| 328 |
+
|
| 329 |
+
The immutable dependency bindings are: outer-train manifest SHA256
|
| 330 |
+
`8e33045badf338ca7f0b802b689dc74765e392014df6b9c3f8f0413d4f9b44f3` and C2
|
| 331 |
+
episode index SHA256 `e7fec3656d6e479a16698f1a96aafb8b6562e99a344d568de4b58e79f76aad26`.
|
| 332 |
+
The download manifest records every selected path and SHA256. `DirectCompactGWAMDatasetV3`
|
| 333 |
+
joins `TRAINING_EPISODES.jsonl` to the outer manifest, reads only the selected
|
| 334 |
+
ZIP/target receipt, and requires the C2 index/receipt only when an OpenDrawer
|
| 335 |
+
row is actually selected. Source ZIPs, v3 files, sidecars, and external RGB
|
| 336 |
+
remain immutable and separate.
|
| 337 |
+
|
| 338 |
+
`DirectCompactSourceV3` selects an `L=8` window and `loader.per_frame.select_frame(example,t)` exposes variable-N typed fields. RGB is external and joined by `(source_tier, task, episode_id, frames.jsonl::source_frame)`, never copied into graph tensors. The live bridge requires an authenticated reset/C2 capability; unknown live resets are `BLOCKED_FAIL_CLOSED`. The current v2.0.4 equations emit exactly `K=16` tokens of width 384. `ZeroGatedGWAMConditionerV3` is a CPU reference seam only: graph-off, zero, detached, and shuffled controls are available, while three RGB streams remain in a separate visual path.
|
| 339 |
+
|
| 340 |
+
### Inspect per-frame / pair frame graph
|
| 341 |
+
|
| 342 |
+
Use `select_frame(example, t)` for the graph and `pair_graph_rgb.py` for the external RGB manifest. From the package directory, its tested self-bootstrap invocation is:
|
| 343 |
+
|
| 344 |
+
~~~bash
|
| 345 |
+
python examples/pair_graph_rgb.py --snapshot-root ./GWAM_training_closure --source-tier target --task PickPlaceCabinetToCounter --episode-id episode_000000 --graph-zip-sha256 SHA256_FROM_TRAINING_EPISODES --graph-t 0 --source-frame 0 --output rgb_pairing.json
|
| 346 |
+
~~~
|
| 347 |
+
|
| 348 |
+
### Live RoboCasa evaluation
|
| 349 |
+
|
| 350 |
+
In a RoboCasa environment, the concrete MuJoCo reader captures a synchronized graph plus three RGB frames without advancing simulator state. This locally validated command materializes an actual L=8 compact packet:
|
| 351 |
+
|
| 352 |
+
```bash
|
| 353 |
+
CUDA_VISIBLE_DEVICES=0 MUJOCO_GL=egl PYOPENGL_PLATFORM=egl PYTHONPATH=. \
|
| 354 |
+
python examples/robocasa_live_compact_eval.py \
|
| 355 |
+
--task PickPlaceCabinetToCounter --split target --steps 8 \
|
| 356 |
+
--output live_summary.json --rgb-npy live_rgb.npy
|
| 357 |
+
```
|
| 358 |
+
|
| 359 |
+
`OpenDrawer` additionally requires the content-addressed v2.0.5 capability receipt whose bytes, SHA, schema, and artifact type are bound into the reset capability. After reset, the reader resolves `ep_meta.fixture_refs.drawer`, requires one exact MuJoCo `<fixture>_slidejoint`/`<fixture>_joint`, and binds its `jnt_qposadr` to the corresponding `<fixture>_drawer` node. The reader verifies receipt bytes/SHA/schema/version and reset inventory/joint binding; it does not independently re-audit the receipt census or authority dependencies. Missing or ambiguous metadata/joints fail closed.
|
| 360 |
+
|
| 361 |
+
```bash
|
| 362 |
+
CUDA_VISIBLE_DEVICES=0 MUJOCO_GL=egl PYOPENGL_PLATFORM=egl PYTHONPATH=. \
|
| 363 |
+
python \
|
| 364 |
+
examples/robocasa_live_compact_eval.py \
|
| 365 |
+
--task OpenDrawer --split target --steps 8 \
|
| 366 |
+
--c2-receipt gwam_active13_c2_v2_0_5_20260731/C2_CAPABILITY_RECEIPT.json \
|
| 367 |
+
--output open_drawer_live_summary.json
|
| 368 |
+
```
|
| 369 |
+
|
| 370 |
+
The reader is `RoboCasaMuJoCoCompactReaderV3`: deterministic `ep_meta`/MuJoCo inventory, body pose/quaternion, explicit source-backed articulation mapping, current contact ancestry, and immediate three-camera segmentation reduction. It never emits velocities, dense masks, or learned visual features. Object-self tasks select the uniquely authored `object_cfgs` entry named `obj`; target identity never comes from a caller-supplied node slot. Capture is checked not to advance state; only the subsequent `env.step` advances it.
|
| 371 |
+
|
| 372 |
+
### Illustrations
|
| 373 |
+
|
| 374 |
+
```mermaid
|
| 375 |
+
flowchart LR
|
| 376 |
+
G[one physical graph\nN variable, typed edges] --> C[robot-target contact\nderived from contact edges]
|
| 377 |
+
V0[agentview_right] --> G
|
| 378 |
+
V1[agentview_left] --> G
|
| 379 |
+
V2[eye_in_hand] --> G
|
| 380 |
+
```
|
| 381 |
+
|
| 382 |
+
```mermaid
|
| 383 |
+
flowchart TB
|
| 384 |
+
N[node: static, family, xyz+quat, C2 q, 24 view values] --> P[46-D convenience\nnon-authoritative]
|
| 385 |
+
E[part_of / controls / contact / geometry_near] --> M[METRIC12 payload]
|
| 386 |
+
E --> C[contact-derived robot-target view]
|
| 387 |
+
```
|
| 388 |
+
|
| 389 |
+
```mermaid
|
| 390 |
+
sequenceDiagram
|
| 391 |
+
participant H as history L=8
|
| 392 |
+
participant A as logged actions
|
| 393 |
+
participant T as future targets H=8
|
| 394 |
+
H->>A: prefix-causal action path
|
| 395 |
+
A->>T: no future leakage
|
| 396 |
+
```
|
| 397 |
+
|
| 398 |
+
```mermaid
|
| 399 |
+
flowchart LR
|
| 400 |
+
Z[graph ZIP + frames.jsonl] --> J[(join key)]
|
| 401 |
+
R[LeRobot RGB videos] --> J
|
| 402 |
+
J --> O[offline pairing manifest]
|
| 403 |
+
L[live reset + render] --> S[synchronized graph/RGB side channel]
|
| 404 |
+
```
|
| 405 |
+
|
| 406 |
+
```mermaid
|
| 407 |
+
flowchart LR
|
| 408 |
+
P[compact packet] --> GNN[sealed v2.0.4 GNN]
|
| 409 |
+
GNN --> K[16 x 384 tokens]
|
| 410 |
+
K --> X[zero-gated cross-attention]
|
| 411 |
+
X --> W[shared GWAM latent]
|
| 412 |
+
RGB[3 RGB streams] --> W
|
| 413 |
+
```
|
| 414 |
+
|
| 415 |
+
Storage keeps source ZIPs, sidecars, and external RGB separate; runtime packs only valid nodes and typed edges, with `N<=256`, `K=16`, and no qvel, dense masks, SAM2, CLIP, finished/completed, or outcome features.
|
gwam_active13_gwam_training_v3_20260801/SCHEMA.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Direct compact target-aware schema v3.0.7
|
| 2 |
+
|
| 3 |
+
The v3.0.7 temporal contract is implemented once in `loader/temporal_precision.py`; float32-origin cadence quantization is accepted and non-finite, negative, or real gaps fail closed. Window legality is 702,094 arithmetic/loadable and zero rejected.
|
| 4 |
+
|
| 5 |
+
Prefix: `gwam_active13_gwam_training_v3_20260801/`
|
| 6 |
+
Status: verified 10-task outer-train v3.0.7 interface successor over unchanged source bytes; training remains unauthorized. This schema excludes `TurnOffStove`, `TurnOnMicrowave`, and `TurnOnSinkFaucet` and does not claim complete Active-13 coverage.
|
| 7 |
+
|
| 8 |
+
The legacy 337-D rich vector is deprecated and is not accepted by this compact boundary.
|
| 9 |
+
|
| 10 |
+
Constants are `L=8`, `H=8`, three ordered cameras, and 12 action coordinates. Canonical storage capacity remains 256 for source/audit. A runtime example uses `N=N_active`, `Q=N(N-1)/2`, and `R=N(N-1)`. A collated batch uses only `N=max(N_active)` for that batch and masks padding.
|
| 11 |
+
|
| 12 |
+
## `CompactGraphPacketV3`
|
| 13 |
+
|
| 14 |
+
| Group | Fields |
|
| 15 |
+
|---|---|
|
| 16 |
+
| time | `history_valid bool[B,8]`, `timestamp_s float64[B,8]`, `timestamp_valid`, `delta_t_s float32[B,7]`, `delta_t_valid` |
|
| 17 |
+
| identity/remap | `slot_id int16[B,N]` (original storage identity; `-1` only for batch padding), `ordered_route_index int16[2,R]`, `ordered_route_valid bool[B,R]` |
|
| 18 |
+
| node/static | `node_valid bool[B,8,N]`, `family_id int64[B,N]`, `family_valid`, `static_flags bool[B,N,2]`, `static_flags_valid` |
|
| 19 |
+
| pose | `pose float32[B,8,N,7]` as canonical-world-frame metres xyz + quaternion XYZW, `pose_valid bool[B,8,N]` |
|
| 20 |
+
| articulation | `articulation_q float32[B,8,N,1]`, `articulation_valid bool[B,8,N,1]`; only C2-audited values are valid |
|
| 21 |
+
| cameras | `view_evidence float32[B,8,N,3,8]`, `view_record_valid bool[B,8,N,3]`; camera order is right, left, wrist |
|
| 22 |
+
| relations | ragged `edge_index int64[2,E]`, `edge_batch int32[E]`, `edge_time int16[E]`, `edge_relation_id uint8[E]`, `edge_payload float32[E,12]`, `edge_payload_valid bool[E,12]` |
|
| 23 |
+
| target/contact context | `is_task_target bool[B,N]`, `task_target_valid bool[B,N]`; audit-only `task_target_source_code uint8[B,N]`; derived `robot_target_contact bool[B,8,N]` and `robot_target_contact_valid bool[B,8,N]` |
|
| 24 |
+
|
| 25 |
+
The packet is the single target-aware graph. Unknown fields fail. Numeric zero under false validity is storage only.
|
| 26 |
+
|
| 27 |
+
## Actions and labels
|
| 28 |
+
|
| 29 |
+
`CompactActionConditionV3` is separate: `future_action float32[B,8,12]`, `future_action_valid bool[B,8]`, `action_timestamp_s float64[B,8]`, and `action_timestamp_valid bool[B,8]`. Actions remain opaque source-native command coordinates.
|
| 30 |
+
|
| 31 |
+
In a collated batch, `edge_index` endpoints are row-local to the selected `[B,N]` row. Pair edges with `edge_batch`, or add `edge_batch * N` before flattening nodes.
|
| 32 |
+
|
| 33 |
+
`CompactTargetsV3` is label-only and includes:
|
| 34 |
+
|
| 35 |
+
- canonical runtime `pair_index int64[2,Q]`;
|
| 36 |
+
- anchor pair/contact and validity `[B,Q]`;
|
| 37 |
+
- future pair validity, contact occupancy, event ID and validity `[B,8,Q]`;
|
| 38 |
+
- future node/timestamp, position delta, rotation log, articulation delta, and camera labels with exact validity;
|
| 39 |
+
- current pose/articulation/contact/view aliases and dense structural labels `[B,N,N]` with validity.
|
| 40 |
+
- current robot-target contact occupancy/validity `[B,N]` and future occupancy, event, and their validity `[B,8,N]`.
|
| 41 |
+
|
| 42 |
+
Future labels never enter the packet, actions, pack selection, target resolver, or relation construction.
|
| 43 |
+
|
| 44 |
+
## Lossless storage-slot pack
|
| 45 |
+
|
| 46 |
+
For one window, select every storage slot active in its eight history frames, sorted by original slot. Construct `storage_slot -> local_index`; apply it identically to every node field, static relation, contact endpoint, target bit, pair/route label, and output identity. Selection is independent of target, future, outcome, contact change, or model state. Batch-only padding is invalid/masked and uses `slot_id=-1`.
|
| 47 |
+
|
| 48 |
+
## Relation profile
|
| 49 |
+
|
| 50 |
+
IDs are `0 part_of`, `1 has_part`, `2 controls`, `3 controlled_by`, `4 contact`, `5 geometry_near`. `controls` is actuator/control-to-articulated-component semantics, not robot handling. `contact` is touch, not grasp. No `holds/held_by` relation is registered in this profile.
|
| 51 |
+
|
| 52 |
+
Every active edge has complete `METRIC12`: sender position minus receiver position (xyz), Euclidean distance, then eight RBF values with centers `2m/7`, `m=0..7`, and sigma `0.25`. Computation widens source float32 positions to binary64 and casts once to float32. Static inverses, contact symmetry, duplicates, endpoints, sorting, and nearest-eight geometry are validated.
|
| 53 |
+
|
| 54 |
+
## Optional convenience
|
| 55 |
+
|
| 56 |
+
`values46 float32[B,8,N,46]` is explicitly non-authoritative: a 44-value physical/family/view prefix with no duplicated visibility, followed by the two target fields. `robot_target_contact[B,8,N]` and `robot_target_contact_valid[B,8,N]` are separate edge-derived views and are not appended. There is no parallel 44/46 graph product and no model conversion.
|
| 57 |
+
|
| 58 |
+
## Provenance and access
|
| 59 |
+
|
| 60 |
+
`CompactProvenanceV3` binds episode/task/window, natural-window hash, source ZIP path/hash, outer-manifest row hash, exact target and geometry receipt bytes/hashes, C2 receipt hash, pre-geometry hash, and source-access trace hash. It is audit state, not embedded input.
|
| 61 |
+
|
| 62 |
+
The normal source trace must list exactly the five decoded members. The two learned-visual/dense-mask members may appear only in the separate opaque-hash trace when explicitly requested. Validation/test paths and non-outer-train descriptors fail closed.
|
| 63 |
+
|
| 64 |
+
## Architecture independence
|
| 65 |
+
|
| 66 |
+
This data-first package keeps the sealed v2.0.4 K=16 implementation unchanged. K=32/K=64 are future capacity ablations only and require separate signed architecture specifications; no model or training work is performed here.
|
| 67 |
+
## v3 public runtime additions
|
| 68 |
+
|
| 69 |
+
The v3 prefix is a lazy, immutable derived view. `loader.per_frame.select_frame` selects one frame while preserving variable `N`, storage slots, typed edges, masks, and target validity. `loader.rgb_pairing.resolve_rgb_pairing` joins original LeRobot videos by `(source_tier, task, episode_id, frames.jsonl::source_frame)` and emits a manifest; RGB arrays never enter GraphPacket tensors. Camera order is exactly `robot0_agentview_right`, `robot0_agentview_left`, `robot0_eye_in_hand`.
|
| 70 |
+
|
| 71 |
+
`loader.robocasa_live_compact` accepts only inventory/family/static flags, absolute xyz+quat, source-backed C2 q/validity, current contact pairs, and segmentation-reduced view evidence. It returns `CompactOnlineFrameV3` plus a separately authenticated `uint8[H,W,3]` RGB bundle. State-marker equality, reset nonce, inventory digest, monotonic frame id, and stale checks fail closed. Novel reset target resolution is not inferred.
|
| 72 |
+
|
| 73 |
+
The sealed v2.0.4 adapter emits `[B,16,384]`; `loader.gwam_conditioning.ZeroGatedGWAMConditionerV3` projects these tokens to a shared latent with an exactly zero-initialized cross-attention gate. `mode=off|zero` is exact baseline; `detach|shuffle` are controls. This is an untrained CPU reference, not an external GWAM checkpoint.
|
| 74 |
+
|
| 75 |
+
The uploadable live path is `loader.robocasa_mujoco_compact.RoboCasaMuJoCoCompactReaderV3`.
|
| 76 |
+
It follows the Phase-1 RoboCasa inventory/body-ancestry rules directly: deterministic
|
| 77 |
+
`ep_meta` object/fixture inventory, MuJoCo `body_xpos/body_xquat` (projected to XYZ+XYZW),
|
| 78 |
+
explicit source-backed articulation qpos indices, `ncon` geom contacts, and immediate
|
| 79 |
+
segmentation reduction. `build_authored_obj_self_capability` binds reset metadata and
|
| 80 |
+
inventory; OpenDrawer additionally requires the content-addressed v2.0.5 capability receipt bytes/SHA/schema bound into reset capability. The reader does not independently re-audit census or authority dependencies. No caller may
|
| 81 |
+
select a target slot.
|
gwam_active13_gwam_training_v3_20260801/TRAINING_EPISODES.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
gwam_active13_gwam_training_v3_20260801/V306_TIMESTAMP_DEFECT_AUDIT.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema": "gwam.v3.0.7.v306_timestamp_defect_audit.v1",
|
| 3 |
+
"historical_tag": "gwam-compact-target-v3.0.6-20260731",
|
| 4 |
+
"historical_loadable_windows": 652495,
|
| 5 |
+
"historical_rejected_windows": 49599,
|
| 6 |
+
"historical_affected_episodes": 614,
|
| 7 |
+
"historical_first_rejected_start": 308,
|
| 8 |
+
"cause": "v3.0.6 used a fixed absolute 1e-6 comparison against float32-origin timestamps; direct_compact_source silently invalidated target timestamps and compact_contract masked those invalid horizons",
|
| 9 |
+
"replacement": "offline_f32_lattice_t0_0_v1 exact float32 lattice with fail-closed target cadence",
|
| 10 |
+
"historical_silent_label_mechanism": "622 accepted windows across 622 episodes lost at least one target horizon while validate passed: direct_compact_source set target_timestamp_valid=false and compact_contract masked that horizon out of its check",
|
| 11 |
+
"source_mutation": false
|
| 12 |
+
}
|
gwam_active13_gwam_training_v3_20260801/V307_COMPLETE_DATA_READINESS_RECEIPT.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# v3.0.7 complete data-readiness receipt
|
| 2 |
+
|
| 3 |
+
Status: **READY_FOR_LOKI_REVIEW**, not uploaded, not tagged, and not training-authorized.
|
| 4 |
+
|
| 5 |
+
Verified CPU-only: package pytest **76 passed**; temporal boundary tests; authenticated cache-enabled/disabled representative first/middle/last windows for all ten tasks (30 windows, including starts above 308 and OpenDrawer); cached and uncached canonical tensor digests byte-identical; package/C2 manifests; compile with bytecode disabled; and the package-scoped cadence census.
|
| 6 |
+
|
| 7 |
+
The v3.0.7 census is **2,699 episodes / 10 tasks / 702,094 arithmetic / 702,094 loadable / 0 rejected / 0 affected**. The preserved v3.0.6 diagnostic is 652,495 loadable, 49,599 rejected, 614 affected, first rejected start 308. The exhaustive production-loader gate is implemented at `tools/exhaustive_gate_v307.py` but was not run in this bounded session; exact launch:
|
| 8 |
+
|
| 9 |
+
```bash
|
| 10 |
+
PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=. python tools/exhaustive_gate_v307.py \
|
| 11 |
+
--root /path/to/authenticated/local/closure \
|
| 12 |
+
--output EXHAUSTIVE_GATE_V307.json
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
Storage remains source ZIPs plus authenticated target/C2 sidecars; no per-window compact tensor corpus is claimed. No source, target, C2, validation/test, HF, optimizer, checkpoint, or training bytes were changed.
|
gwam_active13_gwam_training_v3_20260801/V307_MIGRATION.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# v3.0.7 migration
|
| 2 |
+
|
| 3 |
+
v3.0.7 (`gwam-compact-target-v3.0.7-20260801`) is an additive successor. It preserves the v3.0.6 source ZIP, target-receipt, and OpenDrawer C2 bytes and changes only the loader-facing temporal contract, authenticated worker-local episode cache, legality artifacts, and documentation.
|
| 4 |
+
|
| 5 |
+
The shared `loader.temporal_precision` helper enforces the exact `offline_f32_lattice_t0_0_v1` value `float64(float32(tick*0.05))`, while rejecting non-finite, negative, and real cadence gaps. `DirectCompactGWAMDatasetV3(..., episode_cache_size=1)` caches authenticated immutable episode handles per worker; `0` disables the cache. No pre-materialized per-window tensor corpus is claimed.
|
| 6 |
+
|
| 7 |
+
The v3.0.6 defect record remains historical; v3.0.7 legality is 702,094 arithmetic/loadable windows and zero rejected windows.
|
| 8 |
+
|
| 9 |
+
v3.0.7 lives at `gwam_active13_gwam_training_v3_20260801/`. A root laid out for v3.0.6 (`..._20260731/`) is not readable by the v3.0.7 loader and fails closed with `V3_PREFIX_MISSING`. Re-bootstrap with:
|
| 10 |
+
|
| 11 |
+
```bash
|
| 12 |
+
hf download ChangChrisLiu/GWAM_Data --repo-type dataset --revision gwam-compact-target-v3.0.7-20260801 --include 'gwam_active13_gwam_training_v3_20260801/*' --local-dir <root>
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
For a frozen local v3.0.6-layout closure, pass `index_prefix='gwam_active13_gwam_training_v3_20260731'` explicitly to the dataset or `--data-prefix gwam_active13_gwam_training_v3_20260731` to the bounded gate; the prefix is part of the cache and resume fingerprint.
|
gwam_active13_gwam_training_v3_20260801/VALIDATION_RECEIPT.json
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema": "gwam.compact_v3.local_validation_receipt.v1",
|
| 3 |
+
"date": "2026-07-31",
|
| 4 |
+
"repository": "ChangChrisLiu/GWAM_Data",
|
| 5 |
+
"intended_revision": "gwam-compact-target-v3.0.7-20260801",
|
| 6 |
+
"package_prefix": "gwam_active13_gwam_training_v3_20260801",
|
| 7 |
+
"result": "PASS_FOR_DATA_INTERFACE_PUBLICATION_TRAINING_NOT_AUTHORIZED",
|
| 8 |
+
"training_authorized": false,
|
| 9 |
+
"optimizer_initializations": 0,
|
| 10 |
+
"optimizer_steps": 0,
|
| 11 |
+
"checkpoints_written": 0,
|
| 12 |
+
"gates": {
|
| 13 |
+
"standalone_package_pytest": {
|
| 14 |
+
"result": "PASS",
|
| 15 |
+
"passed": 76,
|
| 16 |
+
"failed": 0,
|
| 17 |
+
"seconds": 11.73,
|
| 18 |
+
"environment": "/home/chris/anaconda3/envs/wdg/bin/python",
|
| 19 |
+
"cwd": "/tmp",
|
| 20 |
+
"pythonpath_scope": "package_prefix_only",
|
| 21 |
+
"cuda_visible_devices": ""
|
| 22 |
+
},
|
| 23 |
+
"fresh_copy_pytest": {
|
| 24 |
+
"result": "PASS",
|
| 25 |
+
"passed": 76,
|
| 26 |
+
"skipped": 2,
|
| 27 |
+
"failed": 0,
|
| 28 |
+
"seconds": 4.73,
|
| 29 |
+
"pythonpath_scope": "copied_package_root_only",
|
| 30 |
+
"skip_reason": "optional repository-local real artifact corpus unavailable; detached full upload-tree gate still exercised all package/C2/docs tests"
|
| 31 |
+
},
|
| 32 |
+
"real_offline_compact_frame": {
|
| 33 |
+
"result": "PASS",
|
| 34 |
+
"task": "PickPlaceCabinetToCounter",
|
| 35 |
+
"episode_key": "pretrain/PickPlaceCabinetToCounter/episode_000000",
|
| 36 |
+
"nodes": 79,
|
| 37 |
+
"pose_shape": [79, 7],
|
| 38 |
+
"view_evidence_shape": [79, 3, 8],
|
| 39 |
+
"edge_count": 722,
|
| 40 |
+
"contact_edge_count": 10,
|
| 41 |
+
"target_count": 1
|
| 42 |
+
},
|
| 43 |
+
"sealed_k16_and_gwam_seam": {
|
| 44 |
+
"result": "PASS",
|
| 45 |
+
"task": "PickPlaceCabinetToCounter",
|
| 46 |
+
"graph_token_shape": [1, 16, 384],
|
| 47 |
+
"zero_gate_baseline_exact": true,
|
| 48 |
+
"conditioned_shape": [1, 8, 384]
|
| 49 |
+
},
|
| 50 |
+
"real_live_robocasa_l8": {
|
| 51 |
+
"result": "PASS",
|
| 52 |
+
"environment": "/home/chris/anaconda3/envs/robocasa/bin/python",
|
| 53 |
+
"task": "PickPlaceCabinetToCounter",
|
| 54 |
+
"split": "target",
|
| 55 |
+
"frames": 8,
|
| 56 |
+
"nodes": 114,
|
| 57 |
+
"camera_order": [
|
| 58 |
+
"robot0_agentview_right",
|
| 59 |
+
"robot0_agentview_left",
|
| 60 |
+
"robot0_eye_in_hand"
|
| 61 |
+
],
|
| 62 |
+
"rgb_shape_per_camera": [256, 256, 3],
|
| 63 |
+
"capture_state_preserved": true,
|
| 64 |
+
"steps_only_after_capture": true,
|
| 65 |
+
"l8_packet_materialized": true,
|
| 66 |
+
"k16_ready_contract": true,
|
| 67 |
+
"packet_canonical_digest": "a993e971e742455887b785b0085d8918410c4a2f5f2a2c2d955cda19eef6a8d5",
|
| 68 |
+
"summary_file_sha256": "6707e82e44b4156d29790a6888a788813c25f2c0ccc9ed5327a8c437a51d5d35"
|
| 69 |
+
},
|
| 70 |
+
"real_live_open_drawer_c2": {
|
| 71 |
+
"result": "PASS",
|
| 72 |
+
"environment": "/home/chris/anaconda3/envs/robocasa/bin/python",
|
| 73 |
+
"task": "OpenDrawer",
|
| 74 |
+
"split": "target",
|
| 75 |
+
"frames": 8,
|
| 76 |
+
"nodes": 147,
|
| 77 |
+
"camera_count": 3,
|
| 78 |
+
"capture_state_preserved": true,
|
| 79 |
+
"l8_packet_materialized": true,
|
| 80 |
+
"packet_canonical_digest": "6c6224448034978ef34a51c13767370fa02fe2deb8f78c6ba4705267c6ffde4c",
|
| 81 |
+
"target_articulation_valid_count": 1,
|
| 82 |
+
"target_articulation_q_final": -1.4562694559572265e-05,
|
| 83 |
+
"articulation_map_source": "reset ep_meta fixture_refs.drawer plus exact MuJoCo joint jnt_qposadr",
|
| 84 |
+
"summary_file_sha256": "1a09045150676c209a56838b6cdf08795dd940e1398c115c7ef043ae4bac69ea"
|
| 85 |
+
},
|
| 86 |
+
"real_rgb_pairing": {
|
| 87 |
+
"result": "PASS",
|
| 88 |
+
"task": "PickPlaceCabinetToCounter",
|
| 89 |
+
"episode_id": "episode_000000",
|
| 90 |
+
"graph_t": 0,
|
| 91 |
+
"source_frame": 0,
|
| 92 |
+
"pairing_sha256": "28de31b244682d2e5264ed67eee4f257755cbcabb0ce11ce9ee62459429e31b6",
|
| 93 |
+
"camera_count": 3,
|
| 94 |
+
"video_frame_count_each": 220,
|
| 95 |
+
"video_resolution_each": [256, 256],
|
| 96 |
+
"decoded_frame_zero_each": true
|
| 97 |
+
},
|
| 98 |
+
"forbidden_input_boundary": {
|
| 99 |
+
"result": "PASS",
|
| 100 |
+
"excluded": [
|
| 101 |
+
"SAM-derived features",
|
| 102 |
+
"type-text embeddings",
|
| 103 |
+
"raster or RLE masks",
|
| 104 |
+
"linear velocity",
|
| 105 |
+
"angular velocity",
|
| 106 |
+
"qvel"
|
| 107 |
+
],
|
| 108 |
+
"contact_source": "MuJoCo contact edges",
|
| 109 |
+
"robot_target_contact": "derived from valid relation-4 edges plus robot family plus authenticated target bits"
|
| 110 |
+
},
|
| 111 |
+
"compile_gate": {
|
| 112 |
+
"result": "PASS",
|
| 113 |
+
"command": "PYTHONDONTWRITEBYTECODE=1 python tools/compile_gate.py",
|
| 114 |
+
"bytecode_files": 0
|
| 115 |
+
},
|
| 116 |
+
"package_manifest": {
|
| 117 |
+
"result": "PASS",
|
| 118 |
+
"command": "python tools/validate_manifest.py",
|
| 119 |
+
"files": 77
|
| 120 |
+
},
|
| 121 |
+
"collated_edge_isolation": {
|
| 122 |
+
"result": "PASS",
|
| 123 |
+
"row0_edge_count": 722,
|
| 124 |
+
"row0_edge_batch": 0,
|
| 125 |
+
"batch_index_range_rejection": true,
|
| 126 |
+
"row_local_endpoints": true
|
| 127 |
+
},
|
| 128 |
+
"shipped_c2_capability": {
|
| 129 |
+
"result": "PASS",
|
| 130 |
+
"artifact_type": "OpenDrawerC2CapabilityReceiptV2_0_5",
|
| 131 |
+
"version": "2.0.5",
|
| 132 |
+
"sha256": "ff5ff53f169e6db753f21c1e91f782110bab8dcda6ae5f1f0a30c9d7c587d383"
|
| 133 |
+
},
|
| 134 |
+
"downloader_closure_plan": {
|
| 135 |
+
"result": "PASS",
|
| 136 |
+
"ordinary_and_open_drawer_dry_run": true,
|
| 137 |
+
"includes_outer_source_target_c2_index_and_episode_receipt": true
|
| 138 |
+
}
|
| 139 |
+
},
|
| 140 |
+
"immutable_dependency_sha256": {
|
| 141 |
+
"training_episode_index": "f54a19de57bb3bd281b119f581762b132ded38cd298b3f7955c1de1217232b00",
|
| 142 |
+
"outer_train_manifest": "8e33045badf338ca7f0b802b689dc74765e392014df6b9c3f8f0413d4f9b44f3",
|
| 143 |
+
"open_drawer_c2_index": "e7fec3656d6e479a16698f1a96aafb8b6562e99a344d568de4b58e79f76aad26"
|
| 144 |
+
}
|
| 145 |
+
}
|
gwam_active13_gwam_training_v3_20260801/WINDOW_LEGALITY_INDEX_V307.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
gwam_active13_gwam_training_v3_20260801/WINDOW_LEGALITY_SUMMARY_V307.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"affected_episodes": 0,
|
| 3 |
+
"arithmetic_windows": 702094,
|
| 4 |
+
"episodes": 2699,
|
| 5 |
+
"historical_v306": {
|
| 6 |
+
"affected_episodes": 614,
|
| 7 |
+
"first_rejected_start": 308,
|
| 8 |
+
"loadable_windows": 652495,
|
| 9 |
+
"rejected_windows": 49599
|
| 10 |
+
},
|
| 11 |
+
"loadable_windows": 702094,
|
| 12 |
+
"rejected_windows": 0,
|
| 13 |
+
"schema": "gwam.v3.0.7.window_legality.v1",
|
| 14 |
+
"status": "PASS",
|
| 15 |
+
"tasks": 10
|
| 16 |
+
}
|
gwam_active13_gwam_training_v3_20260801/examples/buffered_compact_target_aware_eval.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Validate an authenticated eight-frame compact online input on CPU.
|
| 3 |
+
|
| 4 |
+
This example starts after a deployment integration has reduced observations to
|
| 5 |
+
the typed physical record. It neither creates a simulator environment nor
|
| 6 |
+
accepts caller-selected target slots. The target identity comes exclusively
|
| 7 |
+
from the authenticated reset capability.
|
| 8 |
+
"""
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import argparse
|
| 12 |
+
import hashlib
|
| 13 |
+
import json
|
| 14 |
+
import sys
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
|
| 17 |
+
import numpy as np
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
PREFIX_ROOT = Path(__file__).resolve().parents[1]
|
| 21 |
+
if str(PREFIX_ROOT) not in sys.path:
|
| 22 |
+
sys.path.insert(0, str(PREFIX_ROOT))
|
| 23 |
+
|
| 24 |
+
from loader.compact_contract import CompactActionConditionV3, freeze_array # noqa: E402
|
| 25 |
+
from loader.online_compact_adapter import ( # noqa: E402
|
| 26 |
+
AuthenticatedResetTargetCapabilityV3,
|
| 27 |
+
CompactOnlineFrameV3,
|
| 28 |
+
CompactOnlineHistoryBufferV3,
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
HISTORY_KEYS = {
|
| 33 |
+
"articulation_q",
|
| 34 |
+
"articulation_valid",
|
| 35 |
+
"family_id",
|
| 36 |
+
"node_valid",
|
| 37 |
+
"pose",
|
| 38 |
+
"pose_valid",
|
| 39 |
+
"slot_id",
|
| 40 |
+
"static_flags",
|
| 41 |
+
"timestamp_s",
|
| 42 |
+
"view_evidence",
|
| 43 |
+
"view_record_valid",
|
| 44 |
+
}
|
| 45 |
+
ACTION_KEYS = {
|
| 46 |
+
"action_timestamp_s",
|
| 47 |
+
"action_timestamp_valid",
|
| 48 |
+
"future_action",
|
| 49 |
+
"future_action_valid",
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _load_npz(path: Path, expected: set[str]) -> dict[str, np.ndarray]:
|
| 54 |
+
with np.load(path, allow_pickle=False) as archive:
|
| 55 |
+
if set(archive.files) != expected:
|
| 56 |
+
raise ValueError(f"{path.name}: exact keys required: {sorted(expected)}")
|
| 57 |
+
return {name: freeze_array(archive[name]) for name in sorted(expected)}
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def _load_contacts(
|
| 61 |
+
path: Path,
|
| 62 |
+
capability: AuthenticatedResetTargetCapabilityV3,
|
| 63 |
+
) -> tuple[tuple[tuple[int, int], ...], ...]:
|
| 64 |
+
value = json.loads(path.read_bytes())
|
| 65 |
+
expected = {
|
| 66 |
+
"capability_receipt_sha256",
|
| 67 |
+
"frames",
|
| 68 |
+
"inventory_sha256",
|
| 69 |
+
"reset_nonce",
|
| 70 |
+
"schema",
|
| 71 |
+
}
|
| 72 |
+
if type(value) is not dict or set(value) != expected or not (
|
| 73 |
+
value["schema"] == "gwam.compact.online_contacts.v3"
|
| 74 |
+
and value["capability_receipt_sha256"] == capability.receipt_sha256
|
| 75 |
+
and value["inventory_sha256"] == capability.inventory_sha256
|
| 76 |
+
and value["reset_nonce"] == capability.reset_nonce
|
| 77 |
+
and type(value["frames"]) is list
|
| 78 |
+
and len(value["frames"]) == 8
|
| 79 |
+
):
|
| 80 |
+
raise ValueError("contacts receipt/capability binding")
|
| 81 |
+
result: list[tuple[tuple[int, int], ...]] = []
|
| 82 |
+
for frame in value["frames"]:
|
| 83 |
+
if type(frame) is not list:
|
| 84 |
+
raise ValueError("contacts frame must be a list")
|
| 85 |
+
pairs: list[tuple[int, int]] = []
|
| 86 |
+
for pair in frame:
|
| 87 |
+
if (
|
| 88 |
+
type(pair) is not list
|
| 89 |
+
or len(pair) != 2
|
| 90 |
+
or type(pair[0]) is not int
|
| 91 |
+
or type(pair[1]) is not int
|
| 92 |
+
):
|
| 93 |
+
raise ValueError("contact pair must contain two integer storage slots")
|
| 94 |
+
pairs.append((pair[0], pair[1]))
|
| 95 |
+
result.append(tuple(pairs))
|
| 96 |
+
return tuple(result)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def main() -> int:
|
| 100 |
+
parser = argparse.ArgumentParser()
|
| 101 |
+
parser.add_argument("--capability", type=Path, required=True)
|
| 102 |
+
parser.add_argument("--capability-sha256", required=True)
|
| 103 |
+
parser.add_argument("--history-npz", type=Path, required=True)
|
| 104 |
+
parser.add_argument("--actions-npz", type=Path, required=True)
|
| 105 |
+
parser.add_argument("--contacts-json", type=Path, required=True)
|
| 106 |
+
args = parser.parse_args()
|
| 107 |
+
|
| 108 |
+
capability_bytes = args.capability.read_bytes()
|
| 109 |
+
if hashlib.sha256(capability_bytes).hexdigest() != args.capability_sha256:
|
| 110 |
+
raise ValueError("capability command-line hash mismatch")
|
| 111 |
+
capability = AuthenticatedResetTargetCapabilityV3.from_receipt(
|
| 112 |
+
capability_bytes, args.capability_sha256
|
| 113 |
+
)
|
| 114 |
+
history = _load_npz(args.history_npz, HISTORY_KEYS)
|
| 115 |
+
actions = _load_npz(args.actions_npz, ACTION_KEYS)
|
| 116 |
+
contacts = _load_contacts(args.contacts_json, capability)
|
| 117 |
+
|
| 118 |
+
timestamps = history["timestamp_s"]
|
| 119 |
+
if timestamps.dtype != np.dtype("<f8") or timestamps.shape != (8,):
|
| 120 |
+
raise ValueError("timestamp_s must be little-endian float64[8]")
|
| 121 |
+
buffer = CompactOnlineHistoryBufferV3(capability)
|
| 122 |
+
for time_index in range(8):
|
| 123 |
+
buffer.append(
|
| 124 |
+
CompactOnlineFrameV3(
|
| 125 |
+
reset_nonce=capability.reset_nonce,
|
| 126 |
+
inventory_sha256=capability.inventory_sha256,
|
| 127 |
+
timestamp_s=float(timestamps[time_index]),
|
| 128 |
+
slot_id=history["slot_id"],
|
| 129 |
+
family_id=history["family_id"],
|
| 130 |
+
static_flags=history["static_flags"],
|
| 131 |
+
node_valid=freeze_array(history["node_valid"][time_index], dtype="|b1"),
|
| 132 |
+
pose=freeze_array(history["pose"][time_index], dtype="<f4"),
|
| 133 |
+
pose_valid=freeze_array(history["pose_valid"][time_index], dtype="|b1"),
|
| 134 |
+
articulation_q=freeze_array(
|
| 135 |
+
history["articulation_q"][time_index], dtype="<f4"
|
| 136 |
+
),
|
| 137 |
+
articulation_valid=freeze_array(
|
| 138 |
+
history["articulation_valid"][time_index], dtype="|b1"
|
| 139 |
+
),
|
| 140 |
+
view_evidence=freeze_array(
|
| 141 |
+
history["view_evidence"][time_index], dtype="<f4"
|
| 142 |
+
),
|
| 143 |
+
view_record_valid=freeze_array(
|
| 144 |
+
history["view_record_valid"][time_index], dtype="|b1"
|
| 145 |
+
),
|
| 146 |
+
contacts=contacts[time_index],
|
| 147 |
+
)
|
| 148 |
+
)
|
| 149 |
+
action = CompactActionConditionV3(
|
| 150 |
+
future_action=freeze_array(actions["future_action"], dtype="<f4"),
|
| 151 |
+
future_action_valid=freeze_array(actions["future_action_valid"], dtype="|b1"),
|
| 152 |
+
action_timestamp_s=freeze_array(actions["action_timestamp_s"], dtype="<f8"),
|
| 153 |
+
action_timestamp_valid=freeze_array(
|
| 154 |
+
actions["action_timestamp_valid"], dtype="|b1"
|
| 155 |
+
),
|
| 156 |
+
)
|
| 157 |
+
online = buffer.materialize(action)
|
| 158 |
+
result = {
|
| 159 |
+
"capability_receipt_sha256": online.capability_receipt_sha256,
|
| 160 |
+
"edge_count": int(online.packet.edge_relation_id.size),
|
| 161 |
+
"node_count": online.packet.n_nodes,
|
| 162 |
+
"packet_tensor_sha256": online.packet.canonical_tensor_digest(),
|
| 163 |
+
"status": "AUTHENTICATED_EIGHT_FRAME_COMPACT_INPUT_VALIDATED",
|
| 164 |
+
"target_count": int(online.packet.is_task_target.sum()),
|
| 165 |
+
}
|
| 166 |
+
print(json.dumps(result, sort_keys=True, indent=2))
|
| 167 |
+
return 0
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
if __name__ == "__main__":
|
| 171 |
+
raise SystemExit(main())
|
gwam_active13_gwam_training_v3_20260801/examples/compact_gwam_conditioning_cpu.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Load one real compact example, encode K=16 tokens, and test the seam."""
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
import argparse, json
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import sys
|
| 7 |
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
| 8 |
+
import torch
|
| 9 |
+
from loader.compact_target_aware_gwam_training_dataset import DirectCompactGWAMDatasetV3
|
| 10 |
+
from loader.gwam_conditioning import ZeroGatedGWAMConditionerV3, encode_compact_to_k16
|
| 11 |
+
OUTER_SHA="8e33045badf338ca7f0b802b689dc74765e392014df6b9c3f8f0413d4f9b44f3"; C2_SHA="e7fec3656d6e479a16698f1a96aafb8b6562e99a344d568de4b58e79f76aad26"
|
| 12 |
+
def main():
|
| 13 |
+
ap=argparse.ArgumentParser(); ap.add_argument('--root',default='.'); ap.add_argument('--index',type=int,default=0); ap.add_argument('--outer-manifest'); ap.add_argument('--c2-root'); ap.add_argument('--c2-index'); args=ap.parse_args(); root=Path(args.root); outer=Path(args.outer_manifest or root/'gwam_active13_target_physical_v2_0_1_20260731/census/OUTER_TRAIN_MANIFEST.jsonl'); c2idx=Path(args.c2_index) if args.c2_index else None; ds=DirectCompactGWAMDatasetV3(root,outer_manifest_path=outer,outer_manifest_sha256=OUTER_SHA,c2_root=Path(args.c2_root) if args.c2_root else None,c2_index_path=c2idx,c2_index_sha256=C2_SHA if c2idx else None); ex=ds[args.index]; tokens=encode_compact_to_k16(ex); latent=torch.zeros(1,8,384); mod=ZeroGatedGWAMConditionerV3(); baseline=mod(latent,tokens,mode='off'); assert torch.equal(baseline,latent); print(json.dumps({'task':ex.provenance.task[0],'tokens':list(tokens.shape),'zero_gate_baseline_exact':True,'on_shape':list(mod(latent,tokens).shape)},indent=2)); return 0
|
| 14 |
+
if __name__=='__main__': raise SystemExit(main())
|
gwam_active13_gwam_training_v3_20260801/examples/download_compact_example.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Download one immutable compact example and its exact dependency closure.
|
| 3 |
+
|
| 4 |
+
This is preparation only: it reads Hub bytes into a local directory and never
|
| 5 |
+
uploads, tags, trains, or rewrites source data.
|
| 6 |
+
"""
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
import argparse, hashlib, json
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
from huggingface_hub import hf_hub_download, snapshot_download
|
| 11 |
+
|
| 12 |
+
V3_PREFIX="gwam_active13_gwam_training_v3_20260801"
|
| 13 |
+
OUTER_PATH="gwam_active13_target_physical_v2_0_1_20260731/census/OUTER_TRAIN_MANIFEST.jsonl"
|
| 14 |
+
OUTER_SHA="8e33045badf338ca7f0b802b689dc74765e392014df6b9c3f8f0413d4f9b44f3"
|
| 15 |
+
C2_PREFIX="gwam_active13_c2_v2_0_5_20260731"
|
| 16 |
+
C2_INDEX_SHA="e7fec3656d6e479a16698f1a96aafb8b6562e99a344d568de4b58e79f76aad26"
|
| 17 |
+
|
| 18 |
+
def sha(path: Path) -> str: return hashlib.sha256(path.read_bytes()).hexdigest()
|
| 19 |
+
def rows(path: Path): return [json.loads(x) for x in path.read_bytes().splitlines() if x.strip()]
|
| 20 |
+
|
| 21 |
+
def main() -> int:
|
| 22 |
+
ap=argparse.ArgumentParser(); ap.add_argument('--repo-id',default='ChangChrisLiu/GWAM_Data'); ap.add_argument('--revision',default='gwam-compact-target-v3.0.7-20260801'); ap.add_argument('--root',default='compact_example_download'); ap.add_argument('--row',type=int,default=0); args=ap.parse_args()
|
| 23 |
+
root=Path(args.root).resolve(); root.mkdir(parents=True,exist_ok=True)
|
| 24 |
+
# The complete v3 prefix is the public loader/schema/test closure.
|
| 25 |
+
snapshot_download(repo_id=args.repo_id,repo_type='dataset',revision=args.revision,allow_patterns=[f'{V3_PREFIX}/**'],local_dir=str(root))
|
| 26 |
+
index=root/V3_PREFIX/'TRAINING_EPISODES.jsonl'; selected=rows(index)[args.row]
|
| 27 |
+
outer=Path(hf_hub_download(repo_id=args.repo_id,repo_type='dataset',revision=args.revision,filename=OUTER_PATH,local_dir=str(root)))
|
| 28 |
+
if sha(outer)!=OUTER_SHA: raise SystemExit('OUTER_MANIFEST_SHA256_MISMATCH')
|
| 29 |
+
source=Path(hf_hub_download(repo_id=args.repo_id,repo_type='dataset',revision=args.revision,filename=selected['canonical_zip_path'],local_dir=str(root)))
|
| 30 |
+
if sha(source)!=selected['canonical_zip_sha256']: raise SystemExit('SOURCE_ZIP_SHA256_MISMATCH')
|
| 31 |
+
target=Path(hf_hub_download(repo_id=args.repo_id,repo_type='dataset',revision=args.revision,filename=selected['target_receipt_path'],local_dir=str(root)))
|
| 32 |
+
if sha(target)!=selected['target_receipt_sha256']: raise SystemExit('TARGET_RECEIPT_SHA256_MISMATCH')
|
| 33 |
+
c2_index=None; c2_receipt=None
|
| 34 |
+
# Dataset construction validates the full C2 index; the receipt is fetched only for OpenDrawer.
|
| 35 |
+
if selected['task']=='OpenDrawer':
|
| 36 |
+
c2_index=Path(hf_hub_download(repo_id=args.repo_id,repo_type='dataset',revision=args.revision,filename=f'{C2_PREFIX}/C2_EPISODE_INDEX.jsonl',local_dir=str(root)))
|
| 37 |
+
if sha(c2_index)!=C2_INDEX_SHA: raise SystemExit('C2_INDEX_SHA256_MISMATCH')
|
| 38 |
+
c2row=next(x for x in rows(c2_index) if x['episode_key']==selected['episode_key'])
|
| 39 |
+
c2_receipt=Path(hf_hub_download(repo_id=args.repo_id,repo_type='dataset',revision=args.revision,filename=f"{C2_PREFIX}/{c2row['receipt_relative_path']}",local_dir=str(root)))
|
| 40 |
+
if sha(c2_receipt)!=c2row['receipt_sha256']: raise SystemExit('C2_RECEIPT_SHA256_MISMATCH')
|
| 41 |
+
manifest={'schema':'gwam.compact.example_download.v3','repo_id':args.repo_id,'revision':args.revision,'row_index':args.row,'episode_key':selected['episode_key'],'task':selected['task'],'v3_prefix':V3_PREFIX,'outer_manifest_path':str(outer.relative_to(root)),'outer_manifest_sha256':sha(outer),'source_zip_path':str(source.relative_to(root)),'source_zip_sha256':sha(source),'target_receipt_path':str(target.relative_to(root)),'target_receipt_sha256':sha(target),'c2_index_path':None if c2_index is None else str(c2_index.relative_to(root)),'c2_index_sha256':None if c2_index is None else sha(c2_index),'c2_receipt_path':None if c2_receipt is None else str(c2_receipt.relative_to(root)),'c2_receipt_sha256':None if c2_receipt is None else sha(c2_receipt)}
|
| 42 |
+
(root/'COMPACT_EXAMPLE_DOWNLOAD.json').write_text(json.dumps(manifest,indent=2,sort_keys=True)+'\n')
|
| 43 |
+
print(json.dumps(manifest,indent=2)); return 0
|
| 44 |
+
if __name__=='__main__': raise SystemExit(main())
|
gwam_active13_gwam_training_v3_20260801/examples/download_training_closure.py
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Resumable, hash-verifying download of the complete v3.0.7 train closure.
|
| 3 |
+
|
| 4 |
+
This helper only downloads immutable Hub bytes and writes a deterministic
|
| 5 |
+
receipt. It never extracts, rewrites, uploads, trains, or creates checkpoints.
|
| 6 |
+
"""
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import argparse
|
| 10 |
+
import concurrent.futures
|
| 11 |
+
import hashlib
|
| 12 |
+
import json
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
from typing import Any
|
| 15 |
+
|
| 16 |
+
from huggingface_hub import hf_hub_download, snapshot_download
|
| 17 |
+
|
| 18 |
+
V3_PREFIX = "gwam_active13_gwam_training_v3_20260801"
|
| 19 |
+
OUTER_PATH = "gwam_active13_target_physical_v2_0_1_20260731/census/OUTER_TRAIN_MANIFEST.jsonl"
|
| 20 |
+
OUTER_SHA = "8e33045badf338ca7f0b802b689dc74765e392014df6b9c3f8f0413d4f9b44f3"
|
| 21 |
+
C2_PREFIX = "gwam_active13_c2_v2_0_5_20260731"
|
| 22 |
+
C2_INDEX_PATH = f"{C2_PREFIX}/C2_EPISODE_INDEX.jsonl"
|
| 23 |
+
C2_INDEX_SHA = "e7fec3656d6e479a16698f1a96aafb8b6562e99a344d568de4b58e79f76aad26"
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def digest(path: Path) -> str:
|
| 27 |
+
return hashlib.sha256(path.read_bytes()).hexdigest()
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def read_jsonl(path: Path) -> list[dict[str, Any]]:
|
| 31 |
+
return [json.loads(line) for line in path.read_bytes().splitlines() if line.strip()]
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def select_rows(rows: list[dict[str, Any]], *, limit: int | None, task: str | None) -> list[dict[str, Any]]:
|
| 35 |
+
selected = [row for row in rows if task is None or row.get("task") == task]
|
| 36 |
+
if limit is not None:
|
| 37 |
+
selected = selected[:limit]
|
| 38 |
+
return selected
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def expected_downloads(rows: list[dict[str, Any]], c2_rows: dict[str, dict[str, Any]] | None = None) -> list[str]:
|
| 42 |
+
paths = {OUTER_PATH}
|
| 43 |
+
paths.update(str(row["canonical_zip_path"]) for row in rows)
|
| 44 |
+
paths.update(str(row["target_receipt_path"]) for row in rows)
|
| 45 |
+
if any(row.get("task") == "OpenDrawer" for row in rows):
|
| 46 |
+
paths.add(C2_INDEX_PATH)
|
| 47 |
+
if c2_rows:
|
| 48 |
+
paths.update(
|
| 49 |
+
f"{C2_PREFIX}/{value['receipt_relative_path']}"
|
| 50 |
+
for row in rows
|
| 51 |
+
if row.get("task") == "OpenDrawer"
|
| 52 |
+
for value in [c2_rows.get(str(row["episode_key"]))]
|
| 53 |
+
if value is not None
|
| 54 |
+
)
|
| 55 |
+
return sorted(paths)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def _download_one(repo_id: str, revision: str, root: Path, row: dict[str, Any]) -> dict[str, Any]:
|
| 59 |
+
result: dict[str, Any] = {"episode_key": row["episode_key"], "task": row["task"], "status": "ok"}
|
| 60 |
+
try:
|
| 61 |
+
source = Path(hf_hub_download(repo_id=repo_id, repo_type="dataset", revision=revision,
|
| 62 |
+
filename=str(row["canonical_zip_path"]), local_dir=str(root)))
|
| 63 |
+
if source.stat().st_size != int(row["canonical_zip_size"]):
|
| 64 |
+
raise ValueError("SOURCE_ZIP_SIZE_MISMATCH")
|
| 65 |
+
if digest(source) != row["canonical_zip_sha256"]:
|
| 66 |
+
raise ValueError("SOURCE_ZIP_SHA256_MISMATCH")
|
| 67 |
+
target = Path(hf_hub_download(repo_id=repo_id, repo_type="dataset", revision=revision,
|
| 68 |
+
filename=str(row["target_receipt_path"]), local_dir=str(root)))
|
| 69 |
+
if digest(target) != row["target_receipt_sha256"]:
|
| 70 |
+
raise ValueError("TARGET_RECEIPT_SHA256_MISMATCH")
|
| 71 |
+
result.update(source_zip_sha256=digest(source), source_zip_size=source.stat().st_size,
|
| 72 |
+
target_receipt_sha256=digest(target))
|
| 73 |
+
return result
|
| 74 |
+
except Exception as exc:
|
| 75 |
+
result.update(status="failed", error=type(exc).__name__ + ":" + str(exc))
|
| 76 |
+
return result
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def main() -> int:
|
| 80 |
+
parser = argparse.ArgumentParser()
|
| 81 |
+
parser.add_argument("--repo-id", default="ChangChrisLiu/GWAM_Data")
|
| 82 |
+
parser.add_argument("--revision", default="gwam-compact-target-v3.0.7-20260801")
|
| 83 |
+
parser.add_argument("--root", default="gwam_training_closure")
|
| 84 |
+
parser.add_argument("--limit", type=int)
|
| 85 |
+
parser.add_argument("--task")
|
| 86 |
+
parser.add_argument("--workers", type=int, default=4)
|
| 87 |
+
parser.add_argument("--dry-run", action="store_true")
|
| 88 |
+
args = parser.parse_args()
|
| 89 |
+
if args.limit is not None and args.limit < 0:
|
| 90 |
+
parser.error("--limit must be non-negative")
|
| 91 |
+
if args.workers < 1:
|
| 92 |
+
parser.error("--workers must be positive")
|
| 93 |
+
root = Path(args.root).resolve()
|
| 94 |
+
prefix_index = root / V3_PREFIX / "TRAINING_EPISODES.jsonl"
|
| 95 |
+
if not args.dry_run:
|
| 96 |
+
root.mkdir(parents=True, exist_ok=True)
|
| 97 |
+
snapshot_download(repo_id=args.repo_id, repo_type="dataset", revision=args.revision,
|
| 98 |
+
allow_patterns=[f"{V3_PREFIX}/**"], local_dir=str(root))
|
| 99 |
+
if not prefix_index.is_file():
|
| 100 |
+
raise SystemExit("TRAINING_INDEX_REQUIRED_FOR_DRY_RUN" if args.dry_run else "TRAINING_INDEX_MISSING")
|
| 101 |
+
rows = select_rows(read_jsonl(prefix_index), limit=args.limit, task=args.task)
|
| 102 |
+
c2_rows: dict[str, dict[str, Any]] = {}
|
| 103 |
+
c2_index_sha: str | None = None
|
| 104 |
+
if any(row.get("task") == "OpenDrawer" for row in rows):
|
| 105 |
+
c2_index_path = root / C2_INDEX_PATH
|
| 106 |
+
try:
|
| 107 |
+
if not c2_index_path.is_file():
|
| 108 |
+
c2_index_path = Path(hf_hub_download(repo_id=args.repo_id, repo_type="dataset",
|
| 109 |
+
revision=args.revision, filename=C2_INDEX_PATH, local_dir=str(root)))
|
| 110 |
+
if not c2_index_path.is_file():
|
| 111 |
+
raise FileNotFoundError(c2_index_path)
|
| 112 |
+
if digest(c2_index_path) != C2_INDEX_SHA:
|
| 113 |
+
raise ValueError("C2_INDEX_SHA256_MISMATCH")
|
| 114 |
+
c2_rows = {str(row["episode_key"]): row for row in read_jsonl(c2_index_path)}
|
| 115 |
+
c2_index_sha = C2_INDEX_SHA
|
| 116 |
+
except Exception as exc:
|
| 117 |
+
raise SystemExit(
|
| 118 |
+
"C2_INDEX_METADATA_REQUIRED: bootstrap C2_EPISODE_INDEX.jsonl at "
|
| 119 |
+
f"{C2_INDEX_PATH} before dry-run ({type(exc).__name__})"
|
| 120 |
+
) from exc
|
| 121 |
+
planned = expected_downloads(rows, c2_rows)
|
| 122 |
+
receipt: dict[str, Any] = {
|
| 123 |
+
"schema": "gwam.compact.training_closure.v3",
|
| 124 |
+
"repo_id": args.repo_id, "revision": args.revision,
|
| 125 |
+
"v3_prefix": V3_PREFIX, "dry_run": bool(args.dry_run),
|
| 126 |
+
"requested_limit": args.limit, "requested_task": args.task,
|
| 127 |
+
"resolved_episode_count": len(rows), "approved_episode_count": 2699,
|
| 128 |
+
"planned_paths": planned, "failures": [], "episodes": [],
|
| 129 |
+
"c2_receipts": [
|
| 130 |
+
{"episode_key": str(row["episode_key"]), "path": f"{C2_PREFIX}/{c2_rows[str(row['episode_key'])]['receipt_relative_path']}",
|
| 131 |
+
"sha256": str(c2_rows[str(row["episode_key"])]["receipt_sha256"])}
|
| 132 |
+
for row in rows if row.get("task") == "OpenDrawer" and str(row["episode_key"]) in c2_rows
|
| 133 |
+
],
|
| 134 |
+
}
|
| 135 |
+
if args.dry_run:
|
| 136 |
+
receipt["status"] = "PLAN_ONLY"
|
| 137 |
+
(root / "TRAINING_CLOSURE_RECEIPT.json").write_text(json.dumps(receipt, indent=2, sort_keys=True) + "\n")
|
| 138 |
+
print(json.dumps(receipt, indent=2, sort_keys=True))
|
| 139 |
+
return 0
|
| 140 |
+
outer = Path(hf_hub_download(repo_id=args.repo_id, repo_type="dataset", revision=args.revision,
|
| 141 |
+
filename=OUTER_PATH, local_dir=str(root)))
|
| 142 |
+
if digest(outer) != OUTER_SHA:
|
| 143 |
+
raise SystemExit("OUTER_MANIFEST_SHA256_MISMATCH")
|
| 144 |
+
if any(row.get("task") == "OpenDrawer" for row in rows):
|
| 145 |
+
c2_index = Path(hf_hub_download(repo_id=args.repo_id, repo_type="dataset", revision=args.revision,
|
| 146 |
+
filename=C2_INDEX_PATH, local_dir=str(root)))
|
| 147 |
+
if digest(c2_index) != C2_INDEX_SHA:
|
| 148 |
+
raise SystemExit("C2_INDEX_SHA256_MISMATCH")
|
| 149 |
+
c2_rows = {str(row["episode_key"]): row for row in read_jsonl(c2_index)}
|
| 150 |
+
for row in rows:
|
| 151 |
+
if row.get("task") == "OpenDrawer":
|
| 152 |
+
c2 = c2_rows.get(str(row["episode_key"]))
|
| 153 |
+
if not c2:
|
| 154 |
+
receipt["failures"].append({"episode_key": row["episode_key"], "error": "C2_EPISODE_JOIN"})
|
| 155 |
+
continue
|
| 156 |
+
c2_path = Path(hf_hub_download(repo_id=args.repo_id, repo_type="dataset", revision=args.revision,
|
| 157 |
+
filename=f"{C2_PREFIX}/{c2['receipt_relative_path']}", local_dir=str(root)))
|
| 158 |
+
if digest(c2_path) != c2["receipt_sha256"]:
|
| 159 |
+
receipt["failures"].append({"episode_key": row["episode_key"], "error": "C2_RECEIPT_SHA256_MISMATCH"})
|
| 160 |
+
worker_count = min(args.workers, max(1, len(rows)))
|
| 161 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=worker_count) as pool:
|
| 162 |
+
results = list(pool.map(lambda item: _download_one(args.repo_id, args.revision, root, item), rows))
|
| 163 |
+
receipt["episodes"] = sorted(results, key=lambda value: str(value["episode_key"]))
|
| 164 |
+
receipt["failures"].extend({"episode_key": value["episode_key"], "error": value["error"]}
|
| 165 |
+
for value in results if value["status"] != "ok")
|
| 166 |
+
receipt["outer_manifest_sha256"] = digest(outer)
|
| 167 |
+
receipt["c2_index_sha256"] = c2_index_sha or (C2_INDEX_SHA if c2_rows else None)
|
| 168 |
+
receipt["status"] = "PASS" if not receipt["failures"] and len(results) == len(rows) else "FAIL_CLOSED"
|
| 169 |
+
(root / "TRAINING_CLOSURE_RECEIPT.json").write_text(json.dumps(receipt, indent=2, sort_keys=True) + "\n")
|
| 170 |
+
print(json.dumps(receipt, indent=2, sort_keys=True))
|
| 171 |
+
return 0 if receipt["status"] == "PASS" else 2
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
if __name__ == "__main__":
|
| 175 |
+
raise SystemExit(main())
|
gwam_active13_gwam_training_v3_20260801/examples/gnn_loss_dry_run.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Real-row CPU GNN/K16 forward and loss-binding dry-run; never backpropagates."""
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
import argparse, json
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import sys
|
| 7 |
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
| 8 |
+
import torch
|
| 9 |
+
from loader.compact_target_aware_gwam_training_dataset import DirectCompactGWAMDatasetV3
|
| 10 |
+
from loader.compact_collate import collate_compact_examples_v3
|
| 11 |
+
from loader.gwam_conditioning import encode_compact_to_k16
|
| 12 |
+
|
| 13 |
+
OUTER_SHA="8e33045badf338ca7f0b802b689dc74765e392014df6b9c3f8f0413d4f9b44f3"; C2_SHA="e7fec3656d6e479a16698f1a96aafb8b6562e99a344d568de4b58e79f76aad26"
|
| 14 |
+
def main():
|
| 15 |
+
ap=argparse.ArgumentParser(); ap.add_argument('--root',required=True); ap.add_argument('--outer-manifest',required=True); ap.add_argument('--c2-root'); ap.add_argument('--c2-index'); ap.add_argument('--index',type=int,default=0); a=ap.parse_args()
|
| 16 |
+
ds=DirectCompactGWAMDatasetV3(Path(a.root), outer_manifest_path=Path(a.outer_manifest), outer_manifest_sha256=OUTER_SHA, c2_root=Path(a.c2_root) if a.c2_root else None, c2_index_path=Path(a.c2_index) if a.c2_index else None, c2_index_sha256=C2_SHA if a.c2_index else None)
|
| 17 |
+
ex=ds[a.index]; batch=collate_compact_examples_v3((ex,)); tokens=encode_compact_to_k16(ex)
|
| 18 |
+
# Binding-only finite masked terms. Full target heads remain external to the sealed audit seam.
|
| 19 |
+
masks=[torch.as_tensor(ex.targets.target_pose_valid), torch.as_tensor(ex.targets.target_articulation_valid), torch.as_tensor(ex.targets.target_pair_valid), torch.as_tensor(ex.targets.target_view_record_valid)]
|
| 20 |
+
losses=[torch.zeros((),dtype=torch.float32)+m.to(torch.float32).mean() for m in masks]
|
| 21 |
+
assert tokens.shape==(1,16,384) and all(torch.isfinite(v) for v in losses)
|
| 22 |
+
print(json.dumps({'task':ex.provenance.task[0],'batch_node_shape':list(batch.packet.node_valid.shape),'k16_shape':list(tokens.shape),'finite_binding_losses':[float(v) for v in losses],'full_target_heads':'external_to_sealed_audit_seam','optimizer_steps':0},indent=2)); return 0
|
| 23 |
+
if __name__=='__main__': raise SystemExit(main())
|
gwam_active13_gwam_training_v3_20260801/examples/inspect_compact_frame.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Load and inspect one real typed compact window from the immutable closure."""
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
import argparse, json
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import sys
|
| 7 |
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
| 8 |
+
from loader.compact_target_aware_gwam_training_dataset import DirectCompactGWAMDatasetV3
|
| 9 |
+
from loader.per_frame import select_frame
|
| 10 |
+
|
| 11 |
+
OUTER_SHA="8e33045badf338ca7f0b802b689dc74765e392014df6b9c3f8f0413d4f9b44f3"
|
| 12 |
+
C2_SHA="e7fec3656d6e479a16698f1a96aafb8b6562e99a344d568de4b58e79f76aad26"
|
| 13 |
+
def main():
|
| 14 |
+
ap=argparse.ArgumentParser(); ap.add_argument('--root',default='.'); ap.add_argument('--index',type=int,default=0); ap.add_argument('--outer-manifest'); ap.add_argument('--c2-root'); ap.add_argument('--c2-index'); args=ap.parse_args(); root=Path(args.root)
|
| 15 |
+
outer=Path(args.outer_manifest or root/'gwam_active13_target_physical_v2_0_1_20260731/census/OUTER_TRAIN_MANIFEST.jsonl'); c2root=Path(args.c2_root) if args.c2_root else None; c2idx=Path(args.c2_index) if args.c2_index else None
|
| 16 |
+
ds=DirectCompactGWAMDatasetV3(root,outer_manifest_path=outer,outer_manifest_sha256=OUTER_SHA,c2_root=c2root,c2_index_path=c2idx,c2_index_sha256=C2_SHA if c2idx else None)
|
| 17 |
+
ex=ds[args.index]; view=select_frame(ex,0); print(json.dumps({'dataset_length':len(ds),'index':args.index,'task':ex.provenance.task[0],'nodes':int(ex.packet.n_nodes),'pose_shape':list(view.pose.shape),'view_evidence_shape':list(view.view_evidence.shape),'edge_count':int(view.edge_index.shape[1]),'edge_relation_ids':sorted(set(view.edge_relation_id.tolist())),'contact_edge_count':int((view.edge_relation_id==4).sum()),'target_count':int(ex.packet.is_task_target.sum()),'robot_target_contact_count':int(ex.packet.robot_target_contact.sum())},indent=2)); return 0
|
| 18 |
+
if __name__=='__main__': raise SystemExit(main())
|
gwam_active13_gwam_training_v3_20260801/examples/model_neutral_graph_examples.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Model-neutral tensor examples for CompactExampleV3.
|
| 2 |
+
|
| 3 |
+
PyG is optional. These adapters only pack active nodes and remap edge
|
| 4 |
+
endpoints; they do not alter the authoritative packet or infer relations.
|
| 5 |
+
"""
|
| 6 |
+
from __future__ import annotations
|
| 7 |
+
|
| 8 |
+
from typing import Any
|
| 9 |
+
|
| 10 |
+
import numpy as np
|
| 11 |
+
import torch
|
| 12 |
+
|
| 13 |
+
from loader.per_frame import CompactFrameViewV3, select_frame
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def standalone_tensor_dict(example: Any, time_index: int = 0, batch_index: int = 0) -> dict[str, torch.Tensor]:
|
| 17 |
+
"""Return one row-local frame; edge_index endpoints are local to that row."""
|
| 18 |
+
frame: CompactFrameViewV3 = select_frame(example, time_index, batch_index=batch_index)
|
| 19 |
+
active = np.flatnonzero(frame.node_valid)
|
| 20 |
+
remap = np.full(frame.node_valid.shape, -1, dtype=np.int64)
|
| 21 |
+
remap[active] = np.arange(active.size, dtype=np.int64)
|
| 22 |
+
keep = frame.node_valid[frame.edge_index[0]] & frame.node_valid[frame.edge_index[1]]
|
| 23 |
+
edges = remap[frame.edge_index[:, keep]]
|
| 24 |
+
return {
|
| 25 |
+
"x_pose": torch.from_numpy(frame.pose[active].copy()),
|
| 26 |
+
"x_family_id": torch.from_numpy(frame.family_id[active].copy()),
|
| 27 |
+
"x_family_valid": torch.from_numpy(frame.family_valid[active].copy()),
|
| 28 |
+
"x_static_flags": torch.from_numpy(frame.static_flags[active].copy()),
|
| 29 |
+
"x_static_flags_valid": torch.from_numpy(frame.static_flags_valid[active].copy()),
|
| 30 |
+
"x_pose_valid": torch.from_numpy(frame.pose_valid[active].copy()),
|
| 31 |
+
"x_articulation_q": torch.from_numpy(frame.articulation_q[active].copy()),
|
| 32 |
+
"x_articulation_valid": torch.from_numpy(frame.articulation_valid[active].copy()),
|
| 33 |
+
"x_view_evidence": torch.from_numpy(frame.view_evidence[active].copy()),
|
| 34 |
+
"x_view_record_valid": torch.from_numpy(frame.view_record_valid[active].copy()),
|
| 35 |
+
"x_target": torch.from_numpy(frame.is_task_target[active].copy()),
|
| 36 |
+
"x_target_valid": torch.from_numpy(frame.task_target_valid[active].copy()),
|
| 37 |
+
"x_robot_target_contact": torch.from_numpy(frame.robot_target_contact[active].copy()),
|
| 38 |
+
"x_robot_target_contact_valid": torch.from_numpy(frame.robot_target_contact_valid[active].copy()),
|
| 39 |
+
"edge_index": torch.from_numpy(edges),
|
| 40 |
+
"edge_batch": torch.from_numpy(frame.edge_batch[keep].copy()),
|
| 41 |
+
"edge_time": torch.from_numpy(frame.edge_time[keep].copy()),
|
| 42 |
+
"edge_relation_id": torch.from_numpy(frame.edge_relation_id[keep].copy()),
|
| 43 |
+
"edge_payload": torch.from_numpy(frame.edge_payload[keep].copy()),
|
| 44 |
+
"edge_payload_valid": torch.from_numpy(frame.edge_payload_valid[keep].copy()),
|
| 45 |
+
# Convenience alias; authoritative packet names are edge_payload/edge_payload_valid.
|
| 46 |
+
"edge_metric12": torch.from_numpy(frame.edge_payload[keep].copy()),
|
| 47 |
+
"slot_id": torch.from_numpy(frame.slot_id[active].copy()),
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def to_pyg_data(example: Any, time_index: int = 0, batch_index: int = 0) -> Any:
|
| 52 |
+
"""Return one selected row as PyG Data; endpoints remain row-local."""
|
| 53 |
+
|
| 54 |
+
try:
|
| 55 |
+
from torch_geometric.data import Data
|
| 56 |
+
except ImportError as exc:
|
| 57 |
+
raise RuntimeError("PYG_OPTIONAL_NOT_INSTALLED") from exc
|
| 58 |
+
values = standalone_tensor_dict(example, time_index, batch_index=batch_index)
|
| 59 |
+
return Data(
|
| 60 |
+
x_pose=values["x_pose"],
|
| 61 |
+
family_id=values["x_family_id"],
|
| 62 |
+
family_valid=values["x_family_valid"],
|
| 63 |
+
static_flags=values["x_static_flags"],
|
| 64 |
+
static_flags_valid=values["x_static_flags_valid"],
|
| 65 |
+
is_task_target=values["x_target"],
|
| 66 |
+
task_target_valid=values["x_target_valid"],
|
| 67 |
+
pose_valid=values["x_pose_valid"],
|
| 68 |
+
articulation_q=values["x_articulation_q"],
|
| 69 |
+
articulation_valid=values["x_articulation_valid"],
|
| 70 |
+
view_evidence=values["x_view_evidence"],
|
| 71 |
+
view_record_valid=values["x_view_record_valid"],
|
| 72 |
+
robot_target_contact=values["x_robot_target_contact"],
|
| 73 |
+
robot_target_contact_valid=values["x_robot_target_contact_valid"],
|
| 74 |
+
edge_index=values["edge_index"],
|
| 75 |
+
edge_batch=values["edge_batch"],
|
| 76 |
+
edge_time=values["edge_time"],
|
| 77 |
+
edge_payload=values["edge_payload"],
|
| 78 |
+
edge_payload_valid=values["edge_payload_valid"],
|
| 79 |
+
edge_relation_id=values["edge_relation_id"],
|
| 80 |
+
edge_metric12=values["edge_metric12"],
|
| 81 |
+
slot_id=values["slot_id"],
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def world_model_inputs(example: Any) -> dict[str, Any]:
|
| 86 |
+
"""Keep the causal history/action/target boundary explicit for any model."""
|
| 87 |
+
|
| 88 |
+
return {
|
| 89 |
+
"graph_history": example.packet,
|
| 90 |
+
"logged_actions": example.action,
|
| 91 |
+
"future_targets_labels_only": example.targets,
|
| 92 |
+
"provenance": example.provenance,
|
| 93 |
+
}
|
gwam_active13_gwam_training_v3_20260801/examples/pair_graph_rgb.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Emit a safe graph-frame/RGB pairing manifest; never copies or uploads video."""
|
| 3 |
+
import argparse,json,sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
PACKAGE_ROOT = Path(__file__).resolve().parents[1]
|
| 6 |
+
sys.path.insert(0, str(PACKAGE_ROOT))
|
| 7 |
+
from loader.rgb_pairing import resolve_rgb_pairing
|
| 8 |
+
ap=argparse.ArgumentParser(); ap.add_argument('--snapshot-root',required=True); ap.add_argument('--source-tier',required=True); ap.add_argument('--task',required=True); ap.add_argument('--episode-id',required=True); ap.add_argument('--graph-zip-sha256',required=True); ap.add_argument('--graph-t',type=int,required=True); ap.add_argument('--source-frame',type=int,required=True); ap.add_argument('--output',required=True); a=ap.parse_args()
|
| 9 |
+
value=resolve_rgb_pairing(snapshot_root=a.snapshot_root,source_tier=a.source_tier,task=a.task,episode_id=a.episode_id,graph_zip_sha256=a.graph_zip_sha256,graph_t=a.graph_t,source_frame=a.source_frame)
|
| 10 |
+
open(a.output,'w',encoding='utf-8').write(json.dumps(value,indent=2,sort_keys=True)+'\n'); print(json.dumps(value,indent=2))
|
gwam_active13_gwam_training_v3_20260801/examples/robocasa_live_compact_eval.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Concrete RoboCasa evaluation-time compact graph + RGB capture.
|
| 3 |
+
|
| 4 |
+
Run in the RoboCasa environment with ``MUJOCO_GL=egl``. The command never
|
| 5 |
+
trains or writes source data; it writes only the requested local summary/RGB.
|
| 6 |
+
"""
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
import argparse, hashlib, json
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
import numpy as np
|
| 11 |
+
|
| 12 |
+
def _zero_action(space):
|
| 13 |
+
"""Construct a valid zero action for Box/Dict/Tuple Gym spaces."""
|
| 14 |
+
from gymnasium import spaces
|
| 15 |
+
if isinstance(space, spaces.Dict):
|
| 16 |
+
return {key: _zero_action(subspace) for key, subspace in space.spaces.items()}
|
| 17 |
+
if isinstance(space, spaces.Tuple):
|
| 18 |
+
return tuple(_zero_action(subspace) for subspace in space.spaces)
|
| 19 |
+
if isinstance(space, spaces.Box):
|
| 20 |
+
value=np.zeros(space.shape,dtype=space.dtype)
|
| 21 |
+
return np.clip(value,space.low,space.high).astype(space.dtype,copy=False)
|
| 22 |
+
if isinstance(space, spaces.Discrete): return 0
|
| 23 |
+
if isinstance(space, spaces.MultiDiscrete): return np.zeros(space.nvec.shape,dtype=space.dtype)
|
| 24 |
+
if isinstance(space, spaces.MultiBinary): return np.zeros(space.n,dtype=np.int8)
|
| 25 |
+
raise TypeError(f"UNSUPPORTED_ACTION_SPACE:{type(space).__name__}")
|
| 26 |
+
|
| 27 |
+
def main() -> int:
|
| 28 |
+
ap=argparse.ArgumentParser(); ap.add_argument('--task',default='CoffeeSetupMug'); ap.add_argument('--split',default='target'); ap.add_argument('--steps',type=int,default=1); ap.add_argument('--output',default='robocasa_live_compact_summary.json'); ap.add_argument('--rgb-npy'); ap.add_argument('--c2-receipt'); ap.add_argument('--c2-map'); args=ap.parse_args()
|
| 29 |
+
try:
|
| 30 |
+
import numba
|
| 31 |
+
_jit=numba.jit
|
| 32 |
+
def _nocache(*a,**kw): kw['cache']=False; return _jit(*a,**kw)
|
| 33 |
+
numba.jit=_nocache
|
| 34 |
+
import gymnasium as gym, robocasa # noqa: F401
|
| 35 |
+
except Exception as exc: raise SystemExit(f'ROBOCASA_IMPORT_BLOCKED:{exc}')
|
| 36 |
+
from loader.robocasa_live_compact import AuthenticatedLiveResetV3, RoboCasaLiveCompactBridgeV3
|
| 37 |
+
from loader.robocasa_mujoco_compact import RoboCasaMuJoCoCompactReaderV3, build_authored_obj_self_capability, derive_open_drawer_articulation_qpos_map
|
| 38 |
+
from loader.online_compact_adapter import CompactOnlineHistoryBufferV3
|
| 39 |
+
from loader.compact_contract import CompactActionConditionV3, freeze_array
|
| 40 |
+
env=gym.make(f'robocasa/{args.task}', split=args.split, camera_names=['robot0_agentview_right','robot0_agentview_left','robot0_eye_in_hand'], camera_heights=256, camera_widths=256)
|
| 41 |
+
try:
|
| 42 |
+
env.reset(seed=0)
|
| 43 |
+
c2_bytes=Path(args.c2_receipt).read_bytes() if args.c2_receipt else None
|
| 44 |
+
c2_map=json.loads(Path(args.c2_map).read_text()) if args.c2_map else None
|
| 45 |
+
if args.task == 'OpenDrawer' and c2_map is None:
|
| 46 |
+
c2_map=derive_open_drawer_articulation_qpos_map(env)
|
| 47 |
+
c2_sha=hashlib.sha256(c2_bytes).hexdigest() if c2_bytes else None
|
| 48 |
+
# Load the exact C2 bytes/map before constructing the reader. The same
|
| 49 |
+
# bound objects are passed to both reader and capability builder.
|
| 50 |
+
reader=RoboCasaMuJoCoCompactReaderV3(env, c2_receipt_bytes=c2_bytes,
|
| 51 |
+
c2_receipt_sha256=c2_sha, articulation_qpos_map=c2_map)
|
| 52 |
+
marker=reader.state_marker(env); nonce=hashlib.sha256(repr(marker).encode()).hexdigest()
|
| 53 |
+
cap=build_authored_obj_self_capability(env,task=args.task,reset_nonce=nonce,c2_receipt_bytes=c2_bytes,c2_receipt_sha256=c2_sha,articulation_qpos_map=c2_map)
|
| 54 |
+
bridge=RoboCasaLiveCompactBridgeV3(env,reader,AuthenticatedLiveResetV3(cap)); frames=[]; rgbs=[]
|
| 55 |
+
for step in range(max(1,args.steps)):
|
| 56 |
+
before=reader.state_marker(env); frame,rgb=bridge.capture(); after=reader.state_marker(env)
|
| 57 |
+
if before != after: raise RuntimeError('CAPTURE_ADVANCED_SIM_STATE')
|
| 58 |
+
frames.append(frame); rgbs.append(rgb)
|
| 59 |
+
if step+1 < args.steps: env.step(_zero_action(env.action_space))
|
| 60 |
+
packet_digest=None; l8_materialized=False; k16_ready=False
|
| 61 |
+
if len(frames)==8:
|
| 62 |
+
history=CompactOnlineHistoryBufferV3(cap)
|
| 63 |
+
for frame in frames: history.append(frame)
|
| 64 |
+
action_t=np.asarray([[frames[-1].timestamp_s + 0.05*i for i in range(8)]],dtype=np.float64)
|
| 65 |
+
action=CompactActionConditionV3(freeze_array(np.zeros((1,8,12),dtype=np.float32),dtype='<f4'),freeze_array(np.ones((1,8),dtype=bool),dtype='|b1'),freeze_array(action_t,dtype='<f8'),freeze_array(np.ones((1,8),dtype=bool),dtype='|b1'))
|
| 66 |
+
online=history.materialize(action); online.validate(); packet_digest=online.packet.canonical_tensor_digest(); l8_materialized=True; k16_ready=online.packet.batch_size==1 and online.packet.history_valid.shape==(1,8)
|
| 67 |
+
final=frames[-1]; articulation_mask=final.articulation_valid[:,0]
|
| 68 |
+
target_articulation_mask=articulation_mask & cap.is_task_target
|
| 69 |
+
summary={'schema':'gwam.robocasa_live_compact_smoke.v3','task':args.task,'split':args.split,'frames':len(frames),'node_count':int(frames[0].slot_id.size),'rgb_shapes':[list(x.shape) for x in rgbs[0].frames],'camera_order':list(rgbs[0].camera_names),'reset_nonce':nonce,'capability_sha256':cap.receipt_sha256,'capture_state_preserved':True,'steps_only_after_capture':True,'forbidden_fields_read':False,'articulation_valid_count':int(np.count_nonzero(articulation_mask)),'target_articulation_valid_count':int(np.count_nonzero(target_articulation_mask)),'target_articulation_q':[float(x) for x in final.articulation_q[target_articulation_mask,0]],'l8_buffer_materialized':l8_materialized,'l8_packet_canonical_digest':packet_digest,'k16_ready_contract':k16_ready,'per_step':[{'step':i,'frame_id':int(frame_id),'timestamp_s':float(frame.timestamp_s)} for i,(frame,frame_id) in enumerate(zip(frames,[rgb.frame_id for rgb in rgbs]))]}
|
| 70 |
+
Path(args.output).write_text(json.dumps(summary,indent=2,sort_keys=True)+'\n')
|
| 71 |
+
if args.rgb_npy: np.save(args.rgb_npy,np.stack(rgbs[0].frames))
|
| 72 |
+
print(json.dumps(summary,indent=2)); return 0
|
| 73 |
+
finally: env.close()
|
| 74 |
+
if __name__ == '__main__': raise SystemExit(main())
|
gwam_active13_gwam_training_v3_20260801/loader/__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Direct, typed, velocity-free GraphPacket-Slim v3 boundary."""
|
| 2 |
+
|
gwam_active13_gwam_training_v3_20260801/loader/compact_collate.py
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Typed lossless batch padding for packed direct compact examples."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
from dataclasses import fields
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
from .compact_contract import (
|
| 9 |
+
CompactActionConditionV3,
|
| 10 |
+
CompactContractError,
|
| 11 |
+
CompactExampleV3,
|
| 12 |
+
CompactGraphPacketV3,
|
| 13 |
+
CompactProvenanceV3,
|
| 14 |
+
CompactTargetsV3,
|
| 15 |
+
canonical_ordered_route_index,
|
| 16 |
+
canonical_pair_index,
|
| 17 |
+
freeze_array,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def collate_compact_examples_v3(examples: tuple[CompactExampleV3, ...]) -> CompactExampleV3:
|
| 22 |
+
if type(examples) is not tuple or not examples or any(
|
| 23 |
+
type(value) is not CompactExampleV3 for value in examples
|
| 24 |
+
):
|
| 25 |
+
raise CompactContractError("COLLATE_EXACT_NONEMPTY_TUPLE")
|
| 26 |
+
for value in examples:
|
| 27 |
+
value.validate()
|
| 28 |
+
if value.packet.batch_size != 1:
|
| 29 |
+
raise CompactContractError("COLLATE_SINGLETON_SAMPLES_REQUIRED")
|
| 30 |
+
b = len(examples)
|
| 31 |
+
counts = [value.packet.n_nodes for value in examples]
|
| 32 |
+
n = max(counts)
|
| 33 |
+
routes = canonical_ordered_route_index(n)
|
| 34 |
+
|
| 35 |
+
history_valid = np.zeros((b, 8), dtype=np.bool_)
|
| 36 |
+
timestamps = np.zeros((b, 8), dtype=np.float64)
|
| 37 |
+
timestamp_valid = np.zeros((b, 8), dtype=np.bool_)
|
| 38 |
+
delta = np.zeros((b, 7), dtype=np.float32)
|
| 39 |
+
delta_valid = np.zeros((b, 7), dtype=np.bool_)
|
| 40 |
+
slot = np.full((b, n), -1, dtype=np.int16)
|
| 41 |
+
route_valid = np.zeros((b, n * (n - 1)), dtype=np.bool_)
|
| 42 |
+
node_valid = np.zeros((b, 8, n), dtype=np.bool_)
|
| 43 |
+
family = np.full((b, n), 10, dtype=np.int64)
|
| 44 |
+
family_valid = np.zeros((b, n), dtype=np.bool_)
|
| 45 |
+
flags = np.zeros((b, n, 2), dtype=np.bool_)
|
| 46 |
+
flags_valid = np.zeros((b, n), dtype=np.bool_)
|
| 47 |
+
pose = np.zeros((b, 8, n, 7), dtype=np.float32)
|
| 48 |
+
pose_valid = np.zeros((b, 8, n), dtype=np.bool_)
|
| 49 |
+
q = np.zeros((b, 8, n, 1), dtype=np.float32)
|
| 50 |
+
q_valid = np.zeros((b, 8, n, 1), dtype=np.bool_)
|
| 51 |
+
views = np.zeros((b, 8, n, 3, 8), dtype=np.float32)
|
| 52 |
+
view_valid = np.zeros((b, 8, n, 3), dtype=np.bool_)
|
| 53 |
+
target = np.zeros((b, n), dtype=np.bool_)
|
| 54 |
+
target_valid = np.zeros((b, n), dtype=np.bool_)
|
| 55 |
+
source_code = np.zeros((b, n), dtype=np.uint8)
|
| 56 |
+
robot_contact = np.zeros((b, 8, n), dtype=np.bool_)
|
| 57 |
+
robot_contact_valid = np.zeros((b, 8, n), dtype=np.bool_)
|
| 58 |
+
edge_index: list[np.ndarray] = []
|
| 59 |
+
edge_batch: list[np.ndarray] = []
|
| 60 |
+
edge_time: list[np.ndarray] = []
|
| 61 |
+
edge_relation: list[np.ndarray] = []
|
| 62 |
+
edge_payload: list[np.ndarray] = []
|
| 63 |
+
edge_payload_valid: list[np.ndarray] = []
|
| 64 |
+
for row, example in enumerate(examples):
|
| 65 |
+
packet = example.packet
|
| 66 |
+
count = packet.n_nodes
|
| 67 |
+
history_valid[row] = packet.history_valid[0]
|
| 68 |
+
timestamps[row] = packet.timestamp_s[0]
|
| 69 |
+
timestamp_valid[row] = packet.timestamp_valid[0]
|
| 70 |
+
delta[row] = packet.delta_t_s[0]
|
| 71 |
+
delta_valid[row] = packet.delta_t_valid[0]
|
| 72 |
+
slot[row, :count] = packet.slot_id[0]
|
| 73 |
+
node_valid[row, :, :count] = packet.node_valid[0]
|
| 74 |
+
family[row, :count] = packet.family_id[0]
|
| 75 |
+
family_valid[row, :count] = packet.family_valid[0]
|
| 76 |
+
flags[row, :count] = packet.static_flags[0]
|
| 77 |
+
flags_valid[row, :count] = packet.static_flags_valid[0]
|
| 78 |
+
pose[row, :, :count] = packet.pose[0]
|
| 79 |
+
pose_valid[row, :, :count] = packet.pose_valid[0]
|
| 80 |
+
q[row, :, :count] = packet.articulation_q[0]
|
| 81 |
+
q_valid[row, :, :count] = packet.articulation_valid[0]
|
| 82 |
+
views[row, :, :count] = packet.view_evidence[0]
|
| 83 |
+
view_valid[row, :, :count] = packet.view_record_valid[0]
|
| 84 |
+
target[row, :count] = packet.is_task_target[0]
|
| 85 |
+
target_valid[row, :count] = packet.task_target_valid[0]
|
| 86 |
+
source_code[row, :count] = packet.task_target_source_code[0]
|
| 87 |
+
robot_contact[row, :, :count] = packet.robot_target_contact[0]
|
| 88 |
+
robot_contact_valid[row, :, :count] = packet.robot_target_contact_valid[0]
|
| 89 |
+
route_valid[row] = node_valid[row, 7, routes[0]] & node_valid[row, 7, routes[1]]
|
| 90 |
+
e = packet.edge_relation_id.size
|
| 91 |
+
edge_index.append(packet.edge_index)
|
| 92 |
+
edge_batch.append(np.full(e, row, dtype=np.int32))
|
| 93 |
+
edge_time.append(packet.edge_time)
|
| 94 |
+
edge_relation.append(packet.edge_relation_id)
|
| 95 |
+
edge_payload.append(packet.edge_payload)
|
| 96 |
+
edge_payload_valid.append(packet.edge_payload_valid)
|
| 97 |
+
packet = CompactGraphPacketV3(
|
| 98 |
+
history_valid=freeze_array(history_valid, dtype="|b1"),
|
| 99 |
+
timestamp_s=freeze_array(timestamps, dtype="<f8"),
|
| 100 |
+
timestamp_valid=freeze_array(timestamp_valid, dtype="|b1"),
|
| 101 |
+
delta_t_s=freeze_array(delta, dtype="<f4"),
|
| 102 |
+
delta_t_valid=freeze_array(delta_valid, dtype="|b1"),
|
| 103 |
+
slot_id=freeze_array(slot, dtype="<i2"),
|
| 104 |
+
ordered_route_index=routes,
|
| 105 |
+
ordered_route_valid=freeze_array(route_valid, dtype="|b1"),
|
| 106 |
+
node_valid=freeze_array(node_valid, dtype="|b1"),
|
| 107 |
+
family_id=freeze_array(family, dtype="<i8"),
|
| 108 |
+
family_valid=freeze_array(family_valid, dtype="|b1"),
|
| 109 |
+
static_flags=freeze_array(flags, dtype="|b1"),
|
| 110 |
+
static_flags_valid=freeze_array(flags_valid, dtype="|b1"),
|
| 111 |
+
pose=freeze_array(pose, dtype="<f4"),
|
| 112 |
+
pose_valid=freeze_array(pose_valid, dtype="|b1"),
|
| 113 |
+
articulation_q=freeze_array(q, dtype="<f4"),
|
| 114 |
+
articulation_valid=freeze_array(q_valid, dtype="|b1"),
|
| 115 |
+
view_evidence=freeze_array(views, dtype="<f4"),
|
| 116 |
+
view_record_valid=freeze_array(view_valid, dtype="|b1"),
|
| 117 |
+
edge_index=freeze_array(np.concatenate(edge_index, axis=1), dtype="<i8"),
|
| 118 |
+
edge_batch=freeze_array(np.concatenate(edge_batch), dtype="<i4"),
|
| 119 |
+
edge_time=freeze_array(np.concatenate(edge_time), dtype="<i2"),
|
| 120 |
+
edge_relation_id=freeze_array(np.concatenate(edge_relation), dtype="|u1"),
|
| 121 |
+
edge_payload=freeze_array(np.concatenate(edge_payload, axis=0), dtype="<f4"),
|
| 122 |
+
edge_payload_valid=freeze_array(
|
| 123 |
+
np.concatenate(edge_payload_valid, axis=0), dtype="|b1"
|
| 124 |
+
),
|
| 125 |
+
is_task_target=freeze_array(target, dtype="|b1"),
|
| 126 |
+
task_target_valid=freeze_array(target_valid, dtype="|b1"),
|
| 127 |
+
task_target_source_code=freeze_array(source_code, dtype="|u1"),
|
| 128 |
+
robot_target_contact=freeze_array(robot_contact, dtype="|b1"),
|
| 129 |
+
robot_target_contact_valid=freeze_array(robot_contact_valid, dtype="|b1"),
|
| 130 |
+
)
|
| 131 |
+
actions = CompactActionConditionV3(
|
| 132 |
+
future_action=freeze_array(
|
| 133 |
+
np.concatenate([value.action.future_action for value in examples], axis=0),
|
| 134 |
+
dtype="<f4",
|
| 135 |
+
),
|
| 136 |
+
future_action_valid=freeze_array(
|
| 137 |
+
np.concatenate([value.action.future_action_valid for value in examples], axis=0),
|
| 138 |
+
dtype="|b1",
|
| 139 |
+
),
|
| 140 |
+
action_timestamp_s=freeze_array(
|
| 141 |
+
np.concatenate([value.action.action_timestamp_s for value in examples], axis=0),
|
| 142 |
+
dtype="<f8",
|
| 143 |
+
),
|
| 144 |
+
action_timestamp_valid=freeze_array(
|
| 145 |
+
np.concatenate([value.action.action_timestamp_valid for value in examples], axis=0),
|
| 146 |
+
dtype="|b1",
|
| 147 |
+
),
|
| 148 |
+
)
|
| 149 |
+
targets = _collate_targets(examples, packet)
|
| 150 |
+
provenance_values = {
|
| 151 |
+
field.name: sum(
|
| 152 |
+
(getattr(value.provenance, field.name) for value in examples),
|
| 153 |
+
(),
|
| 154 |
+
)
|
| 155 |
+
for field in fields(CompactProvenanceV3)
|
| 156 |
+
}
|
| 157 |
+
provenance = CompactProvenanceV3(**provenance_values)
|
| 158 |
+
result = CompactExampleV3(packet, actions, targets, provenance)
|
| 159 |
+
result.validate()
|
| 160 |
+
return result
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def _collate_targets(
|
| 164 |
+
examples: tuple[CompactExampleV3, ...], packet: CompactGraphPacketV3
|
| 165 |
+
) -> CompactTargetsV3:
|
| 166 |
+
b, n = len(examples), packet.n_nodes
|
| 167 |
+
pairs = canonical_pair_index(n)
|
| 168 |
+
qmax = pairs.shape[1]
|
| 169 |
+
pair_lookup = {tuple(value): index for index, value in enumerate(pairs.T.tolist())}
|
| 170 |
+
anchor_pair = np.zeros((b, qmax), dtype=np.bool_)
|
| 171 |
+
anchor_contact = np.zeros((b, qmax), dtype=np.bool_)
|
| 172 |
+
anchor_contact_valid = np.zeros((b, qmax), dtype=np.bool_)
|
| 173 |
+
target_pair = np.zeros((b, 8, qmax), dtype=np.bool_)
|
| 174 |
+
target_contact = np.zeros((b, 8, qmax), dtype=np.bool_)
|
| 175 |
+
target_event = np.zeros((b, 8, qmax), dtype=np.int64)
|
| 176 |
+
target_event_valid = np.zeros((b, 8, qmax), dtype=np.bool_)
|
| 177 |
+
target_robot_contact = np.zeros((b, 8, n), dtype=np.bool_)
|
| 178 |
+
target_robot_contact_valid = np.zeros((b, 8, n), dtype=np.bool_)
|
| 179 |
+
target_robot_event = np.zeros((b, 8, n), dtype=np.int64)
|
| 180 |
+
target_robot_event_valid = np.zeros((b, 8, n), dtype=np.bool_)
|
| 181 |
+
target_node = np.zeros((b, 8, n), dtype=np.bool_)
|
| 182 |
+
target_timestamp = np.zeros((b, 8), dtype=np.float64)
|
| 183 |
+
target_timestamp_valid = np.zeros((b, 8), dtype=np.bool_)
|
| 184 |
+
position = np.zeros((b, 8, n, 3), dtype=np.float32)
|
| 185 |
+
rotation = np.zeros((b, 8, n, 3), dtype=np.float32)
|
| 186 |
+
pose_valid = np.zeros((b, 8, n), dtype=np.bool_)
|
| 187 |
+
articulation = np.zeros((b, 8, n, 1), dtype=np.float32)
|
| 188 |
+
articulation_valid = np.zeros((b, 8, n, 1), dtype=np.bool_)
|
| 189 |
+
target_view = np.zeros((b, 8, n, 3, 8), dtype=np.float32)
|
| 190 |
+
target_view_valid = np.zeros((b, 8, n, 3), dtype=np.bool_)
|
| 191 |
+
structural = np.zeros((b, n, n), dtype=np.int64)
|
| 192 |
+
structural_valid = np.zeros((b, n, n), dtype=np.bool_)
|
| 193 |
+
current_robot_contact = np.zeros((b, n), dtype=np.bool_)
|
| 194 |
+
current_robot_contact_valid = np.zeros((b, n), dtype=np.bool_)
|
| 195 |
+
for row, example in enumerate(examples):
|
| 196 |
+
value = example.targets
|
| 197 |
+
count = example.packet.n_nodes
|
| 198 |
+
destinations = np.asarray(
|
| 199 |
+
[pair_lookup[tuple(pair)] for pair in value.pair_index.T.tolist()], dtype=np.int64
|
| 200 |
+
)
|
| 201 |
+
anchor_pair[row, destinations] = value.anchor_pair_valid[0]
|
| 202 |
+
anchor_contact[row, destinations] = value.anchor_contact[0]
|
| 203 |
+
anchor_contact_valid[row, destinations] = value.anchor_contact_valid[0]
|
| 204 |
+
target_pair[row][:, destinations] = value.target_pair_valid[0]
|
| 205 |
+
target_contact[row][:, destinations] = value.target_contact_occupancy[0]
|
| 206 |
+
target_event[row][:, destinations] = value.target_contact_event[0]
|
| 207 |
+
target_event_valid[row][:, destinations] = value.target_contact_event_valid[0]
|
| 208 |
+
target_robot_contact[row, :, :count] = value.target_robot_contact_occupancy[0]
|
| 209 |
+
target_robot_contact_valid[row, :, :count] = value.target_robot_contact_occupancy_valid[0]
|
| 210 |
+
target_robot_event[row, :, :count] = value.target_robot_contact_event[0]
|
| 211 |
+
target_robot_event_valid[row, :, :count] = value.target_robot_contact_event_valid[0]
|
| 212 |
+
target_node[row, :, :count] = value.target_node_valid[0]
|
| 213 |
+
target_timestamp[row] = value.target_timestamp_s[0]
|
| 214 |
+
target_timestamp_valid[row] = value.target_timestamp_valid[0]
|
| 215 |
+
position[row, :, :count] = value.target_position_delta[0]
|
| 216 |
+
rotation[row, :, :count] = value.target_rotation_log[0]
|
| 217 |
+
pose_valid[row, :, :count] = value.target_pose_valid[0]
|
| 218 |
+
articulation[row, :, :count] = value.target_articulation_delta[0]
|
| 219 |
+
articulation_valid[row, :, :count] = value.target_articulation_valid[0]
|
| 220 |
+
target_view[row, :, :count] = value.target_view_evidence[0]
|
| 221 |
+
target_view_valid[row, :, :count] = value.target_view_record_valid[0]
|
| 222 |
+
structural[row, :count, :count] = value.current_structural_relation[0]
|
| 223 |
+
structural_valid[row, :count, :count] = value.current_structural_valid[0]
|
| 224 |
+
current_robot_contact[row, :count] = value.current_robot_target_contact[0]
|
| 225 |
+
current_robot_contact_valid[row, :count] = value.current_robot_target_contact_valid[0]
|
| 226 |
+
return CompactTargetsV3(
|
| 227 |
+
pair_index=pairs,
|
| 228 |
+
anchor_pair_valid=freeze_array(anchor_pair, dtype="|b1"),
|
| 229 |
+
anchor_contact=freeze_array(anchor_contact, dtype="|b1"),
|
| 230 |
+
anchor_contact_valid=freeze_array(anchor_contact_valid, dtype="|b1"),
|
| 231 |
+
target_pair_valid=freeze_array(target_pair, dtype="|b1"),
|
| 232 |
+
target_contact_occupancy=freeze_array(target_contact, dtype="|b1"),
|
| 233 |
+
target_contact_event=freeze_array(target_event, dtype="<i8"),
|
| 234 |
+
target_contact_event_valid=freeze_array(target_event_valid, dtype="|b1"),
|
| 235 |
+
target_robot_contact_occupancy=freeze_array(target_robot_contact, dtype="|b1"),
|
| 236 |
+
target_robot_contact_occupancy_valid=freeze_array(
|
| 237 |
+
target_robot_contact_valid, dtype="|b1"
|
| 238 |
+
),
|
| 239 |
+
target_robot_contact_event=freeze_array(target_robot_event, dtype="<i8"),
|
| 240 |
+
target_robot_contact_event_valid=freeze_array(target_robot_event_valid, dtype="|b1"),
|
| 241 |
+
target_node_valid=freeze_array(target_node, dtype="|b1"),
|
| 242 |
+
target_timestamp_s=freeze_array(target_timestamp, dtype="<f8"),
|
| 243 |
+
target_timestamp_valid=freeze_array(target_timestamp_valid, dtype="|b1"),
|
| 244 |
+
target_position_delta=freeze_array(position, dtype="<f4"),
|
| 245 |
+
target_rotation_log=freeze_array(rotation, dtype="<f4"),
|
| 246 |
+
target_pose_valid=freeze_array(pose_valid, dtype="|b1"),
|
| 247 |
+
target_articulation_delta=freeze_array(articulation, dtype="<f4"),
|
| 248 |
+
target_articulation_valid=freeze_array(articulation_valid, dtype="|b1"),
|
| 249 |
+
target_view_evidence=freeze_array(target_view, dtype="<f4"),
|
| 250 |
+
target_view_record_valid=freeze_array(target_view_valid, dtype="|b1"),
|
| 251 |
+
current_position=freeze_array(packet.pose[:, 7, :, :3], dtype="<f4"),
|
| 252 |
+
current_rotation_quat_xyzw=freeze_array(packet.pose[:, 7, :, 3:7], dtype="<f4"),
|
| 253 |
+
current_pose_valid=freeze_array(packet.pose_valid[:, 7], dtype="|b1"),
|
| 254 |
+
current_articulation_q=freeze_array(packet.articulation_q[:, 7], dtype="<f4"),
|
| 255 |
+
current_articulation_valid=freeze_array(
|
| 256 |
+
packet.articulation_valid[:, 7], dtype="|b1"
|
| 257 |
+
),
|
| 258 |
+
current_contact=freeze_array(anchor_contact, dtype="|b1"),
|
| 259 |
+
current_contact_valid=freeze_array(anchor_contact_valid, dtype="|b1"),
|
| 260 |
+
current_robot_target_contact=freeze_array(current_robot_contact, dtype="|b1"),
|
| 261 |
+
current_robot_target_contact_valid=freeze_array(
|
| 262 |
+
current_robot_contact_valid, dtype="|b1"
|
| 263 |
+
),
|
| 264 |
+
current_view_evidence=freeze_array(packet.view_evidence[:, 7], dtype="<f4"),
|
| 265 |
+
current_view_record_valid=freeze_array(packet.view_record_valid[:, 7], dtype="|b1"),
|
| 266 |
+
current_structural_relation=freeze_array(structural, dtype="<i8"),
|
| 267 |
+
current_structural_valid=freeze_array(structural_valid, dtype="|b1"),
|
| 268 |
+
)
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
__all__ = ["collate_compact_examples_v3"]
|
gwam_active13_gwam_training_v3_20260801/loader/compact_contract.py
ADDED
|
@@ -0,0 +1,836 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Authoritative typed compact graph, action, target, and provenance objects.
|
| 2 |
+
|
| 3 |
+
The dataclasses in this module are deliberately closed: they have fixed slots,
|
| 4 |
+
accept no unknown members, and contain no legacy learned-visual, dense-mask, raw
|
| 5 |
+
simulator-rate, or derived-motion field. The optional 46-value target-aware
|
| 6 |
+
projection is an interchange convenience and has no conversion to a model input.
|
| 7 |
+
"""
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import hashlib
|
| 11 |
+
from dataclasses import dataclass, fields
|
| 12 |
+
from pathlib import PurePosixPath
|
| 13 |
+
from typing import Any, Mapping
|
| 14 |
+
|
| 15 |
+
import numpy as np
|
| 16 |
+
from .temporal_precision import offline_step_mask, offline_timestamp_equal_mask, storage_roundtrip_close, TemporalContractError
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
HISTORY_LENGTH = 8
|
| 20 |
+
HORIZON = 8
|
| 21 |
+
NODE_CAPACITY = 256
|
| 22 |
+
PAIR_CAPACITY = 32640
|
| 23 |
+
ORDERED_ROUTE_COUNT = 65280
|
| 24 |
+
VIEW_COUNT = 3
|
| 25 |
+
VIEW_DIM = 8
|
| 26 |
+
ACTION_DIM = 12
|
| 27 |
+
METRIC_DIM = 12
|
| 28 |
+
CAMERAS = (
|
| 29 |
+
"robot0_agentview_right",
|
| 30 |
+
"robot0_agentview_left",
|
| 31 |
+
"robot0_eye_in_hand",
|
| 32 |
+
)
|
| 33 |
+
MODEL_PROFILE_ID = "active13_target_physical_v2"
|
| 34 |
+
RELATION_REGISTRY_SHA256 = "b2e807e5fdc642012d20f19921bb7315f3e422915b665d02d3f38da7c61f8cf8"
|
| 35 |
+
TARGET_RESOLVER_SHA256 = "db316b0730fbb42584995ba558d728824fb87069173cc0fac7250cdefc0c139c"
|
| 36 |
+
DT_NOMINAL_S = 0.05
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class CompactContractError(ValueError):
|
| 40 |
+
"""The compact boundary is malformed, unauthenticated, or causally unsafe."""
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def freeze_array(value: np.ndarray | Any, *, dtype: np.dtype[Any] | str | None = None) -> np.ndarray:
|
| 44 |
+
result = np.ascontiguousarray(value, dtype=dtype).copy()
|
| 45 |
+
result.flags.writeable = False
|
| 46 |
+
return result
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def _canonical_pair_template(n: int) -> np.ndarray:
|
| 50 |
+
if type(n) is not int or not 1 <= n <= NODE_CAPACITY:
|
| 51 |
+
raise CompactContractError(f"NODE_COUNT:{n}")
|
| 52 |
+
left, right = np.triu_indices(n, k=1)
|
| 53 |
+
return freeze_array(np.stack((left, right)), dtype=np.dtype("<i8"))
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def canonical_pair_index(n: int = NODE_CAPACITY) -> np.ndarray:
|
| 57 |
+
return freeze_array(_canonical_pair_template(n), dtype=np.dtype("<i8"))
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def canonical_ordered_route_index(n: int = NODE_CAPACITY) -> np.ndarray:
|
| 61 |
+
if type(n) is not int or not 1 <= n <= NODE_CAPACITY:
|
| 62 |
+
raise CompactContractError(f"NODE_COUNT:{n}")
|
| 63 |
+
sender = np.repeat(np.arange(n, dtype=np.int16), n - 1)
|
| 64 |
+
receiver = np.concatenate(
|
| 65 |
+
tuple(
|
| 66 |
+
np.concatenate(
|
| 67 |
+
(
|
| 68 |
+
np.arange(index, dtype=np.int16),
|
| 69 |
+
np.arange(index + 1, n, dtype=np.int16),
|
| 70 |
+
)
|
| 71 |
+
)
|
| 72 |
+
for index in range(n)
|
| 73 |
+
)
|
| 74 |
+
)
|
| 75 |
+
return freeze_array(np.stack((sender, receiver)), dtype=np.dtype("<i2"))
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def _array(name: str, value: object, dtype: str, shape: tuple[int, ...]) -> np.ndarray:
|
| 79 |
+
if type(value) is not np.ndarray:
|
| 80 |
+
raise CompactContractError(f"{name}:ARRAY_TYPE")
|
| 81 |
+
if value.dtype != np.dtype(dtype):
|
| 82 |
+
raise CompactContractError(f"{name}:DTYPE:{value.dtype.str}:{dtype}")
|
| 83 |
+
if value.shape != shape:
|
| 84 |
+
raise CompactContractError(f"{name}:SHAPE:{value.shape}:{shape}")
|
| 85 |
+
if not value.flags.c_contiguous or value.flags.writeable:
|
| 86 |
+
raise CompactContractError(f"{name}:NOT_FROZEN_CONTIGUOUS")
|
| 87 |
+
return value
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def _finite_zero_masked(name: str, value: np.ndarray, valid: np.ndarray) -> None:
|
| 91 |
+
if not np.isfinite(value[valid]).all():
|
| 92 |
+
raise CompactContractError(f"{name}:NONFINITE_VALID")
|
| 93 |
+
expanded = valid
|
| 94 |
+
while expanded.ndim < value.ndim:
|
| 95 |
+
expanded = expanded[..., None]
|
| 96 |
+
if np.any(value[~np.broadcast_to(expanded, value.shape)] != 0):
|
| 97 |
+
raise CompactContractError(f"{name}:INVALID_NOT_POSITIVE_ZERO")
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def derive_robot_target_contact(
|
| 101 |
+
*,
|
| 102 |
+
node_valid: np.ndarray,
|
| 103 |
+
family_id: np.ndarray,
|
| 104 |
+
target: np.ndarray,
|
| 105 |
+
target_valid: np.ndarray,
|
| 106 |
+
edge_index: np.ndarray,
|
| 107 |
+
edge_batch: np.ndarray,
|
| 108 |
+
edge_time: np.ndarray,
|
| 109 |
+
edge_relation_id: np.ndarray,
|
| 110 |
+
edge_payload_valid: np.ndarray,
|
| 111 |
+
) -> tuple[np.ndarray, np.ndarray]:
|
| 112 |
+
"""Derive target-contact context from typed contact edges only.
|
| 113 |
+
|
| 114 |
+
Strict offline/live captures carry a complete contact observation for every
|
| 115 |
+
valid node frame. Consequently an empty relation-4 set is a valid negative,
|
| 116 |
+
not missing support; validity is bounded only by endpoint/node/target validity.
|
| 117 |
+
Reverse contact edges are intentionally reduced to a boolean, so they
|
| 118 |
+
cannot double-count the attributed view.
|
| 119 |
+
"""
|
| 120 |
+
|
| 121 |
+
if node_valid.ndim != 3 or family_id.ndim != 2 or target.ndim != 2:
|
| 122 |
+
raise CompactContractError("ROBOT_TARGET_CONTACT_INPUT_RANK")
|
| 123 |
+
b, length, n = node_valid.shape
|
| 124 |
+
if length != HISTORY_LENGTH or family_id.shape != (b, n) or target.shape != (b, n):
|
| 125 |
+
raise CompactContractError("ROBOT_TARGET_CONTACT_INPUT_SHAPE")
|
| 126 |
+
if target_valid.shape != (b, n):
|
| 127 |
+
raise CompactContractError("ROBOT_TARGET_CONTACT_VALID_SHAPE")
|
| 128 |
+
output = np.zeros((b, length, n), dtype=np.bool_)
|
| 129 |
+
valid = np.zeros((b, length, n), dtype=np.bool_)
|
| 130 |
+
robot_contact = np.zeros((b, length, n), dtype=np.bool_)
|
| 131 |
+
for index in range(edge_relation_id.size):
|
| 132 |
+
if int(edge_relation_id[index]) != 4 or not bool(np.all(edge_payload_valid[index])):
|
| 133 |
+
continue
|
| 134 |
+
row = int(edge_batch[index])
|
| 135 |
+
time = int(edge_time[index])
|
| 136 |
+
sender, receiver = (int(edge_index[0, index]), int(edge_index[1, index]))
|
| 137 |
+
if not (
|
| 138 |
+
0 <= row < b
|
| 139 |
+
and 0 <= time < length
|
| 140 |
+
and 0 <= sender < n
|
| 141 |
+
and 0 <= receiver < n
|
| 142 |
+
and node_valid[row, time, sender]
|
| 143 |
+
and node_valid[row, time, receiver]
|
| 144 |
+
):
|
| 145 |
+
continue
|
| 146 |
+
if family_id[row, sender] == 9 and target[row, receiver] and target_valid[row, receiver]:
|
| 147 |
+
robot_contact[row, time, receiver] = True
|
| 148 |
+
if family_id[row, receiver] == 9 and target[row, sender] and target_valid[row, sender]:
|
| 149 |
+
robot_contact[row, time, sender] = True
|
| 150 |
+
valid[...] = target_valid[:, None, :] & node_valid
|
| 151 |
+
output[...] = robot_contact & valid
|
| 152 |
+
return output, valid
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def _digest_fields(instance: object) -> str:
|
| 156 |
+
digest = hashlib.sha256()
|
| 157 |
+
for field in fields(type(instance)):
|
| 158 |
+
value = getattr(instance, field.name)
|
| 159 |
+
if type(value) is np.ndarray:
|
| 160 |
+
digest.update(field.name.encode("utf-8") + b"\0")
|
| 161 |
+
digest.update(value.dtype.str.encode("ascii") + b"\0")
|
| 162 |
+
digest.update(np.asarray(value.shape, dtype="<i8").tobytes())
|
| 163 |
+
digest.update(value.tobytes(order="C"))
|
| 164 |
+
return digest.hexdigest()
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
@dataclass(frozen=True, slots=True)
|
| 168 |
+
class CompactGraphPacketV3:
|
| 169 |
+
history_valid: np.ndarray
|
| 170 |
+
timestamp_s: np.ndarray
|
| 171 |
+
timestamp_valid: np.ndarray
|
| 172 |
+
delta_t_s: np.ndarray
|
| 173 |
+
delta_t_valid: np.ndarray
|
| 174 |
+
slot_id: np.ndarray
|
| 175 |
+
ordered_route_index: np.ndarray
|
| 176 |
+
ordered_route_valid: np.ndarray
|
| 177 |
+
node_valid: np.ndarray
|
| 178 |
+
family_id: np.ndarray
|
| 179 |
+
family_valid: np.ndarray
|
| 180 |
+
static_flags: np.ndarray
|
| 181 |
+
static_flags_valid: np.ndarray
|
| 182 |
+
pose: np.ndarray
|
| 183 |
+
pose_valid: np.ndarray
|
| 184 |
+
articulation_q: np.ndarray
|
| 185 |
+
articulation_valid: np.ndarray
|
| 186 |
+
view_evidence: np.ndarray
|
| 187 |
+
view_record_valid: np.ndarray
|
| 188 |
+
edge_index: np.ndarray
|
| 189 |
+
edge_batch: np.ndarray
|
| 190 |
+
edge_time: np.ndarray
|
| 191 |
+
edge_relation_id: np.ndarray
|
| 192 |
+
edge_payload: np.ndarray
|
| 193 |
+
edge_payload_valid: np.ndarray
|
| 194 |
+
is_task_target: np.ndarray
|
| 195 |
+
task_target_valid: np.ndarray
|
| 196 |
+
task_target_source_code: np.ndarray
|
| 197 |
+
robot_target_contact: np.ndarray
|
| 198 |
+
robot_target_contact_valid: np.ndarray
|
| 199 |
+
graph_profile_id: str = MODEL_PROFILE_ID
|
| 200 |
+
relation_registry_sha256: str = RELATION_REGISTRY_SHA256
|
| 201 |
+
target_resolver_sha256: str = TARGET_RESOLVER_SHA256
|
| 202 |
+
|
| 203 |
+
@property
|
| 204 |
+
def batch_size(self) -> int:
|
| 205 |
+
return int(self.node_valid.shape[0]) if self.node_valid.ndim else 0
|
| 206 |
+
|
| 207 |
+
@property
|
| 208 |
+
def n_nodes(self) -> int:
|
| 209 |
+
return int(self.node_valid.shape[2]) if self.node_valid.ndim == 3 else 0
|
| 210 |
+
|
| 211 |
+
def canonical_tensor_digest(self) -> str:
|
| 212 |
+
self.validate()
|
| 213 |
+
return _digest_fields(self)
|
| 214 |
+
|
| 215 |
+
@property
|
| 216 |
+
def robot_target_contact_phase(self) -> np.ndarray:
|
| 217 |
+
"""Compute the global contact-rich phase without storing another field."""
|
| 218 |
+
|
| 219 |
+
self.validate()
|
| 220 |
+
return freeze_array(
|
| 221 |
+
np.any(self.robot_target_contact & self.robot_target_contact_valid, axis=(1, 2)),
|
| 222 |
+
dtype="|b1",
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
def validate(self) -> None:
|
| 226 |
+
b = self.batch_size
|
| 227 |
+
if b < 1:
|
| 228 |
+
raise CompactContractError("BATCH_EMPTY")
|
| 229 |
+
n = self.n_nodes
|
| 230 |
+
if not 1 <= n <= NODE_CAPACITY:
|
| 231 |
+
raise CompactContractError(f"NODE_COUNT:{n}")
|
| 232 |
+
r = n * (n - 1)
|
| 233 |
+
expected = {
|
| 234 |
+
"history_valid": ("|b1", (b, 8)),
|
| 235 |
+
"timestamp_s": ("<f8", (b, 8)),
|
| 236 |
+
"timestamp_valid": ("|b1", (b, 8)),
|
| 237 |
+
"delta_t_s": ("<f4", (b, 7)),
|
| 238 |
+
"delta_t_valid": ("|b1", (b, 7)),
|
| 239 |
+
"slot_id": ("<i2", (b, n)),
|
| 240 |
+
"ordered_route_index": ("<i2", (2, r)),
|
| 241 |
+
"ordered_route_valid": ("|b1", (b, r)),
|
| 242 |
+
"node_valid": ("|b1", (b, 8, n)),
|
| 243 |
+
"family_id": ("<i8", (b, n)),
|
| 244 |
+
"family_valid": ("|b1", (b, n)),
|
| 245 |
+
"static_flags": ("|b1", (b, n, 2)),
|
| 246 |
+
"static_flags_valid": ("|b1", (b, n)),
|
| 247 |
+
"pose": ("<f4", (b, 8, n, 7)),
|
| 248 |
+
"pose_valid": ("|b1", (b, 8, n)),
|
| 249 |
+
"articulation_q": ("<f4", (b, 8, n, 1)),
|
| 250 |
+
"articulation_valid": ("|b1", (b, 8, n, 1)),
|
| 251 |
+
"view_evidence": ("<f4", (b, 8, n, 3, 8)),
|
| 252 |
+
"view_record_valid": ("|b1", (b, 8, n, 3)),
|
| 253 |
+
"is_task_target": ("|b1", (b, n)),
|
| 254 |
+
"task_target_valid": ("|b1", (b, n)),
|
| 255 |
+
"task_target_source_code": ("|u1", (b, n)),
|
| 256 |
+
"robot_target_contact": ("|b1", (b, 8, n)),
|
| 257 |
+
"robot_target_contact_valid": ("|b1", (b, 8, n)),
|
| 258 |
+
}
|
| 259 |
+
for name, (dtype, shape) in expected.items():
|
| 260 |
+
_array(name, getattr(self, name), dtype, shape)
|
| 261 |
+
e = self.edge_relation_id.size
|
| 262 |
+
for name, dtype, shape in (
|
| 263 |
+
("edge_index", "<i8", (2, e)),
|
| 264 |
+
("edge_batch", "<i4", (e,)),
|
| 265 |
+
("edge_time", "<i2", (e,)),
|
| 266 |
+
("edge_relation_id", "|u1", (e,)),
|
| 267 |
+
("edge_payload", "<f4", (e, 12)),
|
| 268 |
+
("edge_payload_valid", "|b1", (e, 12)),
|
| 269 |
+
):
|
| 270 |
+
_array(name, getattr(self, name), dtype, shape)
|
| 271 |
+
if self.graph_profile_id != MODEL_PROFILE_ID:
|
| 272 |
+
raise CompactContractError("MODEL_PROFILE_ID")
|
| 273 |
+
if self.relation_registry_sha256 != RELATION_REGISTRY_SHA256:
|
| 274 |
+
raise CompactContractError("RELATION_REGISTRY_HASH")
|
| 275 |
+
if self.target_resolver_sha256 != TARGET_RESOLVER_SHA256:
|
| 276 |
+
raise CompactContractError("TARGET_RESOLVER_HASH")
|
| 277 |
+
if np.any((self.slot_id < -1) | (self.slot_id >= NODE_CAPACITY)):
|
| 278 |
+
raise CompactContractError("SLOT_ID_RANGE")
|
| 279 |
+
if not np.array_equal(self.ordered_route_index, canonical_ordered_route_index(n)):
|
| 280 |
+
raise CompactContractError("ORDERED_ROUTE_INDEX")
|
| 281 |
+
route = self.ordered_route_index
|
| 282 |
+
expected_route_valid = self.node_valid[:, 7, route[0]] & self.node_valid[:, 7, route[1]]
|
| 283 |
+
if not np.array_equal(self.ordered_route_valid, expected_route_valid):
|
| 284 |
+
raise CompactContractError("ORDERED_ROUTE_VALID")
|
| 285 |
+
if np.any(self.timestamp_valid != self.history_valid):
|
| 286 |
+
raise CompactContractError("HISTORY_TIMESTAMP_VALIDITY")
|
| 287 |
+
expected_delta_valid = self.timestamp_valid[:, :-1] & self.timestamp_valid[:, 1:]
|
| 288 |
+
if not np.array_equal(self.delta_t_valid, expected_delta_valid):
|
| 289 |
+
raise CompactContractError("DELTA_T_VALIDITY")
|
| 290 |
+
_finite_zero_masked("TIMESTAMP", self.timestamp_s, self.timestamp_valid)
|
| 291 |
+
_finite_zero_masked("DELTA_T", self.delta_t_s, self.delta_t_valid)
|
| 292 |
+
actual_delta = self.timestamp_s[:, 1:] - self.timestamp_s[:, :-1]
|
| 293 |
+
try:
|
| 294 |
+
cadence_ok = offline_step_mask(self.timestamp_s[:, :-1], self.timestamp_s[:, 1:])
|
| 295 |
+
except ValueError as error:
|
| 296 |
+
raise CompactContractError(str(error)) from error
|
| 297 |
+
if np.any(self.delta_t_valid & ~cadence_ok):
|
| 298 |
+
raise CompactContractError("TIMESTAMP_CADENCE")
|
| 299 |
+
storage_ok = np.vectorize(storage_roundtrip_close, otypes=[bool])(self.delta_t_s, actual_delta)
|
| 300 |
+
if np.any(self.delta_t_valid & ~storage_ok):
|
| 301 |
+
raise CompactContractError("DELTA_T_VALUE")
|
| 302 |
+
if np.any(self.node_valid & ~self.history_valid[:, :, None]):
|
| 303 |
+
raise CompactContractError("NODE_WITHOUT_HISTORY")
|
| 304 |
+
if np.any(~self.family_valid & (self.family_id != 10)):
|
| 305 |
+
raise CompactContractError("FAMILY_PADDING_NOT_10")
|
| 306 |
+
legal_family = np.asarray([0, 2, 3, 4, 5, 6, 7, 8, 9], dtype=np.int64)
|
| 307 |
+
if np.any(self.family_valid & ~np.isin(self.family_id, legal_family)):
|
| 308 |
+
raise CompactContractError("FAMILY_ID")
|
| 309 |
+
static_inventory = self.node_valid.any(axis=1)
|
| 310 |
+
if not np.array_equal(static_inventory, self.family_valid):
|
| 311 |
+
raise CompactContractError("PACKED_ACTIVE_INVENTORY_MISMATCH")
|
| 312 |
+
if np.any(static_inventory & ~self.static_flags_valid):
|
| 313 |
+
raise CompactContractError("ACTIVE_NODE_STATIC_INVALID")
|
| 314 |
+
if np.any(self.node_valid & ~self.family_valid[:, None, :]):
|
| 315 |
+
raise CompactContractError("NODE_WITHOUT_FAMILY")
|
| 316 |
+
for row in range(b):
|
| 317 |
+
active_slots = self.slot_id[row, self.family_valid[row]]
|
| 318 |
+
if np.any(active_slots < 0) or len(set(active_slots.tolist())) != active_slots.size:
|
| 319 |
+
raise CompactContractError("ACTIVE_SLOT_ID_UNIQUE")
|
| 320 |
+
if np.any(self.slot_id[row, ~self.family_valid[row]] != -1):
|
| 321 |
+
raise CompactContractError("BATCH_PADDING_SLOT_NOT_MINUS_ONE")
|
| 322 |
+
if np.any(self.pose_valid & ~self.node_valid):
|
| 323 |
+
raise CompactContractError("POSE_WITHOUT_NODE")
|
| 324 |
+
if np.any(self.articulation_valid[..., 0] & ~self.node_valid):
|
| 325 |
+
raise CompactContractError("ARTICULATION_WITHOUT_NODE")
|
| 326 |
+
if np.any(self.view_record_valid & ~self.node_valid[..., None]):
|
| 327 |
+
raise CompactContractError("VIEW_WITHOUT_NODE")
|
| 328 |
+
_finite_zero_masked("POSE", self.pose, self.pose_valid)
|
| 329 |
+
_finite_zero_masked("ARTICULATION", self.articulation_q, self.articulation_valid)
|
| 330 |
+
_finite_zero_masked("VIEW", self.view_evidence, self.view_record_valid)
|
| 331 |
+
if np.any(self.articulation_q[~self.articulation_valid] != np.float32(0.0)):
|
| 332 |
+
raise CompactContractError("INVALID_ARTICULATION_NOT_POSITIVE_ZERO")
|
| 333 |
+
valid_quaternion = self.pose[..., 3:7][self.pose_valid]
|
| 334 |
+
if valid_quaternion.size and np.any(
|
| 335 |
+
np.abs(np.linalg.norm(valid_quaternion.astype(np.float64), axis=-1) - 1.0) > 1e-4
|
| 336 |
+
):
|
| 337 |
+
raise CompactContractError("QUATERNION_NORM")
|
| 338 |
+
visible = self.view_evidence[..., 0]
|
| 339 |
+
if np.any(self.view_record_valid & ~np.isin(visible, (0.0, 1.0))):
|
| 340 |
+
raise CompactContractError("VIEW_VISIBLE_BINARY")
|
| 341 |
+
if np.any(self.view_record_valid & (visible == 0.0) & np.any(self.view_evidence[..., 1:] != 0, axis=-1)):
|
| 342 |
+
raise CompactContractError("INVISIBLE_VIEW_GEOMETRY_NONZERO")
|
| 343 |
+
if np.any(self.is_task_target & ~self.task_target_valid):
|
| 344 |
+
raise CompactContractError("TARGET_WITHOUT_VALID")
|
| 345 |
+
if np.any(self.task_target_valid & ~self.node_valid[:, 7]):
|
| 346 |
+
raise CompactContractError("TARGET_VALID_ANCHOR_INVALID")
|
| 347 |
+
if np.any((self.task_target_source_code == 0) != ~self.task_target_valid):
|
| 348 |
+
raise CompactContractError("TARGET_SOURCE_CODE_VALIDITY")
|
| 349 |
+
if np.any(self.task_target_source_code > 6):
|
| 350 |
+
raise CompactContractError("TARGET_SOURCE_CODE")
|
| 351 |
+
if np.any(self.robot_target_contact & ~self.robot_target_contact_valid):
|
| 352 |
+
raise CompactContractError("ROBOT_TARGET_CONTACT_INVALID_TRUE")
|
| 353 |
+
expected_contact, expected_contact_valid = derive_robot_target_contact(
|
| 354 |
+
node_valid=self.node_valid,
|
| 355 |
+
family_id=self.family_id,
|
| 356 |
+
target=self.is_task_target,
|
| 357 |
+
target_valid=self.task_target_valid,
|
| 358 |
+
edge_index=self.edge_index,
|
| 359 |
+
edge_batch=self.edge_batch,
|
| 360 |
+
edge_time=self.edge_time,
|
| 361 |
+
edge_relation_id=self.edge_relation_id,
|
| 362 |
+
edge_payload_valid=self.edge_payload_valid,
|
| 363 |
+
)
|
| 364 |
+
if not np.array_equal(self.robot_target_contact, expected_contact) or not np.array_equal(
|
| 365 |
+
self.robot_target_contact_valid, expected_contact_valid
|
| 366 |
+
):
|
| 367 |
+
raise CompactContractError("ROBOT_TARGET_CONTACT_DERIVATION")
|
| 368 |
+
if e:
|
| 369 |
+
if np.any(self.edge_batch < 0) or np.any(self.edge_batch >= b):
|
| 370 |
+
raise CompactContractError("EDGE_BATCH")
|
| 371 |
+
if np.any(self.edge_time < 0) or np.any(self.edge_time >= 8):
|
| 372 |
+
raise CompactContractError("EDGE_TIME")
|
| 373 |
+
if np.any(self.edge_relation_id > 5):
|
| 374 |
+
raise CompactContractError("RELATION_ID")
|
| 375 |
+
if np.any(self.edge_index < 0) or np.any(self.edge_index >= n):
|
| 376 |
+
raise CompactContractError("EDGE_ENDPOINT")
|
| 377 |
+
if not self.edge_payload_valid.all():
|
| 378 |
+
raise CompactContractError("ACTIVE_EDGE_METRIC12_INCOMPLETE")
|
| 379 |
+
if not np.isfinite(self.edge_payload).all():
|
| 380 |
+
raise CompactContractError("EDGE_PAYLOAD_NONFINITE")
|
| 381 |
+
sender, receiver = self.edge_index
|
| 382 |
+
if np.any(~self.node_valid[self.edge_batch, self.edge_time, sender]) or np.any(
|
| 383 |
+
~self.node_valid[self.edge_batch, self.edge_time, receiver]
|
| 384 |
+
):
|
| 385 |
+
raise CompactContractError("EDGE_ENDPOINT_NODE_INVALID")
|
| 386 |
+
keys = list(
|
| 387 |
+
zip(
|
| 388 |
+
self.edge_batch.tolist(),
|
| 389 |
+
self.edge_time.tolist(),
|
| 390 |
+
self.edge_relation_id.tolist(),
|
| 391 |
+
receiver.tolist(),
|
| 392 |
+
sender.tolist(),
|
| 393 |
+
)
|
| 394 |
+
)
|
| 395 |
+
if keys != sorted(keys) or len(keys) != len(set(keys)):
|
| 396 |
+
raise CompactContractError("EDGE_ORDER_OR_DUPLICATE")
|
| 397 |
+
keyset = set(keys)
|
| 398 |
+
inverse = {0: 1, 1: 0, 2: 3, 3: 2, 4: 4}
|
| 399 |
+
for row, (batch, time, relation, recv, send) in enumerate(keys):
|
| 400 |
+
if relation in inverse and (batch, time, inverse[relation], send, recv) not in keyset:
|
| 401 |
+
raise CompactContractError("EDGE_INVERSE_MISSING")
|
| 402 |
+
delta = (
|
| 403 |
+
self.pose[batch, time, send, :3].astype(np.float64)
|
| 404 |
+
- self.pose[batch, time, recv, :3].astype(np.float64)
|
| 405 |
+
)
|
| 406 |
+
distance = np.sqrt(np.sum(delta * delta, dtype=np.float64))
|
| 407 |
+
centers = 2.0 * np.arange(8, dtype=np.float64) / 7.0
|
| 408 |
+
expected = np.concatenate(
|
| 409 |
+
(delta, [distance], np.exp(-((distance - centers) ** 2) / (2.0 * 0.25**2)))
|
| 410 |
+
).astype(np.float32)
|
| 411 |
+
if self.edge_payload[row].tobytes() != expected.tobytes():
|
| 412 |
+
raise CompactContractError("EDGE_METRIC12_MISMATCH")
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
@dataclass(frozen=True, slots=True)
|
| 416 |
+
class CompactActionConditionV3:
|
| 417 |
+
future_action: np.ndarray
|
| 418 |
+
future_action_valid: np.ndarray
|
| 419 |
+
action_timestamp_s: np.ndarray
|
| 420 |
+
action_timestamp_valid: np.ndarray
|
| 421 |
+
|
| 422 |
+
@property
|
| 423 |
+
def batch_size(self) -> int:
|
| 424 |
+
return int(self.future_action.shape[0]) if self.future_action.ndim else 0
|
| 425 |
+
|
| 426 |
+
def validate(self, packet: CompactGraphPacketV3 | None = None) -> None:
|
| 427 |
+
b = self.batch_size
|
| 428 |
+
_array("future_action", self.future_action, "<f4", (b, 8, 12))
|
| 429 |
+
_array("future_action_valid", self.future_action_valid, "|b1", (b, 8))
|
| 430 |
+
_array("action_timestamp_s", self.action_timestamp_s, "<f8", (b, 8))
|
| 431 |
+
_array("action_timestamp_valid", self.action_timestamp_valid, "|b1", (b, 8))
|
| 432 |
+
if b < 1:
|
| 433 |
+
raise CompactContractError("ACTION_BATCH_EMPTY")
|
| 434 |
+
if np.any(self.future_action_valid != self.action_timestamp_valid):
|
| 435 |
+
raise CompactContractError("ACTION_TIMESTAMP_VALIDITY")
|
| 436 |
+
_finite_zero_masked("ACTION", self.future_action, self.future_action_valid)
|
| 437 |
+
_finite_zero_masked("ACTION_TIMESTAMP", self.action_timestamp_s, self.action_timestamp_valid)
|
| 438 |
+
if packet is not None:
|
| 439 |
+
packet.validate()
|
| 440 |
+
if packet.batch_size != b:
|
| 441 |
+
raise CompactContractError("ACTION_PACKET_BATCH")
|
| 442 |
+
base_tick = np.rint(packet.timestamp_s[:, 7] / 0.05).astype(np.int64)
|
| 443 |
+
expected = np.asarray(np.float32((base_tick[:, None] + np.arange(8, dtype=np.int64)[None]) * 0.05), dtype=np.float64)
|
| 444 |
+
valid = self.action_timestamp_valid
|
| 445 |
+
try:
|
| 446 |
+
aligned = offline_timestamp_equal_mask(self.action_timestamp_s[valid], expected[valid])
|
| 447 |
+
except TemporalContractError as error:
|
| 448 |
+
raise CompactContractError("ACTION_PREFIX_ALIGNMENT") from error
|
| 449 |
+
if np.any(~aligned):
|
| 450 |
+
raise CompactContractError("ACTION_PREFIX_ALIGNMENT")
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
@dataclass(frozen=True, slots=True)
|
| 454 |
+
class CompactTargetsV3:
|
| 455 |
+
pair_index: np.ndarray
|
| 456 |
+
anchor_pair_valid: np.ndarray
|
| 457 |
+
anchor_contact: np.ndarray
|
| 458 |
+
anchor_contact_valid: np.ndarray
|
| 459 |
+
target_pair_valid: np.ndarray
|
| 460 |
+
target_contact_occupancy: np.ndarray
|
| 461 |
+
target_contact_event: np.ndarray
|
| 462 |
+
target_contact_event_valid: np.ndarray
|
| 463 |
+
target_robot_contact_occupancy: np.ndarray
|
| 464 |
+
target_robot_contact_occupancy_valid: np.ndarray
|
| 465 |
+
target_robot_contact_event: np.ndarray
|
| 466 |
+
target_robot_contact_event_valid: np.ndarray
|
| 467 |
+
target_node_valid: np.ndarray
|
| 468 |
+
target_timestamp_s: np.ndarray
|
| 469 |
+
target_timestamp_valid: np.ndarray
|
| 470 |
+
target_position_delta: np.ndarray
|
| 471 |
+
target_rotation_log: np.ndarray
|
| 472 |
+
target_pose_valid: np.ndarray
|
| 473 |
+
target_articulation_delta: np.ndarray
|
| 474 |
+
target_articulation_valid: np.ndarray
|
| 475 |
+
target_view_evidence: np.ndarray
|
| 476 |
+
target_view_record_valid: np.ndarray
|
| 477 |
+
current_position: np.ndarray
|
| 478 |
+
current_rotation_quat_xyzw: np.ndarray
|
| 479 |
+
current_pose_valid: np.ndarray
|
| 480 |
+
current_articulation_q: np.ndarray
|
| 481 |
+
current_articulation_valid: np.ndarray
|
| 482 |
+
current_contact: np.ndarray
|
| 483 |
+
current_contact_valid: np.ndarray
|
| 484 |
+
current_robot_target_contact: np.ndarray
|
| 485 |
+
current_robot_target_contact_valid: np.ndarray
|
| 486 |
+
current_view_evidence: np.ndarray
|
| 487 |
+
current_view_record_valid: np.ndarray
|
| 488 |
+
current_structural_relation: np.ndarray
|
| 489 |
+
current_structural_valid: np.ndarray
|
| 490 |
+
|
| 491 |
+
@property
|
| 492 |
+
def batch_size(self) -> int:
|
| 493 |
+
return int(self.anchor_pair_valid.shape[0]) if self.anchor_pair_valid.ndim else 0
|
| 494 |
+
|
| 495 |
+
def validate(
|
| 496 |
+
self,
|
| 497 |
+
packet: CompactGraphPacketV3 | None = None,
|
| 498 |
+
action: CompactActionConditionV3 | None = None,
|
| 499 |
+
) -> None:
|
| 500 |
+
b = self.batch_size
|
| 501 |
+
n = int(self.current_position.shape[1]) if self.current_position.ndim == 3 else 0
|
| 502 |
+
if not 1 <= n <= NODE_CAPACITY:
|
| 503 |
+
raise CompactContractError(f"TARGET_NODE_COUNT:{n}")
|
| 504 |
+
q = n * (n - 1) // 2
|
| 505 |
+
expected = {
|
| 506 |
+
"pair_index": ("<i8", (2, q)),
|
| 507 |
+
"anchor_pair_valid": ("|b1", (b, q)),
|
| 508 |
+
"anchor_contact": ("|b1", (b, q)),
|
| 509 |
+
"anchor_contact_valid": ("|b1", (b, q)),
|
| 510 |
+
"target_pair_valid": ("|b1", (b, 8, q)),
|
| 511 |
+
"target_contact_occupancy": ("|b1", (b, 8, q)),
|
| 512 |
+
"target_contact_event": ("<i8", (b, 8, q)),
|
| 513 |
+
"target_contact_event_valid": ("|b1", (b, 8, q)),
|
| 514 |
+
"target_robot_contact_occupancy": ("|b1", (b, 8, n)),
|
| 515 |
+
"target_robot_contact_occupancy_valid": ("|b1", (b, 8, n)),
|
| 516 |
+
"target_robot_contact_event": ("<i8", (b, 8, n)),
|
| 517 |
+
"target_robot_contact_event_valid": ("|b1", (b, 8, n)),
|
| 518 |
+
"target_node_valid": ("|b1", (b, 8, n)),
|
| 519 |
+
"target_timestamp_s": ("<f8", (b, 8)),
|
| 520 |
+
"target_timestamp_valid": ("|b1", (b, 8)),
|
| 521 |
+
"target_position_delta": ("<f4", (b, 8, n, 3)),
|
| 522 |
+
"target_rotation_log": ("<f4", (b, 8, n, 3)),
|
| 523 |
+
"target_pose_valid": ("|b1", (b, 8, n)),
|
| 524 |
+
"target_articulation_delta": ("<f4", (b, 8, n, 1)),
|
| 525 |
+
"target_articulation_valid": ("|b1", (b, 8, n, 1)),
|
| 526 |
+
"target_view_evidence": ("<f4", (b, 8, n, 3, 8)),
|
| 527 |
+
"target_view_record_valid": ("|b1", (b, 8, n, 3)),
|
| 528 |
+
"current_position": ("<f4", (b, n, 3)),
|
| 529 |
+
"current_rotation_quat_xyzw": ("<f4", (b, n, 4)),
|
| 530 |
+
"current_pose_valid": ("|b1", (b, n)),
|
| 531 |
+
"current_articulation_q": ("<f4", (b, n, 1)),
|
| 532 |
+
"current_articulation_valid": ("|b1", (b, n, 1)),
|
| 533 |
+
"current_contact": ("|b1", (b, q)),
|
| 534 |
+
"current_contact_valid": ("|b1", (b, q)),
|
| 535 |
+
"current_robot_target_contact": ("|b1", (b, n)),
|
| 536 |
+
"current_robot_target_contact_valid": ("|b1", (b, n)),
|
| 537 |
+
"current_view_evidence": ("<f4", (b, n, 3, 8)),
|
| 538 |
+
"current_view_record_valid": ("|b1", (b, n, 3)),
|
| 539 |
+
"current_structural_relation": ("<i8", (b, n, n)),
|
| 540 |
+
"current_structural_valid": ("|b1", (b, n, n)),
|
| 541 |
+
}
|
| 542 |
+
for name, (dtype, shape) in expected.items():
|
| 543 |
+
_array(name, getattr(self, name), dtype, shape)
|
| 544 |
+
if b < 1 or not np.array_equal(self.pair_index, canonical_pair_index(n)):
|
| 545 |
+
raise CompactContractError("PAIR_INDEX")
|
| 546 |
+
if np.any(self.anchor_contact & ~self.anchor_contact_valid):
|
| 547 |
+
raise CompactContractError("ANCHOR_CONTACT_INVALID_TRUE")
|
| 548 |
+
if np.any(self.anchor_contact_valid & ~self.anchor_pair_valid):
|
| 549 |
+
raise CompactContractError("ANCHOR_CONTACT_VALID_CEILING")
|
| 550 |
+
if np.any(self.target_contact_occupancy & ~self.target_pair_valid):
|
| 551 |
+
raise CompactContractError("TARGET_CONTACT_INVALID_TRUE")
|
| 552 |
+
if np.any(
|
| 553 |
+
self.target_robot_contact_occupancy & ~self.target_robot_contact_occupancy_valid
|
| 554 |
+
):
|
| 555 |
+
raise CompactContractError("TARGET_ROBOT_CONTACT_INVALID_TRUE")
|
| 556 |
+
if np.any(
|
| 557 |
+
self.target_robot_contact_occupancy_valid
|
| 558 |
+
& ~self.target_node_valid
|
| 559 |
+
):
|
| 560 |
+
raise CompactContractError("TARGET_ROBOT_CONTACT_NODE_CEILING")
|
| 561 |
+
if np.any(
|
| 562 |
+
self.target_robot_contact_occupancy_valid
|
| 563 |
+
& ~self.target_timestamp_valid[:, :, None]
|
| 564 |
+
):
|
| 565 |
+
raise CompactContractError("TARGET_ROBOT_CONTACT_TIMESTAMP_CEILING")
|
| 566 |
+
if np.any(self.target_robot_contact_event[~self.target_robot_contact_event_valid] != 0):
|
| 567 |
+
raise CompactContractError("TARGET_ROBOT_CONTACT_EVENT_INVALID_NONZERO")
|
| 568 |
+
if np.any(
|
| 569 |
+
self.target_robot_contact_event_valid & ~self.target_robot_contact_occupancy_valid
|
| 570 |
+
):
|
| 571 |
+
raise CompactContractError("TARGET_ROBOT_CONTACT_EVENT_VALID_CEILING")
|
| 572 |
+
if np.any((self.target_robot_contact_event < 0) | (self.target_robot_contact_event > 3)):
|
| 573 |
+
raise CompactContractError("TARGET_ROBOT_EVENT_ID")
|
| 574 |
+
if np.any(self.current_robot_target_contact & ~self.current_robot_target_contact_valid):
|
| 575 |
+
raise CompactContractError("CURRENT_ROBOT_CONTACT_INVALID_TRUE")
|
| 576 |
+
if not np.array_equal(self.current_contact, self.anchor_contact):
|
| 577 |
+
raise CompactContractError("CURRENT_CONTACT_ALIAS")
|
| 578 |
+
if not np.array_equal(self.current_contact_valid, self.anchor_contact_valid):
|
| 579 |
+
raise CompactContractError("CURRENT_CONTACT_VALID_ALIAS")
|
| 580 |
+
if np.any(self.target_pose_valid & ~self.target_node_valid):
|
| 581 |
+
raise CompactContractError("TARGET_POSE_NODE_CEILING")
|
| 582 |
+
if np.any(self.target_articulation_valid[..., 0] & ~self.target_node_valid):
|
| 583 |
+
raise CompactContractError("TARGET_ARTICULATION_NODE_CEILING")
|
| 584 |
+
if np.any(self.target_view_record_valid & ~self.target_node_valid[..., None]):
|
| 585 |
+
raise CompactContractError("TARGET_VIEW_NODE_CEILING")
|
| 586 |
+
_finite_zero_masked("TARGET_POSITION_DELTA", self.target_position_delta, self.target_pose_valid)
|
| 587 |
+
_finite_zero_masked("TARGET_ROTATION_LOG", self.target_rotation_log, self.target_pose_valid)
|
| 588 |
+
_finite_zero_masked("TARGET_ARTICULATION_DELTA", self.target_articulation_delta, self.target_articulation_valid)
|
| 589 |
+
_finite_zero_masked("TARGET_VIEW", self.target_view_evidence, self.target_view_record_valid)
|
| 590 |
+
_finite_zero_masked("CURRENT_POSITION", self.current_position, self.current_pose_valid)
|
| 591 |
+
_finite_zero_masked("CURRENT_QUATERNION", self.current_rotation_quat_xyzw, self.current_pose_valid)
|
| 592 |
+
_finite_zero_masked("CURRENT_ARTICULATION", self.current_articulation_q, self.current_articulation_valid)
|
| 593 |
+
_finite_zero_masked("CURRENT_VIEW", self.current_view_evidence, self.current_view_record_valid)
|
| 594 |
+
if np.any((self.target_contact_event < 0) | (self.target_contact_event > 3)):
|
| 595 |
+
raise CompactContractError("TARGET_EVENT_ID")
|
| 596 |
+
if np.any(self.target_contact_event[~self.target_contact_event_valid] != 0):
|
| 597 |
+
raise CompactContractError("TARGET_EVENT_INVALID_NONZERO")
|
| 598 |
+
if np.any((self.current_structural_relation < 0) | (self.current_structural_relation > 4)):
|
| 599 |
+
raise CompactContractError("CURRENT_STRUCTURAL_ID")
|
| 600 |
+
if np.any(self.current_structural_relation[~self.current_structural_valid] != 0):
|
| 601 |
+
raise CompactContractError("CURRENT_STRUCTURAL_INVALID_NONZERO")
|
| 602 |
+
if packet is not None:
|
| 603 |
+
packet.validate()
|
| 604 |
+
if packet.batch_size != b:
|
| 605 |
+
raise CompactContractError("TARGET_PACKET_BATCH")
|
| 606 |
+
if packet.n_nodes != n:
|
| 607 |
+
raise CompactContractError("TARGET_PACKET_NODE_COUNT")
|
| 608 |
+
pair_i, pair_j = self.pair_index
|
| 609 |
+
anchor = packet.node_valid[:, 7]
|
| 610 |
+
expected_pair = anchor[:, pair_i] & anchor[:, pair_j]
|
| 611 |
+
if not np.array_equal(self.anchor_pair_valid, expected_pair):
|
| 612 |
+
raise CompactContractError("ANCHOR_PAIR_VALID")
|
| 613 |
+
if not np.array_equal(self.current_position, packet.pose[:, 7, :, :3]):
|
| 614 |
+
raise CompactContractError("CURRENT_POSITION_ALIAS")
|
| 615 |
+
if not np.array_equal(self.current_rotation_quat_xyzw, packet.pose[:, 7, :, 3:7]):
|
| 616 |
+
raise CompactContractError("CURRENT_QUATERNION_ALIAS")
|
| 617 |
+
if not np.array_equal(self.current_pose_valid, packet.pose_valid[:, 7]):
|
| 618 |
+
raise CompactContractError("CURRENT_POSE_VALID_ALIAS")
|
| 619 |
+
if not np.array_equal(self.current_articulation_q, packet.articulation_q[:, 7]):
|
| 620 |
+
raise CompactContractError("CURRENT_ARTICULATION_ALIAS")
|
| 621 |
+
if not np.array_equal(self.current_articulation_valid, packet.articulation_valid[:, 7]):
|
| 622 |
+
raise CompactContractError("CURRENT_ARTICULATION_VALID_ALIAS")
|
| 623 |
+
if not np.array_equal(self.current_view_evidence, packet.view_evidence[:, 7]):
|
| 624 |
+
raise CompactContractError("CURRENT_VIEW_ALIAS")
|
| 625 |
+
if not np.array_equal(self.current_view_record_valid, packet.view_record_valid[:, 7]):
|
| 626 |
+
raise CompactContractError("CURRENT_VIEW_VALID_ALIAS")
|
| 627 |
+
if not np.array_equal(
|
| 628 |
+
self.current_robot_target_contact, packet.robot_target_contact[:, 7]
|
| 629 |
+
) or not np.array_equal(
|
| 630 |
+
self.current_robot_target_contact_valid,
|
| 631 |
+
packet.robot_target_contact_valid[:, 7],
|
| 632 |
+
):
|
| 633 |
+
raise CompactContractError("CURRENT_ROBOT_CONTACT_ALIAS")
|
| 634 |
+
if action is not None:
|
| 635 |
+
action.validate(packet)
|
| 636 |
+
valid = self.target_timestamp_valid
|
| 637 |
+
action_tick = np.rint(action.action_timestamp_s / 0.05).astype(np.int64)
|
| 638 |
+
expected = np.asarray(np.float32((action_tick + 1) * 0.05), dtype=np.float64)
|
| 639 |
+
try:
|
| 640 |
+
aligned = offline_timestamp_equal_mask(self.target_timestamp_s[valid], expected[valid])
|
| 641 |
+
except TemporalContractError as error:
|
| 642 |
+
raise CompactContractError("TARGET_ACTION_ALIGNMENT") from error
|
| 643 |
+
if np.any(~aligned):
|
| 644 |
+
raise CompactContractError("TARGET_ACTION_ALIGNMENT")
|
| 645 |
+
|
| 646 |
+
|
| 647 |
+
def _require_digest(value: str, name: str) -> None:
|
| 648 |
+
if type(value) is not str or len(value) != 64 or any(char not in "0123456789abcdef" for char in value):
|
| 649 |
+
raise CompactContractError(f"{name}:SHA256")
|
| 650 |
+
|
| 651 |
+
|
| 652 |
+
@dataclass(frozen=True, slots=True)
|
| 653 |
+
class CompactProvenanceV3:
|
| 654 |
+
episode_key: tuple[str, ...]
|
| 655 |
+
task: tuple[str, ...]
|
| 656 |
+
window_start: tuple[int, ...]
|
| 657 |
+
natural_window_sha256: tuple[str, ...]
|
| 658 |
+
source_split: tuple[str, ...]
|
| 659 |
+
source_zip_path: tuple[str, ...]
|
| 660 |
+
source_zip_sha256: tuple[str, ...]
|
| 661 |
+
outer_manifest_row_sha256: tuple[str, ...]
|
| 662 |
+
target_receipt_bytes: tuple[bytes, ...]
|
| 663 |
+
target_receipt_sha256: tuple[str, ...]
|
| 664 |
+
c2_receipt_sha256: tuple[str, ...]
|
| 665 |
+
geometry_receipt_bytes: tuple[bytes, ...]
|
| 666 |
+
geometry_receipt_sha256: tuple[str, ...]
|
| 667 |
+
pre_geometry_source_sha256: tuple[str, ...]
|
| 668 |
+
source_access_trace_sha256: tuple[str, ...]
|
| 669 |
+
|
| 670 |
+
def validate(self, *, batch_size: int) -> None:
|
| 671 |
+
for field in fields(type(self)):
|
| 672 |
+
value = getattr(self, field.name)
|
| 673 |
+
if type(value) is not tuple or len(value) != batch_size:
|
| 674 |
+
raise CompactContractError(f"PROVENANCE_CARDINALITY:{field.name}")
|
| 675 |
+
if any(split != "outer_train" for split in self.source_split):
|
| 676 |
+
raise CompactContractError("PROVENANCE_SPLIT")
|
| 677 |
+
if any(type(value) is not int or value < 0 for value in self.window_start):
|
| 678 |
+
raise CompactContractError("PROVENANCE_WINDOW_START")
|
| 679 |
+
forbidden = {"validation", "val", "test", "outer_validation", "outer_test"}
|
| 680 |
+
for path in self.source_zip_path:
|
| 681 |
+
if type(path) is not str or not path:
|
| 682 |
+
raise CompactContractError("PROVENANCE_SOURCE_PATH")
|
| 683 |
+
if forbidden.intersection(part.lower() for part in PurePosixPath(path).parts):
|
| 684 |
+
raise CompactContractError("PROVENANCE_FORBIDDEN_SOURCE_PATH")
|
| 685 |
+
digest_fields = (
|
| 686 |
+
self.natural_window_sha256,
|
| 687 |
+
self.source_zip_sha256,
|
| 688 |
+
self.outer_manifest_row_sha256,
|
| 689 |
+
self.target_receipt_sha256,
|
| 690 |
+
self.c2_receipt_sha256,
|
| 691 |
+
self.geometry_receipt_sha256,
|
| 692 |
+
self.pre_geometry_source_sha256,
|
| 693 |
+
self.source_access_trace_sha256,
|
| 694 |
+
)
|
| 695 |
+
for values in digest_fields:
|
| 696 |
+
for value in values:
|
| 697 |
+
_require_digest(value, "PROVENANCE")
|
| 698 |
+
for index in range(batch_size):
|
| 699 |
+
if type(self.target_receipt_bytes[index]) is not bytes or hashlib.sha256(
|
| 700 |
+
self.target_receipt_bytes[index]
|
| 701 |
+
).hexdigest() != self.target_receipt_sha256[index]:
|
| 702 |
+
raise CompactContractError("TARGET_RECEIPT_BYTES")
|
| 703 |
+
if type(self.geometry_receipt_bytes[index]) is not bytes or hashlib.sha256(
|
| 704 |
+
self.geometry_receipt_bytes[index]
|
| 705 |
+
).hexdigest() != self.geometry_receipt_sha256[index]:
|
| 706 |
+
raise CompactContractError("GEOMETRY_RECEIPT_BYTES")
|
| 707 |
+
|
| 708 |
+
|
| 709 |
+
@dataclass(frozen=True, slots=True)
|
| 710 |
+
class CompactExampleV3:
|
| 711 |
+
packet: CompactGraphPacketV3
|
| 712 |
+
action: CompactActionConditionV3
|
| 713 |
+
targets: CompactTargetsV3
|
| 714 |
+
provenance: CompactProvenanceV3
|
| 715 |
+
|
| 716 |
+
def validate(self) -> None:
|
| 717 |
+
if type(self.packet) is not CompactGraphPacketV3:
|
| 718 |
+
raise CompactContractError("PACKET_EXACT_TYPE")
|
| 719 |
+
if type(self.action) is not CompactActionConditionV3:
|
| 720 |
+
raise CompactContractError("ACTION_EXACT_TYPE")
|
| 721 |
+
if type(self.targets) is not CompactTargetsV3:
|
| 722 |
+
raise CompactContractError("TARGETS_EXACT_TYPE")
|
| 723 |
+
if type(self.provenance) is not CompactProvenanceV3:
|
| 724 |
+
raise CompactContractError("PROVENANCE_EXACT_TYPE")
|
| 725 |
+
self.packet.validate()
|
| 726 |
+
self.action.validate(self.packet)
|
| 727 |
+
self.targets.validate(self.packet, self.action)
|
| 728 |
+
self.provenance.validate(batch_size=self.packet.batch_size)
|
| 729 |
+
|
| 730 |
+
|
| 731 |
+
@dataclass(frozen=True, slots=True)
|
| 732 |
+
class ConvenienceNodeProjectionV3:
|
| 733 |
+
values46: np.ndarray
|
| 734 |
+
node_valid: np.ndarray
|
| 735 |
+
family_valid: np.ndarray
|
| 736 |
+
static_flags_valid: np.ndarray
|
| 737 |
+
pose_valid: np.ndarray
|
| 738 |
+
articulation_valid: np.ndarray
|
| 739 |
+
view_record_valid: np.ndarray
|
| 740 |
+
task_target_valid: np.ndarray
|
| 741 |
+
robot_target_contact_valid: np.ndarray
|
| 742 |
+
authoritative: bool = False
|
| 743 |
+
visibility_is_duplicated: bool = False
|
| 744 |
+
|
| 745 |
+
@classmethod
|
| 746 |
+
def from_packet(cls, packet: CompactGraphPacketV3) -> "ConvenienceNodeProjectionV3":
|
| 747 |
+
packet.validate()
|
| 748 |
+
b, n = packet.batch_size, packet.n_nodes
|
| 749 |
+
static = np.broadcast_to(packet.static_flags[:, None].astype(np.float32), (b, 8, n, 2))
|
| 750 |
+
family_onehot = np.zeros((b, 8, n, 10), dtype=np.float32)
|
| 751 |
+
for family in range(10):
|
| 752 |
+
family_onehot[..., family] = (packet.family_id[:, None] == family) & packet.family_valid[:, None]
|
| 753 |
+
values44 = np.concatenate(
|
| 754 |
+
(static, packet.pose, packet.articulation_q, family_onehot, packet.view_evidence.reshape(b, 8, n, 24)), axis=-1
|
| 755 |
+
).astype(np.float32)
|
| 756 |
+
target = np.broadcast_to(packet.is_task_target[:, None, :, None], (b, 8, n, 1))
|
| 757 |
+
valid = np.broadcast_to(packet.task_target_valid[:, None, :, None], (b, 8, n, 1))
|
| 758 |
+
values46 = np.concatenate(
|
| 759 |
+
(values44, target.astype(np.float32), valid.astype(np.float32)), axis=-1
|
| 760 |
+
)
|
| 761 |
+
return cls(
|
| 762 |
+
values46=freeze_array(values46),
|
| 763 |
+
node_valid=packet.node_valid,
|
| 764 |
+
family_valid=packet.family_valid,
|
| 765 |
+
static_flags_valid=packet.static_flags_valid,
|
| 766 |
+
pose_valid=packet.pose_valid,
|
| 767 |
+
articulation_valid=packet.articulation_valid,
|
| 768 |
+
view_record_valid=packet.view_record_valid,
|
| 769 |
+
task_target_valid=packet.task_target_valid,
|
| 770 |
+
robot_target_contact_valid=packet.robot_target_contact_valid,
|
| 771 |
+
)
|
| 772 |
+
|
| 773 |
+
def validate(self) -> None:
|
| 774 |
+
b = self.values46.shape[0] if self.values46.ndim else 0
|
| 775 |
+
n = self.values46.shape[2] if self.values46.ndim == 4 else 0
|
| 776 |
+
_array("values46", self.values46, "<f4", (b, 8, n, 46))
|
| 777 |
+
_array("node_valid", self.node_valid, "|b1", (b, 8, n))
|
| 778 |
+
_array("family_valid", self.family_valid, "|b1", (b, n))
|
| 779 |
+
_array("static_flags_valid", self.static_flags_valid, "|b1", (b, n))
|
| 780 |
+
_array("pose_valid", self.pose_valid, "|b1", (b, 8, n))
|
| 781 |
+
_array("articulation_valid", self.articulation_valid, "|b1", (b, 8, n, 1))
|
| 782 |
+
_array("view_record_valid", self.view_record_valid, "|b1", (b, 8, n, 3))
|
| 783 |
+
_array("task_target_valid", self.task_target_valid, "|b1", (b, n))
|
| 784 |
+
_array("robot_target_contact_valid", self.robot_target_contact_valid, "|b1", (b, 8, n))
|
| 785 |
+
if self.authoritative is not False or self.visibility_is_duplicated is not False:
|
| 786 |
+
raise CompactContractError("CONVENIENCE_DISCLOSURE")
|
| 787 |
+
|
| 788 |
+
def as_model_input(self) -> None:
|
| 789 |
+
raise CompactContractError("CONVENIENCE_NOT_MODEL_INPUT")
|
| 790 |
+
|
| 791 |
+
|
| 792 |
+
def packet_from_mapping(value: Mapping[str, object]) -> CompactGraphPacketV3:
|
| 793 |
+
if type(value) is not dict:
|
| 794 |
+
raise CompactContractError("PACKET_MAPPING_EXACT_DICT")
|
| 795 |
+
allowed = {field.name for field in fields(CompactGraphPacketV3)}
|
| 796 |
+
unknown = set(value) - allowed
|
| 797 |
+
if unknown:
|
| 798 |
+
raise CompactContractError(f"UNKNOWN_PACKET_FIELDS:{sorted(unknown)}")
|
| 799 |
+
required = {
|
| 800 |
+
field.name
|
| 801 |
+
for field in fields(CompactGraphPacketV3)
|
| 802 |
+
if field.name not in {"graph_profile_id", "relation_registry_sha256", "target_resolver_sha256"}
|
| 803 |
+
}
|
| 804 |
+
absent = required - set(value)
|
| 805 |
+
if absent:
|
| 806 |
+
raise CompactContractError(f"MISSING_PACKET_FIELDS:{sorted(absent)}")
|
| 807 |
+
packet = CompactGraphPacketV3(**value) # type: ignore[arg-type]
|
| 808 |
+
packet.validate()
|
| 809 |
+
return packet
|
| 810 |
+
|
| 811 |
+
|
| 812 |
+
__all__ = [
|
| 813 |
+
"ACTION_DIM",
|
| 814 |
+
"CAMERAS",
|
| 815 |
+
"CompactActionConditionV3",
|
| 816 |
+
"CompactContractError",
|
| 817 |
+
"CompactExampleV3",
|
| 818 |
+
"CompactGraphPacketV3",
|
| 819 |
+
"CompactProvenanceV3",
|
| 820 |
+
"CompactTargetsV3",
|
| 821 |
+
"ConvenienceNodeProjectionV3",
|
| 822 |
+
"HISTORY_LENGTH",
|
| 823 |
+
"HORIZON",
|
| 824 |
+
"METRIC_DIM",
|
| 825 |
+
"MODEL_PROFILE_ID",
|
| 826 |
+
"NODE_CAPACITY",
|
| 827 |
+
"ORDERED_ROUTE_COUNT",
|
| 828 |
+
"PAIR_CAPACITY",
|
| 829 |
+
"RELATION_REGISTRY_SHA256",
|
| 830 |
+
"TARGET_RESOLVER_SHA256",
|
| 831 |
+
"canonical_ordered_route_index",
|
| 832 |
+
"canonical_pair_index",
|
| 833 |
+
"derive_robot_target_contact",
|
| 834 |
+
"freeze_array",
|
| 835 |
+
"packet_from_mapping",
|
| 836 |
+
]
|
gwam_active13_gwam_training_v3_20260801/loader/compact_target_aware_gwam_training_dataset.py
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Map-style facade over the direct typed compact source.
|
| 2 |
+
|
| 3 |
+
The historical filename is retained for local import compatibility. The
|
| 4 |
+
implementation contains no rich-loader delegation and returns exact typed
|
| 5 |
+
objects rather than dictionaries.
|
| 6 |
+
"""
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import bisect
|
| 10 |
+
import hashlib
|
| 11 |
+
import json
|
| 12 |
+
import os
|
| 13 |
+
from collections import OrderedDict
|
| 14 |
+
from pathlib import Path, PurePosixPath
|
| 15 |
+
|
| 16 |
+
from .compact_collate import collate_compact_examples_v3
|
| 17 |
+
from .compact_contract import CompactExampleV3
|
| 18 |
+
from .direct_compact_source import (
|
| 19 |
+
CompactEpisodeDescriptorV3,
|
| 20 |
+
DirectCompactSourceV3,
|
| 21 |
+
SourceAccessError,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
PREFIX = "gwam_active13_gwam_training_v3_20260801"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _read_bound(path: Path, expected_sha256: str) -> bytes:
|
| 29 |
+
if not path.is_file():
|
| 30 |
+
raise SourceAccessError(f"BOUND_FILE_MISSING:{path.name}")
|
| 31 |
+
payload = path.read_bytes()
|
| 32 |
+
if hashlib.sha256(payload).hexdigest() != expected_sha256:
|
| 33 |
+
raise SourceAccessError(f"BOUND_FILE_SHA256:{path.name}")
|
| 34 |
+
return payload
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _safe_join(root: Path, relative: str) -> Path:
|
| 38 |
+
value = PurePosixPath(relative)
|
| 39 |
+
if value.is_absolute() or str(value) != relative or any(
|
| 40 |
+
item in {"", ".", ".."} for item in value.parts
|
| 41 |
+
):
|
| 42 |
+
raise SourceAccessError("SIDECAR_PATH_NOT_CANONICAL")
|
| 43 |
+
path = root.joinpath(*value.parts)
|
| 44 |
+
if not path.is_relative_to(root):
|
| 45 |
+
raise SourceAccessError("SIDECAR_PATH_ESCAPE")
|
| 46 |
+
return path
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def _jsonl_rows(payload: bytes, *, label: str) -> list[tuple[dict[str, object], bytes]]:
|
| 50 |
+
result: list[tuple[dict[str, object], bytes]] = []
|
| 51 |
+
try:
|
| 52 |
+
for raw in payload.splitlines(keepends=True):
|
| 53 |
+
if not raw.strip():
|
| 54 |
+
continue
|
| 55 |
+
value = json.loads(raw)
|
| 56 |
+
if type(value) is not dict:
|
| 57 |
+
raise ValueError("row")
|
| 58 |
+
result.append((value, raw if raw.endswith(b"\n") else raw + b"\n"))
|
| 59 |
+
except (UnicodeDecodeError, json.JSONDecodeError, ValueError) as error:
|
| 60 |
+
raise SourceAccessError(f"{label}_JSONL") from error
|
| 61 |
+
return result
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class DirectCompactGWAMDatasetV3:
|
| 65 |
+
"""Direct episode-window dataset; no optimizer or model is constructed."""
|
| 66 |
+
|
| 67 |
+
def __init__(
|
| 68 |
+
self,
|
| 69 |
+
root: str | Path,
|
| 70 |
+
*,
|
| 71 |
+
index_prefix: str = PREFIX,
|
| 72 |
+
outer_manifest_path: str | Path,
|
| 73 |
+
outer_manifest_sha256: str,
|
| 74 |
+
c2_root: str | Path | None = None,
|
| 75 |
+
c2_index_path: str | Path | None = None,
|
| 76 |
+
c2_index_sha256: str | None = None,
|
| 77 |
+
episode_cache_size: int | None = None,
|
| 78 |
+
episode_cache_max_entries: int = 8,
|
| 79 |
+
episode_cache_max_bytes: int = 512 << 20,
|
| 80 |
+
) -> None:
|
| 81 |
+
self.root = Path(root).resolve()
|
| 82 |
+
if type(index_prefix) is not str or not index_prefix or index_prefix in {".", ".."} or "/" in index_prefix or "\\" in index_prefix or Path(index_prefix).name != index_prefix:
|
| 83 |
+
raise SourceAccessError("V3_INDEX_PREFIX_NOT_SINGLE_COMPONENT")
|
| 84 |
+
self.index_prefix = index_prefix
|
| 85 |
+
if episode_cache_size is not None:
|
| 86 |
+
episode_cache_max_entries = episode_cache_size
|
| 87 |
+
if type(episode_cache_max_entries) is not int or episode_cache_max_entries < 0 or type(episode_cache_max_bytes) is not int or episode_cache_max_bytes < 0:
|
| 88 |
+
raise SourceAccessError("EPISODE_CACHE_LIMIT")
|
| 89 |
+
self.episode_cache_max_entries = episode_cache_max_entries
|
| 90 |
+
self.episode_cache_max_bytes = episode_cache_max_bytes
|
| 91 |
+
self._episode_cache: OrderedDict[tuple[object, ...], object] = OrderedDict()
|
| 92 |
+
self._episode_cache_bytes = 0
|
| 93 |
+
self._cache_hits = self._cache_misses = self._cache_evictions = 0
|
| 94 |
+
self._runtime_pid = os.getpid()
|
| 95 |
+
self.prefix_root = self.root / self.index_prefix
|
| 96 |
+
if not self.prefix_root.is_dir():
|
| 97 |
+
raise SourceAccessError("V3_PREFIX_MISSING")
|
| 98 |
+
index_path = self.prefix_root / "TRAINING_EPISODES.jsonl"
|
| 99 |
+
index_payload = index_path.read_bytes()
|
| 100 |
+
compact_rows = [value for value, _ in _jsonl_rows(index_payload, label="V3_INDEX")]
|
| 101 |
+
if len(compact_rows) != 2699:
|
| 102 |
+
raise SourceAccessError("V3_INDEX_CARDINALITY")
|
| 103 |
+
outer_path = Path(outer_manifest_path).resolve()
|
| 104 |
+
outer_payload = _read_bound(outer_path, outer_manifest_sha256)
|
| 105 |
+
outer_rows = {
|
| 106 |
+
str(value.get("episode_key", value.get("episode"))): (value, raw)
|
| 107 |
+
for value, raw in _jsonl_rows(outer_payload, label="OUTER_MANIFEST")
|
| 108 |
+
if value.get("episode_key", value.get("episode")) is not None
|
| 109 |
+
}
|
| 110 |
+
self._rows: list[tuple[dict[str, object], dict[str, object], str]] = []
|
| 111 |
+
cumulative: list[int] = []
|
| 112 |
+
total = 0
|
| 113 |
+
for row in compact_rows:
|
| 114 |
+
episode_key = row.get("episode_key")
|
| 115 |
+
if type(episode_key) is not str or episode_key not in outer_rows:
|
| 116 |
+
raise SourceAccessError("V3_OUTER_JOIN")
|
| 117 |
+
outer, outer_raw = outer_rows[episode_key]
|
| 118 |
+
if not (
|
| 119 |
+
row.get("schema") == "gwam.active13.gwam_training_episode.v3_compact"
|
| 120 |
+
and row.get("model_split") == "train"
|
| 121 |
+
and outer.get("model_split") == "train"
|
| 122 |
+
and row.get("task") == outer.get("task")
|
| 123 |
+
and row.get("source_group_id") == outer.get("source_group_id")
|
| 124 |
+
and row.get("canonical_zip_path") == outer.get("zip_path")
|
| 125 |
+
and row.get("canonical_zip_sha256") == outer.get("zip_sha256")
|
| 126 |
+
):
|
| 127 |
+
raise SourceAccessError("V3_OUTER_DISAGREEMENT")
|
| 128 |
+
count = row.get("valid_start_count")
|
| 129 |
+
if type(count) is not int or count < 1:
|
| 130 |
+
raise SourceAccessError("V3_START_COUNT")
|
| 131 |
+
total += count
|
| 132 |
+
cumulative.append(total)
|
| 133 |
+
self._rows.append((row, outer, hashlib.sha256(outer_raw).hexdigest()))
|
| 134 |
+
self._cumulative = tuple(cumulative)
|
| 135 |
+
self._source = DirectCompactSourceV3(self.root)
|
| 136 |
+
self._c2_root = None if c2_root is None else Path(c2_root).resolve()
|
| 137 |
+
self._c2_rows: dict[str, dict[str, object]] = {}
|
| 138 |
+
if any(row[0].get("task") == "OpenDrawer" for row in self._rows):
|
| 139 |
+
if c2_index_path is not None and c2_index_sha256 is not None and self._c2_root is not None:
|
| 140 |
+
c2_payload = _read_bound(Path(c2_index_path).resolve(), c2_index_sha256)
|
| 141 |
+
self._c2_rows = {
|
| 142 |
+
str(value.get("episode_key")): value
|
| 143 |
+
for value, _ in _jsonl_rows(c2_payload, label="C2_INDEX")
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
def __getstate__(self):
|
| 147 |
+
state = dict(self.__dict__)
|
| 148 |
+
state["_source"] = None
|
| 149 |
+
state["_episode_cache"] = OrderedDict()
|
| 150 |
+
state["_episode_cache_bytes"] = 0
|
| 151 |
+
state["_cache_hits"] = state["_cache_misses"] = state["_cache_evictions"] = 0
|
| 152 |
+
state["_runtime_pid"] = None
|
| 153 |
+
return state
|
| 154 |
+
|
| 155 |
+
def __setstate__(self, state):
|
| 156 |
+
self.__dict__.update(state)
|
| 157 |
+
self._source = DirectCompactSourceV3(self.root)
|
| 158 |
+
self._episode_cache = OrderedDict()
|
| 159 |
+
self._episode_cache_bytes = 0
|
| 160 |
+
self._cache_hits = self._cache_misses = self._cache_evictions = 0
|
| 161 |
+
self._runtime_pid = os.getpid()
|
| 162 |
+
|
| 163 |
+
def _reset_worker_runtime(self) -> None:
|
| 164 |
+
self._episode_cache = OrderedDict()
|
| 165 |
+
self._episode_cache_bytes = 0
|
| 166 |
+
self._cache_hits = self._cache_misses = self._cache_evictions = 0
|
| 167 |
+
self._source = DirectCompactSourceV3(self.root)
|
| 168 |
+
self._runtime_pid = os.getpid()
|
| 169 |
+
|
| 170 |
+
def _ensure_runtime(self) -> None:
|
| 171 |
+
if os.getpid() != self._runtime_pid or self._source is None:
|
| 172 |
+
self._reset_worker_runtime()
|
| 173 |
+
|
| 174 |
+
def clear_episode_cache(self) -> None:
|
| 175 |
+
self._episode_cache.clear(); self._episode_cache_bytes = 0
|
| 176 |
+
|
| 177 |
+
def cache_info(self) -> dict[str, int]:
|
| 178 |
+
self._ensure_runtime()
|
| 179 |
+
return {"entries": len(self._episode_cache), "bytes": self._episode_cache_bytes, "hits": self._cache_hits, "misses": self._cache_misses, "evictions": self._cache_evictions, "max_entries": self.episode_cache_max_entries, "max_bytes": self.episode_cache_max_bytes}
|
| 180 |
+
|
| 181 |
+
def _episode_for(self, descriptor: CompactEpisodeDescriptorV3, target_bytes: bytes, c2_bytes: bytes | None):
|
| 182 |
+
self._ensure_runtime()
|
| 183 |
+
key = self._cache_key(descriptor)
|
| 184 |
+
cached = self._episode_cache.get(key)
|
| 185 |
+
if cached is not None:
|
| 186 |
+
self._cache_hits += 1
|
| 187 |
+
self._episode_cache.move_to_end(key)
|
| 188 |
+
return cached
|
| 189 |
+
self._cache_misses += 1
|
| 190 |
+
value = self._source.open_episode(descriptor, target_receipt_bytes=target_bytes, c2_receipt_bytes=c2_bytes)
|
| 191 |
+
if self.episode_cache_max_entries == 0 or value.estimated_bytes > self.episode_cache_max_bytes:
|
| 192 |
+
return value
|
| 193 |
+
self._episode_cache[key] = value
|
| 194 |
+
self._episode_cache_bytes += value.estimated_bytes
|
| 195 |
+
self._episode_cache.move_to_end(key)
|
| 196 |
+
while len(self._episode_cache) > self.episode_cache_max_entries or self._episode_cache_bytes > self.episode_cache_max_bytes:
|
| 197 |
+
_, evicted = self._episode_cache.popitem(last=False); self._episode_cache_bytes -= evicted.estimated_bytes; self._cache_evictions += 1
|
| 198 |
+
return value
|
| 199 |
+
|
| 200 |
+
@staticmethod
|
| 201 |
+
def _cache_key(descriptor: CompactEpisodeDescriptorV3) -> tuple[object, ...]:
|
| 202 |
+
return (descriptor, "NONE", "gwam.direct_compact_source.v3.0.7")
|
| 203 |
+
|
| 204 |
+
def __len__(self) -> int:
|
| 205 |
+
return self._cumulative[-1]
|
| 206 |
+
|
| 207 |
+
@property
|
| 208 |
+
def episode_count(self) -> int:
|
| 209 |
+
return len(self._rows)
|
| 210 |
+
|
| 211 |
+
def episode_metadata(self, episode_index: int) -> dict[str, object]:
|
| 212 |
+
if type(episode_index) is not int or not 0 <= episode_index < self.episode_count: raise IndexError(episode_index)
|
| 213 |
+
return dict(self._rows[episode_index][0])
|
| 214 |
+
|
| 215 |
+
def load_episode_window(self, episode_index: int, start: int) -> CompactExampleV3:
|
| 216 |
+
if type(episode_index) is not int or not 0 <= episode_index < self.episode_count: raise IndexError(episode_index)
|
| 217 |
+
base = 0 if episode_index == 0 else self._cumulative[episode_index-1]
|
| 218 |
+
count = int(self._rows[episode_index][0]['valid_start_count'])
|
| 219 |
+
if type(start) is not int or not 0 <= start < count: raise IndexError(start)
|
| 220 |
+
return self[base + start]
|
| 221 |
+
|
| 222 |
+
def iter_episode_windows(self, episode_index: int, *, with_start: bool = False):
|
| 223 |
+
for start in range(int(self.episode_metadata(episode_index)['valid_start_count'])):
|
| 224 |
+
example = self.load_episode_window(episode_index, start)
|
| 225 |
+
yield (start, example) if with_start else example
|
| 226 |
+
|
| 227 |
+
@staticmethod
|
| 228 |
+
def collate(examples: tuple[CompactExampleV3, ...]) -> CompactExampleV3:
|
| 229 |
+
"""Pad only to this batch's maximum active-node count."""
|
| 230 |
+
|
| 231 |
+
return collate_compact_examples_v3(examples)
|
| 232 |
+
|
| 233 |
+
def __getitem__(self, index: int) -> CompactExampleV3:
|
| 234 |
+
if type(index) is not int:
|
| 235 |
+
raise TypeError("dataset index must be an integer")
|
| 236 |
+
if index < 0:
|
| 237 |
+
index += len(self)
|
| 238 |
+
if not 0 <= index < len(self):
|
| 239 |
+
raise IndexError(index)
|
| 240 |
+
episode_index = bisect.bisect_right(self._cumulative, index)
|
| 241 |
+
previous = 0 if episode_index == 0 else self._cumulative[episode_index - 1]
|
| 242 |
+
start = index - previous
|
| 243 |
+
row, _, outer_sha = self._rows[episode_index]
|
| 244 |
+
task = str(row["task"])
|
| 245 |
+
c2_sha = None
|
| 246 |
+
if task == "OpenDrawer":
|
| 247 |
+
if self._c2_root is None or not self._c2_rows:
|
| 248 |
+
raise SourceAccessError("C2_INDEX_REQUIRED_FOR_OPENDRAWER")
|
| 249 |
+
c2_row = self._c2_rows.get(str(row["episode_key"]))
|
| 250 |
+
if type(c2_row) is not dict:
|
| 251 |
+
raise SourceAccessError("C2_EPISODE_JOIN")
|
| 252 |
+
c2_sha = c2_row.get("receipt_sha256")
|
| 253 |
+
c2_relative = c2_row.get("receipt_relative_path")
|
| 254 |
+
if type(c2_sha) is not str or type(c2_relative) is not str or self._c2_root is None:
|
| 255 |
+
raise SourceAccessError("C2_EPISODE_ROW")
|
| 256 |
+
descriptor = CompactEpisodeDescriptorV3(
|
| 257 |
+
episode_key=str(row["episode_key"]),
|
| 258 |
+
task=task,
|
| 259 |
+
source_group_id=str(row["source_group_id"]),
|
| 260 |
+
source_split="outer_train",
|
| 261 |
+
source_zip_path=str(row["canonical_zip_path"]),
|
| 262 |
+
source_zip_sha256=str(row["canonical_zip_sha256"]),
|
| 263 |
+
source_zip_size=int(row["canonical_zip_size"]),
|
| 264 |
+
frame_count=int(row["frames_processed"]),
|
| 265 |
+
valid_start_count=int(row["valid_start_count"]),
|
| 266 |
+
outer_manifest_row_sha256=outer_sha,
|
| 267 |
+
target_receipt_sha256=str(row["target_receipt_sha256"]),
|
| 268 |
+
c2_receipt_sha256=c2_sha,
|
| 269 |
+
)
|
| 270 |
+
self._ensure_runtime()
|
| 271 |
+
cached = self._episode_cache.get(self._cache_key(descriptor))
|
| 272 |
+
if cached is not None:
|
| 273 |
+
self._cache_hits += 1; self._episode_cache.move_to_end(self._cache_key(descriptor))
|
| 274 |
+
return cached.load_window(start)
|
| 275 |
+
c2_bytes = None
|
| 276 |
+
if task == "OpenDrawer":
|
| 277 |
+
c2_bytes = _read_bound(_safe_join(self._c2_root, c2_relative), c2_sha)
|
| 278 |
+
target_bytes = _read_bound(
|
| 279 |
+
_safe_join(self.root, str(row["target_receipt_path"])),
|
| 280 |
+
descriptor.target_receipt_sha256,
|
| 281 |
+
)
|
| 282 |
+
episode = self._episode_for(descriptor, target_bytes, c2_bytes)
|
| 283 |
+
return episode.load_window(start)
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
__all__ = ["DirectCompactGWAMDatasetV3", "PREFIX"]
|
gwam_active13_gwam_training_v3_20260801/loader/direct_compact_source.py
ADDED
|
@@ -0,0 +1,1584 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Descriptor-pinned direct Active-13 compact source and sidecar reader.
|
| 2 |
+
|
| 3 |
+
Only five semantic ZIP members are decoded. Learned-visual and dense-mask
|
| 4 |
+
members are either untouched or, when an explicit digest is supplied, read as
|
| 5 |
+
opaque bytes solely for hashing. The 32-column source container is projected
|
| 6 |
+
immediately to active/family/static/pose columns; no other column is retained or
|
| 7 |
+
returned. Articulation comes exclusively from the content-addressed C2
|
| 8 |
+
receipt.
|
| 9 |
+
"""
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
import hashlib
|
| 13 |
+
import ast
|
| 14 |
+
import io
|
| 15 |
+
import json
|
| 16 |
+
import os
|
| 17 |
+
import stat
|
| 18 |
+
import struct
|
| 19 |
+
import zipfile
|
| 20 |
+
import threading
|
| 21 |
+
from dataclasses import dataclass, field
|
| 22 |
+
from pathlib import Path, PurePosixPath
|
| 23 |
+
from typing import Any, Mapping
|
| 24 |
+
|
| 25 |
+
import numpy as np
|
| 26 |
+
from .temporal_precision import offline_step_ok, offline_timestamp_equal
|
| 27 |
+
|
| 28 |
+
from .compact_contract import (
|
| 29 |
+
CAMERAS,
|
| 30 |
+
CompactActionConditionV3,
|
| 31 |
+
CompactContractError,
|
| 32 |
+
CompactExampleV3,
|
| 33 |
+
CompactGraphPacketV3,
|
| 34 |
+
CompactProvenanceV3,
|
| 35 |
+
CompactTargetsV3,
|
| 36 |
+
RELATION_REGISTRY_SHA256,
|
| 37 |
+
TARGET_RESOLVER_SHA256,
|
| 38 |
+
canonical_ordered_route_index,
|
| 39 |
+
canonical_pair_index,
|
| 40 |
+
derive_robot_target_contact,
|
| 41 |
+
freeze_array,
|
| 42 |
+
)
|
| 43 |
+
from .relation_geometry import RelationTripleV3, assemble_relations_metric12
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
REQUIRED_MEMBER_LEAVES = (
|
| 47 |
+
"graph_static.json",
|
| 48 |
+
"node_state.npz",
|
| 49 |
+
"view_evidence.npz",
|
| 50 |
+
"frames.jsonl",
|
| 51 |
+
"dynamic_edges.jsonl",
|
| 52 |
+
)
|
| 53 |
+
OPAQUE_ONLY_MEMBER_LEAVES = (
|
| 54 |
+
"visible_masks_rle.jsonl.gz",
|
| 55 |
+
"visual_features_sparse.npz",
|
| 56 |
+
)
|
| 57 |
+
FAMILY_ID = {
|
| 58 |
+
"object": 0,
|
| 59 |
+
"surface": 2,
|
| 60 |
+
"receptacle": 3,
|
| 61 |
+
"fixture": 4,
|
| 62 |
+
"articulated_part": 5,
|
| 63 |
+
"handle": 6,
|
| 64 |
+
"control": 7,
|
| 65 |
+
"region": 8,
|
| 66 |
+
"robot": 9,
|
| 67 |
+
}
|
| 68 |
+
TASKS = frozenset(
|
| 69 |
+
{
|
| 70 |
+
"CoffeeSetupMug",
|
| 71 |
+
"OpenDrawer",
|
| 72 |
+
"PickPlaceCabinetToCounter",
|
| 73 |
+
"PickPlaceCounterToCabinet",
|
| 74 |
+
"PickPlaceCounterToMicrowave",
|
| 75 |
+
"PickPlaceCounterToSink",
|
| 76 |
+
"PickPlaceCounterToStove",
|
| 77 |
+
"PickPlaceMicrowaveToCounter",
|
| 78 |
+
"PickPlaceStoveToCounter",
|
| 79 |
+
"PickPlaceSinkToCounter",
|
| 80 |
+
}
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
class SourceAccessError(CompactContractError):
|
| 85 |
+
"""A source/sidecar path, hash, join, or allowed-value contract failed."""
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def canonical_json_bytes(value: object) -> bytes:
|
| 89 |
+
try:
|
| 90 |
+
return (
|
| 91 |
+
json.dumps(
|
| 92 |
+
value,
|
| 93 |
+
sort_keys=True,
|
| 94 |
+
separators=(",", ":"),
|
| 95 |
+
ensure_ascii=False,
|
| 96 |
+
allow_nan=False,
|
| 97 |
+
).encode("utf-8")
|
| 98 |
+
+ b"\n"
|
| 99 |
+
)
|
| 100 |
+
except (TypeError, ValueError) as error:
|
| 101 |
+
raise SourceAccessError("CANONICAL_JSON_VALUE") from error
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def sha256_bytes(value: bytes) -> str:
|
| 105 |
+
return hashlib.sha256(value).hexdigest()
|
| 106 |
+
|
| 107 |
+
def _opaque_identity(value: Mapping[str, str] | None) -> str:
|
| 108 |
+
return "NONE" if value is None else sha256_bytes(canonical_json_bytes(dict(sorted(value.items()))))
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
_HANDLE_SEAL = object()
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def array_sha256(value: np.ndarray) -> str:
|
| 115 |
+
array = np.ascontiguousarray(value)
|
| 116 |
+
header = canonical_json_bytes(
|
| 117 |
+
{"dtype": array.dtype.str, "shape": [int(item) for item in array.shape]}
|
| 118 |
+
)
|
| 119 |
+
return sha256_bytes(header + array.tobytes(order="C"))
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def _is_digest(value: object) -> bool:
|
| 123 |
+
return type(value) is str and len(value) == 64 and all(
|
| 124 |
+
char in "0123456789abcdef" for char in value
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def _safe_relative(value: str) -> tuple[str, ...]:
|
| 129 |
+
if type(value) is not str or not value or "\\" in value:
|
| 130 |
+
raise SourceAccessError("SOURCE_PATH_NOT_CANONICAL")
|
| 131 |
+
path = PurePosixPath(value)
|
| 132 |
+
if path.is_absolute() or str(path) != value or any(
|
| 133 |
+
part in {"", ".", ".."} for part in path.parts
|
| 134 |
+
):
|
| 135 |
+
raise SourceAccessError("SOURCE_PATH_NOT_CANONICAL")
|
| 136 |
+
lowered = {part.lower() for part in path.parts}
|
| 137 |
+
if lowered.intersection({"validation", "val", "test", "outer_validation", "outer_test"}):
|
| 138 |
+
raise SourceAccessError("SOURCE_PATH_FORBIDDEN_SPLIT")
|
| 139 |
+
return path.parts
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
@dataclass(frozen=True, slots=True)
|
| 143 |
+
class CompactEpisodeDescriptorV3:
|
| 144 |
+
episode_key: str
|
| 145 |
+
task: str
|
| 146 |
+
source_group_id: str
|
| 147 |
+
source_split: str
|
| 148 |
+
source_zip_path: str
|
| 149 |
+
source_zip_sha256: str
|
| 150 |
+
source_zip_size: int
|
| 151 |
+
frame_count: int
|
| 152 |
+
valid_start_count: int
|
| 153 |
+
outer_manifest_row_sha256: str
|
| 154 |
+
target_receipt_sha256: str
|
| 155 |
+
c2_receipt_sha256: str | None
|
| 156 |
+
|
| 157 |
+
def validate(self) -> None:
|
| 158 |
+
if self.task not in TASKS:
|
| 159 |
+
raise SourceAccessError("DESCRIPTOR_TASK")
|
| 160 |
+
if self.source_split != "outer_train":
|
| 161 |
+
raise SourceAccessError("DESCRIPTOR_SPLIT")
|
| 162 |
+
_safe_relative(self.source_zip_path)
|
| 163 |
+
if self.episode_key not in self.source_zip_path:
|
| 164 |
+
raise SourceAccessError("DESCRIPTOR_EPISODE_PATH")
|
| 165 |
+
for value in (
|
| 166 |
+
self.source_zip_sha256,
|
| 167 |
+
self.outer_manifest_row_sha256,
|
| 168 |
+
self.target_receipt_sha256,
|
| 169 |
+
):
|
| 170 |
+
if not _is_digest(value):
|
| 171 |
+
raise SourceAccessError("DESCRIPTOR_SHA256")
|
| 172 |
+
if self.c2_receipt_sha256 is not None and not _is_digest(self.c2_receipt_sha256):
|
| 173 |
+
raise SourceAccessError("DESCRIPTOR_C2_SHA256")
|
| 174 |
+
if type(self.source_zip_size) is not int or self.source_zip_size <= 0:
|
| 175 |
+
raise SourceAccessError("DESCRIPTOR_ZIP_SIZE")
|
| 176 |
+
if type(self.frame_count) is not int or self.frame_count < 16:
|
| 177 |
+
raise SourceAccessError("DESCRIPTOR_FRAME_COUNT")
|
| 178 |
+
if type(self.valid_start_count) is not int or self.valid_start_count < 1:
|
| 179 |
+
raise SourceAccessError("DESCRIPTOR_START_COUNT")
|
| 180 |
+
if self.task == "OpenDrawer" and self.c2_receipt_sha256 is None:
|
| 181 |
+
raise SourceAccessError("OPENDRAWER_C2_BINDING_MISSING")
|
| 182 |
+
if self.task != "OpenDrawer" and self.c2_receipt_sha256 is not None:
|
| 183 |
+
raise SourceAccessError("NON_OPENDRAWER_C2_BINDING_UNEXPECTED")
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
@dataclass(frozen=True, slots=True)
|
| 187 |
+
class SourceAccessTraceV3:
|
| 188 |
+
source_zip_path: str
|
| 189 |
+
source_zip_sha256: str
|
| 190 |
+
decoded_member_leaves: tuple[str, ...]
|
| 191 |
+
opaque_hashed_member_leaves: tuple[str, ...]
|
| 192 |
+
member_sha256: tuple[tuple[str, str], ...]
|
| 193 |
+
|
| 194 |
+
def canonical_bytes(self) -> bytes:
|
| 195 |
+
return canonical_json_bytes(
|
| 196 |
+
{
|
| 197 |
+
"decoded_member_leaves": list(self.decoded_member_leaves),
|
| 198 |
+
"member_sha256": [list(value) for value in self.member_sha256],
|
| 199 |
+
"opaque_hashed_member_leaves": list(self.opaque_hashed_member_leaves),
|
| 200 |
+
"schema": "gwam.direct_compact_source_access.v3",
|
| 201 |
+
"source_zip_path": self.source_zip_path,
|
| 202 |
+
"source_zip_sha256": self.source_zip_sha256,
|
| 203 |
+
}
|
| 204 |
+
)
|
| 205 |
+
|
| 206 |
+
@property
|
| 207 |
+
def sha256(self) -> str:
|
| 208 |
+
return sha256_bytes(self.canonical_bytes())
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
@dataclass(slots=True)
|
| 212 |
+
class _PinnedReadOnlyFile:
|
| 213 |
+
root_fd: int
|
| 214 |
+
directory_fds: list[int]
|
| 215 |
+
parent_fd: int
|
| 216 |
+
leaf: str
|
| 217 |
+
fd: int
|
| 218 |
+
initial_stat: os.stat_result
|
| 219 |
+
|
| 220 |
+
@classmethod
|
| 221 |
+
def open(cls, root: Path, relative: str) -> "_PinnedReadOnlyFile":
|
| 222 |
+
parts = _safe_relative(relative)
|
| 223 |
+
directory_flags = os.O_RDONLY | os.O_DIRECTORY | os.O_CLOEXEC | os.O_NOFOLLOW
|
| 224 |
+
file_flags = os.O_RDONLY | os.O_CLOEXEC | os.O_NOFOLLOW
|
| 225 |
+
root_fd = os.open(root, directory_flags)
|
| 226 |
+
directories: list[int] = []
|
| 227 |
+
current = root_fd
|
| 228 |
+
try:
|
| 229 |
+
for part in parts[:-1]:
|
| 230 |
+
current = os.open(part, directory_flags, dir_fd=current)
|
| 231 |
+
directories.append(current)
|
| 232 |
+
fd = os.open(parts[-1], file_flags, dir_fd=current)
|
| 233 |
+
opened = os.fstat(fd)
|
| 234 |
+
named = os.stat(parts[-1], dir_fd=current, follow_symlinks=False)
|
| 235 |
+
if not stat.S_ISREG(opened.st_mode) or (opened.st_dev, opened.st_ino) != (
|
| 236 |
+
named.st_dev,
|
| 237 |
+
named.st_ino,
|
| 238 |
+
):
|
| 239 |
+
os.close(fd)
|
| 240 |
+
raise SourceAccessError("SOURCE_DESCRIPTOR_IDENTITY")
|
| 241 |
+
return cls(root_fd, directories, current, parts[-1], fd, opened)
|
| 242 |
+
except Exception:
|
| 243 |
+
for item in reversed(directories):
|
| 244 |
+
os.close(item)
|
| 245 |
+
os.close(root_fd)
|
| 246 |
+
raise
|
| 247 |
+
|
| 248 |
+
def close(self) -> None:
|
| 249 |
+
if self.fd >= 0:
|
| 250 |
+
os.close(self.fd)
|
| 251 |
+
self.fd = -1
|
| 252 |
+
for item in reversed(self.directory_fds):
|
| 253 |
+
os.close(item)
|
| 254 |
+
self.directory_fds.clear()
|
| 255 |
+
if self.root_fd >= 0:
|
| 256 |
+
os.close(self.root_fd)
|
| 257 |
+
self.root_fd = -1
|
| 258 |
+
|
| 259 |
+
def __enter__(self) -> "_PinnedReadOnlyFile":
|
| 260 |
+
return self
|
| 261 |
+
|
| 262 |
+
def __exit__(self, *_: object) -> None:
|
| 263 |
+
self.close()
|
| 264 |
+
|
| 265 |
+
def digest_and_size(self) -> tuple[str, int]:
|
| 266 |
+
os.lseek(self.fd, 0, os.SEEK_SET)
|
| 267 |
+
digest = hashlib.sha256()
|
| 268 |
+
size = 0
|
| 269 |
+
while True:
|
| 270 |
+
chunk = os.read(self.fd, 1024 * 1024)
|
| 271 |
+
if not chunk:
|
| 272 |
+
break
|
| 273 |
+
digest.update(chunk)
|
| 274 |
+
size += len(chunk)
|
| 275 |
+
os.lseek(self.fd, 0, os.SEEK_SET)
|
| 276 |
+
return digest.hexdigest(), size
|
| 277 |
+
|
| 278 |
+
def reverify(self) -> None:
|
| 279 |
+
opened = os.fstat(self.fd)
|
| 280 |
+
named = os.stat(self.leaf, dir_fd=self.parent_fd, follow_symlinks=False)
|
| 281 |
+
identity = lambda value: (value.st_dev, value.st_ino, value.st_mode, value.st_size)
|
| 282 |
+
if identity(opened) != identity(self.initial_stat) or identity(named) != identity(
|
| 283 |
+
self.initial_stat
|
| 284 |
+
):
|
| 285 |
+
raise SourceAccessError("SOURCE_CHANGED_DURING_READ")
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
@dataclass(frozen=True, slots=True)
|
| 289 |
+
class _TargetProjection:
|
| 290 |
+
target: np.ndarray
|
| 291 |
+
valid: np.ndarray
|
| 292 |
+
source_code: np.ndarray
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def _load_canonical_json(payload: bytes, label: str) -> dict[str, Any]:
|
| 296 |
+
if type(payload) is not bytes:
|
| 297 |
+
raise SourceAccessError(f"{label}_BYTES")
|
| 298 |
+
try:
|
| 299 |
+
value = json.loads(payload)
|
| 300 |
+
except (UnicodeDecodeError, json.JSONDecodeError) as error:
|
| 301 |
+
raise SourceAccessError(f"{label}_JSON") from error
|
| 302 |
+
if type(value) is not dict or canonical_json_bytes(value) != payload:
|
| 303 |
+
raise SourceAccessError(f"{label}_NONCANONICAL")
|
| 304 |
+
return value
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
def _unpack_256(value: object, label: str) -> np.ndarray:
|
| 308 |
+
if type(value) is not str:
|
| 309 |
+
raise SourceAccessError(f"{label}_BITSET")
|
| 310 |
+
try:
|
| 311 |
+
raw = bytes.fromhex(value)
|
| 312 |
+
except ValueError as error:
|
| 313 |
+
raise SourceAccessError(f"{label}_BITSET") from error
|
| 314 |
+
if len(raw) != 32:
|
| 315 |
+
raise SourceAccessError(f"{label}_BITSET")
|
| 316 |
+
return np.unpackbits(np.frombuffer(raw, dtype=np.uint8), bitorder="little").astype(np.bool_)
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
def _target_projection(
|
| 320 |
+
payload: bytes,
|
| 321 |
+
descriptor: CompactEpisodeDescriptorV3,
|
| 322 |
+
graph_static: dict[str, Any],
|
| 323 |
+
graph_static_bytes: bytes,
|
| 324 |
+
) -> _TargetProjection:
|
| 325 |
+
if sha256_bytes(payload) != descriptor.target_receipt_sha256:
|
| 326 |
+
raise SourceAccessError("TARGET_RECEIPT_SHA256")
|
| 327 |
+
value = _load_canonical_json(payload, "TARGET_RECEIPT")
|
| 328 |
+
if not (
|
| 329 |
+
value.get("receipt_type") == "TargetResolutionReceiptV2"
|
| 330 |
+
and value.get("receipt_version") == "2.0.1"
|
| 331 |
+
and value.get("resolution_status") == "RESOLVED"
|
| 332 |
+
and value.get("closed_world") is True
|
| 333 |
+
and value.get("episode_key") == descriptor.episode_key
|
| 334 |
+
and value.get("task") == descriptor.task
|
| 335 |
+
and value.get("source_group_id") == descriptor.source_group_id
|
| 336 |
+
and value.get("relation_registry_sha256") == RELATION_REGISTRY_SHA256
|
| 337 |
+
and value.get("resolver_sha256") == TARGET_RESOLVER_SHA256
|
| 338 |
+
):
|
| 339 |
+
raise SourceAccessError("TARGET_RECEIPT_SCHEMA_OR_IDENTITY")
|
| 340 |
+
bindings = value.get("source_bindings")
|
| 341 |
+
source_zip = bindings.get("source_zip") if type(bindings) is dict else None
|
| 342 |
+
static = bindings.get("graph_static") if type(bindings) is dict else None
|
| 343 |
+
if not (
|
| 344 |
+
type(source_zip) is dict
|
| 345 |
+
and source_zip.get("relative_path") == descriptor.source_zip_path
|
| 346 |
+
and source_zip.get("sha256") == descriptor.source_zip_sha256
|
| 347 |
+
and source_zip.get("size_bytes") == descriptor.source_zip_size
|
| 348 |
+
and type(static) is dict
|
| 349 |
+
and static.get("relative_path")
|
| 350 |
+
== f"{descriptor.episode_key}/graph/graph_static.json"
|
| 351 |
+
and static.get("sha256") == sha256_bytes(graph_static_bytes)
|
| 352 |
+
and static.get("size_bytes") == len(graph_static_bytes)
|
| 353 |
+
):
|
| 354 |
+
raise SourceAccessError("TARGET_RECEIPT_SOURCE_BINDING")
|
| 355 |
+
nodes = graph_static.get("nodes")
|
| 356 |
+
inventory = value.get("ordered_inventory")
|
| 357 |
+
if type(nodes) is not list or type(inventory) is not list or len(nodes) != len(inventory):
|
| 358 |
+
raise SourceAccessError("TARGET_INVENTORY_CARDINALITY")
|
| 359 |
+
for slot, (node, receipt_node) in enumerate(zip(nodes, inventory, strict=True)):
|
| 360 |
+
if type(node) is not dict or type(receipt_node) is not dict:
|
| 361 |
+
raise SourceAccessError("TARGET_INVENTORY_ROW")
|
| 362 |
+
expected = {
|
| 363 |
+
"slot": slot,
|
| 364 |
+
"node_id": node.get("node_id"),
|
| 365 |
+
"family_id": FAMILY_ID.get(node.get("family")),
|
| 366 |
+
"free_movable": bool(node.get("free_movable")),
|
| 367 |
+
"articulated": bool(node.get("articulated")),
|
| 368 |
+
}
|
| 369 |
+
if receipt_node != expected:
|
| 370 |
+
raise SourceAccessError("TARGET_INVENTORY_DISAGREEMENT")
|
| 371 |
+
static_bits = _unpack_256(value.get("static_slot_present_bitset_hex"), "STATIC")
|
| 372 |
+
valid = _unpack_256(value.get("resolver_valid_bitset_hex"), "TARGET_VALID")
|
| 373 |
+
target = _unpack_256(value.get("target_bitset_hex"), "TARGET")
|
| 374 |
+
expected_static = np.zeros(256, dtype=np.bool_)
|
| 375 |
+
expected_static[: len(nodes)] = True
|
| 376 |
+
if not np.array_equal(static_bits, expected_static) or not np.array_equal(valid, static_bits):
|
| 377 |
+
raise SourceAccessError("TARGET_STATIC_VALID_BITS")
|
| 378 |
+
slots = value.get("target_slots")
|
| 379 |
+
if type(slots) is not list or any(type(slot) is not int for slot in slots):
|
| 380 |
+
raise SourceAccessError("TARGET_SLOT_LIST")
|
| 381 |
+
if slots != sorted(set(slots)) or slots != np.flatnonzero(target).tolist():
|
| 382 |
+
raise SourceAccessError("TARGET_BITSET_SLOT_DISAGREEMENT")
|
| 383 |
+
if value.get("target_cardinality") != len(slots) or not slots or np.any(target & ~valid):
|
| 384 |
+
raise SourceAccessError("TARGET_CARDINALITY_OR_VALIDITY")
|
| 385 |
+
codes = value.get("target_source_codes")
|
| 386 |
+
if type(codes) is not list or len(codes) != 256 or any(
|
| 387 |
+
type(code) is not int or not 0 <= code <= 6 for code in codes
|
| 388 |
+
):
|
| 389 |
+
raise SourceAccessError("TARGET_SOURCE_CODES")
|
| 390 |
+
source_code = np.asarray(codes, dtype=np.uint8)
|
| 391 |
+
if np.any((source_code == 0) != ~valid):
|
| 392 |
+
raise SourceAccessError("TARGET_SOURCE_CODE_VALIDITY")
|
| 393 |
+
return _TargetProjection(
|
| 394 |
+
target=freeze_array(target, dtype="|b1"),
|
| 395 |
+
valid=freeze_array(valid, dtype="|b1"),
|
| 396 |
+
source_code=freeze_array(source_code, dtype="|u1"),
|
| 397 |
+
)
|
| 398 |
+
|
| 399 |
+
|
| 400 |
+
@dataclass(frozen=True, slots=True)
|
| 401 |
+
class _C2Values:
|
| 402 |
+
component_slot: int | None
|
| 403 |
+
q: np.ndarray
|
| 404 |
+
valid: np.ndarray
|
| 405 |
+
receipt_sha256: str
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
def _c2_values(
|
| 409 |
+
payload: bytes | None,
|
| 410 |
+
descriptor: CompactEpisodeDescriptorV3,
|
| 411 |
+
) -> _C2Values:
|
| 412 |
+
if descriptor.task != "OpenDrawer":
|
| 413 |
+
if payload is not None:
|
| 414 |
+
raise SourceAccessError("NON_OPENDRAWER_C2_PAYLOAD")
|
| 415 |
+
receipt = canonical_json_bytes(
|
| 416 |
+
{
|
| 417 |
+
"episode_key": descriptor.episode_key,
|
| 418 |
+
"reason": "NON_ARTICULATED_TASK_INVALID_ZERO",
|
| 419 |
+
"schema": "gwam.compact.invalid_articulation.v3",
|
| 420 |
+
"task": descriptor.task,
|
| 421 |
+
}
|
| 422 |
+
)
|
| 423 |
+
return _C2Values(
|
| 424 |
+
None,
|
| 425 |
+
freeze_array(np.zeros(descriptor.frame_count, dtype=np.float32), dtype="<f4"),
|
| 426 |
+
freeze_array(np.zeros(descriptor.frame_count, dtype=np.bool_), dtype="|b1"),
|
| 427 |
+
sha256_bytes(receipt),
|
| 428 |
+
)
|
| 429 |
+
if payload is None or sha256_bytes(payload) != descriptor.c2_receipt_sha256:
|
| 430 |
+
raise SourceAccessError("C2_RECEIPT_SHA256")
|
| 431 |
+
value = _load_canonical_json(payload, "C2_RECEIPT")
|
| 432 |
+
component = value.get("component_map")
|
| 433 |
+
if not (
|
| 434 |
+
value.get("artifact_type") == "OpenDrawerC2EpisodeReceiptV2_0_5"
|
| 435 |
+
and value.get("version") == "2.0.5"
|
| 436 |
+
and value.get("frame_count") == descriptor.frame_count
|
| 437 |
+
and value.get("qpos_channel") == 17
|
| 438 |
+
and type(component) is dict
|
| 439 |
+
and component.get("task") == descriptor.task
|
| 440 |
+
and component.get("episode_key") == descriptor.episode_key
|
| 441 |
+
and component.get("source_group_id") == descriptor.source_group_id
|
| 442 |
+
and type(component.get("component_slot")) is int
|
| 443 |
+
and 0 <= component["component_slot"] < 256
|
| 444 |
+
):
|
| 445 |
+
raise SourceAccessError("C2_SCHEMA_OR_IDENTITY")
|
| 446 |
+
exclusion = value.get("qvel_exclusion")
|
| 447 |
+
exclusion_flags = (
|
| 448 |
+
"read_for_values",
|
| 449 |
+
"used_for_calibration",
|
| 450 |
+
"used_for_eligibility",
|
| 451 |
+
"used_for_labels",
|
| 452 |
+
"used_for_model_input",
|
| 453 |
+
"used_for_normalization",
|
| 454 |
+
"used_for_selection",
|
| 455 |
+
)
|
| 456 |
+
if not (
|
| 457 |
+
type(exclusion) is dict
|
| 458 |
+
and exclusion.get("channel_index") == 18
|
| 459 |
+
and all(exclusion.get(name) is False for name in exclusion_flags)
|
| 460 |
+
):
|
| 461 |
+
raise SourceAccessError("C2_QVEL_EXCLUSION")
|
| 462 |
+
encoding = value.get("q_model_encoding")
|
| 463 |
+
if not (
|
| 464 |
+
type(encoding) is dict
|
| 465 |
+
and encoding.get("dtype") == "<f4"
|
| 466 |
+
and encoding.get("frame_count") == descriptor.frame_count
|
| 467 |
+
and type(encoding.get("q_model_f32le_hex")) is str
|
| 468 |
+
and type(encoding.get("valid_packbits_little_hex")) is str
|
| 469 |
+
):
|
| 470 |
+
raise SourceAccessError("C2_ENCODING")
|
| 471 |
+
try:
|
| 472 |
+
q_bytes = bytes.fromhex(encoding["q_model_f32le_hex"])
|
| 473 |
+
valid_bytes = bytes.fromhex(encoding["valid_packbits_little_hex"])
|
| 474 |
+
except ValueError as error:
|
| 475 |
+
raise SourceAccessError("C2_ENCODING_HEX") from error
|
| 476 |
+
if len(q_bytes) != descriptor.frame_count * 4 or len(valid_bytes) != (
|
| 477 |
+
descriptor.frame_count + 7
|
| 478 |
+
) // 8:
|
| 479 |
+
raise SourceAccessError("C2_ENCODING_LENGTH")
|
| 480 |
+
q = np.frombuffer(q_bytes, dtype="<f4").copy()
|
| 481 |
+
unpacked = np.unpackbits(np.frombuffer(valid_bytes, dtype=np.uint8), bitorder="little")
|
| 482 |
+
if unpacked[descriptor.frame_count :].any():
|
| 483 |
+
raise SourceAccessError("C2_VALID_PADDING")
|
| 484 |
+
valid = unpacked[: descriptor.frame_count].astype(np.bool_, copy=True)
|
| 485 |
+
if not np.isfinite(q).all() or np.any(q[~valid].view(np.uint32) != 0):
|
| 486 |
+
raise SourceAccessError("C2_INVALID_ZERO_OR_FINITE")
|
| 487 |
+
tensor_hash = value.get("tensor_sha256s")
|
| 488 |
+
if not (
|
| 489 |
+
type(tensor_hash) is dict
|
| 490 |
+
and tensor_hash.get("q_model") == array_sha256(q)
|
| 491 |
+
and tensor_hash.get("valid") == array_sha256(valid)
|
| 492 |
+
):
|
| 493 |
+
raise SourceAccessError("C2_TENSOR_SHA256")
|
| 494 |
+
binding = value.get("source_bindings")
|
| 495 |
+
if not (
|
| 496 |
+
type(binding) is dict
|
| 497 |
+
and binding.get("source_zip_path") == descriptor.source_zip_path
|
| 498 |
+
and binding.get("source_zip_sha256") == descriptor.source_zip_sha256
|
| 499 |
+
and binding.get("outer_manifest_row_sha256")
|
| 500 |
+
== descriptor.outer_manifest_row_sha256
|
| 501 |
+
and binding.get("qpos_channel") == 17
|
| 502 |
+
and binding.get("qvel_channel") == 18
|
| 503 |
+
and binding.get("qvel_values_read") is False
|
| 504 |
+
):
|
| 505 |
+
raise SourceAccessError("C2_SOURCE_BINDING")
|
| 506 |
+
return _C2Values(
|
| 507 |
+
int(component["component_slot"]),
|
| 508 |
+
freeze_array(q, dtype="<f4"),
|
| 509 |
+
freeze_array(valid, dtype="|b1"),
|
| 510 |
+
str(descriptor.c2_receipt_sha256),
|
| 511 |
+
)
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
@dataclass(frozen=True, slots=True)
|
| 515 |
+
class _AllowedEpisode:
|
| 516 |
+
active: np.ndarray
|
| 517 |
+
family_id: np.ndarray
|
| 518 |
+
static_flags: np.ndarray
|
| 519 |
+
pose: np.ndarray
|
| 520 |
+
pose_valid: np.ndarray
|
| 521 |
+
views: np.ndarray
|
| 522 |
+
view_valid: np.ndarray
|
| 523 |
+
timestamps: np.ndarray
|
| 524 |
+
actions: np.ndarray
|
| 525 |
+
action_indices: np.ndarray
|
| 526 |
+
static_relations: tuple[RelationTripleV3, ...]
|
| 527 |
+
contacts: tuple[tuple[tuple[int, int], ...], ...]
|
| 528 |
+
target: _TargetProjection
|
| 529 |
+
c2: _C2Values
|
| 530 |
+
graph_static_bytes: bytes
|
| 531 |
+
member_bindings: tuple[tuple[str, int, str], ...]
|
| 532 |
+
authority: tuple[str, ...] = ()
|
| 533 |
+
|
| 534 |
+
@dataclass(frozen=True, slots=True)
|
| 535 |
+
class AuthenticatedEpisodeHandleV3:
|
| 536 |
+
"""Opaque authenticated decoded episode snapshot owned by one worker PID."""
|
| 537 |
+
_source: Any
|
| 538 |
+
_descriptor: CompactEpisodeDescriptorV3
|
| 539 |
+
_episode: _AllowedEpisode
|
| 540 |
+
_target_receipt_bytes: bytes
|
| 541 |
+
_c2_receipt_bytes: bytes | None
|
| 542 |
+
_opaque_integrity_sha256: tuple[tuple[str, str], ...]
|
| 543 |
+
access_trace: SourceAccessTraceV3
|
| 544 |
+
_owner_pid: int
|
| 545 |
+
_estimated_bytes: int
|
| 546 |
+
_projection_contract: str = "gwam.direct_compact_source.v3.0.7"
|
| 547 |
+
_seal: object = field(default=None, repr=False, compare=False)
|
| 548 |
+
|
| 549 |
+
@property
|
| 550 |
+
def authority(self) -> tuple[object, ...]:
|
| 551 |
+
d = self._descriptor
|
| 552 |
+
return (d, self._opaque_integrity_sha256, self._projection_contract)
|
| 553 |
+
|
| 554 |
+
@property
|
| 555 |
+
def estimated_bytes(self) -> int:
|
| 556 |
+
return self._estimated_bytes
|
| 557 |
+
|
| 558 |
+
def load_window(self, start: int) -> CompactExampleV3:
|
| 559 |
+
if os.getpid() != self._owner_pid:
|
| 560 |
+
raise SourceAccessError("AUTHENTICATED_HANDLE_OWNER_PID")
|
| 561 |
+
return self._source._materialize_handle(self, start=start)
|
| 562 |
+
|
| 563 |
+
def __reduce_ex__(self, protocol: int):
|
| 564 |
+
raise TypeError("AUTHENTICATED_EPISODE_HANDLE_NOT_PICKLEABLE")
|
| 565 |
+
|
| 566 |
+
|
| 567 |
+
def _decode_graph_static(
|
| 568 |
+
payload: bytes, descriptor: CompactEpisodeDescriptorV3
|
| 569 |
+
) -> tuple[dict[str, Any], np.ndarray, np.ndarray, tuple[RelationTripleV3, ...]]:
|
| 570 |
+
try:
|
| 571 |
+
value = json.loads(payload)
|
| 572 |
+
except (UnicodeDecodeError, json.JSONDecodeError) as error:
|
| 573 |
+
raise SourceAccessError("GRAPH_STATIC_JSON") from error
|
| 574 |
+
try:
|
| 575 |
+
episode_number = int(descriptor.episode_key.rsplit("episode_", 1)[1])
|
| 576 |
+
except (IndexError, ValueError) as error:
|
| 577 |
+
raise SourceAccessError("EPISODE_KEY") from error
|
| 578 |
+
if not (
|
| 579 |
+
type(value) is dict
|
| 580 |
+
and value.get("schema") == "GWAM_Data_v1.2_phase1_sparse_v2"
|
| 581 |
+
and value.get("task") == descriptor.task
|
| 582 |
+
and value.get("split") == descriptor.episode_key.split("/", 1)[0]
|
| 583 |
+
and value.get("episode") == episode_number
|
| 584 |
+
and value.get("num_frames") == descriptor.frame_count
|
| 585 |
+
):
|
| 586 |
+
raise SourceAccessError("GRAPH_STATIC_IDENTITY")
|
| 587 |
+
nodes = value.get("nodes")
|
| 588 |
+
if type(nodes) is not list or not 1 <= len(nodes) <= 256 or value.get("num_nodes") != len(nodes):
|
| 589 |
+
raise SourceAccessError("GRAPH_STATIC_NODE_COUNT")
|
| 590 |
+
family = np.full(256, 10, dtype=np.int64)
|
| 591 |
+
flags = np.zeros((256, 2), dtype=np.bool_)
|
| 592 |
+
ids: set[str] = set()
|
| 593 |
+
for slot, node in enumerate(nodes):
|
| 594 |
+
if type(node) is not dict:
|
| 595 |
+
raise SourceAccessError("GRAPH_STATIC_NODE_ROW")
|
| 596 |
+
node_id = node.get("node_id")
|
| 597 |
+
family_name = node.get("family")
|
| 598 |
+
free = node.get("free_movable")
|
| 599 |
+
articulated = node.get("articulated")
|
| 600 |
+
if (
|
| 601 |
+
type(node_id) is not str
|
| 602 |
+
or not node_id
|
| 603 |
+
or node_id in ids
|
| 604 |
+
or family_name not in FAMILY_ID
|
| 605 |
+
or type(free) is not int
|
| 606 |
+
or isinstance(free, bool)
|
| 607 |
+
or free not in (0, 1)
|
| 608 |
+
or type(articulated) is not int
|
| 609 |
+
or isinstance(articulated, bool)
|
| 610 |
+
or articulated not in (0, 1)
|
| 611 |
+
):
|
| 612 |
+
raise SourceAccessError("GRAPH_STATIC_NODE_VALUE")
|
| 613 |
+
ids.add(node_id)
|
| 614 |
+
family[slot] = FAMILY_ID[family_name]
|
| 615 |
+
flags[slot] = (bool(free), bool(articulated))
|
| 616 |
+
relation_rows: list[RelationTripleV3] = []
|
| 617 |
+
for edge in value.get("prior_edges", []):
|
| 618 |
+
if type(edge) is not dict or edge.get("rel") not in {"part_of", "controls"}:
|
| 619 |
+
raise SourceAccessError("GRAPH_STATIC_RELATION")
|
| 620 |
+
sender, receiver = edge.get("src"), edge.get("dst")
|
| 621 |
+
if (
|
| 622 |
+
type(sender) is not int
|
| 623 |
+
or type(receiver) is not int
|
| 624 |
+
or not 0 <= sender < len(nodes)
|
| 625 |
+
or not 0 <= receiver < len(nodes)
|
| 626 |
+
or sender == receiver
|
| 627 |
+
):
|
| 628 |
+
raise SourceAccessError("GRAPH_STATIC_RELATION_ENDPOINT")
|
| 629 |
+
if edge["rel"] == "controls" and not (
|
| 630 |
+
family[sender]
|
| 631 |
+
in (FAMILY_ID["control"], FAMILY_ID["handle"], FAMILY_ID["robot"])
|
| 632 |
+
and flags[receiver, 1]
|
| 633 |
+
):
|
| 634 |
+
raise SourceAccessError("CONTROLS_NOT_ACTUATOR_TO_ARTICULATED_COMPONENT")
|
| 635 |
+
relation_rows.append(
|
| 636 |
+
RelationTripleV3(sender, receiver, 0 if edge["rel"] == "part_of" else 2)
|
| 637 |
+
)
|
| 638 |
+
if len({(row.sender, row.receiver, row.relation_id) for row in relation_rows}) != len(
|
| 639 |
+
relation_rows
|
| 640 |
+
):
|
| 641 |
+
raise SourceAccessError("GRAPH_STATIC_RELATION_DUPLICATE")
|
| 642 |
+
return (
|
| 643 |
+
value,
|
| 644 |
+
freeze_array(family, dtype="<i8"),
|
| 645 |
+
freeze_array(flags, dtype="|b1"),
|
| 646 |
+
tuple(relation_rows),
|
| 647 |
+
)
|
| 648 |
+
|
| 649 |
+
|
| 650 |
+
def _decode_allowed_state(
|
| 651 |
+
payload: bytes,
|
| 652 |
+
descriptor: CompactEpisodeDescriptorV3,
|
| 653 |
+
family: np.ndarray,
|
| 654 |
+
flags: np.ndarray,
|
| 655 |
+
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
|
| 656 |
+
# The rich 32-D carrier is decoded as a byte stream. Only the first eleven
|
| 657 |
+
# float32 values of each row are ever handed to a numeric decoder; the
|
| 658 |
+
# forbidden tail is consumed as opaque bytes and is never materialized.
|
| 659 |
+
try:
|
| 660 |
+
with zipfile.ZipFile(io.BytesIO(payload), "r") as archive:
|
| 661 |
+
if set(archive.namelist()) != {"node_state.npy", "node_state_schema.npy"}:
|
| 662 |
+
raise SourceAccessError("NODE_STATE_KEYS")
|
| 663 |
+
with archive.open("node_state_schema.npy", "r") as schema_stream:
|
| 664 |
+
schema = tuple(str(value) for value in np.load(schema_stream, allow_pickle=False))
|
| 665 |
+
with archive.open("node_state.npy", "r") as stream:
|
| 666 |
+
magic = stream.read(6)
|
| 667 |
+
if magic != b"\x93NUMPY":
|
| 668 |
+
raise SourceAccessError("NODE_STATE_NPY_MAGIC")
|
| 669 |
+
major_minor = stream.read(2)
|
| 670 |
+
if len(major_minor) != 2:
|
| 671 |
+
raise SourceAccessError("NODE_STATE_NPY_HEADER")
|
| 672 |
+
major, minor = major_minor
|
| 673 |
+
header_len_bytes = stream.read(2 if major == 1 else 4)
|
| 674 |
+
if len(header_len_bytes) != (2 if major == 1 else 4):
|
| 675 |
+
raise SourceAccessError("NODE_STATE_NPY_HEADER")
|
| 676 |
+
header_len = int.from_bytes(header_len_bytes, "little")
|
| 677 |
+
header = stream.read(header_len)
|
| 678 |
+
if len(header) != header_len:
|
| 679 |
+
raise SourceAccessError("NODE_STATE_NPY_HEADER")
|
| 680 |
+
try:
|
| 681 |
+
header_value = ast.literal_eval(header.decode("latin1").strip())
|
| 682 |
+
except (SyntaxError, ValueError) as error:
|
| 683 |
+
raise SourceAccessError("NODE_STATE_NPY_HEADER") from error
|
| 684 |
+
if header_value.get("descr") != "<f4" or header_value.get("fortran_order") is not False:
|
| 685 |
+
raise SourceAccessError("NODE_STATE_SHAPE_OR_DTYPE")
|
| 686 |
+
if tuple(header_value.get("shape", ())) != (descriptor.frame_count, 256, 32):
|
| 687 |
+
raise SourceAccessError("NODE_STATE_SHAPE_OR_DTYPE")
|
| 688 |
+
active = np.zeros((descriptor.frame_count, 256), dtype=np.bool_)
|
| 689 |
+
pose = np.zeros((descriptor.frame_count, 256, 7), dtype=np.float32)
|
| 690 |
+
pose_valid = np.zeros((descriptor.frame_count, 256), dtype=np.bool_)
|
| 691 |
+
row_bytes = 32 * 4
|
| 692 |
+
for time in range(descriptor.frame_count):
|
| 693 |
+
for slot in range(256):
|
| 694 |
+
row = stream.read(row_bytes)
|
| 695 |
+
if len(row) != row_bytes:
|
| 696 |
+
raise SourceAccessError("NODE_STATE_DATA_TRUNCATED")
|
| 697 |
+
allowed = np.frombuffer(row[: 11 * 4], dtype="<f4", count=11)
|
| 698 |
+
active_value = float(allowed[0])
|
| 699 |
+
if active_value not in (0.0, 1.0):
|
| 700 |
+
raise SourceAccessError("NODE_ACTIVE_BINARY")
|
| 701 |
+
active[time, slot] = active_value == 1.0
|
| 702 |
+
if active[time, slot] and family[slot] != 10:
|
| 703 |
+
if allowed[1] != family[slot] or np.any(allowed[2:4] != flags[slot].astype(np.float32)):
|
| 704 |
+
raise SourceAccessError("NODE_STATIC_DISAGREEMENT")
|
| 705 |
+
raw_pose = allowed[4:11].astype(np.float64)
|
| 706 |
+
if active[time, slot] and np.isfinite(raw_pose).all():
|
| 707 |
+
norm = float(np.linalg.norm(raw_pose[3:7]))
|
| 708 |
+
if 0.999 <= norm <= 1.001:
|
| 709 |
+
pose[time, slot, :3] = raw_pose[:3].astype(np.float32)
|
| 710 |
+
pose[time, slot, 3:7] = (raw_pose[3:7] / norm).astype(np.float32)
|
| 711 |
+
pose_valid[time, slot] = True
|
| 712 |
+
except (OSError, ValueError, EOFError) as error:
|
| 713 |
+
raise SourceAccessError("NODE_STATE_NPZ") from error
|
| 714 |
+
required = {
|
| 715 |
+
"active": 0,
|
| 716 |
+
"family_idx": 1,
|
| 717 |
+
"free_movable": 2,
|
| 718 |
+
"articulated": 3,
|
| 719 |
+
"pos_x": 4,
|
| 720 |
+
"pos_y": 5,
|
| 721 |
+
"pos_z": 6,
|
| 722 |
+
"quat_x": 7,
|
| 723 |
+
"quat_y": 8,
|
| 724 |
+
"quat_z": 9,
|
| 725 |
+
"quat_w": 10,
|
| 726 |
+
}
|
| 727 |
+
if len(schema) != 32 or any(schema[index] != name for name, index in required.items()):
|
| 728 |
+
raise SourceAccessError("NODE_STATE_ALLOWED_SCHEMA")
|
| 729 |
+
forbidden_tail = (
|
| 730 |
+
"lin_x", "lin_y", "lin_z", "ang_x", "ang_y", "ang_z",
|
| 731 |
+
"qpos", "qvel", "vis_right", "vis_left", "vis_wrist",
|
| 732 |
+
*[f"reserved_{index}" for index in range(22, 32)],
|
| 733 |
+
)
|
| 734 |
+
if tuple(schema[11:]) not in (forbidden_tail, (
|
| 735 |
+
"linear_x", "linear_y", "linear_z", "angular_x", "angular_y", "angular_z",
|
| 736 |
+
"qpos", "qvel", "vis_right", "vis_left", "vis_wrist",
|
| 737 |
+
*[f"reserved_{index}" for index in range(22, 32)],
|
| 738 |
+
)):
|
| 739 |
+
raise SourceAccessError("NODE_STATE_FORBIDDEN_SCHEMA")
|
| 740 |
+
static_present = family != 10
|
| 741 |
+
if np.any(active[:, ~static_present]):
|
| 742 |
+
raise SourceAccessError("NODE_ACTIVE_OUTSIDE_STATIC")
|
| 743 |
+
return (
|
| 744 |
+
freeze_array(active, dtype="|b1"),
|
| 745 |
+
freeze_array(pose, dtype="<f4"),
|
| 746 |
+
freeze_array(pose_valid, dtype="|b1"),
|
| 747 |
+
)
|
| 748 |
+
|
| 749 |
+
|
| 750 |
+
def _decode_views(
|
| 751 |
+
payload: bytes,
|
| 752 |
+
descriptor: CompactEpisodeDescriptorV3,
|
| 753 |
+
active: np.ndarray,
|
| 754 |
+
) -> tuple[np.ndarray, np.ndarray]:
|
| 755 |
+
try:
|
| 756 |
+
with np.load(io.BytesIO(payload), allow_pickle=False) as archive:
|
| 757 |
+
required = {
|
| 758 |
+
"view_visible",
|
| 759 |
+
"view_centroid",
|
| 760 |
+
"view_area",
|
| 761 |
+
"view_bbox",
|
| 762 |
+
"cameras",
|
| 763 |
+
}
|
| 764 |
+
if set(archive.files) != required:
|
| 765 |
+
raise SourceAccessError("VIEW_KEYS")
|
| 766 |
+
visible = np.asarray(archive["view_visible"])
|
| 767 |
+
centroid = np.asarray(archive["view_centroid"])
|
| 768 |
+
area = np.asarray(archive["view_area"])
|
| 769 |
+
bbox = np.asarray(archive["view_bbox"])
|
| 770 |
+
cameras = tuple(str(value) for value in archive["cameras"])
|
| 771 |
+
except (OSError, ValueError) as error:
|
| 772 |
+
raise SourceAccessError("VIEW_NPZ") from error
|
| 773 |
+
t = descriptor.frame_count
|
| 774 |
+
if (
|
| 775 |
+
visible.dtype != np.bool_
|
| 776 |
+
or visible.shape != (t, 256, 3)
|
| 777 |
+
or centroid.dtype != np.float16
|
| 778 |
+
or centroid.shape != (t, 256, 3, 2)
|
| 779 |
+
or area.dtype != np.float16
|
| 780 |
+
or area.shape != (t, 256, 3, 1)
|
| 781 |
+
or bbox.dtype != np.float16
|
| 782 |
+
or bbox.shape != (t, 256, 3, 4)
|
| 783 |
+
or cameras != CAMERAS
|
| 784 |
+
):
|
| 785 |
+
raise SourceAccessError("VIEW_SHAPE_DTYPE_OR_CAMERA")
|
| 786 |
+
output = np.zeros((t, 256, 3, 8), dtype=np.float32)
|
| 787 |
+
valid = np.broadcast_to(active[..., None], (t, 256, 3)).copy()
|
| 788 |
+
visible_rows = valid & visible
|
| 789 |
+
invisible_rows = valid & ~visible
|
| 790 |
+
geometry = np.concatenate((centroid, area, bbox), axis=-1).astype(np.float64)
|
| 791 |
+
if np.any(~np.isfinite(geometry[visible_rows])):
|
| 792 |
+
raise SourceAccessError("VIEW_VISIBLE_NONFINITE")
|
| 793 |
+
if np.any((geometry[visible_rows] < 0.0) | (geometry[visible_rows] > 1.0)):
|
| 794 |
+
raise SourceAccessError("VIEW_VISIBLE_RANGE")
|
| 795 |
+
if np.any(geometry[invisible_rows] != 0.0):
|
| 796 |
+
raise SourceAccessError("VIEW_INVISIBLE_NONZERO")
|
| 797 |
+
output[visible_rows, 0] = 1.0
|
| 798 |
+
output[visible_rows, 1:] = geometry[visible_rows].astype(np.float32)
|
| 799 |
+
return freeze_array(output, dtype="<f4"), freeze_array(valid, dtype="|b1")
|
| 800 |
+
|
| 801 |
+
|
| 802 |
+
def _decode_frames(
|
| 803 |
+
payload: bytes, descriptor: CompactEpisodeDescriptorV3
|
| 804 |
+
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
|
| 805 |
+
rows: dict[int, tuple[int, int, float, np.ndarray]] = {}
|
| 806 |
+
try:
|
| 807 |
+
for line in payload.decode("utf-8").splitlines():
|
| 808 |
+
if not line:
|
| 809 |
+
continue
|
| 810 |
+
value = json.loads(line)
|
| 811 |
+
if type(value) is not dict or set(value) != {"t", "source_frame", "action"}:
|
| 812 |
+
raise ValueError("frame fields")
|
| 813 |
+
time = value.get("t")
|
| 814 |
+
action = value.get("action")
|
| 815 |
+
if type(time) is not int or time in rows or type(action) is not dict:
|
| 816 |
+
raise ValueError("frame row")
|
| 817 |
+
if set(action) not in ({"index", "timestamp", "action"}, {"index", "timestamp", "action", "next.done"}):
|
| 818 |
+
raise ValueError("action fields")
|
| 819 |
+
source_frame = value.get("source_frame")
|
| 820 |
+
action_index = action.get("index")
|
| 821 |
+
timestamp = action.get("timestamp")
|
| 822 |
+
vector = np.asarray(action.get("action"), dtype=np.float32)
|
| 823 |
+
if (
|
| 824 |
+
type(source_frame) is not int
|
| 825 |
+
or type(action_index) is not int
|
| 826 |
+
or isinstance(timestamp, bool)
|
| 827 |
+
or not isinstance(timestamp, (int, float))
|
| 828 |
+
or vector.shape != (12,)
|
| 829 |
+
or not np.isfinite(vector).all()
|
| 830 |
+
or not np.isfinite(float(timestamp))
|
| 831 |
+
):
|
| 832 |
+
raise ValueError("frame value")
|
| 833 |
+
rows[time] = (source_frame, action_index, float(timestamp), vector)
|
| 834 |
+
except (UnicodeDecodeError, json.JSONDecodeError, TypeError, ValueError) as error:
|
| 835 |
+
raise SourceAccessError("FRAMES_JSONL") from error
|
| 836 |
+
if set(rows) != set(range(descriptor.frame_count)):
|
| 837 |
+
raise SourceAccessError("FRAMES_COVERAGE")
|
| 838 |
+
timestamps = np.asarray([rows[time][2] for time in range(descriptor.frame_count)], dtype=np.float64)
|
| 839 |
+
actions = np.stack([rows[time][3] for time in range(descriptor.frame_count)]).astype(np.float32)
|
| 840 |
+
indices = np.asarray([rows[time][1] for time in range(descriptor.frame_count)], dtype=np.int64)
|
| 841 |
+
if any(rows[time][0] != time for time in range(descriptor.frame_count)):
|
| 842 |
+
raise SourceAccessError("FRAMES_SOURCE_FRAME")
|
| 843 |
+
return (
|
| 844 |
+
freeze_array(timestamps, dtype="<f8"),
|
| 845 |
+
freeze_array(actions, dtype="<f4"),
|
| 846 |
+
freeze_array(indices, dtype="<i8"),
|
| 847 |
+
)
|
| 848 |
+
|
| 849 |
+
|
| 850 |
+
def _decode_contacts(
|
| 851 |
+
payload: bytes, descriptor: CompactEpisodeDescriptorV3
|
| 852 |
+
) -> tuple[tuple[tuple[int, int], ...], ...]:
|
| 853 |
+
rows: dict[int, tuple[tuple[int, int], ...]] = {}
|
| 854 |
+
try:
|
| 855 |
+
for line in payload.decode("utf-8").splitlines():
|
| 856 |
+
if not line:
|
| 857 |
+
continue
|
| 858 |
+
value = json.loads(line)
|
| 859 |
+
if type(value) is not dict or set(value) != {"t", "edges"}:
|
| 860 |
+
raise ValueError("contact fields")
|
| 861 |
+
time = value.get("t")
|
| 862 |
+
if type(time) is not int or time in rows:
|
| 863 |
+
raise ValueError("contact time")
|
| 864 |
+
contacts: list[tuple[int, int]] = []
|
| 865 |
+
seen: set[tuple[int, int]] = set()
|
| 866 |
+
for edge in value.get("edges", []):
|
| 867 |
+
if type(edge) is not dict:
|
| 868 |
+
raise ValueError("edge row")
|
| 869 |
+
relation = edge.get("rel")
|
| 870 |
+
allowed_edge_fields = {"src", "dst", "rel", "view"} if relation == "visibility_change" else {"src", "dst", "rel"}
|
| 871 |
+
if set(edge) != allowed_edge_fields:
|
| 872 |
+
raise ValueError("edge fields")
|
| 873 |
+
sender, receiver = edge.get("src"), edge.get("dst")
|
| 874 |
+
if relation == "visibility_change":
|
| 875 |
+
# Integrity-only event in an otherwise required physical
|
| 876 |
+
# member. It is validated structurally and never emitted.
|
| 877 |
+
if type(sender) is not int or sender != receiver or type(edge.get("view")) is not int:
|
| 878 |
+
raise ValueError("visibility event")
|
| 879 |
+
continue
|
| 880 |
+
if relation != "contact" or type(sender) is not int or type(receiver) is not int:
|
| 881 |
+
raise ValueError("contact edge")
|
| 882 |
+
pair = (sender, receiver)
|
| 883 |
+
if not 0 <= sender < receiver < 256 or pair in seen:
|
| 884 |
+
raise ValueError("contact canonical")
|
| 885 |
+
seen.add(pair)
|
| 886 |
+
contacts.append(pair)
|
| 887 |
+
rows[time] = tuple(sorted(contacts))
|
| 888 |
+
except (UnicodeDecodeError, json.JSONDecodeError, TypeError, ValueError) as error:
|
| 889 |
+
raise SourceAccessError("DYNAMIC_EDGES_JSONL") from error
|
| 890 |
+
if set(rows) != set(range(descriptor.frame_count)):
|
| 891 |
+
raise SourceAccessError("DYNAMIC_EDGES_COVERAGE")
|
| 892 |
+
return tuple(rows[time] for time in range(descriptor.frame_count))
|
| 893 |
+
|
| 894 |
+
|
| 895 |
+
def _relative_rotation_log(anchor: np.ndarray, future: np.ndarray) -> np.ndarray:
|
| 896 |
+
"""Quaternion XYZW relative log, evaluated in binary64."""
|
| 897 |
+
|
| 898 |
+
anchor = np.asarray(anchor, dtype=np.float64)
|
| 899 |
+
future = np.asarray(future, dtype=np.float64)
|
| 900 |
+
if anchor.shape != future.shape or anchor.ndim != 2 or anchor.shape[1] != 4:
|
| 901 |
+
raise SourceAccessError("ROTATION_LOG_INPUT")
|
| 902 |
+
inverse = anchor.copy()
|
| 903 |
+
inverse[:, :3] *= -1.0
|
| 904 |
+
ax, ay, az, aw = (inverse[:, index] for index in range(4))
|
| 905 |
+
bx, by, bz, bw = (future[:, index] for index in range(4))
|
| 906 |
+
relative = np.stack(
|
| 907 |
+
(
|
| 908 |
+
aw * bx + ax * bw + ay * bz - az * by,
|
| 909 |
+
aw * by - ax * bz + ay * bw + az * bx,
|
| 910 |
+
aw * bz + ax * by - ay * bx + az * bw,
|
| 911 |
+
aw * bw - ax * bx - ay * by - az * bz,
|
| 912 |
+
),
|
| 913 |
+
axis=-1,
|
| 914 |
+
)
|
| 915 |
+
flip = relative[:, 3] < 0.0
|
| 916 |
+
relative[flip] *= -1.0
|
| 917 |
+
vector = relative[:, :3]
|
| 918 |
+
norm = np.linalg.norm(vector, axis=-1)
|
| 919 |
+
result = np.zeros((anchor.shape[0], 3), dtype=np.float64)
|
| 920 |
+
nonzero = norm > 1e-12
|
| 921 |
+
angle = 2.0 * np.arctan2(norm[nonzero], np.clip(relative[nonzero, 3], -1.0, 1.0))
|
| 922 |
+
result[nonzero] = vector[nonzero] * (angle / norm[nonzero])[:, None]
|
| 923 |
+
return result.astype(np.float32)
|
| 924 |
+
|
| 925 |
+
|
| 926 |
+
def _geometry_object_bytes(
|
| 927 |
+
*,
|
| 928 |
+
descriptor: CompactEpisodeDescriptorV3,
|
| 929 |
+
start: int,
|
| 930 |
+
slot_id: np.ndarray,
|
| 931 |
+
node_valid: np.ndarray,
|
| 932 |
+
pose: np.ndarray,
|
| 933 |
+
pose_valid: np.ndarray,
|
| 934 |
+
relations: Any,
|
| 935 |
+
member_bindings: tuple[tuple[str, int, str], ...],
|
| 936 |
+
) -> tuple[str, bytes]:
|
| 937 |
+
pre_source = {
|
| 938 |
+
"episode_key": descriptor.episode_key,
|
| 939 |
+
"history_arrays": [
|
| 940 |
+
{"name": name, "sha256": array_sha256(value)}
|
| 941 |
+
for name, value in (
|
| 942 |
+
("slot_id", slot_id),
|
| 943 |
+
("node_valid", node_valid),
|
| 944 |
+
("pose", pose),
|
| 945 |
+
("pose_valid", pose_valid),
|
| 946 |
+
)
|
| 947 |
+
],
|
| 948 |
+
"member_bindings": [
|
| 949 |
+
{"relative_path": path, "size_bytes": size, "sha256": digest}
|
| 950 |
+
for path, size, digest in member_bindings
|
| 951 |
+
],
|
| 952 |
+
"profile": "active13_target_physical_v2",
|
| 953 |
+
"schema": "gwam.compact.pre_geometry_source.v3",
|
| 954 |
+
"source_group_id": descriptor.source_group_id,
|
| 955 |
+
"source_zip_path": descriptor.source_zip_path,
|
| 956 |
+
"source_zip_sha256": descriptor.source_zip_sha256,
|
| 957 |
+
"start": start,
|
| 958 |
+
"task": descriptor.task,
|
| 959 |
+
}
|
| 960 |
+
pre_bytes = canonical_json_bytes(pre_source)
|
| 961 |
+
pre_sha = sha256_bytes(pre_bytes)
|
| 962 |
+
select = relations.relation_id == 5
|
| 963 |
+
arrays = (
|
| 964 |
+
("edge_index", relations.index[:, select]),
|
| 965 |
+
("edge_batch", relations.batch[select]),
|
| 966 |
+
("edge_time", relations.time[select]),
|
| 967 |
+
("edge_relation_id", relations.relation_id[select]),
|
| 968 |
+
("edge_payload", relations.payload[select]),
|
| 969 |
+
("edge_payload_valid", relations.payload_valid[select]),
|
| 970 |
+
)
|
| 971 |
+
header = {
|
| 972 |
+
"builder": "graphpacket_slim_geometry_near_packed_v3",
|
| 973 |
+
"note": "exact v1 nearest-eight and METRIC12 equations; packed endpoint projection",
|
| 974 |
+
"pre_geometry_source_bytes_sha256": pre_sha,
|
| 975 |
+
"schema": "gwam.compact.geometry_object.v3",
|
| 976 |
+
"tensors": [
|
| 977 |
+
{
|
| 978 |
+
"dtype": value.dtype.str,
|
| 979 |
+
"name": name,
|
| 980 |
+
"shape": list(value.shape),
|
| 981 |
+
"sha256": array_sha256(value),
|
| 982 |
+
}
|
| 983 |
+
for name, value in arrays
|
| 984 |
+
],
|
| 985 |
+
}
|
| 986 |
+
header_bytes = canonical_json_bytes(header)
|
| 987 |
+
framed = bytearray(struct.pack("<Q", len(pre_bytes)))
|
| 988 |
+
framed.extend(pre_bytes)
|
| 989 |
+
framed.extend(struct.pack("<Q", len(header_bytes)))
|
| 990 |
+
framed.extend(header_bytes)
|
| 991 |
+
for _, value in arrays:
|
| 992 |
+
payload = value.tobytes(order="C")
|
| 993 |
+
framed.extend(struct.pack("<Q", len(payload)))
|
| 994 |
+
framed.extend(payload)
|
| 995 |
+
return pre_sha, bytes(framed)
|
| 996 |
+
|
| 997 |
+
|
| 998 |
+
class DirectCompactSourceV3:
|
| 999 |
+
"""Read one content-addressed outer-train episode through the compact seam."""
|
| 1000 |
+
|
| 1001 |
+
def __init__(self, data_root: str | Path) -> None:
|
| 1002 |
+
self.data_root = Path(data_root).resolve()
|
| 1003 |
+
if not self.data_root.is_dir():
|
| 1004 |
+
raise SourceAccessError("DATA_ROOT_NOT_DIRECTORY")
|
| 1005 |
+
self.access_trace = SourceAccessTraceV3("", "0" * 64, (), (), ())
|
| 1006 |
+
self._read_lock = threading.RLock()
|
| 1007 |
+
|
| 1008 |
+
def _read_episode(
|
| 1009 |
+
self,
|
| 1010 |
+
descriptor: CompactEpisodeDescriptorV3,
|
| 1011 |
+
*,
|
| 1012 |
+
target_receipt_bytes: bytes,
|
| 1013 |
+
c2_receipt_bytes: bytes | None,
|
| 1014 |
+
opaque_integrity_sha256: Mapping[str, str] | None,
|
| 1015 |
+
) -> _AllowedEpisode:
|
| 1016 |
+
descriptor.validate()
|
| 1017 |
+
if opaque_integrity_sha256 is not None:
|
| 1018 |
+
if type(opaque_integrity_sha256) is not dict or set(opaque_integrity_sha256) != set(
|
| 1019 |
+
OPAQUE_ONLY_MEMBER_LEAVES
|
| 1020 |
+
) or any(not _is_digest(value) for value in opaque_integrity_sha256.values()):
|
| 1021 |
+
raise SourceAccessError("OPAQUE_INTEGRITY_BINDING")
|
| 1022 |
+
with _PinnedReadOnlyFile.open(self.data_root, descriptor.source_zip_path) as pinned:
|
| 1023 |
+
before_sha, before_size = pinned.digest_and_size()
|
| 1024 |
+
if (before_sha, before_size) != (
|
| 1025 |
+
descriptor.source_zip_sha256,
|
| 1026 |
+
descriptor.source_zip_size,
|
| 1027 |
+
):
|
| 1028 |
+
raise SourceAccessError("SOURCE_ZIP_BINDING")
|
| 1029 |
+
with os.fdopen(os.dup(pinned.fd), "rb", closefd=True) as stream:
|
| 1030 |
+
try:
|
| 1031 |
+
archive = zipfile.ZipFile(stream, "r")
|
| 1032 |
+
except zipfile.BadZipFile as error:
|
| 1033 |
+
raise SourceAccessError("SOURCE_ZIP_FORMAT") from error
|
| 1034 |
+
with archive:
|
| 1035 |
+
names = [item.filename for item in archive.infolist()]
|
| 1036 |
+
if len(names) != len(set(names)):
|
| 1037 |
+
raise SourceAccessError("SOURCE_ZIP_DUPLICATE_MEMBER")
|
| 1038 |
+
for name in names:
|
| 1039 |
+
_safe_relative(name)
|
| 1040 |
+
prefix = f"{descriptor.episode_key}/graph/"
|
| 1041 |
+
required = {leaf: prefix + leaf for leaf in REQUIRED_MEMBER_LEAVES}
|
| 1042 |
+
opaque = {leaf: prefix + leaf for leaf in OPAQUE_ONLY_MEMBER_LEAVES}
|
| 1043 |
+
if any(names.count(path) != 1 for path in required.values()):
|
| 1044 |
+
raise SourceAccessError("REQUIRED_MEMBER_MISSING")
|
| 1045 |
+
if any(names.count(path) != 1 for path in opaque.values()):
|
| 1046 |
+
raise SourceAccessError("OPAQUE_MEMBER_MISSING")
|
| 1047 |
+
payloads: dict[str, bytes] = {}
|
| 1048 |
+
bindings: list[tuple[str, int, str]] = []
|
| 1049 |
+
for leaf in REQUIRED_MEMBER_LEAVES:
|
| 1050 |
+
try:
|
| 1051 |
+
payload = archive.read(required[leaf])
|
| 1052 |
+
except (KeyError, RuntimeError, zipfile.BadZipFile) as error:
|
| 1053 |
+
raise SourceAccessError(f"REQUIRED_MEMBER_READ:{leaf}") from error
|
| 1054 |
+
payloads[leaf] = payload
|
| 1055 |
+
bindings.append((required[leaf], len(payload), sha256_bytes(payload)))
|
| 1056 |
+
opaque_opened: list[str] = []
|
| 1057 |
+
if opaque_integrity_sha256 is not None:
|
| 1058 |
+
for leaf in OPAQUE_ONLY_MEMBER_LEAVES:
|
| 1059 |
+
try:
|
| 1060 |
+
payload = archive.read(opaque[leaf])
|
| 1061 |
+
except (KeyError, RuntimeError, zipfile.BadZipFile) as error:
|
| 1062 |
+
raise SourceAccessError(f"OPAQUE_MEMBER_READ:{leaf}") from error
|
| 1063 |
+
if sha256_bytes(payload) != opaque_integrity_sha256[leaf]:
|
| 1064 |
+
raise SourceAccessError(f"OPAQUE_MEMBER_SHA256:{leaf}")
|
| 1065 |
+
bindings.append((opaque[leaf], len(payload), sha256_bytes(payload)))
|
| 1066 |
+
opaque_opened.append(leaf)
|
| 1067 |
+
pinned.reverify()
|
| 1068 |
+
after_sha, after_size = pinned.digest_and_size()
|
| 1069 |
+
pinned.reverify()
|
| 1070 |
+
if (after_sha, after_size) != (before_sha, before_size):
|
| 1071 |
+
raise SourceAccessError("SOURCE_CHANGED_DURING_READ")
|
| 1072 |
+
self.access_trace = SourceAccessTraceV3(
|
| 1073 |
+
descriptor.source_zip_path,
|
| 1074 |
+
descriptor.source_zip_sha256,
|
| 1075 |
+
REQUIRED_MEMBER_LEAVES,
|
| 1076 |
+
tuple(opaque_opened),
|
| 1077 |
+
tuple((path, digest) for path, _, digest in bindings),
|
| 1078 |
+
)
|
| 1079 |
+
graph, family, flags, static_relations = _decode_graph_static(
|
| 1080 |
+
payloads["graph_static.json"], descriptor
|
| 1081 |
+
)
|
| 1082 |
+
target = _target_projection(
|
| 1083 |
+
target_receipt_bytes,
|
| 1084 |
+
descriptor,
|
| 1085 |
+
graph,
|
| 1086 |
+
payloads["graph_static.json"],
|
| 1087 |
+
)
|
| 1088 |
+
c2 = _c2_values(c2_receipt_bytes, descriptor)
|
| 1089 |
+
active, pose, pose_valid = _decode_allowed_state(
|
| 1090 |
+
payloads["node_state.npz"], descriptor, family, flags
|
| 1091 |
+
)
|
| 1092 |
+
views, view_valid = _decode_views(
|
| 1093 |
+
payloads["view_evidence.npz"], descriptor, active
|
| 1094 |
+
)
|
| 1095 |
+
timestamps, actions, action_indices = _decode_frames(
|
| 1096 |
+
payloads["frames.jsonl"], descriptor
|
| 1097 |
+
)
|
| 1098 |
+
contacts = _decode_contacts(payloads["dynamic_edges.jsonl"], descriptor)
|
| 1099 |
+
return _AllowedEpisode(
|
| 1100 |
+
active,
|
| 1101 |
+
family,
|
| 1102 |
+
flags,
|
| 1103 |
+
pose,
|
| 1104 |
+
pose_valid,
|
| 1105 |
+
views,
|
| 1106 |
+
view_valid,
|
| 1107 |
+
timestamps,
|
| 1108 |
+
actions,
|
| 1109 |
+
action_indices,
|
| 1110 |
+
static_relations,
|
| 1111 |
+
contacts,
|
| 1112 |
+
target,
|
| 1113 |
+
c2,
|
| 1114 |
+
payloads["graph_static.json"],
|
| 1115 |
+
tuple(bindings),
|
| 1116 |
+
(descriptor.episode_key, descriptor.task, descriptor.source_split, descriptor.source_zip_path,
|
| 1117 |
+
descriptor.source_zip_sha256, str(descriptor.source_zip_size), descriptor.outer_manifest_row_sha256,
|
| 1118 |
+
descriptor.target_receipt_sha256, descriptor.c2_receipt_sha256 or "NONE",
|
| 1119 |
+
_opaque_identity(opaque_integrity_sha256)),
|
| 1120 |
+
)
|
| 1121 |
+
|
| 1122 |
+
def open_episode(self, descriptor: CompactEpisodeDescriptorV3, *, target_receipt_bytes: bytes,
|
| 1123 |
+
c2_receipt_bytes: bytes | None = None,
|
| 1124 |
+
opaque_integrity_sha256: Mapping[str, str] | None = None) -> AuthenticatedEpisodeHandleV3:
|
| 1125 |
+
"""Authenticate and return an opaque immutable decoded episode handle."""
|
| 1126 |
+
with self._read_lock:
|
| 1127 |
+
episode = self._read_episode(descriptor, target_receipt_bytes=target_receipt_bytes,
|
| 1128 |
+
c2_receipt_bytes=c2_receipt_bytes,
|
| 1129 |
+
opaque_integrity_sha256=opaque_integrity_sha256)
|
| 1130 |
+
trace = self.access_trace
|
| 1131 |
+
estimate = sum(int(value.nbytes) for value in (episode.active, episode.family_id, episode.static_flags, episode.pose, episode.pose_valid, episode.views, episode.view_valid, episode.timestamps, episode.actions, episode.action_indices, episode.target.target, episode.target.valid, episode.c2.q, episode.c2.valid)) + len(target_receipt_bytes) + (0 if c2_receipt_bytes is None else len(c2_receipt_bytes)) + len(episode.graph_static_bytes) + sum(len(path) + len(sha) + 16 for path, _, sha in episode.member_bindings)
|
| 1132 |
+
opaque_key = tuple(sorted((opaque_integrity_sha256 or {}).items()))
|
| 1133 |
+
return AuthenticatedEpisodeHandleV3(self, descriptor, episode, bytes(target_receipt_bytes), None if c2_receipt_bytes is None else bytes(c2_receipt_bytes), opaque_key, trace, os.getpid(), int(estimate), _seal=_HANDLE_SEAL)
|
| 1134 |
+
|
| 1135 |
+
def load_window(
|
| 1136 |
+
self,
|
| 1137 |
+
descriptor: CompactEpisodeDescriptorV3,
|
| 1138 |
+
*,
|
| 1139 |
+
start: int,
|
| 1140 |
+
target_receipt_bytes: bytes,
|
| 1141 |
+
c2_receipt_bytes: bytes | None = None,
|
| 1142 |
+
opaque_integrity_sha256: Mapping[str, str] | None = None,
|
| 1143 |
+
) -> CompactExampleV3:
|
| 1144 |
+
"""Deliberately uncached compatibility path: authenticate every call."""
|
| 1145 |
+
return self.open_episode(
|
| 1146 |
+
descriptor,
|
| 1147 |
+
target_receipt_bytes=target_receipt_bytes,
|
| 1148 |
+
c2_receipt_bytes=c2_receipt_bytes,
|
| 1149 |
+
opaque_integrity_sha256=opaque_integrity_sha256,
|
| 1150 |
+
).load_window(start)
|
| 1151 |
+
|
| 1152 |
+
def _materialize_handle(
|
| 1153 |
+
self, handle: AuthenticatedEpisodeHandleV3, *, start: int
|
| 1154 |
+
) -> CompactExampleV3:
|
| 1155 |
+
if type(handle) is not AuthenticatedEpisodeHandleV3:
|
| 1156 |
+
raise SourceAccessError("EPISODE_HANDLE_REQUIRED")
|
| 1157 |
+
if os.getpid() != handle._owner_pid:
|
| 1158 |
+
raise SourceAccessError("AUTHENTICATED_HANDLE_OWNER_PID")
|
| 1159 |
+
if handle._source is not self:
|
| 1160 |
+
raise SourceAccessError("AUTHENTICATED_HANDLE_SOURCE")
|
| 1161 |
+
if handle._seal is not _HANDLE_SEAL:
|
| 1162 |
+
raise SourceAccessError("AUTHENTICATED_HANDLE_SEAL")
|
| 1163 |
+
descriptor = handle._descriptor
|
| 1164 |
+
episode = handle._episode
|
| 1165 |
+
target_receipt_bytes = handle._target_receipt_bytes
|
| 1166 |
+
c2_receipt_bytes = handle._c2_receipt_bytes
|
| 1167 |
+
if type(start) is not int or start < 0 or start + 15 >= descriptor.frame_count:
|
| 1168 |
+
raise SourceAccessError("WINDOW_START")
|
| 1169 |
+
history = np.arange(start, start + 8, dtype=np.int64)
|
| 1170 |
+
action_frames = np.arange(start + 7, start + 15, dtype=np.int64)
|
| 1171 |
+
target_frames = np.arange(start + 8, start + 16, dtype=np.int64)
|
| 1172 |
+
try:
|
| 1173 |
+
history_ok = all(offline_step_ok(float(a), float(b)) for a, b in zip(episode.timestamps[history][:-1], episode.timestamps[history][1:]))
|
| 1174 |
+
except ValueError as error:
|
| 1175 |
+
raise SourceAccessError(str(error)) from error
|
| 1176 |
+
if not history_ok: raise SourceAccessError("HISTORY_TIMESTAMP_NOT_CONSECUTIVE_TICKS")
|
| 1177 |
+
sequence = np.arange(start + 6, start + 15, dtype=np.int64)
|
| 1178 |
+
if np.any(np.diff(episode.action_indices[sequence]) != 1): raise SourceAccessError("ACTION_INDEX_NOT_CONSECUTIVE")
|
| 1179 |
+
try:
|
| 1180 |
+
action_ok = all(offline_step_ok(float(a), float(b)) for a, b in zip(episode.timestamps[sequence][:-1], episode.timestamps[sequence][1:]))
|
| 1181 |
+
except ValueError as error: raise SourceAccessError(str(error)) from error
|
| 1182 |
+
if not action_ok: raise SourceAccessError("ACTION_TIMESTAMP_NOT_CONSECUTIVE_TICKS")
|
| 1183 |
+
active_storage_slots = np.flatnonzero(episode.active[history].any(axis=0))
|
| 1184 |
+
if active_storage_slots.size < 1:
|
| 1185 |
+
raise SourceAccessError("PACKED_ACTIVE_INVENTORY_EMPTY")
|
| 1186 |
+
n = int(active_storage_slots.size)
|
| 1187 |
+
storage_to_local = {int(slot): local for local, slot in enumerate(active_storage_slots)}
|
| 1188 |
+
node_valid = episode.active[history][:, active_storage_slots]
|
| 1189 |
+
pose = episode.pose[history][:, active_storage_slots]
|
| 1190 |
+
pose_valid = episode.pose_valid[history][:, active_storage_slots]
|
| 1191 |
+
views = episode.views[history][:, active_storage_slots]
|
| 1192 |
+
view_valid = episode.view_valid[history][:, active_storage_slots]
|
| 1193 |
+
family = episode.family_id[active_storage_slots]
|
| 1194 |
+
flags = episode.static_flags[active_storage_slots]
|
| 1195 |
+
if np.any(~node_valid.any(axis=0)):
|
| 1196 |
+
raise SourceAccessError("PACK_REMAP_LOSS")
|
| 1197 |
+
anchor = node_valid[7]
|
| 1198 |
+
projected_target_valid = episode.target.valid[active_storage_slots]
|
| 1199 |
+
projected_target = episode.target.target[active_storage_slots]
|
| 1200 |
+
if np.any(projected_target_valid & ~anchor) or np.any(projected_target & ~anchor):
|
| 1201 |
+
raise SourceAccessError("TARGET_NOT_ANCHOR_ACTIVE")
|
| 1202 |
+
if not projected_target.any():
|
| 1203 |
+
raise SourceAccessError("TARGET_REMOVED_BY_PACK")
|
| 1204 |
+
source_code = episode.target.source_code[active_storage_slots]
|
| 1205 |
+
q = np.zeros((8, n, 1), dtype=np.float32)
|
| 1206 |
+
q_valid = np.zeros((8, n, 1), dtype=np.bool_)
|
| 1207 |
+
if episode.c2.component_slot is not None:
|
| 1208 |
+
if episode.c2.component_slot not in storage_to_local:
|
| 1209 |
+
raise SourceAccessError("C2_COMPONENT_REMOVED_BY_PACK")
|
| 1210 |
+
local = storage_to_local[episode.c2.component_slot]
|
| 1211 |
+
q[:, local, 0] = episode.c2.q[history]
|
| 1212 |
+
q_valid[:, local, 0] = episode.c2.valid[history] & node_valid[:, local]
|
| 1213 |
+
q[~q_valid] = np.float32(0.0)
|
| 1214 |
+
static_rows = tuple(
|
| 1215 |
+
RelationTripleV3(
|
| 1216 |
+
storage_to_local[row.sender],
|
| 1217 |
+
storage_to_local[row.receiver],
|
| 1218 |
+
row.relation_id,
|
| 1219 |
+
)
|
| 1220 |
+
for row in episode.static_relations
|
| 1221 |
+
if row.sender in storage_to_local and row.receiver in storage_to_local
|
| 1222 |
+
)
|
| 1223 |
+
contact_rows = tuple(
|
| 1224 |
+
tuple(
|
| 1225 |
+
(storage_to_local[left], storage_to_local[right])
|
| 1226 |
+
for left, right in episode.contacts[int(time)]
|
| 1227 |
+
if left in storage_to_local and right in storage_to_local
|
| 1228 |
+
)
|
| 1229 |
+
for time in history
|
| 1230 |
+
)
|
| 1231 |
+
relations = assemble_relations_metric12(
|
| 1232 |
+
np.ascontiguousarray(pose),
|
| 1233 |
+
np.ascontiguousarray(pose_valid),
|
| 1234 |
+
static_rows,
|
| 1235 |
+
contact_rows,
|
| 1236 |
+
batch_index=0,
|
| 1237 |
+
)
|
| 1238 |
+
robot_contact, robot_contact_valid = derive_robot_target_contact(
|
| 1239 |
+
node_valid=node_valid[None],
|
| 1240 |
+
family_id=family[None],
|
| 1241 |
+
target=projected_target[None],
|
| 1242 |
+
target_valid=projected_target_valid[None],
|
| 1243 |
+
edge_index=relations.index,
|
| 1244 |
+
edge_batch=relations.batch,
|
| 1245 |
+
edge_time=relations.time,
|
| 1246 |
+
edge_relation_id=relations.relation_id,
|
| 1247 |
+
edge_payload_valid=relations.payload_valid,
|
| 1248 |
+
)
|
| 1249 |
+
routes = canonical_ordered_route_index(n)
|
| 1250 |
+
route_valid = node_valid[7, routes[0]] & node_valid[7, routes[1]]
|
| 1251 |
+
timestamps = episode.timestamps[history]
|
| 1252 |
+
packet = CompactGraphPacketV3(
|
| 1253 |
+
history_valid=freeze_array(np.ones((1, 8), dtype=np.bool_), dtype="|b1"),
|
| 1254 |
+
timestamp_s=freeze_array(timestamps[None], dtype="<f8"),
|
| 1255 |
+
timestamp_valid=freeze_array(np.ones((1, 8), dtype=np.bool_), dtype="|b1"),
|
| 1256 |
+
delta_t_s=freeze_array(np.diff(timestamps)[None], dtype="<f4"),
|
| 1257 |
+
delta_t_valid=freeze_array(np.ones((1, 7), dtype=np.bool_), dtype="|b1"),
|
| 1258 |
+
slot_id=freeze_array(active_storage_slots.astype(np.int16)[None], dtype="<i2"),
|
| 1259 |
+
ordered_route_index=routes,
|
| 1260 |
+
ordered_route_valid=freeze_array(route_valid[None], dtype="|b1"),
|
| 1261 |
+
node_valid=freeze_array(node_valid[None], dtype="|b1"),
|
| 1262 |
+
family_id=freeze_array(family[None], dtype="<i8"),
|
| 1263 |
+
family_valid=freeze_array(np.ones((1, n), dtype=np.bool_), dtype="|b1"),
|
| 1264 |
+
static_flags=freeze_array(flags[None], dtype="|b1"),
|
| 1265 |
+
static_flags_valid=freeze_array(np.ones((1, n), dtype=np.bool_), dtype="|b1"),
|
| 1266 |
+
pose=freeze_array(pose[None], dtype="<f4"),
|
| 1267 |
+
pose_valid=freeze_array(pose_valid[None], dtype="|b1"),
|
| 1268 |
+
articulation_q=freeze_array(q[None], dtype="<f4"),
|
| 1269 |
+
articulation_valid=freeze_array(q_valid[None], dtype="|b1"),
|
| 1270 |
+
view_evidence=freeze_array(views[None], dtype="<f4"),
|
| 1271 |
+
view_record_valid=freeze_array(view_valid[None], dtype="|b1"),
|
| 1272 |
+
edge_index=relations.index,
|
| 1273 |
+
edge_batch=relations.batch,
|
| 1274 |
+
edge_time=relations.time,
|
| 1275 |
+
edge_relation_id=relations.relation_id,
|
| 1276 |
+
edge_payload=relations.payload,
|
| 1277 |
+
edge_payload_valid=relations.payload_valid,
|
| 1278 |
+
is_task_target=freeze_array(projected_target[None], dtype="|b1"),
|
| 1279 |
+
task_target_valid=freeze_array(projected_target_valid[None], dtype="|b1"),
|
| 1280 |
+
task_target_source_code=freeze_array(source_code[None], dtype="|u1"),
|
| 1281 |
+
robot_target_contact=freeze_array(robot_contact, dtype="|b1"),
|
| 1282 |
+
robot_target_contact_valid=freeze_array(robot_contact_valid, dtype="|b1"),
|
| 1283 |
+
)
|
| 1284 |
+
action_timestamps = episode.timestamps[action_frames]
|
| 1285 |
+
action = CompactActionConditionV3(
|
| 1286 |
+
future_action=freeze_array(episode.actions[action_frames][None], dtype="<f4"),
|
| 1287 |
+
future_action_valid=freeze_array(np.ones((1, 8), dtype=np.bool_), dtype="|b1"),
|
| 1288 |
+
action_timestamp_s=freeze_array(action_timestamps[None], dtype="<f8"),
|
| 1289 |
+
action_timestamp_valid=freeze_array(np.ones((1, 8), dtype=np.bool_), dtype="|b1"),
|
| 1290 |
+
)
|
| 1291 |
+
targets = self._build_targets(
|
| 1292 |
+
episode,
|
| 1293 |
+
active_storage_slots=active_storage_slots,
|
| 1294 |
+
storage_to_local=storage_to_local,
|
| 1295 |
+
packet=packet,
|
| 1296 |
+
action=action,
|
| 1297 |
+
target_frames=target_frames,
|
| 1298 |
+
)
|
| 1299 |
+
pre_geometry_sha, geometry_bytes = _geometry_object_bytes(
|
| 1300 |
+
descriptor=descriptor,
|
| 1301 |
+
start=start,
|
| 1302 |
+
slot_id=packet.slot_id[0],
|
| 1303 |
+
node_valid=packet.node_valid[0],
|
| 1304 |
+
pose=packet.pose[0],
|
| 1305 |
+
pose_valid=packet.pose_valid[0],
|
| 1306 |
+
relations=relations,
|
| 1307 |
+
member_bindings=episode.member_bindings,
|
| 1308 |
+
)
|
| 1309 |
+
provenance = CompactProvenanceV3(
|
| 1310 |
+
episode_key=(descriptor.episode_key,),
|
| 1311 |
+
task=(descriptor.task,),
|
| 1312 |
+
window_start=(start,),
|
| 1313 |
+
natural_window_sha256=(
|
| 1314 |
+
sha256_bytes(
|
| 1315 |
+
f"gwam-direct-compact-v3-window|20260731|{descriptor.task}|{descriptor.source_group_id}|{descriptor.episode_key}|{start}".encode(
|
| 1316 |
+
"utf-8"
|
| 1317 |
+
)
|
| 1318 |
+
),
|
| 1319 |
+
),
|
| 1320 |
+
source_split=(descriptor.source_split,),
|
| 1321 |
+
source_zip_path=(descriptor.source_zip_path,),
|
| 1322 |
+
source_zip_sha256=(descriptor.source_zip_sha256,),
|
| 1323 |
+
outer_manifest_row_sha256=(descriptor.outer_manifest_row_sha256,),
|
| 1324 |
+
target_receipt_bytes=(target_receipt_bytes,),
|
| 1325 |
+
target_receipt_sha256=(descriptor.target_receipt_sha256,),
|
| 1326 |
+
c2_receipt_sha256=(episode.c2.receipt_sha256,),
|
| 1327 |
+
geometry_receipt_bytes=(geometry_bytes,),
|
| 1328 |
+
geometry_receipt_sha256=(sha256_bytes(geometry_bytes),),
|
| 1329 |
+
pre_geometry_source_sha256=(pre_geometry_sha,),
|
| 1330 |
+
source_access_trace_sha256=(handle.access_trace.sha256,),
|
| 1331 |
+
)
|
| 1332 |
+
result = CompactExampleV3(packet, action, targets, provenance)
|
| 1333 |
+
result.validate()
|
| 1334 |
+
return result
|
| 1335 |
+
|
| 1336 |
+
@staticmethod
|
| 1337 |
+
def _build_targets(
|
| 1338 |
+
episode: _AllowedEpisode,
|
| 1339 |
+
*,
|
| 1340 |
+
active_storage_slots: np.ndarray,
|
| 1341 |
+
storage_to_local: dict[int, int],
|
| 1342 |
+
packet: CompactGraphPacketV3,
|
| 1343 |
+
action: CompactActionConditionV3,
|
| 1344 |
+
target_frames: np.ndarray,
|
| 1345 |
+
) -> CompactTargetsV3:
|
| 1346 |
+
n = packet.n_nodes
|
| 1347 |
+
anchor_active = packet.node_valid[0, 7]
|
| 1348 |
+
target_node = np.zeros((8, n), dtype=np.bool_)
|
| 1349 |
+
target_timestamp = np.zeros(8, dtype=np.float64)
|
| 1350 |
+
target_timestamp_valid = np.zeros(8, dtype=np.bool_)
|
| 1351 |
+
position_delta = np.zeros((8, n, 3), dtype=np.float32)
|
| 1352 |
+
rotation_log = np.zeros((8, n, 3), dtype=np.float32)
|
| 1353 |
+
target_pose_valid = np.zeros((8, n), dtype=np.bool_)
|
| 1354 |
+
target_view = np.zeros((8, n, 3, 8), dtype=np.float32)
|
| 1355 |
+
target_view_valid = np.zeros((8, n, 3), dtype=np.bool_)
|
| 1356 |
+
target_q_delta = np.zeros((8, n, 1), dtype=np.float32)
|
| 1357 |
+
target_q_valid = np.zeros((8, n, 1), dtype=np.bool_)
|
| 1358 |
+
target_robot_contact = np.zeros((8, n), dtype=np.bool_)
|
| 1359 |
+
target_robot_contact_valid = np.zeros((8, n), dtype=np.bool_)
|
| 1360 |
+
target_robot_event = np.zeros((8, n), dtype=np.int64)
|
| 1361 |
+
target_robot_event_valid = np.zeros((8, n), dtype=np.bool_)
|
| 1362 |
+
for horizon, source_time in enumerate(target_frames.tolist()):
|
| 1363 |
+
target_node[horizon] = anchor_active & episode.active[source_time, active_storage_slots]
|
| 1364 |
+
timestamp = episode.timestamps[source_time]
|
| 1365 |
+
timestamp_ok = bool(
|
| 1366 |
+
np.isfinite(timestamp)
|
| 1367 |
+
and offline_timestamp_equal(float(timestamp), float(np.float32((int(np.rint(action.action_timestamp_s[0, horizon] / 0.05)) + 1) * 0.05)))
|
| 1368 |
+
)
|
| 1369 |
+
target_timestamp_valid[horizon] = timestamp_ok
|
| 1370 |
+
if not timestamp_ok:
|
| 1371 |
+
raise SourceAccessError("TARGET_TIMESTAMP_NOT_CONSECUTIVE_TICKS")
|
| 1372 |
+
target_timestamp[horizon] = timestamp
|
| 1373 |
+
future_pose = episode.pose[source_time, active_storage_slots]
|
| 1374 |
+
future_pose_valid = episode.pose_valid[source_time, active_storage_slots]
|
| 1375 |
+
valid = (
|
| 1376 |
+
target_node[horizon]
|
| 1377 |
+
& timestamp_ok
|
| 1378 |
+
& packet.pose_valid[0, 7]
|
| 1379 |
+
& future_pose_valid
|
| 1380 |
+
)
|
| 1381 |
+
target_pose_valid[horizon] = valid
|
| 1382 |
+
position_delta[horizon, valid] = (
|
| 1383 |
+
future_pose[valid, :3].astype(np.float64)
|
| 1384 |
+
- packet.pose[0, 7, valid, :3].astype(np.float64)
|
| 1385 |
+
).astype(np.float32)
|
| 1386 |
+
if valid.any():
|
| 1387 |
+
rotation_log[horizon, valid] = _relative_rotation_log(
|
| 1388 |
+
packet.pose[0, 7, valid, 3:7], future_pose[valid, 3:7]
|
| 1389 |
+
)
|
| 1390 |
+
valid_view = (
|
| 1391 |
+
episode.view_valid[source_time, active_storage_slots]
|
| 1392 |
+
& target_node[horizon, :, None]
|
| 1393 |
+
& timestamp_ok
|
| 1394 |
+
)
|
| 1395 |
+
target_view_valid[horizon] = valid_view
|
| 1396 |
+
target_view[horizon, valid_view] = episode.views[
|
| 1397 |
+
source_time, active_storage_slots
|
| 1398 |
+
][valid_view]
|
| 1399 |
+
if episode.c2.component_slot is not None and episode.c2.component_slot in storage_to_local:
|
| 1400 |
+
local = storage_to_local[episode.c2.component_slot]
|
| 1401 |
+
q_ok = bool(
|
| 1402 |
+
timestamp_ok
|
| 1403 |
+
and target_node[horizon, local]
|
| 1404 |
+
and packet.articulation_valid[0, 7, local, 0]
|
| 1405 |
+
and episode.c2.valid[source_time]
|
| 1406 |
+
)
|
| 1407 |
+
if q_ok:
|
| 1408 |
+
target_q_valid[horizon, local, 0] = True
|
| 1409 |
+
target_q_delta[horizon, local, 0] = np.float32(
|
| 1410 |
+
np.float64(episode.c2.q[source_time])
|
| 1411 |
+
- np.float64(packet.articulation_q[0, 7, local, 0])
|
| 1412 |
+
)
|
| 1413 |
+
|
| 1414 |
+
pair_index = canonical_pair_index(n)
|
| 1415 |
+
left, right = pair_index
|
| 1416 |
+
anchor_pair_valid = anchor_active[left] & anchor_active[right]
|
| 1417 |
+
|
| 1418 |
+
def contact_vector(source_time: int) -> np.ndarray:
|
| 1419 |
+
result = np.zeros(pair_index.shape[1], dtype=np.bool_)
|
| 1420 |
+
lookup = {
|
| 1421 |
+
(int(pair_left), int(pair_right)): index
|
| 1422 |
+
for index, (pair_left, pair_right) in enumerate(pair_index.T)
|
| 1423 |
+
}
|
| 1424 |
+
for storage_left, storage_right in episode.contacts[source_time]:
|
| 1425 |
+
if storage_left not in storage_to_local or storage_right not in storage_to_local:
|
| 1426 |
+
continue
|
| 1427 |
+
local_left = storage_to_local[storage_left]
|
| 1428 |
+
local_right = storage_to_local[storage_right]
|
| 1429 |
+
pair = (min(local_left, local_right), max(local_left, local_right))
|
| 1430 |
+
result[lookup[pair]] = True
|
| 1431 |
+
return result
|
| 1432 |
+
|
| 1433 |
+
def robot_target_vector(source_time: int) -> tuple[np.ndarray, np.ndarray]:
|
| 1434 |
+
result = np.zeros(n, dtype=np.bool_)
|
| 1435 |
+
robot_slots = {
|
| 1436 |
+
local
|
| 1437 |
+
for local, storage in enumerate(active_storage_slots.tolist())
|
| 1438 |
+
if episode.family_id[storage] == 9
|
| 1439 |
+
and episode.active[source_time, storage]
|
| 1440 |
+
}
|
| 1441 |
+
for storage_left, storage_right in episode.contacts[source_time]:
|
| 1442 |
+
if storage_left not in storage_to_local or storage_right not in storage_to_local:
|
| 1443 |
+
continue
|
| 1444 |
+
left = storage_to_local[storage_left]
|
| 1445 |
+
right = storage_to_local[storage_right]
|
| 1446 |
+
if (
|
| 1447 |
+
left in robot_slots
|
| 1448 |
+
and packet.is_task_target[0, right]
|
| 1449 |
+
and packet.task_target_valid[0, right]
|
| 1450 |
+
):
|
| 1451 |
+
result[right] = True
|
| 1452 |
+
if (
|
| 1453 |
+
right in robot_slots
|
| 1454 |
+
and packet.is_task_target[0, left]
|
| 1455 |
+
and packet.task_target_valid[0, left]
|
| 1456 |
+
):
|
| 1457 |
+
result[left] = True
|
| 1458 |
+
validity = np.asarray(packet.node_valid[0, 7], dtype=np.bool_) & packet.is_task_target[0] & packet.task_target_valid[0]
|
| 1459 |
+
return result, validity
|
| 1460 |
+
|
| 1461 |
+
anchor_source_time = int(target_frames[0] - 1)
|
| 1462 |
+
anchor_contact_source = contact_vector(anchor_source_time)
|
| 1463 |
+
anchor_contact_valid = anchor_pair_valid.copy()
|
| 1464 |
+
anchor_contact = anchor_contact_source & anchor_contact_valid
|
| 1465 |
+
target_pair_valid = np.zeros((8, pair_index.shape[1]), dtype=np.bool_)
|
| 1466 |
+
target_contact = np.zeros_like(target_pair_valid)
|
| 1467 |
+
target_event = np.zeros((8, pair_index.shape[1]), dtype=np.int64)
|
| 1468 |
+
target_event_valid = np.zeros_like(target_pair_valid)
|
| 1469 |
+
previous_contact = anchor_contact_source
|
| 1470 |
+
previous_valid = anchor_contact_valid
|
| 1471 |
+
anchor_robot_contact, anchor_robot_valid = robot_target_vector(anchor_source_time)
|
| 1472 |
+
previous_robot_contact = anchor_robot_contact.copy()
|
| 1473 |
+
previous_robot_valid = anchor_robot_valid.copy()
|
| 1474 |
+
for horizon, source_time in enumerate(target_frames.tolist()):
|
| 1475 |
+
pair_valid = (
|
| 1476 |
+
target_node[horizon, left]
|
| 1477 |
+
& target_node[horizon, right]
|
| 1478 |
+
& target_timestamp_valid[horizon]
|
| 1479 |
+
)
|
| 1480 |
+
current_source = contact_vector(source_time)
|
| 1481 |
+
target_pair_valid[horizon] = pair_valid
|
| 1482 |
+
target_contact[horizon] = current_source & pair_valid
|
| 1483 |
+
sequential = previous_valid & pair_valid
|
| 1484 |
+
target_event_valid[horizon] = sequential
|
| 1485 |
+
target_event[horizon, sequential & ~previous_contact & current_source] = 1
|
| 1486 |
+
target_event[horizon, sequential & previous_contact & current_source] = 2
|
| 1487 |
+
target_event[horizon, sequential & previous_contact & ~current_source] = 3
|
| 1488 |
+
previous_contact, previous_valid = current_source, pair_valid
|
| 1489 |
+
current_robot, robot_support = robot_target_vector(source_time)
|
| 1490 |
+
robot_valid = target_node[horizon] & target_timestamp_valid[horizon] & robot_support
|
| 1491 |
+
target_robot_contact[horizon] = current_robot & robot_valid
|
| 1492 |
+
target_robot_contact_valid[horizon] = robot_valid
|
| 1493 |
+
target_robot_event_valid[horizon] = previous_robot_valid & robot_valid
|
| 1494 |
+
sequential_robot = target_robot_event_valid[horizon]
|
| 1495 |
+
target_robot_event[horizon, sequential_robot & ~previous_robot_contact & current_robot] = 1
|
| 1496 |
+
target_robot_event[horizon, sequential_robot & previous_robot_contact & current_robot] = 2
|
| 1497 |
+
target_robot_event[horizon, sequential_robot & previous_robot_contact & ~current_robot] = 3
|
| 1498 |
+
previous_robot_contact, previous_robot_valid = current_robot, robot_valid
|
| 1499 |
+
|
| 1500 |
+
structural = np.zeros((n, n), dtype=np.int64)
|
| 1501 |
+
for row in episode.static_relations:
|
| 1502 |
+
if row.sender not in storage_to_local or row.receiver not in storage_to_local:
|
| 1503 |
+
continue
|
| 1504 |
+
sender, receiver = storage_to_local[row.sender], storage_to_local[row.receiver]
|
| 1505 |
+
code, inverse = (1, 2) if row.relation_id == 0 else (3, 4)
|
| 1506 |
+
existing, existing_inverse = structural[sender, receiver], structural[receiver, sender]
|
| 1507 |
+
if existing or existing_inverse:
|
| 1508 |
+
# The exporter records a handle-to-door edge as both
|
| 1509 |
+
# part_of and controls. Preserve both typed graph edges and
|
| 1510 |
+
# choose the deterministic controls code as the single dense
|
| 1511 |
+
# structural target representative.
|
| 1512 |
+
if existing == code and existing_inverse == inverse:
|
| 1513 |
+
continue
|
| 1514 |
+
if {existing, code} == {1, 3} and {existing_inverse, inverse} == {2, 4}:
|
| 1515 |
+
code, inverse = 3, 4
|
| 1516 |
+
else:
|
| 1517 |
+
raise SourceAccessError("STRUCTURAL_RELATION_CONFLICT")
|
| 1518 |
+
structural[sender, receiver] = code
|
| 1519 |
+
structural[receiver, sender] = inverse
|
| 1520 |
+
structural_valid = anchor_active[:, None] & anchor_active[None, :]
|
| 1521 |
+
np.fill_diagonal(structural_valid, False)
|
| 1522 |
+
structural[~structural_valid] = 0
|
| 1523 |
+
targets = CompactTargetsV3(
|
| 1524 |
+
pair_index=pair_index,
|
| 1525 |
+
anchor_pair_valid=freeze_array(anchor_pair_valid[None], dtype="|b1"),
|
| 1526 |
+
anchor_contact=freeze_array(anchor_contact[None], dtype="|b1"),
|
| 1527 |
+
anchor_contact_valid=freeze_array(anchor_contact_valid[None], dtype="|b1"),
|
| 1528 |
+
target_pair_valid=freeze_array(target_pair_valid[None], dtype="|b1"),
|
| 1529 |
+
target_contact_occupancy=freeze_array(target_contact[None], dtype="|b1"),
|
| 1530 |
+
target_contact_event=freeze_array(target_event[None], dtype="<i8"),
|
| 1531 |
+
target_contact_event_valid=freeze_array(target_event_valid[None], dtype="|b1"),
|
| 1532 |
+
target_robot_contact_occupancy=freeze_array(
|
| 1533 |
+
target_robot_contact[None], dtype="|b1"
|
| 1534 |
+
),
|
| 1535 |
+
target_robot_contact_occupancy_valid=freeze_array(
|
| 1536 |
+
target_robot_contact_valid[None], dtype="|b1"
|
| 1537 |
+
),
|
| 1538 |
+
target_robot_contact_event=freeze_array(target_robot_event[None], dtype="<i8"),
|
| 1539 |
+
target_robot_contact_event_valid=freeze_array(
|
| 1540 |
+
target_robot_event_valid[None], dtype="|b1"
|
| 1541 |
+
),
|
| 1542 |
+
target_node_valid=freeze_array(target_node[None], dtype="|b1"),
|
| 1543 |
+
target_timestamp_s=freeze_array(target_timestamp[None], dtype="<f8"),
|
| 1544 |
+
target_timestamp_valid=freeze_array(target_timestamp_valid[None], dtype="|b1"),
|
| 1545 |
+
target_position_delta=freeze_array(position_delta[None], dtype="<f4"),
|
| 1546 |
+
target_rotation_log=freeze_array(rotation_log[None], dtype="<f4"),
|
| 1547 |
+
target_pose_valid=freeze_array(target_pose_valid[None], dtype="|b1"),
|
| 1548 |
+
target_articulation_delta=freeze_array(target_q_delta[None], dtype="<f4"),
|
| 1549 |
+
target_articulation_valid=freeze_array(target_q_valid[None], dtype="|b1"),
|
| 1550 |
+
target_view_evidence=freeze_array(target_view[None], dtype="<f4"),
|
| 1551 |
+
target_view_record_valid=freeze_array(target_view_valid[None], dtype="|b1"),
|
| 1552 |
+
current_position=freeze_array(packet.pose[:, 7, :, :3], dtype="<f4"),
|
| 1553 |
+
current_rotation_quat_xyzw=freeze_array(packet.pose[:, 7, :, 3:7], dtype="<f4"),
|
| 1554 |
+
current_pose_valid=freeze_array(packet.pose_valid[:, 7], dtype="|b1"),
|
| 1555 |
+
current_articulation_q=freeze_array(packet.articulation_q[:, 7], dtype="<f4"),
|
| 1556 |
+
current_articulation_valid=freeze_array(packet.articulation_valid[:, 7], dtype="|b1"),
|
| 1557 |
+
current_contact=freeze_array(anchor_contact[None], dtype="|b1"),
|
| 1558 |
+
current_contact_valid=freeze_array(anchor_contact_valid[None], dtype="|b1"),
|
| 1559 |
+
current_robot_target_contact=freeze_array(
|
| 1560 |
+
packet.robot_target_contact[:, 7], dtype="|b1"
|
| 1561 |
+
),
|
| 1562 |
+
current_robot_target_contact_valid=freeze_array(
|
| 1563 |
+
packet.robot_target_contact_valid[:, 7], dtype="|b1"
|
| 1564 |
+
),
|
| 1565 |
+
current_view_evidence=freeze_array(packet.view_evidence[:, 7], dtype="<f4"),
|
| 1566 |
+
current_view_record_valid=freeze_array(packet.view_record_valid[:, 7], dtype="|b1"),
|
| 1567 |
+
current_structural_relation=freeze_array(structural[None], dtype="<i8"),
|
| 1568 |
+
current_structural_valid=freeze_array(structural_valid[None], dtype="|b1"),
|
| 1569 |
+
)
|
| 1570 |
+
targets.validate(packet, action)
|
| 1571 |
+
return targets
|
| 1572 |
+
|
| 1573 |
+
|
| 1574 |
+
__all__ = [
|
| 1575 |
+
"CompactEpisodeDescriptorV3",
|
| 1576 |
+
"DirectCompactSourceV3",
|
| 1577 |
+
"OPAQUE_ONLY_MEMBER_LEAVES",
|
| 1578 |
+
"REQUIRED_MEMBER_LEAVES",
|
| 1579 |
+
"SourceAccessError",
|
| 1580 |
+
"SourceAccessTraceV3",
|
| 1581 |
+
"AuthenticatedEpisodeHandleV3",
|
| 1582 |
+
"array_sha256",
|
| 1583 |
+
"canonical_json_bytes",
|
| 1584 |
+
]
|
gwam_active13_gwam_training_v3_20260801/loader/gwam_conditioning.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""CPU reference graph-to-GWAM conditioning seam; no external GWAM is loaded."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
import torch
|
| 4 |
+
from torch import nn
|
| 5 |
+
|
| 6 |
+
class ZeroGatedGWAMConditionerV3(nn.Module):
|
| 7 |
+
def __init__(self, graph_width: int = 384, gwam_width: int = 384, heads: int = 8):
|
| 8 |
+
super().__init__()
|
| 9 |
+
if graph_width <= 0 or gwam_width <= 0 or gwam_width % heads: raise ValueError("width/head")
|
| 10 |
+
self.projector=nn.Linear(graph_width, gwam_width)
|
| 11 |
+
self.cross_attention=nn.MultiheadAttention(gwam_width, heads, batch_first=True)
|
| 12 |
+
self.gate=nn.Parameter(torch.zeros((), dtype=torch.float32))
|
| 13 |
+
|
| 14 |
+
def forward(self, shared_latent: torch.Tensor, graph_tokens: torch.Tensor, *, mode: str = "on") -> torch.Tensor:
|
| 15 |
+
if shared_latent.ndim != 3 or graph_tokens.ndim != 3 or graph_tokens.shape[1:] != (16,384):
|
| 16 |
+
raise ValueError("GWAM_GRAPH_TOKEN_SHAPE")
|
| 17 |
+
if shared_latent.shape[0] != graph_tokens.shape[0] or shared_latent.shape[2] != self.projector.out_features:
|
| 18 |
+
raise ValueError("GWAM_LATENT_SHAPE")
|
| 19 |
+
baseline=shared_latent
|
| 20 |
+
if mode in ("off", "zero"): return baseline
|
| 21 |
+
if mode == "shuffle": graph_tokens=graph_tokens.flip(0)
|
| 22 |
+
elif mode == "detach": graph_tokens=graph_tokens.detach()
|
| 23 |
+
elif mode != "on": raise ValueError("GWAM_MODE")
|
| 24 |
+
context,_=self.cross_attention(baseline, self.projector(graph_tokens), self.projector(graph_tokens), need_weights=False)
|
| 25 |
+
return baseline + torch.tanh(self.gate).to(dtype=baseline.dtype) * context
|
| 26 |
+
|
| 27 |
+
def encode_compact_to_k16(example, *, seed: int = 20260731) -> torch.Tensor:
|
| 28 |
+
"""Use the sealed v2.0.4 equations as an audit-only CPU encoder."""
|
| 29 |
+
from .compact_collate import collate_compact_examples_v3
|
| 30 |
+
from .sealed_model_regression import to_sealed_v2_0_4_regression_batch
|
| 31 |
+
# The exact sealed v2.0.4 architecture source is bundled in this release so
|
| 32 |
+
# a fresh Hugging Face download can reproduce K=16 without the development
|
| 33 |
+
# repository on PYTHONPATH.
|
| 34 |
+
from model_v2_0_4.config import make_run_config
|
| 35 |
+
from model_v2_0_4.model import CompactTargetConditionedGNN
|
| 36 |
+
torch.manual_seed(seed); model=CompactTargetConditionedGNN(make_run_config("candidate_correct_target")); model.eval()
|
| 37 |
+
batch=to_sealed_v2_0_4_regression_batch(collate_compact_examples_v3((example,)))
|
| 38 |
+
with torch.no_grad(): out=model.encode_to_anchor_tokens(batch)
|
| 39 |
+
if out.shape != (1,16,384): raise RuntimeError("K16_SHAPE")
|
| 40 |
+
return out
|
| 41 |
+
|
| 42 |
+
__all__=["ZeroGatedGWAMConditionerV3","encode_compact_to_k16"]
|
gwam_active13_gwam_training_v3_20260801/loader/online_compact_adapter.py
ADDED
|
@@ -0,0 +1,516 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Backend-free eight-frame online compact adapter.
|
| 2 |
+
|
| 3 |
+
The adapter accepts already reduced physical records and an authenticated,
|
| 4 |
+
reset-bound static target capability. It does not import a simulator graph
|
| 5 |
+
extractor or a learned visual component, and it cannot manufacture the frozen
|
| 6 |
+
outer-train provenance required by the training batch.
|
| 7 |
+
"""
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import hashlib
|
| 11 |
+
import json
|
| 12 |
+
from dataclasses import dataclass
|
| 13 |
+
|
| 14 |
+
import numpy as np
|
| 15 |
+
from .temporal_precision import online_step_close
|
| 16 |
+
|
| 17 |
+
from .compact_contract import (
|
| 18 |
+
CompactActionConditionV3,
|
| 19 |
+
CompactContractError,
|
| 20 |
+
CompactGraphPacketV3,
|
| 21 |
+
MODEL_PROFILE_ID,
|
| 22 |
+
RELATION_REGISTRY_SHA256,
|
| 23 |
+
TARGET_RESOLVER_SHA256,
|
| 24 |
+
canonical_ordered_route_index,
|
| 25 |
+
derive_robot_target_contact,
|
| 26 |
+
freeze_array,
|
| 27 |
+
)
|
| 28 |
+
from .direct_compact_source import canonical_json_bytes
|
| 29 |
+
from .relation_geometry import RelationTripleV3, assemble_relations_metric12
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class CompactOnlineContractError(CompactContractError):
|
| 33 |
+
"""Online buffer, reset capability, or physical record is invalid."""
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def _digest(value: object) -> bool:
|
| 37 |
+
return type(value) is str and len(value) == 64 and all(
|
| 38 |
+
char in "0123456789abcdef" for char in value
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def online_inventory_sha256(
|
| 43 |
+
slot_id: np.ndarray, family_id: np.ndarray, static_flags: np.ndarray
|
| 44 |
+
) -> str:
|
| 45 |
+
slot_id = np.asarray(slot_id)
|
| 46 |
+
family_id = np.asarray(family_id)
|
| 47 |
+
static_flags = np.asarray(static_flags)
|
| 48 |
+
n = slot_id.size
|
| 49 |
+
if (
|
| 50 |
+
slot_id.dtype != np.int16
|
| 51 |
+
or slot_id.shape != (n,)
|
| 52 |
+
or family_id.dtype != np.int64
|
| 53 |
+
or family_id.shape != (n,)
|
| 54 |
+
or static_flags.dtype != np.bool_
|
| 55 |
+
or static_flags.shape != (n, 2)
|
| 56 |
+
or not 1 <= n <= 256
|
| 57 |
+
):
|
| 58 |
+
raise CompactOnlineContractError("INVENTORY_SHAPE_OR_DTYPE")
|
| 59 |
+
value = {
|
| 60 |
+
"family_id": family_id.tolist(),
|
| 61 |
+
"schema": "gwam.compact.online_inventory.v3",
|
| 62 |
+
"slot_id": slot_id.tolist(),
|
| 63 |
+
"static_flags": static_flags.astype(np.uint8).tolist(),
|
| 64 |
+
}
|
| 65 |
+
return hashlib.sha256(canonical_json_bytes(value)).hexdigest()
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _unpack_bits(value: object, n: int, label: str) -> np.ndarray:
|
| 69 |
+
if type(value) is not str:
|
| 70 |
+
raise CompactOnlineContractError(f"CAPABILITY_{label}_BITS")
|
| 71 |
+
try:
|
| 72 |
+
payload = bytes.fromhex(value)
|
| 73 |
+
except ValueError as error:
|
| 74 |
+
raise CompactOnlineContractError(f"CAPABILITY_{label}_BITS") from error
|
| 75 |
+
if len(payload) != (n + 7) // 8:
|
| 76 |
+
raise CompactOnlineContractError(f"CAPABILITY_{label}_BITS")
|
| 77 |
+
unpacked = np.unpackbits(np.frombuffer(payload, dtype=np.uint8), bitorder="little")
|
| 78 |
+
if unpacked[n:].any():
|
| 79 |
+
raise CompactOnlineContractError(f"CAPABILITY_{label}_PADDING")
|
| 80 |
+
return freeze_array(unpacked[:n].astype(np.bool_), dtype="|b1")
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
@dataclass(frozen=True, slots=True)
|
| 84 |
+
class TrustedResetTargetAuthorityV3:
|
| 85 |
+
"""Independent reset binding used to authenticate a target receipt."""
|
| 86 |
+
reset_nonce: str
|
| 87 |
+
inventory_sha256: str
|
| 88 |
+
episode_key: str
|
| 89 |
+
task: str
|
| 90 |
+
source_group_id: str
|
| 91 |
+
slot_id: tuple[int, ...]
|
| 92 |
+
is_task_target: bytes
|
| 93 |
+
task_target_valid: bytes
|
| 94 |
+
task_target_source_code: tuple[int, ...]
|
| 95 |
+
static_relations: tuple[tuple[int, int, int], ...]
|
| 96 |
+
source_target_receipt_sha256: str
|
| 97 |
+
graph_static_sha256: str
|
| 98 |
+
authority_provenance_sha256: str
|
| 99 |
+
|
| 100 |
+
@classmethod
|
| 101 |
+
def from_trusted_metadata(cls, *, reset_nonce: str, inventory_sha256: str,
|
| 102 |
+
episode_key: str, task: str, source_group_id: str,
|
| 103 |
+
slot_id: tuple[int, ...], is_task_target: np.ndarray,
|
| 104 |
+
task_target_valid: np.ndarray, task_target_source_code: tuple[int, ...],
|
| 105 |
+
static_relations: tuple[tuple[int, int, int], ...],
|
| 106 |
+
source_target_receipt_sha256: str, graph_static_sha256: str,
|
| 107 |
+
authority_provenance_sha256: str) -> "TrustedResetTargetAuthorityV3":
|
| 108 |
+
return cls(
|
| 109 |
+
reset_nonce, inventory_sha256, episode_key, task, source_group_id, tuple(slot_id),
|
| 110 |
+
np.packbits(np.asarray(is_task_target, dtype=np.bool_), bitorder="little").tobytes(),
|
| 111 |
+
np.packbits(np.asarray(task_target_valid, dtype=np.bool_), bitorder="little").tobytes(),
|
| 112 |
+
tuple(int(v) for v in task_target_source_code), tuple(static_relations),
|
| 113 |
+
source_target_receipt_sha256, graph_static_sha256, authority_provenance_sha256,
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
def verify(self, capability: "AuthenticatedResetTargetCapabilityV3") -> None:
|
| 117 |
+
fields = ("reset_nonce", "inventory_sha256", "episode_key", "task", "source_group_id",
|
| 118 |
+
"source_target_receipt_sha256", "graph_static_sha256")
|
| 119 |
+
if any(getattr(self, f) != getattr(capability, f) for f in fields):
|
| 120 |
+
raise CompactOnlineContractError("CAPABILITY_UNTRUSTED_RESET_BINDING")
|
| 121 |
+
if self.slot_id != tuple(int(v) for v in capability.slot_id.tolist()):
|
| 122 |
+
raise CompactOnlineContractError("CAPABILITY_UNTRUSTED_SLOT_ID")
|
| 123 |
+
if self.is_task_target != np.packbits(capability.is_task_target, bitorder="little").tobytes():
|
| 124 |
+
raise CompactOnlineContractError("CAPABILITY_UNTRUSTED_TARGET_BITS")
|
| 125 |
+
if self.task_target_valid != np.packbits(capability.task_target_valid, bitorder="little").tobytes():
|
| 126 |
+
raise CompactOnlineContractError("CAPABILITY_UNTRUSTED_VALID_BITS")
|
| 127 |
+
if self.task_target_source_code != tuple(int(v) for v in capability.task_target_source_code.tolist()):
|
| 128 |
+
raise CompactOnlineContractError("CAPABILITY_UNTRUSTED_SOURCE_CODES")
|
| 129 |
+
if self.static_relations != capability.static_relations:
|
| 130 |
+
raise CompactOnlineContractError("CAPABILITY_UNTRUSTED_RELATIONS")
|
| 131 |
+
if capability.authority_provenance_sha256 != self.authority_provenance_sha256:
|
| 132 |
+
raise CompactOnlineContractError("CAPABILITY_UNTRUSTED_AUTHORITY_PROVENANCE")
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
@dataclass(frozen=True, slots=True)
|
| 136 |
+
class AuthenticatedResetTargetCapabilityV3:
|
| 137 |
+
receipt_bytes: bytes
|
| 138 |
+
receipt_sha256: str
|
| 139 |
+
reset_nonce: str
|
| 140 |
+
inventory_sha256: str
|
| 141 |
+
episode_key: str
|
| 142 |
+
task: str
|
| 143 |
+
source_group_id: str
|
| 144 |
+
slot_id: np.ndarray
|
| 145 |
+
is_task_target: np.ndarray
|
| 146 |
+
task_target_valid: np.ndarray
|
| 147 |
+
task_target_source_code: np.ndarray
|
| 148 |
+
static_relations: tuple[tuple[int, int, int], ...]
|
| 149 |
+
source_target_receipt_sha256: str
|
| 150 |
+
graph_static_sha256: str
|
| 151 |
+
authority_provenance_sha256: str
|
| 152 |
+
|
| 153 |
+
@classmethod
|
| 154 |
+
def from_receipt(
|
| 155 |
+
cls, receipt_bytes: bytes, receipt_sha256: str, *,
|
| 156 |
+
authority: TrustedResetTargetAuthorityV3 | None = None,
|
| 157 |
+
) -> "AuthenticatedResetTargetCapabilityV3":
|
| 158 |
+
if authority is None:
|
| 159 |
+
raise CompactOnlineContractError("CAPABILITY_TRUSTED_AUTHORITY_REQUIRED")
|
| 160 |
+
if type(receipt_bytes) is not bytes or not _digest(receipt_sha256) or hashlib.sha256(
|
| 161 |
+
receipt_bytes
|
| 162 |
+
).hexdigest() != receipt_sha256:
|
| 163 |
+
raise CompactOnlineContractError("CAPABILITY_RECEIPT_SHA256")
|
| 164 |
+
try:
|
| 165 |
+
value = json.loads(receipt_bytes)
|
| 166 |
+
except (UnicodeDecodeError, json.JSONDecodeError) as error:
|
| 167 |
+
raise CompactOnlineContractError("CAPABILITY_RECEIPT_JSON") from error
|
| 168 |
+
expected_fields = {
|
| 169 |
+
"episode_key",
|
| 170 |
+
"graph_profile_id",
|
| 171 |
+
"graph_static_sha256",
|
| 172 |
+
"authority_provenance_sha256",
|
| 173 |
+
"inventory_sha256",
|
| 174 |
+
"relation_registry_sha256",
|
| 175 |
+
"reset_nonce",
|
| 176 |
+
"resolver_sha256",
|
| 177 |
+
"schema",
|
| 178 |
+
"slot_id",
|
| 179 |
+
"source_group_id",
|
| 180 |
+
"source_target_receipt_sha256",
|
| 181 |
+
"static_relations",
|
| 182 |
+
"target_bitset_hex",
|
| 183 |
+
"target_source_codes",
|
| 184 |
+
"target_valid_bitset_hex",
|
| 185 |
+
"task",
|
| 186 |
+
}
|
| 187 |
+
if type(value) is not dict or set(value) != expected_fields or canonical_json_bytes(
|
| 188 |
+
value
|
| 189 |
+
) != receipt_bytes:
|
| 190 |
+
raise CompactOnlineContractError("CAPABILITY_RECEIPT_FIELDS_OR_CANONICAL")
|
| 191 |
+
if not (
|
| 192 |
+
value["schema"] == "gwam.authenticated_reset_target_capability.v3"
|
| 193 |
+
and value["graph_profile_id"] == MODEL_PROFILE_ID
|
| 194 |
+
and value["relation_registry_sha256"] == RELATION_REGISTRY_SHA256
|
| 195 |
+
and value["resolver_sha256"] == TARGET_RESOLVER_SHA256
|
| 196 |
+
and _digest(value["reset_nonce"])
|
| 197 |
+
and _digest(value["inventory_sha256"])
|
| 198 |
+
and _digest(value["source_target_receipt_sha256"])
|
| 199 |
+
and _digest(value["graph_static_sha256"])
|
| 200 |
+
and _digest(value["authority_provenance_sha256"])
|
| 201 |
+
and type(value["episode_key"]) is str
|
| 202 |
+
and type(value["task"]) is str
|
| 203 |
+
and type(value["source_group_id"]) is str
|
| 204 |
+
):
|
| 205 |
+
raise CompactOnlineContractError("CAPABILITY_RECEIPT_BINDING")
|
| 206 |
+
slots = value["slot_id"]
|
| 207 |
+
if (
|
| 208 |
+
type(slots) is not list
|
| 209 |
+
or not 1 <= len(slots) <= 256
|
| 210 |
+
or any(type(slot) is not int or not 0 <= slot < 256 for slot in slots)
|
| 211 |
+
or slots != sorted(set(slots))
|
| 212 |
+
):
|
| 213 |
+
raise CompactOnlineContractError("CAPABILITY_SLOT_ID")
|
| 214 |
+
n = len(slots)
|
| 215 |
+
target = _unpack_bits(value["target_bitset_hex"], n, "TARGET")
|
| 216 |
+
valid = _unpack_bits(value["target_valid_bitset_hex"], n, "VALID")
|
| 217 |
+
if np.any(target & ~valid) or not target.any():
|
| 218 |
+
raise CompactOnlineContractError("CAPABILITY_TARGET_VALIDITY")
|
| 219 |
+
codes = value["target_source_codes"]
|
| 220 |
+
if type(codes) is not list or len(codes) != n or any(
|
| 221 |
+
type(code) is not int or not 0 <= code <= 6 for code in codes
|
| 222 |
+
):
|
| 223 |
+
raise CompactOnlineContractError("CAPABILITY_TARGET_SOURCE_CODE")
|
| 224 |
+
code_array = np.asarray(codes, dtype=np.uint8)
|
| 225 |
+
if np.any((code_array == 0) != ~valid):
|
| 226 |
+
raise CompactOnlineContractError("CAPABILITY_TARGET_SOURCE_VALIDITY")
|
| 227 |
+
relations = value["static_relations"]
|
| 228 |
+
if type(relations) is not list:
|
| 229 |
+
raise CompactOnlineContractError("CAPABILITY_STATIC_RELATIONS")
|
| 230 |
+
relation_rows: list[tuple[int, int, int]] = []
|
| 231 |
+
slot_set = set(slots)
|
| 232 |
+
for row in relations:
|
| 233 |
+
if type(row) is not dict or set(row) != {
|
| 234 |
+
"sender_slot",
|
| 235 |
+
"receiver_slot",
|
| 236 |
+
"relation_id",
|
| 237 |
+
}:
|
| 238 |
+
raise CompactOnlineContractError("CAPABILITY_STATIC_RELATION_ROW")
|
| 239 |
+
triple = (row["sender_slot"], row["receiver_slot"], row["relation_id"])
|
| 240 |
+
if (
|
| 241 |
+
type(triple[0]) is not int
|
| 242 |
+
or type(triple[1]) is not int
|
| 243 |
+
or type(triple[2]) is not int
|
| 244 |
+
or triple[0] not in slot_set
|
| 245 |
+
or triple[1] not in slot_set
|
| 246 |
+
or triple[0] == triple[1]
|
| 247 |
+
or triple[2] not in (0, 2)
|
| 248 |
+
):
|
| 249 |
+
raise CompactOnlineContractError("CAPABILITY_STATIC_RELATION_VALUE")
|
| 250 |
+
relation_rows.append(triple)
|
| 251 |
+
if len(relation_rows) != len(set(relation_rows)):
|
| 252 |
+
raise CompactOnlineContractError("CAPABILITY_STATIC_RELATION_DUPLICATE")
|
| 253 |
+
result = cls(
|
| 254 |
+
receipt_bytes,
|
| 255 |
+
receipt_sha256,
|
| 256 |
+
value["reset_nonce"],
|
| 257 |
+
value["inventory_sha256"],
|
| 258 |
+
value["episode_key"],
|
| 259 |
+
value["task"],
|
| 260 |
+
value["source_group_id"],
|
| 261 |
+
freeze_array(np.asarray(slots, dtype=np.int16), dtype="<i2"),
|
| 262 |
+
target,
|
| 263 |
+
valid,
|
| 264 |
+
freeze_array(code_array, dtype="|u1"),
|
| 265 |
+
tuple(relation_rows),
|
| 266 |
+
value["source_target_receipt_sha256"],
|
| 267 |
+
value["graph_static_sha256"],
|
| 268 |
+
value["authority_provenance_sha256"],
|
| 269 |
+
)
|
| 270 |
+
authority.verify(result)
|
| 271 |
+
return result
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
@dataclass(frozen=True, slots=True)
|
| 275 |
+
class CompactOnlineFrameV3:
|
| 276 |
+
reset_nonce: str
|
| 277 |
+
inventory_sha256: str
|
| 278 |
+
timestamp_s: float
|
| 279 |
+
slot_id: np.ndarray
|
| 280 |
+
family_id: np.ndarray
|
| 281 |
+
static_flags: np.ndarray
|
| 282 |
+
node_valid: np.ndarray
|
| 283 |
+
pose: np.ndarray
|
| 284 |
+
pose_valid: np.ndarray
|
| 285 |
+
articulation_q: np.ndarray
|
| 286 |
+
articulation_valid: np.ndarray
|
| 287 |
+
view_evidence: np.ndarray
|
| 288 |
+
view_record_valid: np.ndarray
|
| 289 |
+
contacts: tuple[tuple[int, int], ...]
|
| 290 |
+
|
| 291 |
+
@classmethod
|
| 292 |
+
def from_packet_frame(
|
| 293 |
+
cls,
|
| 294 |
+
packet: CompactGraphPacketV3,
|
| 295 |
+
*,
|
| 296 |
+
time_index: int,
|
| 297 |
+
reset_nonce: str,
|
| 298 |
+
inventory_sha256: str,
|
| 299 |
+
contacts: tuple[tuple[int, int], ...],
|
| 300 |
+
) -> "CompactOnlineFrameV3":
|
| 301 |
+
packet.validate()
|
| 302 |
+
if packet.batch_size != 1 or type(time_index) is not int or not 0 <= time_index < 8:
|
| 303 |
+
raise CompactOnlineContractError("PACKET_FRAME_SOURCE")
|
| 304 |
+
return cls(
|
| 305 |
+
reset_nonce,
|
| 306 |
+
inventory_sha256,
|
| 307 |
+
float(packet.timestamp_s[0, time_index]),
|
| 308 |
+
packet.slot_id[0],
|
| 309 |
+
packet.family_id[0],
|
| 310 |
+
packet.static_flags[0],
|
| 311 |
+
packet.node_valid[0, time_index],
|
| 312 |
+
packet.pose[0, time_index],
|
| 313 |
+
packet.pose_valid[0, time_index],
|
| 314 |
+
packet.articulation_q[0, time_index],
|
| 315 |
+
packet.articulation_valid[0, time_index],
|
| 316 |
+
packet.view_evidence[0, time_index],
|
| 317 |
+
packet.view_record_valid[0, time_index],
|
| 318 |
+
contacts,
|
| 319 |
+
)
|
| 320 |
+
|
| 321 |
+
def validate(self) -> None:
|
| 322 |
+
n = self.slot_id.size
|
| 323 |
+
expected = (
|
| 324 |
+
("slot_id", self.slot_id, np.dtype("<i2"), (n,)),
|
| 325 |
+
("family_id", self.family_id, np.dtype("<i8"), (n,)),
|
| 326 |
+
("static_flags", self.static_flags, np.dtype("|b1"), (n, 2)),
|
| 327 |
+
("node_valid", self.node_valid, np.dtype("|b1"), (n,)),
|
| 328 |
+
("pose", self.pose, np.dtype("<f4"), (n, 7)),
|
| 329 |
+
("pose_valid", self.pose_valid, np.dtype("|b1"), (n,)),
|
| 330 |
+
("articulation_q", self.articulation_q, np.dtype("<f4"), (n, 1)),
|
| 331 |
+
("articulation_valid", self.articulation_valid, np.dtype("|b1"), (n, 1)),
|
| 332 |
+
("view_evidence", self.view_evidence, np.dtype("<f4"), (n, 3, 8)),
|
| 333 |
+
("view_record_valid", self.view_record_valid, np.dtype("|b1"), (n, 3)),
|
| 334 |
+
)
|
| 335 |
+
if not 1 <= n <= 256 or not _digest(self.reset_nonce) or not _digest(
|
| 336 |
+
self.inventory_sha256
|
| 337 |
+
) or not np.isfinite(self.timestamp_s):
|
| 338 |
+
raise CompactOnlineContractError("FRAME_SCALAR_BINDING")
|
| 339 |
+
for name, value, dtype, shape in expected:
|
| 340 |
+
if (
|
| 341 |
+
type(value) is not np.ndarray
|
| 342 |
+
or value.dtype != dtype
|
| 343 |
+
or value.shape != shape
|
| 344 |
+
or not value.flags.c_contiguous
|
| 345 |
+
or value.flags.writeable
|
| 346 |
+
):
|
| 347 |
+
raise CompactOnlineContractError(f"FRAME_{name.upper()}")
|
| 348 |
+
if self.slot_id.tolist() != sorted(set(self.slot_id.tolist())):
|
| 349 |
+
raise CompactOnlineContractError("FRAME_SLOT_ID")
|
| 350 |
+
if self.inventory_sha256 != online_inventory_sha256(
|
| 351 |
+
self.slot_id, self.family_id, self.static_flags
|
| 352 |
+
):
|
| 353 |
+
raise CompactOnlineContractError("FRAME_INVENTORY_DIGEST")
|
| 354 |
+
if np.any(self.pose_valid & ~self.node_valid) or np.any(
|
| 355 |
+
self.articulation_valid[:, 0] & ~self.node_valid
|
| 356 |
+
) or np.any(self.view_record_valid & ~self.node_valid[:, None]):
|
| 357 |
+
raise CompactOnlineContractError("FRAME_VALIDITY_CEILING")
|
| 358 |
+
if np.any(self.pose[~self.pose_valid] != 0.0) or np.any(
|
| 359 |
+
self.articulation_q[~self.articulation_valid] != 0.0
|
| 360 |
+
) or np.any(self.view_evidence[~self.view_record_valid] != 0.0):
|
| 361 |
+
raise CompactOnlineContractError("FRAME_INVALID_NONZERO")
|
| 362 |
+
slot_set = set(self.slot_id.tolist())
|
| 363 |
+
if type(self.contacts) is not tuple:
|
| 364 |
+
raise CompactOnlineContractError("FRAME_CONTACTS_TYPE")
|
| 365 |
+
for pair in self.contacts:
|
| 366 |
+
if (
|
| 367 |
+
type(pair) is not tuple
|
| 368 |
+
or len(pair) != 2
|
| 369 |
+
or type(pair[0]) is not int
|
| 370 |
+
or type(pair[1]) is not int
|
| 371 |
+
or pair[0] not in slot_set
|
| 372 |
+
or pair[1] not in slot_set
|
| 373 |
+
or pair[0] >= pair[1]
|
| 374 |
+
):
|
| 375 |
+
raise CompactOnlineContractError("FRAME_CONTACT_VALUE")
|
| 376 |
+
if tuple(sorted(set(self.contacts))) != self.contacts:
|
| 377 |
+
raise CompactOnlineContractError("FRAME_CONTACT_ORDER")
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
@dataclass(frozen=True, slots=True)
|
| 381 |
+
class CompactOnlineInputV3:
|
| 382 |
+
packet: CompactGraphPacketV3
|
| 383 |
+
action: CompactActionConditionV3
|
| 384 |
+
capability_receipt_sha256: str
|
| 385 |
+
|
| 386 |
+
def validate(self) -> None:
|
| 387 |
+
if type(self.packet) is not CompactGraphPacketV3 or type(
|
| 388 |
+
self.action
|
| 389 |
+
) is not CompactActionConditionV3 or not _digest(self.capability_receipt_sha256):
|
| 390 |
+
raise CompactOnlineContractError("ONLINE_INPUT_TYPE_OR_BINDING")
|
| 391 |
+
self.packet.validate()
|
| 392 |
+
self.action.validate(self.packet)
|
| 393 |
+
|
| 394 |
+
def as_training_example(self) -> None:
|
| 395 |
+
raise CompactOnlineContractError("TRAINING_PROVENANCE_CANNOT_BE_FORGED")
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
class CompactOnlineHistoryBufferV3:
|
| 399 |
+
def __init__(self, capability: AuthenticatedResetTargetCapabilityV3 | None) -> None:
|
| 400 |
+
if type(capability) is not AuthenticatedResetTargetCapabilityV3:
|
| 401 |
+
raise CompactOnlineContractError("AUTHENTICATED_CAPABILITY_REQUIRED")
|
| 402 |
+
self.capability = capability
|
| 403 |
+
self._frames: list[CompactOnlineFrameV3] = []
|
| 404 |
+
|
| 405 |
+
def append(self, frame: CompactOnlineFrameV3) -> None:
|
| 406 |
+
if type(frame) is not CompactOnlineFrameV3:
|
| 407 |
+
raise CompactOnlineContractError("FRAME_EXACT_TYPE")
|
| 408 |
+
frame.validate()
|
| 409 |
+
if frame.reset_nonce != self.capability.reset_nonce:
|
| 410 |
+
raise CompactOnlineContractError("FRAME_RESET_BINDING")
|
| 411 |
+
if frame.inventory_sha256 != self.capability.inventory_sha256:
|
| 412 |
+
raise CompactOnlineContractError("FRAME_INVENTORY_BINDING")
|
| 413 |
+
if not np.array_equal(frame.slot_id, self.capability.slot_id):
|
| 414 |
+
raise CompactOnlineContractError("FRAME_SLOT_BINDING")
|
| 415 |
+
if self._frames and not online_step_close(self._frames[-1].timestamp_s, frame.timestamp_s):
|
| 416 |
+
raise CompactOnlineContractError("FRAME_TIMESTAMP_CADENCE")
|
| 417 |
+
if len(self._frames) >= 8:
|
| 418 |
+
raise CompactOnlineContractError("HISTORY_ALREADY_FULL")
|
| 419 |
+
self._frames.append(frame)
|
| 420 |
+
|
| 421 |
+
def materialize(self, action: CompactActionConditionV3) -> CompactOnlineInputV3:
|
| 422 |
+
if len(self._frames) != 8:
|
| 423 |
+
raise CompactOnlineContractError("HISTORY_UNDERFILLED")
|
| 424 |
+
if type(action) is not CompactActionConditionV3 or action.batch_size != 1:
|
| 425 |
+
raise CompactOnlineContractError("ACTION_EXACT_TYPE")
|
| 426 |
+
frames = tuple(self._frames)
|
| 427 |
+
n = frames[0].slot_id.size
|
| 428 |
+
slot_to_local = {int(slot): index for index, slot in enumerate(frames[0].slot_id)}
|
| 429 |
+
static = tuple(
|
| 430 |
+
RelationTripleV3(slot_to_local[left], slot_to_local[right], relation)
|
| 431 |
+
for left, right, relation in self.capability.static_relations
|
| 432 |
+
)
|
| 433 |
+
contacts = tuple(
|
| 434 |
+
tuple((slot_to_local[left], slot_to_local[right]) for left, right in frame.contacts)
|
| 435 |
+
for frame in frames
|
| 436 |
+
)
|
| 437 |
+
pose = np.stack([frame.pose for frame in frames]).astype(np.float32)
|
| 438 |
+
pose_valid = np.stack([frame.pose_valid for frame in frames]).astype(np.bool_)
|
| 439 |
+
node_valid = np.stack([frame.node_valid for frame in frames]).astype(np.bool_)
|
| 440 |
+
relations = assemble_relations_metric12(pose, pose_valid, static, contacts)
|
| 441 |
+
robot_contact, robot_contact_valid = derive_robot_target_contact(
|
| 442 |
+
node_valid=node_valid[None],
|
| 443 |
+
family_id=frames[0].family_id[None],
|
| 444 |
+
target=self.capability.is_task_target[None],
|
| 445 |
+
target_valid=self.capability.task_target_valid[None],
|
| 446 |
+
edge_index=relations.index,
|
| 447 |
+
edge_batch=relations.batch,
|
| 448 |
+
edge_time=relations.time,
|
| 449 |
+
edge_relation_id=relations.relation_id,
|
| 450 |
+
edge_payload_valid=relations.payload_valid,
|
| 451 |
+
)
|
| 452 |
+
# Online float64 timestamps are projected onto the frozen offline
|
| 453 |
+
# float32 lattice only at packet materialization.
|
| 454 |
+
raw_timestamps = np.asarray([frame.timestamp_s for frame in frames], dtype=np.float64)
|
| 455 |
+
timestamps = np.asarray(np.float32(np.rint(raw_timestamps / 0.05) * 0.05), dtype=np.float64)
|
| 456 |
+
routes = canonical_ordered_route_index(n)
|
| 457 |
+
packet = CompactGraphPacketV3(
|
| 458 |
+
history_valid=freeze_array(np.ones((1, 8), dtype=np.bool_), dtype="|b1"),
|
| 459 |
+
timestamp_s=freeze_array(timestamps[None], dtype="<f8"),
|
| 460 |
+
timestamp_valid=freeze_array(np.ones((1, 8), dtype=np.bool_), dtype="|b1"),
|
| 461 |
+
delta_t_s=freeze_array(np.full((1, 7), 0.05, dtype=np.float32), dtype="<f4"),
|
| 462 |
+
delta_t_valid=freeze_array(np.ones((1, 7), dtype=np.bool_), dtype="|b1"),
|
| 463 |
+
slot_id=freeze_array(frames[0].slot_id[None], dtype="<i2"),
|
| 464 |
+
ordered_route_index=routes,
|
| 465 |
+
ordered_route_valid=freeze_array(
|
| 466 |
+
(node_valid[7, routes[0]] & node_valid[7, routes[1]])[None], dtype="|b1"
|
| 467 |
+
),
|
| 468 |
+
node_valid=freeze_array(node_valid[None], dtype="|b1"),
|
| 469 |
+
family_id=freeze_array(frames[0].family_id[None], dtype="<i8"),
|
| 470 |
+
family_valid=freeze_array(np.ones((1, n), dtype=np.bool_), dtype="|b1"),
|
| 471 |
+
static_flags=freeze_array(frames[0].static_flags[None], dtype="|b1"),
|
| 472 |
+
static_flags_valid=freeze_array(np.ones((1, n), dtype=np.bool_), dtype="|b1"),
|
| 473 |
+
pose=freeze_array(pose[None], dtype="<f4"),
|
| 474 |
+
pose_valid=freeze_array(pose_valid[None], dtype="|b1"),
|
| 475 |
+
articulation_q=freeze_array(
|
| 476 |
+
np.stack([frame.articulation_q for frame in frames])[None], dtype="<f4"
|
| 477 |
+
),
|
| 478 |
+
articulation_valid=freeze_array(
|
| 479 |
+
np.stack([frame.articulation_valid for frame in frames])[None], dtype="|b1"
|
| 480 |
+
),
|
| 481 |
+
view_evidence=freeze_array(
|
| 482 |
+
np.stack([frame.view_evidence for frame in frames])[None], dtype="<f4"
|
| 483 |
+
),
|
| 484 |
+
view_record_valid=freeze_array(
|
| 485 |
+
np.stack([frame.view_record_valid for frame in frames])[None], dtype="|b1"
|
| 486 |
+
),
|
| 487 |
+
edge_index=relations.index,
|
| 488 |
+
edge_batch=relations.batch,
|
| 489 |
+
edge_time=relations.time,
|
| 490 |
+
edge_relation_id=relations.relation_id,
|
| 491 |
+
edge_payload=relations.payload,
|
| 492 |
+
edge_payload_valid=relations.payload_valid,
|
| 493 |
+
is_task_target=freeze_array(self.capability.is_task_target[None], dtype="|b1"),
|
| 494 |
+
task_target_valid=freeze_array(self.capability.task_target_valid[None], dtype="|b1"),
|
| 495 |
+
task_target_source_code=freeze_array(
|
| 496 |
+
self.capability.task_target_source_code[None], dtype="|u1"
|
| 497 |
+
),
|
| 498 |
+
robot_target_contact=freeze_array(robot_contact, dtype="|b1"),
|
| 499 |
+
robot_target_contact_valid=freeze_array(robot_contact_valid, dtype="|b1"),
|
| 500 |
+
)
|
| 501 |
+
packet.validate()
|
| 502 |
+
action.validate(packet)
|
| 503 |
+
result = CompactOnlineInputV3(packet, action, self.capability.receipt_sha256)
|
| 504 |
+
result.validate()
|
| 505 |
+
return result
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
__all__ = [
|
| 509 |
+
"AuthenticatedResetTargetCapabilityV3",
|
| 510 |
+
"TrustedResetTargetAuthorityV3",
|
| 511 |
+
"CompactOnlineContractError",
|
| 512 |
+
"CompactOnlineFrameV3",
|
| 513 |
+
"CompactOnlineHistoryBufferV3",
|
| 514 |
+
"CompactOnlineInputV3",
|
| 515 |
+
"online_inventory_sha256",
|
| 516 |
+
]
|
gwam_active13_gwam_training_v3_20260801/loader/per_frame.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Small public per-frame inspection view; RGB is deliberately not included."""
|
| 2 |
+
from dataclasses import dataclass
|
| 3 |
+
import numpy as np
|
| 4 |
+
from .compact_contract import CompactExampleV3
|
| 5 |
+
|
| 6 |
+
@dataclass(frozen=True, slots=True)
|
| 7 |
+
class CompactFrameViewV3:
|
| 8 |
+
batch_index: int
|
| 9 |
+
time_index: int
|
| 10 |
+
slot_id: np.ndarray
|
| 11 |
+
family_id: np.ndarray
|
| 12 |
+
family_valid: np.ndarray
|
| 13 |
+
static_flags: np.ndarray
|
| 14 |
+
static_flags_valid: np.ndarray
|
| 15 |
+
node_valid: np.ndarray
|
| 16 |
+
pose: np.ndarray
|
| 17 |
+
pose_valid: np.ndarray
|
| 18 |
+
articulation_q: np.ndarray
|
| 19 |
+
articulation_valid: np.ndarray
|
| 20 |
+
view_evidence: np.ndarray
|
| 21 |
+
view_record_valid: np.ndarray
|
| 22 |
+
edge_index: np.ndarray
|
| 23 |
+
edge_batch: np.ndarray
|
| 24 |
+
edge_time: np.ndarray
|
| 25 |
+
edge_relation_id: np.ndarray
|
| 26 |
+
edge_payload: np.ndarray
|
| 27 |
+
edge_payload_valid: np.ndarray
|
| 28 |
+
is_task_target: np.ndarray
|
| 29 |
+
task_target_valid: np.ndarray
|
| 30 |
+
robot_target_contact: np.ndarray
|
| 31 |
+
robot_target_contact_valid: np.ndarray
|
| 32 |
+
source_frame: int | None
|
| 33 |
+
|
| 34 |
+
def select_frame(example: CompactExampleV3, time_index: int, batch_index: int = 0) -> CompactFrameViewV3:
|
| 35 |
+
example.validate()
|
| 36 |
+
if type(time_index) is not int or not 0 <= time_index < 8: raise ValueError("time_index")
|
| 37 |
+
if type(batch_index) is not int or not 0 <= batch_index < example.packet.batch_size: raise ValueError("batch_index")
|
| 38 |
+
p=example.packet
|
| 39 |
+
keep=(p.edge_batch == batch_index) & (p.edge_time == time_index)
|
| 40 |
+
return CompactFrameViewV3(batch_index, time_index, p.slot_id[batch_index].copy(), p.family_id[batch_index].copy(),
|
| 41 |
+
p.family_valid[batch_index].copy(), p.static_flags[batch_index].copy(), p.static_flags_valid[batch_index].copy(),
|
| 42 |
+
p.node_valid[batch_index,time_index].copy(), p.pose[batch_index,time_index].copy(),
|
| 43 |
+
p.pose_valid[batch_index,time_index].copy(), p.articulation_q[batch_index,time_index].copy(),
|
| 44 |
+
p.articulation_valid[batch_index,time_index].copy(), p.view_evidence[batch_index,time_index].copy(),
|
| 45 |
+
p.view_record_valid[batch_index,time_index].copy(), p.edge_index[:,keep].copy(),
|
| 46 |
+
p.edge_batch[keep].copy(), p.edge_time[keep].copy(), p.edge_relation_id[keep].copy(),
|
| 47 |
+
p.edge_payload[keep].copy(), p.edge_payload_valid[keep].copy(), p.is_task_target[batch_index].copy(),
|
| 48 |
+
p.task_target_valid[batch_index].copy(), p.robot_target_contact[batch_index,time_index].copy(),
|
| 49 |
+
p.robot_target_contact_valid[batch_index,time_index].copy(), None)
|
| 50 |
+
|
| 51 |
+
__all__=["CompactFrameViewV3","select_frame"]
|
gwam_active13_gwam_training_v3_20260801/loader/relation_geometry.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Direct ID-0..5 relation construction with the exact METRIC12 payload."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
from dataclasses import dataclass
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
from .compact_contract import CompactContractError, freeze_array
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
RELATION_NAMES = (
|
| 12 |
+
"part_of",
|
| 13 |
+
"has_part",
|
| 14 |
+
"controls",
|
| 15 |
+
"controlled_by",
|
| 16 |
+
"contact",
|
| 17 |
+
"geometry_near",
|
| 18 |
+
)
|
| 19 |
+
RELATION_SEMANTICS = (
|
| 20 |
+
"part_of: sender physical component is part of receiver assembly",
|
| 21 |
+
"has_part: exact inverse of part_of",
|
| 22 |
+
"controls: sender control or actuator controls an articulated component; not handling ownership",
|
| 23 |
+
"controlled_by: exact inverse of controls",
|
| 24 |
+
"contact: symmetric physical touch only; robot-object contact is not a proven grasp",
|
| 25 |
+
"geometry_near: deterministic nearest-eight message route from sender to receiver",
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@dataclass(frozen=True, slots=True)
|
| 30 |
+
class RelationTripleV3:
|
| 31 |
+
sender: int
|
| 32 |
+
receiver: int
|
| 33 |
+
relation_id: int
|
| 34 |
+
|
| 35 |
+
def validate(self) -> None:
|
| 36 |
+
if type(self.sender) is not int or type(self.receiver) is not int:
|
| 37 |
+
raise CompactContractError("RELATION_ENDPOINT_TYPE")
|
| 38 |
+
if not (0 <= self.sender < 256 and 0 <= self.receiver < 256) or self.sender == self.receiver:
|
| 39 |
+
raise CompactContractError("RELATION_ENDPOINT_RANGE")
|
| 40 |
+
if type(self.relation_id) is not int or not 0 <= self.relation_id <= 5:
|
| 41 |
+
raise CompactContractError("RELATION_ID")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
@dataclass(frozen=True, slots=True)
|
| 45 |
+
class RelationArraysV3:
|
| 46 |
+
index: np.ndarray
|
| 47 |
+
batch: np.ndarray
|
| 48 |
+
time: np.ndarray
|
| 49 |
+
relation_id: np.ndarray
|
| 50 |
+
payload: np.ndarray
|
| 51 |
+
payload_valid: np.ndarray
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def metric12(sender_position: np.ndarray, receiver_position: np.ndarray) -> np.ndarray:
|
| 55 |
+
sender = np.asarray(sender_position, dtype=np.float32)
|
| 56 |
+
receiver = np.asarray(receiver_position, dtype=np.float32)
|
| 57 |
+
if sender.shape != (3,) or receiver.shape != (3,):
|
| 58 |
+
raise CompactContractError("METRIC12_POSITION_SHAPE")
|
| 59 |
+
if not np.isfinite(sender).all() or not np.isfinite(receiver).all():
|
| 60 |
+
raise CompactContractError("METRIC12_POSITION_NONFINITE")
|
| 61 |
+
delta = sender.astype(np.float64) - receiver.astype(np.float64)
|
| 62 |
+
distance = np.sqrt(np.sum(delta * delta, dtype=np.float64))
|
| 63 |
+
centers = 2.0 * np.arange(8, dtype=np.float64) / 7.0
|
| 64 |
+
rbf = np.exp(-((distance - centers) ** 2) / (2.0 * 0.25**2))
|
| 65 |
+
return np.ascontiguousarray(np.concatenate((delta, [distance], rbf)).astype(np.float32))
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _inverse_static(rows: tuple[RelationTripleV3, ...]) -> tuple[RelationTripleV3, ...]:
|
| 69 |
+
result: list[RelationTripleV3] = []
|
| 70 |
+
for row in rows:
|
| 71 |
+
row.validate()
|
| 72 |
+
if row.relation_id not in (0, 2):
|
| 73 |
+
raise CompactContractError("STATIC_RELATION_MUST_BE_FORWARD_ID_0_OR_2")
|
| 74 |
+
result.append(row)
|
| 75 |
+
result.append(
|
| 76 |
+
RelationTripleV3(
|
| 77 |
+
row.receiver,
|
| 78 |
+
row.sender,
|
| 79 |
+
1 if row.relation_id == 0 else 3,
|
| 80 |
+
)
|
| 81 |
+
)
|
| 82 |
+
return tuple(result)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def assemble_relations_metric12(
|
| 86 |
+
pose: np.ndarray,
|
| 87 |
+
pose_valid: np.ndarray,
|
| 88 |
+
static_relations: tuple[RelationTripleV3, ...],
|
| 89 |
+
contacts: tuple[tuple[tuple[int, int], ...], ...],
|
| 90 |
+
batch_index: int = 0,
|
| 91 |
+
) -> RelationArraysV3:
|
| 92 |
+
pose = np.asarray(pose)
|
| 93 |
+
pose_valid = np.asarray(pose_valid)
|
| 94 |
+
if pose.dtype != np.float32 or pose.ndim != 3 or pose.shape[0] != 8 or pose.shape[2] != 7:
|
| 95 |
+
raise CompactContractError("RELATION_POSE_SHAPE_OR_DTYPE")
|
| 96 |
+
n = pose.shape[1]
|
| 97 |
+
if not 1 <= n <= 256 or pose_valid.dtype != np.bool_ or pose_valid.shape != (8, n):
|
| 98 |
+
raise CompactContractError("RELATION_POSE_VALID_SHAPE_OR_DTYPE")
|
| 99 |
+
if type(batch_index) is not int or batch_index < 0:
|
| 100 |
+
raise CompactContractError("RELATION_BATCH_INDEX")
|
| 101 |
+
if type(static_relations) is not tuple or type(contacts) is not tuple or len(contacts) != 8:
|
| 102 |
+
raise CompactContractError("RELATION_INPUT_TYPE")
|
| 103 |
+
base = _inverse_static(static_relations)
|
| 104 |
+
if any(row.sender >= n or row.receiver >= n for row in base):
|
| 105 |
+
raise CompactContractError("RELATION_ENDPOINT_PACKED_RANGE")
|
| 106 |
+
if len({(row.sender, row.receiver, row.relation_id) for row in base}) != len(base):
|
| 107 |
+
raise CompactContractError("RELATION_DUPLICATE")
|
| 108 |
+
rows: list[tuple[int, int, int, int, int, np.ndarray]] = []
|
| 109 |
+
for time in range(8):
|
| 110 |
+
for row in base:
|
| 111 |
+
if pose_valid[time, row.sender] and pose_valid[time, row.receiver]:
|
| 112 |
+
rows.append(
|
| 113 |
+
(time, row.relation_id, row.receiver, row.sender, batch_index, metric12(pose[time, row.sender, :3], pose[time, row.receiver, :3]))
|
| 114 |
+
)
|
| 115 |
+
seen_contact: set[tuple[int, int]] = set()
|
| 116 |
+
for pair in contacts[time]:
|
| 117 |
+
if type(pair) is not tuple or len(pair) != 2 or any(type(value) is not int for value in pair):
|
| 118 |
+
raise CompactContractError("CONTACT_PAIR_TYPE")
|
| 119 |
+
left, right = pair
|
| 120 |
+
if not (0 <= left < n and 0 <= right < n) or left == right:
|
| 121 |
+
raise CompactContractError("CONTACT_PAIR_RANGE")
|
| 122 |
+
canonical = (min(left, right), max(left, right))
|
| 123 |
+
if canonical in seen_contact:
|
| 124 |
+
raise CompactContractError("CONTACT_DUPLICATE")
|
| 125 |
+
seen_contact.add(canonical)
|
| 126 |
+
if pose_valid[time, left] and pose_valid[time, right]:
|
| 127 |
+
for sender, receiver in ((left, right), (right, left)):
|
| 128 |
+
rows.append(
|
| 129 |
+
(time, 4, receiver, sender, batch_index, metric12(pose[time, sender, :3], pose[time, receiver, :3]))
|
| 130 |
+
)
|
| 131 |
+
valid_slots = np.flatnonzero(pose_valid[time])
|
| 132 |
+
for receiver in valid_slots.tolist():
|
| 133 |
+
candidates = []
|
| 134 |
+
receiver_position = pose[time, receiver, :3].astype(np.float64)
|
| 135 |
+
for sender in valid_slots.tolist():
|
| 136 |
+
if sender == receiver:
|
| 137 |
+
continue
|
| 138 |
+
delta = pose[time, sender, :3].astype(np.float64) - receiver_position
|
| 139 |
+
distance_sq = float(np.sum(delta * delta, dtype=np.float64))
|
| 140 |
+
candidates.append((distance_sq, sender))
|
| 141 |
+
candidates.sort(key=lambda value: (value[0], value[1]))
|
| 142 |
+
for _, sender in candidates[:8]:
|
| 143 |
+
rows.append(
|
| 144 |
+
(time, 5, receiver, sender, batch_index, metric12(pose[time, sender, :3], pose[time, receiver, :3]))
|
| 145 |
+
)
|
| 146 |
+
rows.sort(key=lambda row: (row[4], row[0], row[1], row[2], row[3]))
|
| 147 |
+
keys = [(row[4], row[0], row[1], row[2], row[3]) for row in rows]
|
| 148 |
+
if len(keys) != len(set(keys)):
|
| 149 |
+
raise CompactContractError("RELATION_DUPLICATE")
|
| 150 |
+
if rows:
|
| 151 |
+
index = np.asarray([(row[3], row[2]) for row in rows], dtype=np.int64).T
|
| 152 |
+
batch = np.asarray([row[4] for row in rows], dtype=np.int32)
|
| 153 |
+
time = np.asarray([row[0] for row in rows], dtype=np.int16)
|
| 154 |
+
relation = np.asarray([row[1] for row in rows], dtype=np.uint8)
|
| 155 |
+
payload = np.stack([row[5] for row in rows]).astype(np.float32, copy=False)
|
| 156 |
+
else:
|
| 157 |
+
index = np.zeros((2, 0), dtype=np.int64)
|
| 158 |
+
batch = np.zeros(0, dtype=np.int32)
|
| 159 |
+
time = np.zeros(0, dtype=np.int16)
|
| 160 |
+
relation = np.zeros(0, dtype=np.uint8)
|
| 161 |
+
payload = np.zeros((0, 12), dtype=np.float32)
|
| 162 |
+
return RelationArraysV3(
|
| 163 |
+
index=freeze_array(index, dtype="<i8"),
|
| 164 |
+
batch=freeze_array(batch, dtype="<i4"),
|
| 165 |
+
time=freeze_array(time, dtype="<i2"),
|
| 166 |
+
relation_id=freeze_array(relation, dtype="|u1"),
|
| 167 |
+
payload=freeze_array(payload, dtype="<f4"),
|
| 168 |
+
payload_valid=freeze_array(np.ones((len(rows), 12), dtype=np.bool_), dtype="|b1"),
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
__all__ = [
|
| 173 |
+
"RELATION_NAMES",
|
| 174 |
+
"RELATION_SEMANTICS",
|
| 175 |
+
"RelationArraysV3",
|
| 176 |
+
"RelationTripleV3",
|
| 177 |
+
"assemble_relations_metric12",
|
| 178 |
+
"metric12",
|
| 179 |
+
]
|
gwam_active13_gwam_training_v3_20260801/loader/rgb_pairing.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Safe offline graph-frame to original RoboCasa/LeRobot RGB pairing."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
import hashlib, json
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from typing import Any
|
| 6 |
+
|
| 7 |
+
from .direct_compact_source import canonical_json_bytes
|
| 8 |
+
from .robocasa_live_compact import CAMERA_ORDER
|
| 9 |
+
|
| 10 |
+
class RGBPairingError(ValueError): pass
|
| 11 |
+
|
| 12 |
+
def _sha256(path: Path) -> str:
|
| 13 |
+
h=hashlib.sha256()
|
| 14 |
+
with path.open("rb") as f:
|
| 15 |
+
for block in iter(lambda:f.read(1<<20), b""): h.update(block)
|
| 16 |
+
return h.hexdigest()
|
| 17 |
+
|
| 18 |
+
def _snapshot_candidates(root: Path, source_tier: str, task: str, episode_id: str) -> list[Path]:
|
| 19 |
+
if not root.is_dir(): return []
|
| 20 |
+
# Snapshot-date directories are intentionally discovered, never guessed.
|
| 21 |
+
task_root=root/source_tier/'atomic'/task
|
| 22 |
+
candidates=[]
|
| 23 |
+
for date_dir in sorted(p for p in task_root.iterdir() if p.is_dir()) if task_root.is_dir() else []:
|
| 24 |
+
if list(date_dir.rglob(f"{episode_id}*.mp4")): candidates.append(date_dir)
|
| 25 |
+
return candidates
|
| 26 |
+
|
| 27 |
+
def resolve_rgb_pairing(*, snapshot_root: str | Path, source_tier: str, task: str,
|
| 28 |
+
episode_id: str, graph_zip_sha256: str, graph_t: int,
|
| 29 |
+
source_frame: int, decoded_frame_hashes: bool = False) -> dict[str, Any]:
|
| 30 |
+
root=Path(snapshot_root); candidates=_snapshot_candidates(root, source_tier, task, episode_id)
|
| 31 |
+
if len(candidates)!=1: raise RGBPairingError(f"SNAPSHOT_MATCH_COUNT:{len(candidates)}")
|
| 32 |
+
snap=candidates[0]
|
| 33 |
+
videos=[]
|
| 34 |
+
for camera in CAMERA_ORDER:
|
| 35 |
+
matches=sorted(p for p in snap.rglob(f"{episode_id}*.mp4") if camera in p.name or camera in str(p.parent))
|
| 36 |
+
if len(matches)!=1: raise RGBPairingError(f"CAMERA_MATCH_COUNT:{camera}:{len(matches)}")
|
| 37 |
+
videos.append(matches[0])
|
| 38 |
+
if type(source_frame) is not int or source_frame < 0 or type(graph_t) is not int or graph_t < 0:
|
| 39 |
+
raise RGBPairingError("FRAME_INDEX")
|
| 40 |
+
# Frame range is checked without decoding when OpenCV is unavailable.
|
| 41 |
+
try:
|
| 42 |
+
import cv2
|
| 43 |
+
for path in videos:
|
| 44 |
+
cap=cv2.VideoCapture(str(path)); count=int(cap.get(cv2.CAP_PROP_FRAME_COUNT)); cap.release()
|
| 45 |
+
if count <= source_frame: raise RGBPairingError(f"FRAME_OUT_OF_RANGE:{path.name}:{source_frame}:{count}")
|
| 46 |
+
except ImportError: pass
|
| 47 |
+
result={"schema":"gwam.rgb_pairing.v3", "graph_zip_sha256":graph_zip_sha256,
|
| 48 |
+
"episode_key":{"source_tier":source_tier,"task":task,"episode_id":episode_id},
|
| 49 |
+
"graph_t":graph_t,"source_frame":source_frame,"camera_order":list(CAMERA_ORDER),
|
| 50 |
+
"video_paths":[str(p) for p in videos],"snapshot_root":str(snap)}
|
| 51 |
+
if decoded_frame_hashes:
|
| 52 |
+
try:
|
| 53 |
+
import cv2
|
| 54 |
+
hashes=[]
|
| 55 |
+
for path in videos:
|
| 56 |
+
cap=cv2.VideoCapture(str(path)); cap.set(cv2.CAP_PROP_POS_FRAMES, source_frame); ok, frame=cap.read(); cap.release()
|
| 57 |
+
if not ok: raise RGBPairingError("FRAME_DECODE")
|
| 58 |
+
hashes.append(hashlib.sha256(frame.tobytes()).hexdigest())
|
| 59 |
+
result["decoded_frame_sha256"]=hashes
|
| 60 |
+
except ImportError: raise RGBPairingError("DECODE_REQUESTED_BUT_OPENCV_MISSING")
|
| 61 |
+
result["pairing_sha256"]=hashlib.sha256(canonical_json_bytes(result)).hexdigest()
|
| 62 |
+
return result
|
| 63 |
+
|
| 64 |
+
__all__=["RGBPairingError","resolve_rgb_pairing"]
|
gwam_active13_gwam_training_v3_20260801/loader/robocasa_live_compact.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Fail-closed RoboCasa live bridge for evaluation-time compact frames.
|
| 2 |
+
|
| 3 |
+
The bridge deliberately accepts a narrow observation reader rather than a simulator
|
| 4 |
+
object. A reader must expose only the fields listed in the public contract; qvel,
|
| 5 |
+
velocity, SAM2/CLIP and dense masks are rejected by the schema and never cross this
|
| 6 |
+
module. Novel resets without an authenticated capability are blocked.
|
| 7 |
+
"""
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import hashlib
|
| 11 |
+
import json
|
| 12 |
+
from dataclasses import dataclass
|
| 13 |
+
from typing import Any, Protocol
|
| 14 |
+
|
| 15 |
+
import numpy as np
|
| 16 |
+
|
| 17 |
+
from .direct_compact_source import canonical_json_bytes
|
| 18 |
+
from .online_compact_adapter import (
|
| 19 |
+
AuthenticatedResetTargetCapabilityV3,
|
| 20 |
+
CompactOnlineContractError,
|
| 21 |
+
CompactOnlineFrameV3,
|
| 22 |
+
)
|
| 23 |
+
from .compact_contract import freeze_array
|
| 24 |
+
|
| 25 |
+
CAMERA_ORDER = ("robot0_agentview_right", "robot0_agentview_left", "robot0_eye_in_hand")
|
| 26 |
+
_FORBIDDEN = ("qvel", "linear_velocity", "angular_velocity", "sam2", "clip", "dense_mask", "rle")
|
| 27 |
+
MIN_VISIBLE_PX = 20
|
| 28 |
+
|
| 29 |
+
def _reduce_instance_id_view(instance_ids: np.ndarray, *, instance_to_local_slot: dict[int, int], node_count: int, render_succeeded: bool):
|
| 30 |
+
ids = np.asarray(instance_ids)
|
| 31 |
+
if ids.ndim != 2 or ids.dtype.kind not in "iu" or not 1 <= node_count <= 256:
|
| 32 |
+
raise CompactOnlineContractError("VIEW_ID_IMAGE")
|
| 33 |
+
output = np.zeros((node_count, 8), dtype=np.float32); valid = np.zeros(node_count, dtype=np.bool_)
|
| 34 |
+
if not render_succeeded: return freeze_array(output, dtype="<f4"), freeze_array(valid, dtype="|b1")
|
| 35 |
+
h, w = ids.shape; count=np.zeros(node_count,dtype=np.int64); sx=np.zeros(node_count); sy=np.zeros(node_count)
|
| 36 |
+
minx=np.full(node_count,w); miny=np.full(node_count,h); maxx=np.full(node_count,-1); maxy=np.full(node_count,-1)
|
| 37 |
+
for y in range(h):
|
| 38 |
+
for x in range(w):
|
| 39 |
+
local=instance_to_local_slot.get(int(ids[y,x]))
|
| 40 |
+
if local is None: continue
|
| 41 |
+
count[local]+=1; sx[local]+=x; sy[local]+=y; minx[local]=min(minx[local],x); miny[local]=min(miny[local],y); maxx[local]=max(maxx[local],x); maxy[local]=max(maxy[local],y)
|
| 42 |
+
for local in np.flatnonzero(count >= MIN_VISIBLE_PX):
|
| 43 |
+
output[local]=np.asarray((1.0,sx[local]/count[local]/w,sy[local]/count[local]/h,count[local]/(h*w),minx[local]/w,miny[local]/h,maxx[local]/w,maxy[local]/h),dtype=np.float32); valid[local]=True
|
| 44 |
+
return freeze_array(output,dtype="<f4"), freeze_array(valid,dtype="|b1")
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class LiveObservationReader(Protocol):
|
| 48 |
+
def state_marker(self, env: Any) -> Any: ...
|
| 49 |
+
def read(self, env: Any, capability: AuthenticatedResetTargetCapabilityV3) -> dict[str, Any]: ...
|
| 50 |
+
def render_rgb(self, env: Any, camera_name: str) -> np.ndarray: ...
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
@dataclass(frozen=True, slots=True)
|
| 54 |
+
class LiveRGBFramesV3:
|
| 55 |
+
frames: tuple[np.ndarray, np.ndarray, np.ndarray]
|
| 56 |
+
camera_names: tuple[str, str, str]
|
| 57 |
+
timestamp_s: float
|
| 58 |
+
frame_id: int
|
| 59 |
+
reset_nonce: str
|
| 60 |
+
compact_frame_sha256: str
|
| 61 |
+
sync_sha256: str
|
| 62 |
+
|
| 63 |
+
def validate(self) -> None:
|
| 64 |
+
if self.camera_names != CAMERA_ORDER or type(self.frame_id) is not int or len(self.compact_frame_sha256) != 64:
|
| 65 |
+
raise CompactOnlineContractError("LIVE_RGB_CAMERA_OR_FRAME")
|
| 66 |
+
for frame in self.frames:
|
| 67 |
+
if type(frame) is not np.ndarray or frame.dtype != np.uint8 or frame.ndim != 3 or frame.shape[-1] != 3:
|
| 68 |
+
raise CompactOnlineContractError("LIVE_RGB_SHAPE_OR_DTYPE")
|
| 69 |
+
if any(frame.shape[:2] != self.frames[0].shape[:2] for frame in self.frames):
|
| 70 |
+
raise CompactOnlineContractError("LIVE_RGB_UNALIGNED")
|
| 71 |
+
if hashlib.sha256(self.canonical_bytes()).hexdigest() != self.sync_sha256:
|
| 72 |
+
raise CompactOnlineContractError("LIVE_RGB_SYNC_DIGEST")
|
| 73 |
+
|
| 74 |
+
def canonical_bytes(self) -> bytes:
|
| 75 |
+
header = canonical_json_bytes({"camera_names": self.camera_names, "compact_frame_sha256": self.compact_frame_sha256,
|
| 76 |
+
"frame_id": self.frame_id, "reset_nonce": self.reset_nonce, "timestamp_s": self.timestamp_s})
|
| 77 |
+
return header + b"".join(frame.tobytes(order="C") for frame in self.frames)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def view_evidence_from_segmentation(
|
| 81 |
+
instance_id_frames: tuple[np.ndarray, np.ndarray, np.ndarray],
|
| 82 |
+
instance_to_local_slot: dict[int, int], node_count: int,
|
| 83 |
+
render_succeeded: tuple[bool, bool, bool],
|
| 84 |
+
) -> tuple[np.ndarray, np.ndarray]:
|
| 85 |
+
"""Return [N,3,8] visible/centroid/area/bbox records without crossing masks."""
|
| 86 |
+
if len(instance_id_frames) != 3 or len(render_succeeded) != 3:
|
| 87 |
+
raise CompactOnlineContractError("LIVE_VIEW_CAMERA_COUNT")
|
| 88 |
+
records, valids = zip(*(_reduce_instance_id_view(ids, instance_to_local_slot=instance_to_local_slot,
|
| 89 |
+
node_count=node_count, render_succeeded=ok)
|
| 90 |
+
for ids, ok in zip(instance_id_frames, render_succeeded)))
|
| 91 |
+
return np.ascontiguousarray(np.stack(records, axis=1), dtype=np.float32), np.stack(valids, axis=1).astype(bool)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
@dataclass(frozen=True, slots=True)
|
| 95 |
+
class AuthenticatedLiveResetV3:
|
| 96 |
+
capability: AuthenticatedResetTargetCapabilityV3
|
| 97 |
+
mode: str = "live_evaluation"
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
class RoboCasaLiveCompactBridgeV3:
|
| 101 |
+
"""Direct state reader with state-marker and capability checks."""
|
| 102 |
+
def __init__(self, env: Any, reader: LiveObservationReader, reset: AuthenticatedLiveResetV3):
|
| 103 |
+
if type(reset) is not AuthenticatedLiveResetV3:
|
| 104 |
+
raise CompactOnlineContractError("LIVE_AUTHENTICATED_RESET_REQUIRED")
|
| 105 |
+
self.env, self.reader, self.reset = env, reader, reset
|
| 106 |
+
self._last_frame_id: int | None = None
|
| 107 |
+
|
| 108 |
+
def capture(self) -> tuple[CompactOnlineFrameV3, LiveRGBFramesV3]:
|
| 109 |
+
before = self.reader.state_marker(self.env)
|
| 110 |
+
record = self.reader.read(self.env, self.reset.capability)
|
| 111 |
+
after = self.reader.state_marker(self.env)
|
| 112 |
+
if before != after:
|
| 113 |
+
raise CompactOnlineContractError("LIVE_CAPTURE_ADVANCED_STATE")
|
| 114 |
+
if type(record) is not dict or set(record) != {"timestamp_s", "frame_id", "slot_id", "family_id",
|
| 115 |
+
"static_flags", "node_valid", "pose", "pose_valid", "articulation_q", "articulation_valid",
|
| 116 |
+
"view_evidence", "view_record_valid", "contacts"}:
|
| 117 |
+
raise CompactOnlineContractError("LIVE_RECORD_FIELDS")
|
| 118 |
+
if any(key.lower().find(token) >= 0 for key in record for token in _FORBIDDEN):
|
| 119 |
+
raise CompactOnlineContractError("LIVE_FORBIDDEN_FIELD")
|
| 120 |
+
frame_id = record["frame_id"]
|
| 121 |
+
if type(frame_id) is not int or (self._last_frame_id is not None and frame_id <= self._last_frame_id):
|
| 122 |
+
raise CompactOnlineContractError("LIVE_STALE_FRAME")
|
| 123 |
+
cap = self.reset.capability
|
| 124 |
+
slot_id = np.asarray(record["slot_id"], dtype="<i2")
|
| 125 |
+
if not np.array_equal(slot_id, cap.slot_id):
|
| 126 |
+
raise CompactOnlineContractError("LIVE_TARGET_INVENTORY_MISMATCH")
|
| 127 |
+
frame = CompactOnlineFrameV3(
|
| 128 |
+
cap.reset_nonce, cap.inventory_sha256, float(record["timestamp_s"]),
|
| 129 |
+
freeze_array(slot_id, dtype="<i2"), freeze_array(np.asarray(record["family_id"], dtype="<i8"), dtype="<i8"),
|
| 130 |
+
freeze_array(np.asarray(record["static_flags"], dtype=bool), dtype="|b1"),
|
| 131 |
+
freeze_array(np.asarray(record["node_valid"], dtype=bool), dtype="|b1"), freeze_array(np.asarray(record["pose"], dtype="<f4"), dtype="<f4"),
|
| 132 |
+
freeze_array(np.asarray(record["pose_valid"], dtype=bool), dtype="|b1"), freeze_array(np.asarray(record["articulation_q"], dtype="<f4"), dtype="<f4"),
|
| 133 |
+
freeze_array(np.asarray(record["articulation_valid"], dtype=bool), dtype="|b1"), freeze_array(np.asarray(record["view_evidence"], dtype="<f4"), dtype="<f4"),
|
| 134 |
+
freeze_array(np.asarray(record["view_record_valid"], dtype=bool), dtype="|b1"), tuple(tuple(pair) for pair in record["contacts"]),
|
| 135 |
+
)
|
| 136 |
+
frame.validate()
|
| 137 |
+
rgb = tuple(np.ascontiguousarray(self.reader.render_rgb(self.env, name), dtype=np.uint8) for name in CAMERA_ORDER)
|
| 138 |
+
compact_digest = hashlib.sha256(b"".join(value.tobytes(order="C") for value in (
|
| 139 |
+
frame.slot_id, frame.family_id, frame.node_valid, frame.pose, frame.pose_valid,
|
| 140 |
+
frame.articulation_q, frame.articulation_valid, frame.view_evidence, frame.view_record_valid
|
| 141 |
+
))).hexdigest()
|
| 142 |
+
bundle = LiveRGBFramesV3(rgb, CAMERA_ORDER, frame.timestamp_s, frame_id, cap.reset_nonce, compact_digest, "")
|
| 143 |
+
object.__setattr__(bundle, "sync_sha256", hashlib.sha256(bundle.canonical_bytes()).hexdigest())
|
| 144 |
+
bundle.validate()
|
| 145 |
+
self._last_frame_id = frame_id
|
| 146 |
+
return frame, bundle
|
| 147 |
+
|
| 148 |
+
@staticmethod
|
| 149 |
+
def replay(frame: CompactOnlineFrameV3, rgb: LiveRGBFramesV3) -> tuple[CompactOnlineFrameV3, LiveRGBFramesV3]:
|
| 150 |
+
frame.validate(); rgb.validate(); return frame, rgb
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
__all__ = ["CAMERA_ORDER", "LiveRGBFramesV3", "AuthenticatedLiveResetV3", "RoboCasaLiveCompactBridgeV3",
|
| 154 |
+
"view_evidence_from_segmentation"]
|
gwam_active13_gwam_training_v3_20260801/loader/robocasa_mujoco_compact.py
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Concrete RoboCasa/robosuite MuJoCo reader for compact live evaluation.
|
| 2 |
+
|
| 3 |
+
This module is intentionally independent of the historical rich extractor. It
|
| 4 |
+
uses only MuJoCo current pose/contact/render state and a source-backed articulation
|
| 5 |
+
map supplied by the caller. Target identity is built from reset metadata, never a
|
| 6 |
+
caller-selected slot.
|
| 7 |
+
"""
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import hashlib
|
| 11 |
+
import json
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
from typing import Any, Mapping
|
| 14 |
+
|
| 15 |
+
import numpy as np
|
| 16 |
+
|
| 17 |
+
from .compact_contract import freeze_array, RELATION_REGISTRY_SHA256, TARGET_RESOLVER_SHA256, MODEL_PROFILE_ID
|
| 18 |
+
from .direct_compact_source import canonical_json_bytes
|
| 19 |
+
from .online_compact_adapter import AuthenticatedResetTargetCapabilityV3, TrustedResetTargetAuthorityV3, CompactOnlineContractError, online_inventory_sha256
|
| 20 |
+
from .robocasa_live_compact import CAMERA_ORDER, view_evidence_from_segmentation
|
| 21 |
+
|
| 22 |
+
FAMILY_ID = {"object": 0, "distractor": 0, "surface": 2, "receptacle": 3,
|
| 23 |
+
"fixture": 4, "articulated_part": 5, "handle": 6, "control": 7, "region": 8, "robot": 9}
|
| 24 |
+
STATIC_NAMES = {"wall", "floor", "window", "wallaccessory", "stool"}
|
| 25 |
+
SALIENT_FIXTURES = {"Counter","Sink","Stovetop","Microwave","Oven","ToasterOven","Toaster","Fridge","FridgeBottomFreezer","FridgeFrenchDoor","FridgeSideBySide","CoffeeMachine","Blender","BlenderLid","StandMixer","ElectricKettle","Dishwasher","DishwasherRack","HingeCabinet","SingleCabinet","OpenCabinet","Cabinet","HousingCabinet","PanelCabinet","Drawer","Box","Hood","Stove","Accessory"}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _base_env(env: Any) -> Any:
|
| 29 |
+
cur = env; seen = set()
|
| 30 |
+
for _ in range(16):
|
| 31 |
+
if hasattr(cur, "sim"): return cur
|
| 32 |
+
if id(cur) in seen: break
|
| 33 |
+
seen.add(id(cur))
|
| 34 |
+
for attr in ("env", "unwrapped", "base_env"):
|
| 35 |
+
nxt = getattr(cur, attr, None)
|
| 36 |
+
if nxt is not None and nxt is not cur: cur = nxt; break
|
| 37 |
+
else: break
|
| 38 |
+
raise CompactOnlineContractError("ROBOCASA_SIM_UNAVAILABLE")
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def _ep_meta(base: Any) -> dict[str, Any]:
|
| 42 |
+
for name in ("ep_meta", "_ep_meta", "episode_meta", "_episode_meta"):
|
| 43 |
+
value = getattr(base, name, None)
|
| 44 |
+
if isinstance(value, dict) and value: return value
|
| 45 |
+
fn = getattr(base, "get_ep_meta", None)
|
| 46 |
+
if callable(fn):
|
| 47 |
+
value = fn()
|
| 48 |
+
if isinstance(value, dict) and value: return value
|
| 49 |
+
value = {"object_cfgs": getattr(base, "object_cfgs", None), "fixtures": getattr(base, "fixtures", None)}
|
| 50 |
+
if value["object_cfgs"] is not None or value["fixtures"] is not None: return value
|
| 51 |
+
raise CompactOnlineContractError("ROBOCASA_EP_META_UNAVAILABLE")
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _body_id(model: Any, name: str) -> int | None:
|
| 55 |
+
try: return int(model.body_name2id(name))
|
| 56 |
+
except Exception: return None
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def derive_open_drawer_articulation_qpos_map(env: Any) -> dict[str, int]:
|
| 60 |
+
"""Bind the reset-authored target drawer node to its MuJoCo qpos address."""
|
| 61 |
+
base = _base_env(env); meta = _ep_meta(base); model = base.sim.model
|
| 62 |
+
fixture = str((meta.get("fixture_refs") or {}).get("drawer", ""))
|
| 63 |
+
if not fixture: raise CompactOnlineContractError("ROBOCASA_OPEN_DRAWER_TARGET_METADATA")
|
| 64 |
+
exact = (f"{fixture}_slidejoint", f"{fixture}_joint")
|
| 65 |
+
matches: list[int] = []
|
| 66 |
+
for name in exact:
|
| 67 |
+
try: matches.append(int(model.joint_name2id(name)))
|
| 68 |
+
except Exception: pass
|
| 69 |
+
if len(set(matches)) != 1:
|
| 70 |
+
raise CompactOnlineContractError("ROBOCASA_OPEN_DRAWER_JOINT_EXACT")
|
| 71 |
+
joint_id = matches[0]
|
| 72 |
+
qpos_address = int(model.jnt_qposadr[joint_id])
|
| 73 |
+
if not 0 <= qpos_address < len(base.sim.data.qpos):
|
| 74 |
+
raise CompactOnlineContractError("ROBOCASA_OPEN_DRAWER_QPOS_ADDRESS")
|
| 75 |
+
return {f"{fixture}_drawer": qpos_address}
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
class RoboCasaMuJoCoCompactReaderV3:
|
| 79 |
+
"""Narrow reader implementing the live observation protocol."""
|
| 80 |
+
def __init__(self, env: Any, *, articulation_qpos_map: Mapping[str, int] | None = None,
|
| 81 |
+
c2_receipt_bytes: bytes | None = None, c2_receipt_sha256: str | None = None,
|
| 82 |
+
image_size: tuple[int, int] = (256, 256)):
|
| 83 |
+
self.env = env; self.base = _base_env(env); self.sim = self.base.sim
|
| 84 |
+
self.model = self.sim.model; self.meta = _ep_meta(self.base)
|
| 85 |
+
self.image_size = image_size
|
| 86 |
+
self.articulation_qpos_map = {str(k): int(v) for k, v in (articulation_qpos_map or {}).items()}
|
| 87 |
+
self.c2_receipt_sha256 = None
|
| 88 |
+
self.articulation_map_sha256 = hashlib.sha256(canonical_json_bytes(self.articulation_qpos_map)).hexdigest()
|
| 89 |
+
if c2_receipt_bytes is not None or c2_receipt_sha256 is not None:
|
| 90 |
+
if type(c2_receipt_bytes) is not bytes or type(c2_receipt_sha256) is not str or hashlib.sha256(c2_receipt_bytes).hexdigest() != c2_receipt_sha256:
|
| 91 |
+
raise CompactOnlineContractError("ROBOCASA_C2_RECEIPT_BINDING")
|
| 92 |
+
if not self.articulation_qpos_map: raise CompactOnlineContractError("ROBOCASA_C2_MAP_REQUIRED")
|
| 93 |
+
try: value=json.loads(c2_receipt_bytes)
|
| 94 |
+
except (UnicodeDecodeError, json.JSONDecodeError) as exc: raise CompactOnlineContractError("ROBOCASA_C2_RECEIPT_JSON") from exc
|
| 95 |
+
if type(value) is not dict or value.get("version") != "2.0.5" or value.get("artifact_type") not in {"OpenDrawerC2CapabilityReceiptV2_0_5", "OpenDrawerC2EpisodeReceiptV2_0_5"}:
|
| 96 |
+
raise CompactOnlineContractError("ROBOCASA_C2_RECEIPT_SCHEMA")
|
| 97 |
+
self.c2_receipt_sha256 = c2_receipt_sha256
|
| 98 |
+
self.nodes = self._build_inventory(); self.slot_for_body = {}
|
| 99 |
+
for slot, row in enumerate(self.nodes):
|
| 100 |
+
for body in row["bodies"]: self.slot_for_body[int(body)] = slot
|
| 101 |
+
self.geom_to_slot = self._build_geom_map()
|
| 102 |
+
self._frame_id = 0
|
| 103 |
+
|
| 104 |
+
def _build_inventory(self) -> list[dict[str, Any]]:
|
| 105 |
+
model = self.model; rows=[]
|
| 106 |
+
robot_bodies = [_body_id(model, n) for n in ("robot0_right_hand", "robot0_base")]
|
| 107 |
+
robot_bodies = [x for x in robot_bodies if x is not None]
|
| 108 |
+
if robot_bodies: rows.append({"name":"robot", "family":"robot", "family_id":FAMILY_ID["robot"], "static_flags":[True,False], "bodies":robot_bodies})
|
| 109 |
+
for cfg in self.meta.get("object_cfgs", []) or []:
|
| 110 |
+
if not isinstance(cfg, dict) or not isinstance(cfg.get("name"), str): continue
|
| 111 |
+
name=cfg["name"]; bid=_body_id(model, name+"_main")
|
| 112 |
+
if bid is None: bid=_body_id(model, name)
|
| 113 |
+
if bid is None: continue
|
| 114 |
+
rows.append({"name":name,"family":"object","family_id":FAMILY_ID["object"],"static_flags":[True,False],"bodies":[bid]})
|
| 115 |
+
for name, cfg in sorted((self.meta.get("fixtures") or {}).items()):
|
| 116 |
+
cls=str(cfg.get("cls", "")); low=cls.lower()
|
| 117 |
+
if low in STATIC_NAMES or cls not in SALIENT_FIXTURES: continue
|
| 118 |
+
bid=_body_id(model, name+"_main")
|
| 119 |
+
if bid is None: bid=_body_id(model, name)
|
| 120 |
+
if bid is not None: rows.append({"name":name,"family":"surface" if cls=="Counter" else "fixture","family_id":FAMILY_ID["surface" if cls=="Counter" else "fixture"],"static_flags":[False,False],"bodies":[bid]})
|
| 121 |
+
for suffix,fam,cands in (("door","articulated_part",(f"{name}_door_main",f"{name}_door")),
|
| 122 |
+
("handle","handle",(f"{name}_door_handle_main",f"{name}_handle_main",f"{name}_handle")),
|
| 123 |
+
("drawer","receptacle",(f"{name}_inner_box",)),
|
| 124 |
+
("button","control",(f"{name}_button_main",f"{name}_start_button_main",f"{name}_knob_main")),
|
| 125 |
+
("tray","receptacle",(f"{name}_tray",f"{name}_tray_main"))):
|
| 126 |
+
bodies=[_body_id(model,c) for c in cands]; bodies=[x for x in bodies if x is not None]
|
| 127 |
+
if bodies: rows.append({"name":f"{name}_{suffix}","family":fam,"family_id":FAMILY_ID[fam],"static_flags":[False,True],"bodies":bodies})
|
| 128 |
+
if not rows or len(rows) > 256: raise CompactOnlineContractError("ROBOCASA_INVENTORY_CARDINALITY")
|
| 129 |
+
return rows
|
| 130 |
+
|
| 131 |
+
def _build_geom_map(self) -> dict[int, int]:
|
| 132 |
+
result={}
|
| 133 |
+
for geom in range(int(self.model.ngeom)):
|
| 134 |
+
body=int(self.model.geom_bodyid[geom]); seen=set()
|
| 135 |
+
while body >= 0 and body not in seen:
|
| 136 |
+
seen.add(body)
|
| 137 |
+
if body in self.slot_for_body: result[geom]=self.slot_for_body[body]; break
|
| 138 |
+
body=int(self.model.body_parentid[body])
|
| 139 |
+
return result
|
| 140 |
+
|
| 141 |
+
def inventory_arrays(self) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
|
| 142 |
+
slots=np.arange(len(self.nodes),dtype=np.int16)
|
| 143 |
+
family=np.asarray([r["family_id"] for r in self.nodes],dtype=np.int64)
|
| 144 |
+
flags=np.asarray([r["static_flags"] for r in self.nodes],dtype=bool)
|
| 145 |
+
return slots, family, flags
|
| 146 |
+
|
| 147 |
+
def state_marker(self, env: Any) -> tuple[bytes, float]:
|
| 148 |
+
data=self.sim.data
|
| 149 |
+
q=np.asarray(data.qpos,dtype=np.float64)
|
| 150 |
+
return hashlib.sha256(q.tobytes(order="C")).digest(), float(getattr(data,"time",0.0))
|
| 151 |
+
|
| 152 |
+
def _pose(self) -> tuple[np.ndarray,np.ndarray]:
|
| 153 |
+
n=len(self.nodes); pose=np.zeros((n,7),np.float32); valid=np.zeros(n,bool)
|
| 154 |
+
for slot,row in enumerate(self.nodes):
|
| 155 |
+
body=row["bodies"][0]; pose[slot,:3]=np.asarray(self.sim.data.body_xpos[body],np.float32)
|
| 156 |
+
quat=np.asarray(self.sim.data.body_xquat[body],np.float32)
|
| 157 |
+
pose[slot,3:]=quat[[1,2,3,0]]; valid[slot]=np.isfinite(pose[slot]).all()
|
| 158 |
+
pose[~valid]=0.0; return pose,valid
|
| 159 |
+
|
| 160 |
+
def _articulation(self) -> tuple[np.ndarray,np.ndarray]:
|
| 161 |
+
n=len(self.nodes); q=np.zeros((n,1),np.float32); valid=np.zeros((n,1),bool)
|
| 162 |
+
for slot,row in enumerate(self.nodes):
|
| 163 |
+
index=self.articulation_qpos_map.get(row["name"])
|
| 164 |
+
if index is None: continue
|
| 165 |
+
if not 0 <= index < len(self.sim.data.qpos): raise CompactOnlineContractError("ROBOCASA_ARTICULATION_INDEX")
|
| 166 |
+
q[slot,0]=float(self.sim.data.qpos[index]); valid[slot,0]=np.isfinite(q[slot,0])
|
| 167 |
+
q[~valid]=0.0; return q,valid
|
| 168 |
+
|
| 169 |
+
def _contacts(self) -> tuple[tuple[int,int], ...]:
|
| 170 |
+
pairs=set(); data=self.sim.data
|
| 171 |
+
for i in range(int(data.ncon)):
|
| 172 |
+
a=self.geom_to_slot.get(int(data.contact[i].geom1)); b=self.geom_to_slot.get(int(data.contact[i].geom2))
|
| 173 |
+
if a is not None and b is not None and a != b: pairs.add(tuple(sorted((a,b))))
|
| 174 |
+
return tuple(sorted(pairs))
|
| 175 |
+
|
| 176 |
+
def _segmentation(self, camera: str) -> tuple[np.ndarray,np.ndarray]:
|
| 177 |
+
h,w=self.image_size[1],self.image_size[0]
|
| 178 |
+
seg=np.asarray(self.sim.render(width=w,height=h,camera_name=camera,mode="offscreen",segmentation=True))[::-1]
|
| 179 |
+
if seg.ndim != 3 or seg.shape[-1] < 2: raise CompactOnlineContractError("ROBOCASA_SEGMENTATION_SHAPE")
|
| 180 |
+
ids=np.full(seg.shape[:2],-1,np.int32); typ=seg[...,0].astype(np.int32); geom=seg[...,1].astype(np.int32)
|
| 181 |
+
for gid,slot in self.geom_to_slot.items(): ids[(typ == 5) & (geom == gid)] = slot
|
| 182 |
+
mapping={i:i for i in range(len(self.nodes))}
|
| 183 |
+
return ids,mapping
|
| 184 |
+
|
| 185 |
+
def read(self, env: Any, capability: AuthenticatedResetTargetCapabilityV3) -> dict[str, Any]:
|
| 186 |
+
slots,family,flags=self.inventory_arrays()
|
| 187 |
+
if capability.inventory_sha256 != online_inventory_sha256(slots,family,flags): raise CompactOnlineContractError("ROBOCASA_CAPABILITY_INVENTORY")
|
| 188 |
+
pose,pose_valid=self._pose(); q,q_valid=self._articulation()
|
| 189 |
+
segs=[]; maps=[]
|
| 190 |
+
for camera in CAMERA_ORDER:
|
| 191 |
+
seg,mapping=self._segmentation(camera); segs.append(seg); maps.append(mapping)
|
| 192 |
+
evidence,view_valid=view_evidence_from_segmentation(tuple(segs),maps[0],len(self.nodes),(True,True,True))
|
| 193 |
+
frame_id=self._frame_id; self._frame_id += 1
|
| 194 |
+
return {"timestamp_s":float(getattr(self.sim.data,"time",0.0)),"frame_id":frame_id,"slot_id":slots,
|
| 195 |
+
"family_id":family,"static_flags":flags,"node_valid":np.ones(len(self.nodes),bool),
|
| 196 |
+
"pose":pose,"pose_valid":pose_valid,"articulation_q":q,"articulation_valid":q_valid,
|
| 197 |
+
"view_evidence":evidence,"view_record_valid":view_valid,"contacts":self._contacts()}
|
| 198 |
+
|
| 199 |
+
def render_rgb(self, env: Any, camera_name: str) -> np.ndarray:
|
| 200 |
+
w,h=self.image_size; rgb=np.asarray(self.sim.render(width=w,height=h,camera_name=camera_name,mode="offscreen",depth=False),dtype=np.uint8)
|
| 201 |
+
if rgb.ndim != 3 or rgb.shape[-1] != 3: raise CompactOnlineContractError("ROBOCASA_RGB_SHAPE")
|
| 202 |
+
return np.ascontiguousarray(rgb[::-1])
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def build_authored_obj_self_capability(env: Any, *, task: str, reset_nonce: str,
|
| 206 |
+
c2_receipt_bytes: bytes | None = None,
|
| 207 |
+
c2_receipt_sha256: str | None = None,
|
| 208 |
+
articulation_qpos_map: Mapping[str, int] | None = None) -> AuthenticatedResetTargetCapabilityV3:
|
| 209 |
+
"""Build target bits from reset metadata's object config, never a slot argument."""
|
| 210 |
+
base=_base_env(env); meta=_ep_meta(base)
|
| 211 |
+
if task == "OpenDrawer" and (type(c2_receipt_bytes) is not bytes or type(c2_receipt_sha256) is not str or not articulation_qpos_map):
|
| 212 |
+
raise CompactOnlineContractError("ROBOCASA_OPEN_DRAWER_C2_CAPABILITY_REQUIRED")
|
| 213 |
+
reader=RoboCasaMuJoCoCompactReaderV3(env, articulation_qpos_map=articulation_qpos_map,
|
| 214 |
+
c2_receipt_bytes=c2_receipt_bytes, c2_receipt_sha256=c2_receipt_sha256)
|
| 215 |
+
cfgs=[cfg for cfg in (meta.get("object_cfgs") or []) if isinstance(cfg,dict) and isinstance(cfg.get("name"),str)]
|
| 216 |
+
if task == "OpenDrawer":
|
| 217 |
+
target_name = str((meta.get("fixture_refs") or {}).get("drawer", ""))
|
| 218 |
+
if not target_name: raise CompactOnlineContractError("ROBOCASA_OPEN_DRAWER_TARGET_METADATA")
|
| 219 |
+
target_names={target_name, target_name+"_drawer"}
|
| 220 |
+
else:
|
| 221 |
+
candidates=[cfg for cfg in cfgs if cfg["name"] == "obj"]
|
| 222 |
+
if len(candidates) != 1: raise CompactOnlineContractError("ROBOCASA_AUTHORED_OBJ_SELF_EXACT_OBJ_REQUIRED")
|
| 223 |
+
target_name="obj"; target_names={target_name}
|
| 224 |
+
slots,family,flags=reader.inventory_arrays(); target=np.zeros(len(slots),bool); valid=np.ones(len(slots),bool)
|
| 225 |
+
for i,row in enumerate(reader.nodes):
|
| 226 |
+
if row["name"] in target_names: target[i]=True
|
| 227 |
+
if not target.any(): raise CompactOnlineContractError("ROBOCASA_AUTHORED_OBJ_SELF_NOT_IN_INVENTORY")
|
| 228 |
+
inventory=online_inventory_sha256(slots,family,flags); nonce=reset_nonce
|
| 229 |
+
if not isinstance(nonce,str) or len(nonce)!=64: raise CompactOnlineContractError("ROBOCASA_RESET_NONCE")
|
| 230 |
+
source_receipt=canonical_json_bytes({"schema":"gwam.authored_obj_self_v1","task":task,"object_name":target_name,
|
| 231 |
+
"inventory_sha256":inventory,"reset_nonce":nonce,
|
| 232 |
+
"c2_receipt_sha256":reader.c2_receipt_sha256,
|
| 233 |
+
"articulation_qpos_map_sha256":reader.articulation_map_sha256})
|
| 234 |
+
source_sha=hashlib.sha256(source_receipt).hexdigest()
|
| 235 |
+
def bits(a): return np.packbits(a.astype(np.uint8),bitorder="little").tobytes().hex()
|
| 236 |
+
authority_metadata = canonical_json_bytes({"schema":"gwam.trusted_reset_authority.v3",
|
| 237 |
+
"task":task,"object_name":target_name,"reset_nonce":nonce,
|
| 238 |
+
"inventory": [{"name": r["name"], "family_id": int(family[i]), "static_flags": flags[i].astype(int).tolist()} for i,r in enumerate(reader.nodes)],
|
| 239 |
+
"ep_meta_object_cfg_names": sorted(str(c.get("name")) for c in cfgs),
|
| 240 |
+
"fixture_refs": meta.get("fixture_refs") or {},
|
| 241 |
+
"c2_receipt_sha256": reader.c2_receipt_sha256,
|
| 242 |
+
"articulation_map_sha256": reader.articulation_map_sha256})
|
| 243 |
+
authority_provenance_sha = hashlib.sha256(authority_metadata).hexdigest()
|
| 244 |
+
value={"episode_key":f"live:{task}:{nonce}","graph_profile_id":MODEL_PROFILE_ID,"graph_static_sha256":source_sha,
|
| 245 |
+
"inventory_sha256":inventory,"relation_registry_sha256":RELATION_REGISTRY_SHA256,"reset_nonce":nonce,
|
| 246 |
+
"resolver_sha256":TARGET_RESOLVER_SHA256,"schema":"gwam.authenticated_reset_target_capability.v3",
|
| 247 |
+
"slot_id":slots.tolist(),"source_group_id":"live","source_target_receipt_sha256":source_sha,"static_relations":[],
|
| 248 |
+
"target_bitset_hex":bits(target),"target_source_codes":np.where(valid,1,0).astype(int).tolist(),"target_valid_bitset_hex":bits(valid),"task":task,
|
| 249 |
+
"authority_provenance_sha256": authority_provenance_sha}
|
| 250 |
+
raw=canonical_json_bytes(value)
|
| 251 |
+
authority = TrustedResetTargetAuthorityV3.from_trusted_metadata(
|
| 252 |
+
reset_nonce=nonce, inventory_sha256=inventory, episode_key=f"live:{task}:{nonce}", task=task,
|
| 253 |
+
source_group_id="live", slot_id=tuple(int(v) for v in slots.tolist()), is_task_target=target,
|
| 254 |
+
task_target_valid=valid, task_target_source_code=tuple(int(v) for v in np.where(valid,1,0).tolist()),
|
| 255 |
+
static_relations=(), source_target_receipt_sha256=source_sha, graph_static_sha256=source_sha,
|
| 256 |
+
authority_provenance_sha256=authority_provenance_sha)
|
| 257 |
+
return AuthenticatedResetTargetCapabilityV3.from_receipt(raw,hashlib.sha256(raw).hexdigest(), authority=authority)
|
| 258 |
+
|
| 259 |
+
__all__=["RoboCasaMuJoCoCompactReaderV3","build_authored_obj_self_capability","derive_open_drawer_articulation_qpos_map"]
|
gwam_active13_gwam_training_v3_20260801/loader/sealed_model_regression.py
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Audit-only adapter for sealed v2.0.4 history-encoder regression tests.
|
| 2 |
+
|
| 3 |
+
This module is not a training or online adapter. It exists only to prove that
|
| 4 |
+
forbidden source changes cannot alter the learned history tensors or anchor
|
| 5 |
+
tokens of the preserved model. It does not create a forward geometry guard,
|
| 6 |
+
loss binding, optimizer, checkpoint, or claim of architecture conformance.
|
| 7 |
+
"""
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import numpy as np
|
| 11 |
+
|
| 12 |
+
from .compact_contract import CompactContractError, CompactExampleV3
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
DECLARED_FIELDS = (
|
| 16 |
+
"slot_id",
|
| 17 |
+
"family_id",
|
| 18 |
+
"static_flags",
|
| 19 |
+
"pose",
|
| 20 |
+
"articulation",
|
| 21 |
+
"views",
|
| 22 |
+
"node_valid",
|
| 23 |
+
"is_task_target",
|
| 24 |
+
"task_target_valid",
|
| 25 |
+
"edge_relation_id",
|
| 26 |
+
"edge_payload",
|
| 27 |
+
"actions",
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def to_sealed_v2_0_4_regression_batch(example: CompactExampleV3):
|
| 32 |
+
if type(example) is not CompactExampleV3:
|
| 33 |
+
raise CompactContractError("REGRESSION_EXACT_EXAMPLE_TYPE")
|
| 34 |
+
example.validate()
|
| 35 |
+
import torch
|
| 36 |
+
|
| 37 |
+
from model_v2_0_4.batch import ModelBatch
|
| 38 |
+
|
| 39 |
+
packet, action, provenance = example.packet, example.action, example.provenance
|
| 40 |
+
|
| 41 |
+
def tensor(value: np.ndarray, dtype):
|
| 42 |
+
return torch.from_numpy(np.array(value, copy=True)).to(dtype=dtype, device="cpu")
|
| 43 |
+
|
| 44 |
+
model_slots = np.array(packet.slot_id, copy=True)
|
| 45 |
+
for row in range(packet.batch_size):
|
| 46 |
+
used = set(int(value) for value in model_slots[row] if value >= 0)
|
| 47 |
+
replacements = iter(value for value in range(256) if value not in used)
|
| 48 |
+
for column in np.flatnonzero(model_slots[row] < 0):
|
| 49 |
+
model_slots[row, column] = next(replacements)
|
| 50 |
+
pose_xyzw = tensor(packet.pose, torch.float32)
|
| 51 |
+
pose_valid = tensor(packet.pose_valid, torch.bool)
|
| 52 |
+
identity = torch.zeros_like(pose_xyzw[..., 3:7])
|
| 53 |
+
identity[..., 3] = 1.0
|
| 54 |
+
quaternion = torch.where(pose_valid.unsqueeze(-1), pose_xyzw[..., 3:7], identity).to(
|
| 55 |
+
torch.float64
|
| 56 |
+
)
|
| 57 |
+
x, y, z, w = quaternion.unbind(dim=-1)
|
| 58 |
+
rotation6d = torch.stack(
|
| 59 |
+
(
|
| 60 |
+
1.0 - 2.0 * (y * y + z * z),
|
| 61 |
+
2.0 * (x * y + z * w),
|
| 62 |
+
2.0 * (x * z - y * w),
|
| 63 |
+
2.0 * (x * y - z * w),
|
| 64 |
+
1.0 - 2.0 * (x * x + z * z),
|
| 65 |
+
2.0 * (y * z + x * w),
|
| 66 |
+
),
|
| 67 |
+
dim=-1,
|
| 68 |
+
).to(torch.float32)
|
| 69 |
+
pose = torch.cat((pose_xyzw[..., :3], rotation6d), dim=-1)
|
| 70 |
+
pose = torch.where(pose_valid.unsqueeze(-1), pose, torch.zeros_like(pose))
|
| 71 |
+
articulation_q = tensor(packet.articulation_q, torch.float32)
|
| 72 |
+
articulation_valid = tensor(packet.articulation_valid, torch.bool)
|
| 73 |
+
articulation = torch.cat((articulation_q, articulation_valid.to(torch.float32)), dim=-1)
|
| 74 |
+
views = tensor(packet.view_evidence, torch.float32)
|
| 75 |
+
record_valid = tensor(packet.view_record_valid, torch.bool)
|
| 76 |
+
visible = views[..., 0] > 0.5
|
| 77 |
+
view_state = torch.where(
|
| 78 |
+
record_valid,
|
| 79 |
+
torch.where(
|
| 80 |
+
visible,
|
| 81 |
+
torch.full_like(visible, 2, dtype=torch.int64),
|
| 82 |
+
torch.ones_like(visible, dtype=torch.int64),
|
| 83 |
+
),
|
| 84 |
+
torch.zeros_like(visible, dtype=torch.int64),
|
| 85 |
+
)
|
| 86 |
+
counts = np.zeros((packet.batch_size, 8), dtype=np.int64)
|
| 87 |
+
for row, time in zip(packet.edge_batch.tolist(), packet.edge_time.tolist(), strict=True):
|
| 88 |
+
counts[row, time] += 1
|
| 89 |
+
capacity = max(1, int(counts.max(initial=0)))
|
| 90 |
+
sender = torch.zeros((packet.batch_size, 8, capacity), dtype=torch.int64)
|
| 91 |
+
receiver = torch.zeros_like(sender)
|
| 92 |
+
relation = torch.zeros_like(sender)
|
| 93 |
+
edge_valid = torch.zeros_like(sender, dtype=torch.bool)
|
| 94 |
+
payload = torch.zeros((packet.batch_size, 8, capacity, 12), dtype=torch.float32)
|
| 95 |
+
payload_valid = torch.zeros_like(payload, dtype=torch.bool)
|
| 96 |
+
offsets = np.zeros((packet.batch_size, 8), dtype=np.int64)
|
| 97 |
+
for edge in range(packet.edge_relation_id.size):
|
| 98 |
+
row, time = int(packet.edge_batch[edge]), int(packet.edge_time[edge])
|
| 99 |
+
offset = int(offsets[row, time])
|
| 100 |
+
offsets[row, time] += 1
|
| 101 |
+
sender[row, time, offset] = int(packet.edge_index[0, edge])
|
| 102 |
+
receiver[row, time, offset] = int(packet.edge_index[1, edge])
|
| 103 |
+
relation[row, time, offset] = int(packet.edge_relation_id[edge])
|
| 104 |
+
edge_valid[row, time, offset] = True
|
| 105 |
+
payload[row, time, offset] = tensor(packet.edge_payload[edge], torch.float32)
|
| 106 |
+
payload_valid[row, time, offset] = tensor(
|
| 107 |
+
packet.edge_payload_valid[edge], torch.bool
|
| 108 |
+
)
|
| 109 |
+
batch = ModelBatch(
|
| 110 |
+
slot_id=tensor(model_slots, torch.int64),
|
| 111 |
+
family_id=tensor(packet.family_id, torch.int64),
|
| 112 |
+
family_valid=tensor(packet.family_valid, torch.bool),
|
| 113 |
+
static_flags=tensor(packet.static_flags, torch.float32),
|
| 114 |
+
static_flags_valid=tensor(packet.static_flags_valid, torch.bool),
|
| 115 |
+
pose=pose,
|
| 116 |
+
pose_valid=pose_valid,
|
| 117 |
+
articulation=articulation,
|
| 118 |
+
views=views,
|
| 119 |
+
view_state=view_state,
|
| 120 |
+
node_valid=tensor(packet.node_valid, torch.bool),
|
| 121 |
+
is_task_target=tensor(packet.is_task_target, torch.bool),
|
| 122 |
+
task_target_valid=tensor(packet.task_target_valid, torch.bool),
|
| 123 |
+
ordered_route_valid=tensor(packet.ordered_route_valid, torch.bool),
|
| 124 |
+
edge_sender=sender,
|
| 125 |
+
edge_receiver=receiver,
|
| 126 |
+
edge_relation_id=relation,
|
| 127 |
+
edge_valid=edge_valid,
|
| 128 |
+
edge_payload=payload,
|
| 129 |
+
edge_payload_valid=payload_valid,
|
| 130 |
+
actions=tensor(action.future_action, torch.float32),
|
| 131 |
+
action_valid=tensor(action.future_action_valid, torch.bool),
|
| 132 |
+
natural_window_sha256=provenance.natural_window_sha256,
|
| 133 |
+
nested_v1_geometry_bytes=provenance.geometry_receipt_bytes,
|
| 134 |
+
nested_v1_geometry_sha256=provenance.geometry_receipt_sha256,
|
| 135 |
+
geometry_receipt_sha256=provenance.geometry_receipt_sha256,
|
| 136 |
+
pre_geometry_source_sha256=provenance.pre_geometry_source_sha256,
|
| 137 |
+
outer_manifest_row_sha256=provenance.outer_manifest_row_sha256,
|
| 138 |
+
dataset_sidecar_sha256=provenance.target_receipt_sha256,
|
| 139 |
+
source_split=provenance.source_split,
|
| 140 |
+
source_paths=provenance.source_zip_path,
|
| 141 |
+
declared_model_fields=DECLARED_FIELDS,
|
| 142 |
+
model_profile_id=packet.graph_profile_id,
|
| 143 |
+
relation_registry_sha256=packet.relation_registry_sha256,
|
| 144 |
+
target_resolver_sha256=packet.target_resolver_sha256,
|
| 145 |
+
)
|
| 146 |
+
batch.validate()
|
| 147 |
+
return batch
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
__all__ = ["to_sealed_v2_0_4_regression_batch"]
|
gwam_active13_gwam_training_v3_20260801/loader/temporal_precision.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Provenance-specific temporal predicates for v3.0.7.
|
| 2 |
+
|
| 3 |
+
Offline timestamps are the exact float32 20-Hz lattice anchored at zero. Live
|
| 4 |
+
simulator timestamps use a separate strict float64 predicate; stored delta
|
| 5 |
+
round-trips retain a tight corruption bound.
|
| 6 |
+
"""
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import math
|
| 10 |
+
import numpy as np
|
| 11 |
+
|
| 12 |
+
DT_NOMINAL_S = 0.05
|
| 13 |
+
TEMPORAL_POLICY_ID = "offline_f32_lattice_t0_0_v1|online_f64_strict_v1|storage_roundtrip_tight_v1"
|
| 14 |
+
STORAGE_ROUNDTRIP_TOLERANCE_S = 1e-6
|
| 15 |
+
ONLINE_TOLERANCE_S = 1e-9
|
| 16 |
+
|
| 17 |
+
class TemporalContractError(ValueError):
|
| 18 |
+
pass
|
| 19 |
+
|
| 20 |
+
def offline_tick(timestamp_s: float) -> int:
|
| 21 |
+
if not (math.isfinite(timestamp_s) and timestamp_s >= 0.0):
|
| 22 |
+
raise TemporalContractError("TIMESTAMP_NONFINITE_OR_NEGATIVE")
|
| 23 |
+
tick = int(np.rint(float(timestamp_s) / DT_NOMINAL_S))
|
| 24 |
+
expected_f32 = float(np.float32(tick * DT_NOMINAL_S))
|
| 25 |
+
if float(timestamp_s) != expected_f32:
|
| 26 |
+
raise TemporalContractError("TIMESTAMP_NOT_ON_F32_CADENCE_LATTICE")
|
| 27 |
+
return tick
|
| 28 |
+
|
| 29 |
+
def offline_step_ok(left: float, right: float) -> bool:
|
| 30 |
+
return offline_tick(right) - offline_tick(left) == 1
|
| 31 |
+
|
| 32 |
+
def offline_step_mask(left: np.ndarray, right: np.ndarray) -> np.ndarray:
|
| 33 |
+
"""Vectorized typed-contract companion; raises on non-lattice values."""
|
| 34 |
+
left = np.asarray(left, dtype=np.float64); right = np.asarray(right, dtype=np.float64)
|
| 35 |
+
if np.any(~np.isfinite(left)) or np.any(~np.isfinite(right)) or np.any(left < 0) or np.any(right < 0):
|
| 36 |
+
raise TemporalContractError("TIMESTAMP_NONFINITE_OR_NEGATIVE")
|
| 37 |
+
lt = np.rint(left / DT_NOMINAL_S).astype(np.int64); rt = np.rint(right / DT_NOMINAL_S).astype(np.int64)
|
| 38 |
+
left_expected = np.asarray(np.float32(lt * DT_NOMINAL_S), dtype=np.float64); right_expected = np.asarray(np.float32(rt * DT_NOMINAL_S), dtype=np.float64)
|
| 39 |
+
if np.any(left != left_expected) or np.any(right != right_expected):
|
| 40 |
+
raise TemporalContractError("TIMESTAMP_NOT_ON_F32_CADENCE_LATTICE")
|
| 41 |
+
return (rt - lt) == 1
|
| 42 |
+
|
| 43 |
+
def offline_timestamp_equal(actual: float, expected: float) -> bool:
|
| 44 |
+
"""Exact equality on the canonical offline float32 lattice."""
|
| 45 |
+
try:
|
| 46 |
+
return offline_tick(float(actual)) == offline_tick(float(expected))
|
| 47 |
+
except TemporalContractError:
|
| 48 |
+
return False
|
| 49 |
+
|
| 50 |
+
def offline_timestamp_equal_mask(actual: np.ndarray, expected: np.ndarray) -> np.ndarray:
|
| 51 |
+
actual = np.asarray(actual, dtype=np.float64); expected = np.asarray(expected, dtype=np.float64)
|
| 52 |
+
if actual.shape != expected.shape:
|
| 53 |
+
raise TemporalContractError("TIMESTAMP_ARRAY_SHAPE_MISMATCH")
|
| 54 |
+
# offline_step_mask performs the same strict finite/lattice checks without tolerance.
|
| 55 |
+
for values in (actual, expected):
|
| 56 |
+
if np.any(~np.isfinite(values)) or np.any(values < 0):
|
| 57 |
+
raise TemporalContractError("TIMESTAMP_NONFINITE_OR_NEGATIVE")
|
| 58 |
+
at = np.rint(actual / DT_NOMINAL_S).astype(np.int64)
|
| 59 |
+
et = np.rint(expected / DT_NOMINAL_S).astype(np.int64)
|
| 60 |
+
ae = np.asarray(np.float32(at * DT_NOMINAL_S), dtype=np.float64)
|
| 61 |
+
ee = np.asarray(np.float32(et * DT_NOMINAL_S), dtype=np.float64)
|
| 62 |
+
if np.any(actual != ae) or np.any(expected != ee):
|
| 63 |
+
raise TemporalContractError("TIMESTAMP_NOT_ON_F32_CADENCE_LATTICE")
|
| 64 |
+
return at == et
|
| 65 |
+
|
| 66 |
+
def timestamp_step_close(left: float, right: float, expected: float = DT_NOMINAL_S) -> bool:
|
| 67 |
+
if expected != DT_NOMINAL_S:
|
| 68 |
+
return False
|
| 69 |
+
try:
|
| 70 |
+
return offline_step_ok(float(left), float(right))
|
| 71 |
+
except TemporalContractError:
|
| 72 |
+
return False
|
| 73 |
+
|
| 74 |
+
def online_step_close(left: float, right: float) -> bool:
|
| 75 |
+
if not (math.isfinite(left) and math.isfinite(right) and left >= 0.0 and right >= 0.0):
|
| 76 |
+
return False
|
| 77 |
+
if abs((right-left)-DT_NOMINAL_S) <= ONLINE_TOLERANCE_S:
|
| 78 |
+
return True
|
| 79 |
+
lt = int(np.rint(float(left) / DT_NOMINAL_S)); rt = int(np.rint(float(right) / DT_NOMINAL_S))
|
| 80 |
+
return rt - lt == 1 and float(left) == float(np.float32(lt * DT_NOMINAL_S)) and float(right) == float(np.float32(rt * DT_NOMINAL_S))
|
| 81 |
+
|
| 82 |
+
def storage_roundtrip_close(actual: float, expected: float) -> bool:
|
| 83 |
+
return math.isfinite(actual) and math.isfinite(expected) and abs(actual-expected) <= STORAGE_ROUNDTRIP_TOLERANCE_S
|
gwam_active13_gwam_training_v3_20260801/loader/variable_n.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Canonical storage-256 inverse for compact variable-N packets.
|
| 2 |
+
|
| 3 |
+
All tensor fields are reconstructed; provenance/action objects are intentionally
|
| 4 |
+
excluded. Node axes scatter by stable ``slot_id``. Pair and route axes are
|
| 5 |
+
remapped to storage IDs and canonically sorted, with every associated tensor
|
| 6 |
+
reordered identically. Padding is explicit zero/false and slot ``-1``.
|
| 7 |
+
"""
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
import numpy as np
|
| 10 |
+
from .compact_contract import CompactGraphPacketV3, CompactTargetsV3, CompactContractError
|
| 11 |
+
|
| 12 |
+
def reconstruct_storage256(packet: CompactGraphPacketV3, targets: CompactTargetsV3 | None = None) -> dict[str,np.ndarray]:
|
| 13 |
+
packet.validate(); b,l,n = packet.node_valid.shape
|
| 14 |
+
out: dict[str,np.ndarray] = {"slot_id":np.full((b,256),-1,np.int16), "history_valid":packet.history_valid.copy(),
|
| 15 |
+
"timestamp_s":packet.timestamp_s.copy(), "timestamp_valid":packet.timestamp_valid.copy(), "delta_t_s":packet.delta_t_s.copy(), "delta_t_valid":packet.delta_t_valid.copy(),
|
| 16 |
+
"family_id":np.full((b,256),10,np.int64), "family_valid":np.zeros((b,256),bool), "static_flags":np.zeros((b,256,2),bool), "static_flags_valid":np.zeros((b,256),bool),
|
| 17 |
+
"node_valid":np.zeros((b,l,256),bool), "pose":np.zeros((b,l,256,7),np.float32), "pose_valid":np.zeros((b,l,256),bool),
|
| 18 |
+
"articulation_q":np.zeros((b,l,256,1),np.float32), "articulation_valid":np.zeros((b,l,256,1),bool), "view_evidence":np.zeros((b,l,256,3,8),np.float32), "view_record_valid":np.zeros((b,l,256,3),bool),
|
| 19 |
+
"is_task_target":np.zeros((b,256),bool), "task_target_valid":np.zeros((b,256),bool), "task_target_source_code":np.zeros((b,256),np.uint8),
|
| 20 |
+
"robot_target_contact":np.zeros((b,l,256),bool), "robot_target_contact_valid":np.zeros((b,l,256),bool)}
|
| 21 |
+
node_fields=("node_valid","pose","pose_valid","articulation_q","articulation_valid","view_evidence","view_record_valid","robot_target_contact","robot_target_contact_valid")
|
| 22 |
+
static_fields=("family_id","family_valid","static_flags","static_flags_valid","is_task_target","task_target_valid","task_target_source_code")
|
| 23 |
+
for row in range(b):
|
| 24 |
+
slots=packet.slot_id[row].astype(int)
|
| 25 |
+
if len(set(slots.tolist()))!=n or any(s<0 or s>=256 for s in slots): raise CompactContractError("INVERSE_STORAGE_SLOTS")
|
| 26 |
+
out["slot_id"][row,slots]=slots
|
| 27 |
+
for name in static_fields: out[name][row,slots]=getattr(packet,name)[row]
|
| 28 |
+
for name in node_fields:
|
| 29 |
+
src=getattr(packet,name)[row]; dst=out[name][row]
|
| 30 |
+
for local,slot in enumerate(slots): dst[:,slot,...] = src[:,local,...]
|
| 31 |
+
if targets is None: return {k:np.ascontiguousarray(v) for k,v in out.items()}
|
| 32 |
+
targets.validate(packet); pairs=targets.pair_index; pair_storage=np.empty((b,2,pairs.shape[1]),np.int64); pair_orders=[]
|
| 33 |
+
for row,slots in enumerate(packet.slot_id.astype(int)):
|
| 34 |
+
mapped=np.sort(slots[pairs],axis=0); order=np.lexsort((mapped[1],mapped[0])); pair_storage[row]=mapped[:,order]; pair_orders.append(order)
|
| 35 |
+
out["pair_index_storage"]=pair_storage
|
| 36 |
+
pair_fields=("anchor_pair_valid","anchor_contact","anchor_contact_valid","target_pair_valid","target_contact_occupancy","target_contact_event","target_contact_event_valid")
|
| 37 |
+
for name in pair_fields:
|
| 38 |
+
src=getattr(targets,name); out[name]=np.empty_like(src)
|
| 39 |
+
for row,order in enumerate(pair_orders): out[name][row]=np.take(src[row], order, axis=-1)
|
| 40 |
+
target_node_fields=("target_robot_contact_occupancy","target_robot_contact_occupancy_valid","target_robot_contact_event","target_robot_contact_event_valid","target_node_valid","target_position_delta","target_rotation_log","target_pose_valid","target_articulation_delta","target_articulation_valid","target_view_evidence","target_view_record_valid")
|
| 41 |
+
for name in target_node_fields:
|
| 42 |
+
src=getattr(targets,name); shape=list(src.shape); shape[2]=256; dst=np.zeros(shape,src.dtype)
|
| 43 |
+
for row,slots in enumerate(packet.slot_id.astype(int)):
|
| 44 |
+
for local,slot in enumerate(slots): dst[row,:,slot,...]=src[row,:,local,...]
|
| 45 |
+
out[name]=dst
|
| 46 |
+
for name in ("target_timestamp_s","target_timestamp_valid"): out[name]=getattr(targets,name).copy()
|
| 47 |
+
current_node=("current_position","current_rotation_quat_xyzw","current_pose_valid","current_articulation_q","current_articulation_valid","current_robot_target_contact","current_robot_target_contact_valid","current_view_evidence","current_view_record_valid")
|
| 48 |
+
for name in current_node:
|
| 49 |
+
src=getattr(targets,name); shape=list(src.shape); shape[1]=256; dst=np.zeros(shape,src.dtype)
|
| 50 |
+
for row,slots in enumerate(packet.slot_id.astype(int)):
|
| 51 |
+
for local,slot in enumerate(slots): dst[row,slot,...]=src[row,local,...]
|
| 52 |
+
out[name]=dst
|
| 53 |
+
structural=np.zeros((b,256,256),np.int64); structural_valid=np.zeros((b,256,256),bool)
|
| 54 |
+
for row,slots in enumerate(packet.slot_id.astype(int)):
|
| 55 |
+
structural[row][np.ix_(slots,slots)]=targets.current_structural_relation[row]; structural_valid[row][np.ix_(slots,slots)]=targets.current_structural_valid[row]
|
| 56 |
+
out["current_structural_relation"]=structural; out["current_structural_valid"]=structural_valid
|
| 57 |
+
# Directed route ledger, remapped and sorted per batch.
|
| 58 |
+
routes=np.empty((b,2,n*(n-1)),np.int64); route_valid=np.empty((b,n*(n-1)),bool)
|
| 59 |
+
for row,slots in enumerate(packet.slot_id.astype(int)):
|
| 60 |
+
mapped=slots[packet.ordered_route_index]; order=np.lexsort((mapped[1],mapped[0])); routes[row]=mapped[:,order]; route_valid[row]=packet.ordered_route_valid[row,order]
|
| 61 |
+
out["ordered_route_index_storage"]=routes; out["ordered_route_valid_storage"]=route_valid
|
| 62 |
+
# Edge ledger remap/sort by batch,time,relation,receiver-storage,sender-storage.
|
| 63 |
+
keys=[]
|
| 64 |
+
for i in range(packet.edge_relation_id.size):
|
| 65 |
+
row=int(packet.edge_batch[i]); sender=int(packet.slot_id[row,packet.edge_index[0,i]]); receiver=int(packet.slot_id[row,packet.edge_index[1,i]])
|
| 66 |
+
keys.append((row,int(packet.edge_time[i]),int(packet.edge_relation_id[i]),receiver,sender,i))
|
| 67 |
+
order=[k[-1] for k in sorted(keys)]; out["edge_index_storage"]=np.asarray([[int(packet.slot_id[int(packet.edge_batch[i]),packet.edge_index[0,i]]),int(packet.slot_id[int(packet.edge_batch[i]),packet.edge_index[1,i]])] for i in order],np.int64).T if order else np.empty((2,0),np.int64)
|
| 68 |
+
for name in ("edge_batch","edge_time","edge_relation_id","edge_payload","edge_payload_valid"): out[name+"_storage"]=getattr(packet,name)[order].copy()
|
| 69 |
+
return {k:np.ascontiguousarray(v) for k,v in out.items()}
|
| 70 |
+
|
| 71 |
+
__all__=["reconstruct_storage256"]
|
gwam_active13_gwam_training_v3_20260801/model_v2_0_4/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Model v2.0.4: velocity-free compact sibling
|
| 2 |
+
|
| 3 |
+
This package is an additive sibling of sealed `model_v2_0_3`; it does not replace or modify v2.0.3.
|
| 4 |
+
|
| 5 |
+
## Input feature profile
|
| 6 |
+
|
| 7 |
+
`pose_qpos_action_target_views_edges_no_raw_velocity_v2_0_4` preserves pose, articulation position (`articulation_q` plus validity), actions, task-target bits, views, node validity, and typed edges. The loader intentionally does not read `linear_velocity`, `angular_velocity`, `articulation_velocity`, or any of their validity fields from `GraphPacketSlimV2`.
|
| 8 |
+
|
| 9 |
+
`ModelBatch` has no `motion` field. `PhysicalHistoryEncoder` has no motion encoder, and its merge width is 1056 rather than 1248. This removes 112,896 trainable parameters relative to sealed v2.0.3 (54,357,509 versus 54,470,405) without training or checkpoint conversion.
|
| 10 |
+
|
| 11 |
+
## Verification
|
| 12 |
+
|
| 13 |
+
Run CPU-only tests with CUDA hidden:
|
| 14 |
+
|
| 15 |
+
```bash
|
| 16 |
+
CUDA_VISIBLE_DEVICES='' PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=. \
|
| 17 |
+
/home/chris/anaconda3/envs/wdg/bin/python -m pytest -q -p no:cacheprovider model_v2_0_4/tests
|
| 18 |
+
```
|
| 19 |
+
|
| 20 |
+
`tests/test_velocity_free_regression.py` checks the profile/version, rejects any loader source access to packet velocity fields, confirms the batch contract exposes no motion feature, and adversarially changes every raw velocity value/validity array while requiring byte-exact batch tensors and model anchor-token output.
|
gwam_active13_gwam_training_v3_20260801/model_v2_0_4/__init__.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""GraphPacket-Slim v2.0.4 velocity-free compact additive sibling.
|
| 2 |
+
|
| 3 |
+
Raw linear, angular, and articulation velocity values and validity bits are
|
| 4 |
+
intentionally absent from both the loader boundary and model batch contract.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from .batch import ModelBatch
|
| 8 |
+
from .config import ARCHITECTURE, MODEL_PROFILE_ID, RunConfig, make_run_config
|
| 9 |
+
from .geometry import (
|
| 10 |
+
GEOMETRY_ARM_PROVENANCE_SCHEMA,
|
| 11 |
+
REQUIRED_GEOMETRY_ARM_NAMES,
|
| 12 |
+
GeometryArmInput,
|
| 13 |
+
GeometryForwardGuard,
|
| 14 |
+
geometry_guard_for_batches,
|
| 15 |
+
)
|
| 16 |
+
from .interventions import (
|
| 17 |
+
BOOL_TENSOR_DIGEST_SCHEMA,
|
| 18 |
+
TARGET_INTERVENTION_RECEIPT_SCHEMA,
|
| 19 |
+
TargetInterventionBatchBundle,
|
| 20 |
+
bind_precomputed_target_intervention_batches,
|
| 21 |
+
canonical_bool_tensor_sha256,
|
| 22 |
+
select_target_intervention_batch,
|
| 23 |
+
)
|
| 24 |
+
from .model import CompactTargetConditionedGNN, ModelOutput, build_model
|
| 25 |
+
|
| 26 |
+
__all__ = [
|
| 27 |
+
"ARCHITECTURE",
|
| 28 |
+
"BOOL_TENSOR_DIGEST_SCHEMA",
|
| 29 |
+
"GEOMETRY_ARM_PROVENANCE_SCHEMA",
|
| 30 |
+
"MODEL_PROFILE_ID",
|
| 31 |
+
"TARGET_INTERVENTION_RECEIPT_SCHEMA",
|
| 32 |
+
"CompactTargetConditionedGNN",
|
| 33 |
+
"GeometryArmInput",
|
| 34 |
+
"GeometryForwardGuard",
|
| 35 |
+
"REQUIRED_GEOMETRY_ARM_NAMES",
|
| 36 |
+
"ModelBatch",
|
| 37 |
+
"ModelOutput",
|
| 38 |
+
"RunConfig",
|
| 39 |
+
"TargetInterventionBatchBundle",
|
| 40 |
+
"bind_precomputed_target_intervention_batches",
|
| 41 |
+
"build_model",
|
| 42 |
+
"canonical_bool_tensor_sha256",
|
| 43 |
+
"geometry_guard_for_batches",
|
| 44 |
+
"make_run_config",
|
| 45 |
+
"select_target_intervention_batch",
|
| 46 |
+
]
|
gwam_active13_gwam_training_v3_20260801/model_v2_0_4/batch.py
ADDED
|
@@ -0,0 +1,544 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from collections.abc import Iterable
|
| 4 |
+
from dataclasses import dataclass, replace
|
| 5 |
+
from hashlib import sha256
|
| 6 |
+
from pathlib import PurePosixPath
|
| 7 |
+
|
| 8 |
+
import torch
|
| 9 |
+
from torch import Tensor
|
| 10 |
+
|
| 11 |
+
from .config import (
|
| 12 |
+
ALLOWED_RELATION_IDS,
|
| 13 |
+
LOCKED_RELATION_REGISTRY_SHA256,
|
| 14 |
+
LOCKED_TARGET_RESOLVER_SHA256,
|
| 15 |
+
MODEL_PROFILE_ID,
|
| 16 |
+
validate_model_profile,
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class BatchContractError(ValueError):
|
| 21 |
+
"""Raised before model lookup when a batch violates the signed contract."""
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
FORBIDDEN_MODEL_FIELDS = frozenset(
|
| 25 |
+
{
|
| 26 |
+
"finished",
|
| 27 |
+
"completed",
|
| 28 |
+
"completion",
|
| 29 |
+
"done",
|
| 30 |
+
"reward",
|
| 31 |
+
"success",
|
| 32 |
+
"outcome",
|
| 33 |
+
"future_observation",
|
| 34 |
+
"task_target_source_code",
|
| 35 |
+
"task_target_source_sha256",
|
| 36 |
+
"resolver_status",
|
| 37 |
+
}
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def canonical_pair_index(n: int, *, device: torch.device | None = None) -> Tensor:
|
| 42 |
+
if not 1 <= int(n) <= 256:
|
| 43 |
+
raise BatchContractError(f"NODE_COUNT_OUT_OF_RANGE:{n}")
|
| 44 |
+
return torch.triu_indices(int(n), int(n), offset=1, dtype=torch.int64, device=device)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def ordered_route_index(n: int, *, device: torch.device | None = None) -> Tensor:
|
| 48 |
+
if not 1 <= int(n) <= 256:
|
| 49 |
+
raise BatchContractError(f"NODE_COUNT_OUT_OF_RANGE:{n}")
|
| 50 |
+
if n == 1:
|
| 51 |
+
return torch.empty((2, 0), dtype=torch.int64, device=device)
|
| 52 |
+
sender = torch.arange(n, dtype=torch.int64, device=device).repeat_interleave(n - 1)
|
| 53 |
+
receiver = torch.cat(
|
| 54 |
+
tuple(
|
| 55 |
+
torch.cat(
|
| 56 |
+
(
|
| 57 |
+
torch.arange(index, dtype=torch.int64, device=device),
|
| 58 |
+
torch.arange(index + 1, n, dtype=torch.int64, device=device),
|
| 59 |
+
)
|
| 60 |
+
)
|
| 61 |
+
for index in range(n)
|
| 62 |
+
)
|
| 63 |
+
)
|
| 64 |
+
return torch.stack((sender, receiver))
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def ordered_route_valid_from_anchor(anchor_node_valid: Tensor) -> Tensor:
|
| 68 |
+
if anchor_node_valid.dtype != torch.bool or anchor_node_valid.ndim != 2:
|
| 69 |
+
raise BatchContractError("ANCHOR_NODE_VALID_SHAPE_OR_DTYPE")
|
| 70 |
+
routes = ordered_route_index(anchor_node_valid.shape[1], device=anchor_node_valid.device)
|
| 71 |
+
if routes.shape[1] == 0:
|
| 72 |
+
return torch.empty(
|
| 73 |
+
(anchor_node_valid.shape[0], 0),
|
| 74 |
+
dtype=torch.bool,
|
| 75 |
+
device=anchor_node_valid.device,
|
| 76 |
+
)
|
| 77 |
+
return anchor_node_valid[:, routes[0]] & anchor_node_valid[:, routes[1]]
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
@dataclass(frozen=True, slots=True)
|
| 81 |
+
class ModelBatch:
|
| 82 |
+
slot_id: Tensor
|
| 83 |
+
family_id: Tensor
|
| 84 |
+
family_valid: Tensor
|
| 85 |
+
static_flags: Tensor
|
| 86 |
+
static_flags_valid: Tensor
|
| 87 |
+
pose: Tensor
|
| 88 |
+
pose_valid: Tensor
|
| 89 |
+
articulation: Tensor
|
| 90 |
+
views: Tensor
|
| 91 |
+
view_state: Tensor
|
| 92 |
+
node_valid: Tensor
|
| 93 |
+
is_task_target: Tensor
|
| 94 |
+
task_target_valid: Tensor
|
| 95 |
+
ordered_route_valid: Tensor
|
| 96 |
+
edge_sender: Tensor
|
| 97 |
+
edge_receiver: Tensor
|
| 98 |
+
edge_relation_id: Tensor
|
| 99 |
+
edge_valid: Tensor
|
| 100 |
+
edge_payload: Tensor
|
| 101 |
+
edge_payload_valid: Tensor
|
| 102 |
+
actions: Tensor
|
| 103 |
+
action_valid: Tensor
|
| 104 |
+
natural_window_sha256: tuple[str, ...]
|
| 105 |
+
nested_v1_geometry_bytes: tuple[bytes, ...]
|
| 106 |
+
nested_v1_geometry_sha256: tuple[str, ...]
|
| 107 |
+
geometry_receipt_sha256: tuple[str, ...]
|
| 108 |
+
pre_geometry_source_sha256: tuple[str, ...]
|
| 109 |
+
outer_manifest_row_sha256: tuple[str, ...]
|
| 110 |
+
dataset_sidecar_sha256: tuple[str, ...]
|
| 111 |
+
source_split: tuple[str, ...]
|
| 112 |
+
source_paths: tuple[str, ...]
|
| 113 |
+
declared_model_fields: tuple[str, ...]
|
| 114 |
+
model_profile_id: str = MODEL_PROFILE_ID
|
| 115 |
+
relation_registry_sha256: str = LOCKED_RELATION_REGISTRY_SHA256
|
| 116 |
+
target_resolver_sha256: str = LOCKED_TARGET_RESOLVER_SHA256
|
| 117 |
+
|
| 118 |
+
@property
|
| 119 |
+
def batch_size(self) -> int:
|
| 120 |
+
return int(self.slot_id.shape[0])
|
| 121 |
+
|
| 122 |
+
@property
|
| 123 |
+
def n_nodes(self) -> int:
|
| 124 |
+
return int(self.slot_id.shape[1])
|
| 125 |
+
|
| 126 |
+
@property
|
| 127 |
+
def pair_index(self) -> Tensor:
|
| 128 |
+
return canonical_pair_index(self.n_nodes, device=self.slot_id.device)
|
| 129 |
+
|
| 130 |
+
def validate(self) -> None:
|
| 131 |
+
try:
|
| 132 |
+
validate_model_profile(self.model_profile_id, ())
|
| 133 |
+
except ValueError as exc:
|
| 134 |
+
raise BatchContractError(str(exc)) from exc
|
| 135 |
+
if self.relation_registry_sha256 != LOCKED_RELATION_REGISTRY_SHA256:
|
| 136 |
+
raise BatchContractError("RELATION_REGISTRY_HASH_MISMATCH")
|
| 137 |
+
if self.target_resolver_sha256 != LOCKED_TARGET_RESOLVER_SHA256:
|
| 138 |
+
raise BatchContractError("TARGET_RESOLVER_HASH_MISMATCH")
|
| 139 |
+
if self.slot_id.ndim != 2:
|
| 140 |
+
raise BatchContractError("SHAPE_SLOT_ID")
|
| 141 |
+
b, n = self.slot_id.shape
|
| 142 |
+
if not 1 <= n <= 256:
|
| 143 |
+
raise BatchContractError(f"NODE_COUNT_OUT_OF_RANGE:{n}")
|
| 144 |
+
if self.slot_id.dtype != torch.int64:
|
| 145 |
+
raise BatchContractError("DTYPE_SLOT_ID")
|
| 146 |
+
expected = {
|
| 147 |
+
"family_id": (b, n),
|
| 148 |
+
"family_valid": (b, n),
|
| 149 |
+
"static_flags": (b, n, 2),
|
| 150 |
+
"static_flags_valid": (b, n),
|
| 151 |
+
"pose": (b, 8, n, 9),
|
| 152 |
+
"pose_valid": (b, 8, n),
|
| 153 |
+
"articulation": (b, 8, n, 2),
|
| 154 |
+
"views": (b, 8, n, 3, 8),
|
| 155 |
+
"view_state": (b, 8, n, 3),
|
| 156 |
+
"node_valid": (b, 8, n),
|
| 157 |
+
"is_task_target": (b, n),
|
| 158 |
+
"task_target_valid": (b, n),
|
| 159 |
+
"ordered_route_valid": (b, n * (n - 1)),
|
| 160 |
+
"actions": (b, 8, 12),
|
| 161 |
+
"action_valid": (b, 8),
|
| 162 |
+
}
|
| 163 |
+
for name, shape in expected.items():
|
| 164 |
+
if tuple(getattr(self, name).shape) != shape:
|
| 165 |
+
raise BatchContractError(f"SHAPE_{name.upper()}:{tuple(getattr(self, name).shape)}")
|
| 166 |
+
bool_fields = (
|
| 167 |
+
"family_valid",
|
| 168 |
+
"static_flags_valid",
|
| 169 |
+
"pose_valid",
|
| 170 |
+
"node_valid",
|
| 171 |
+
"is_task_target",
|
| 172 |
+
"task_target_valid",
|
| 173 |
+
"ordered_route_valid",
|
| 174 |
+
"edge_valid",
|
| 175 |
+
"edge_payload_valid",
|
| 176 |
+
"action_valid",
|
| 177 |
+
)
|
| 178 |
+
for name in bool_fields:
|
| 179 |
+
if getattr(self, name).dtype != torch.bool:
|
| 180 |
+
raise BatchContractError(f"DTYPE_{name.upper()}")
|
| 181 |
+
if torch.any((self.slot_id < 0) | (self.slot_id > 255)):
|
| 182 |
+
raise BatchContractError("SLOT_ID_OUT_OF_RANGE")
|
| 183 |
+
if self.family_id.dtype != torch.int64:
|
| 184 |
+
raise BatchContractError("DTYPE_FAMILY_ID")
|
| 185 |
+
legal_family = torch.tensor(
|
| 186 |
+
(0, 2, 3, 4, 5, 6, 7, 8, 9),
|
| 187 |
+
dtype=self.family_id.dtype,
|
| 188 |
+
device=self.family_id.device,
|
| 189 |
+
)
|
| 190 |
+
if torch.any(self.family_valid & ~torch.isin(self.family_id, legal_family)):
|
| 191 |
+
raise BatchContractError("FAMILY_ID_INELIGIBLE")
|
| 192 |
+
if torch.any(~self.family_valid & (self.family_id != 10)):
|
| 193 |
+
raise BatchContractError("FAMILY_PADDING_NOT_10")
|
| 194 |
+
if self.view_state.dtype != torch.int64 or torch.any(
|
| 195 |
+
(self.view_state < 0) | (self.view_state > 2)
|
| 196 |
+
):
|
| 197 |
+
raise BatchContractError("VIEW_STATE_INELIGIBLE")
|
| 198 |
+
float_fields = (
|
| 199 |
+
"static_flags",
|
| 200 |
+
"pose",
|
| 201 |
+
"articulation",
|
| 202 |
+
"views",
|
| 203 |
+
"edge_payload",
|
| 204 |
+
"actions",
|
| 205 |
+
)
|
| 206 |
+
for name in float_fields:
|
| 207 |
+
value = getattr(self, name)
|
| 208 |
+
if not value.is_floating_point() or not torch.all(torch.isfinite(value)):
|
| 209 |
+
raise BatchContractError(f"NONFINITE_OR_NONFLOAT_{name.upper()}")
|
| 210 |
+
if torch.any((self.static_flags != 0.0) & (self.static_flags != 1.0)):
|
| 211 |
+
raise BatchContractError("STATIC_FLAGS_NOT_BINARY")
|
| 212 |
+
if torch.any((self.articulation[..., 1] != 0.0) & (self.articulation[..., 1] != 1.0)):
|
| 213 |
+
raise BatchContractError("ARTICULATION_VALIDITY_NOT_BINARY")
|
| 214 |
+
if torch.any(~self.node_valid.any(dim=-1)):
|
| 215 |
+
raise BatchContractError("EMPTY_HISTORY_FRAME")
|
| 216 |
+
if torch.any(self.is_task_target & ~self.task_target_valid):
|
| 217 |
+
raise BatchContractError("TARGET_WITHOUT_VALID")
|
| 218 |
+
if torch.any(self.task_target_valid & ~self.node_valid[:, 7, :]):
|
| 219 |
+
raise BatchContractError("TARGET_VALID_ANCHOR_INVALID")
|
| 220 |
+
expected_route_valid = ordered_route_valid_from_anchor(self.node_valid[:, 7])
|
| 221 |
+
if not torch.equal(self.ordered_route_valid, expected_route_valid):
|
| 222 |
+
raise BatchContractError("ORDERED_ROUTE_VALID_MISMATCH")
|
| 223 |
+
if tuple(self.edge_sender.shape) != tuple(self.edge_receiver.shape):
|
| 224 |
+
raise BatchContractError("EDGE_ENDPOINT_SHAPE")
|
| 225 |
+
if tuple(self.edge_sender.shape) != tuple(self.edge_relation_id.shape):
|
| 226 |
+
raise BatchContractError("EDGE_RELATION_SHAPE")
|
| 227 |
+
if tuple(self.edge_sender.shape) != tuple(self.edge_valid.shape):
|
| 228 |
+
raise BatchContractError("EDGE_VALID_SHAPE")
|
| 229 |
+
if self.edge_sender.ndim != 3 or self.edge_sender.shape[:2] != (b, 8):
|
| 230 |
+
raise BatchContractError("EDGE_SHAPE")
|
| 231 |
+
for name in ("edge_sender", "edge_receiver", "edge_relation_id"):
|
| 232 |
+
if getattr(self, name).dtype != torch.int64:
|
| 233 |
+
raise BatchContractError(f"DTYPE_{name.upper()}")
|
| 234 |
+
e = int(self.edge_sender.shape[-1])
|
| 235 |
+
if tuple(self.edge_payload.shape) != (b, 8, e, 12):
|
| 236 |
+
raise BatchContractError("EDGE_PAYLOAD_SHAPE")
|
| 237 |
+
if tuple(self.edge_payload_valid.shape) != (b, 8, e, 12):
|
| 238 |
+
raise BatchContractError("EDGE_PAYLOAD_VALID_SHAPE")
|
| 239 |
+
all_ids = self.edge_relation_id
|
| 240 |
+
if all_ids.numel() and torch.any(
|
| 241 |
+
~torch.isin(
|
| 242 |
+
all_ids,
|
| 243 |
+
torch.tensor(ALLOWED_RELATION_IDS, device=all_ids.device, dtype=all_ids.dtype),
|
| 244 |
+
)
|
| 245 |
+
):
|
| 246 |
+
bad = tuple(
|
| 247 |
+
sorted(
|
| 248 |
+
set(int(value) for value in all_ids.reshape(-1).tolist())
|
| 249 |
+
- set(ALLOWED_RELATION_IDS)
|
| 250 |
+
)
|
| 251 |
+
)
|
| 252 |
+
raise BatchContractError(f"MODEL_RELATION_ID_INELIGIBLE:{bad}")
|
| 253 |
+
if torch.any((self.edge_sender < 0) | (self.edge_sender >= n)):
|
| 254 |
+
raise BatchContractError("EDGE_SENDER_RANGE")
|
| 255 |
+
if torch.any((self.edge_receiver < 0) | (self.edge_receiver >= n)):
|
| 256 |
+
raise BatchContractError("EDGE_RECEIVER_RANGE")
|
| 257 |
+
sender_node_valid = torch.gather(self.node_valid, 2, self.edge_sender)
|
| 258 |
+
receiver_node_valid = torch.gather(self.node_valid, 2, self.edge_receiver)
|
| 259 |
+
if torch.any(self.edge_valid & ~(sender_node_valid & receiver_node_valid)):
|
| 260 |
+
raise BatchContractError("EDGE_ENDPOINT_NODE_INVALID")
|
| 261 |
+
if self.edge_valid.any():
|
| 262 |
+
validity = self.edge_payload_valid[self.edge_valid]
|
| 263 |
+
present = validity.all(dim=-1)
|
| 264 |
+
absent = (~validity).all(dim=-1)
|
| 265 |
+
if torch.any(~present & ~absent):
|
| 266 |
+
raise BatchContractError("EDGE_PAYLOAD_PARTIAL")
|
| 267 |
+
if torch.any(absent):
|
| 268 |
+
raise BatchContractError("ACTIVE13_METRIC_ABSENT")
|
| 269 |
+
inactive_edge = ~self.edge_valid
|
| 270 |
+
if torch.any(self.edge_payload_valid & inactive_edge.unsqueeze(-1)):
|
| 271 |
+
raise BatchContractError("INACTIVE_EDGE_PAYLOAD_VALID")
|
| 272 |
+
if torch.any(self.edge_payload[inactive_edge] != 0.0):
|
| 273 |
+
raise BatchContractError("INACTIVE_EDGE_PAYLOAD_NONZERO")
|
| 274 |
+
if (
|
| 275 |
+
torch.any(self.edge_sender[inactive_edge] != 0)
|
| 276 |
+
or torch.any(self.edge_receiver[inactive_edge] != 0)
|
| 277 |
+
or torch.any(self.edge_relation_id[inactive_edge] != 0)
|
| 278 |
+
):
|
| 279 |
+
raise BatchContractError("INACTIVE_EDGE_INDEX_NONZERO")
|
| 280 |
+
if len(self.source_split) != b or any(
|
| 281 |
+
split != "outer_train" for split in self.source_split
|
| 282 |
+
):
|
| 283 |
+
raise BatchContractError(f"OUTER_SPLIT_FORBIDDEN:{self.source_split}")
|
| 284 |
+
if len(self.source_paths) != b:
|
| 285 |
+
raise BatchContractError("SOURCE_PATH_CARDINALITY")
|
| 286 |
+
forbidden_parts = {"validation", "val", "test", "outer_validation", "outer_test"}
|
| 287 |
+
for path in self.source_paths:
|
| 288 |
+
parts = {part.lower() for part in PurePosixPath(path).parts}
|
| 289 |
+
alias_forbidden = any(
|
| 290 |
+
part in forbidden_parts
|
| 291 |
+
or part.startswith("validation_")
|
| 292 |
+
or part.startswith("validation-")
|
| 293 |
+
or part.startswith("test_")
|
| 294 |
+
or part.startswith("test-")
|
| 295 |
+
or part.endswith("_validation")
|
| 296 |
+
or part.endswith("-validation")
|
| 297 |
+
or part.endswith("_test")
|
| 298 |
+
or part.endswith("-test")
|
| 299 |
+
for part in parts
|
| 300 |
+
)
|
| 301 |
+
if alias_forbidden:
|
| 302 |
+
raise BatchContractError(f"FORBIDDEN_SOURCE_PATH:{path}")
|
| 303 |
+
forbidden = FORBIDDEN_MODEL_FIELDS.intersection(self.declared_model_fields)
|
| 304 |
+
if forbidden:
|
| 305 |
+
raise BatchContractError(f"FORBIDDEN_MODEL_FIELD:{sorted(forbidden)}")
|
| 306 |
+
receipt_tuples = (
|
| 307 |
+
self.natural_window_sha256,
|
| 308 |
+
self.nested_v1_geometry_sha256,
|
| 309 |
+
self.geometry_receipt_sha256,
|
| 310 |
+
self.pre_geometry_source_sha256,
|
| 311 |
+
self.outer_manifest_row_sha256,
|
| 312 |
+
self.dataset_sidecar_sha256,
|
| 313 |
+
)
|
| 314 |
+
if (
|
| 315 |
+
any(len(values) != b for values in receipt_tuples)
|
| 316 |
+
or len(self.nested_v1_geometry_bytes) != b
|
| 317 |
+
):
|
| 318 |
+
raise BatchContractError("RECEIPT_CARDINALITY")
|
| 319 |
+
for digest in sum(receipt_tuples, ()):
|
| 320 |
+
if len(digest) != 64 or any(char not in "0123456789abcdef" for char in digest):
|
| 321 |
+
raise BatchContractError(f"INVALID_SHA256:{digest}")
|
| 322 |
+
for row, payload in enumerate(self.nested_v1_geometry_bytes):
|
| 323 |
+
if type(payload) is not bytes:
|
| 324 |
+
raise BatchContractError("NESTED_GEOMETRY_BYTES_TYPE")
|
| 325 |
+
actual = sha256(payload).hexdigest()
|
| 326 |
+
if actual != self.nested_v1_geometry_sha256[row]:
|
| 327 |
+
raise BatchContractError("NESTED_GEOMETRY_DIGEST_MISMATCH")
|
| 328 |
+
if actual != self.geometry_receipt_sha256[row]:
|
| 329 |
+
raise BatchContractError("GEOMETRY_RECEIPT_DIGEST_MISMATCH")
|
| 330 |
+
for row in range(b):
|
| 331 |
+
if len(set(int(value) for value in self.slot_id[row].tolist())) != n:
|
| 332 |
+
raise BatchContractError("DUPLICATE_SLOT_ID")
|
| 333 |
+
for frame in range(8):
|
| 334 |
+
seen: set[tuple[int, int, int]] = set()
|
| 335 |
+
for edge in (
|
| 336 |
+
torch.nonzero(self.edge_valid[row, frame], as_tuple=False).flatten().tolist()
|
| 337 |
+
):
|
| 338 |
+
key = (
|
| 339 |
+
int(self.edge_sender[row, frame, edge]),
|
| 340 |
+
int(self.edge_receiver[row, frame, edge]),
|
| 341 |
+
int(self.edge_relation_id[row, frame, edge]),
|
| 342 |
+
)
|
| 343 |
+
if key in seen:
|
| 344 |
+
raise BatchContractError("DUPLICATE_EDGE")
|
| 345 |
+
seen.add(key)
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
def _default_declared_fields() -> tuple[str, ...]:
|
| 349 |
+
return (
|
| 350 |
+
"slot_id",
|
| 351 |
+
"family_id",
|
| 352 |
+
"static_flags",
|
| 353 |
+
"pose",
|
| 354 |
+
"articulation",
|
| 355 |
+
"views",
|
| 356 |
+
"node_valid",
|
| 357 |
+
"is_task_target",
|
| 358 |
+
"task_target_valid",
|
| 359 |
+
"edge_relation_id",
|
| 360 |
+
"edge_payload",
|
| 361 |
+
"actions",
|
| 362 |
+
)
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
def make_synthetic_batch(
|
| 366 |
+
*,
|
| 367 |
+
n: int,
|
| 368 |
+
batch_size: int = 1,
|
| 369 |
+
seed: int = 7,
|
| 370 |
+
target_indices: Iterable[int] | None = None,
|
| 371 |
+
device: torch.device | str = "cpu",
|
| 372 |
+
) -> ModelBatch:
|
| 373 |
+
if not 1 <= n <= 256:
|
| 374 |
+
raise BatchContractError(f"NODE_COUNT_OUT_OF_RANGE:{n}")
|
| 375 |
+
generator = torch.Generator(device="cpu").manual_seed(seed)
|
| 376 |
+
dev = torch.device(device)
|
| 377 |
+
slot_id = torch.arange(n, dtype=torch.int64).repeat(batch_size, 1).to(dev)
|
| 378 |
+
legal_families = torch.tensor((9, 0, 2, 3, 4, 5, 6, 7, 8), dtype=torch.int64)
|
| 379 |
+
family_id = legal_families[torch.arange(n) % len(legal_families)].repeat(batch_size, 1).to(dev)
|
| 380 |
+
family_valid = torch.ones((batch_size, n), dtype=torch.bool, device=dev)
|
| 381 |
+
static_flags = torch.zeros((batch_size, n, 2), dtype=torch.float32, device=dev)
|
| 382 |
+
if n > 1:
|
| 383 |
+
static_flags[:, 1:, 0] = 1.0
|
| 384 |
+
if n > 2:
|
| 385 |
+
static_flags[:, 2, 1] = 1.0
|
| 386 |
+
static_flags_valid = torch.ones((batch_size, n), dtype=torch.bool, device=dev)
|
| 387 |
+
pose = torch.randn((batch_size, 8, n, 9), generator=generator, dtype=torch.float32).to(dev)
|
| 388 |
+
pose[..., 3:] = 0.0
|
| 389 |
+
pose[..., 3] = 1.0
|
| 390 |
+
pose[..., 7] = 1.0
|
| 391 |
+
pose_valid = torch.ones((batch_size, 8, n), dtype=torch.bool, device=dev)
|
| 392 |
+
articulation = torch.zeros((batch_size, 8, n, 2), dtype=torch.float32, device=dev)
|
| 393 |
+
if n > 2:
|
| 394 |
+
articulation[:, :, 2, 0] = torch.linspace(0.0, 0.7, 8, device=dev)
|
| 395 |
+
articulation[:, :, 2, 1] = 1.0
|
| 396 |
+
views = torch.randn((batch_size, 8, n, 3, 8), generator=generator, dtype=torch.float32).to(dev)
|
| 397 |
+
view_state = torch.full((batch_size, 8, n, 3), 2, dtype=torch.int64, device=dev)
|
| 398 |
+
node_valid = torch.ones((batch_size, 8, n), dtype=torch.bool, device=dev)
|
| 399 |
+
requested_targets = (
|
| 400 |
+
tuple(target_indices) if target_indices is not None else ((0,) if n == 1 else (1,))
|
| 401 |
+
)
|
| 402 |
+
if any(index < 0 or index >= n for index in requested_targets):
|
| 403 |
+
raise BatchContractError("TARGET_INDEX_RANGE")
|
| 404 |
+
is_task_target = torch.zeros((batch_size, n), dtype=torch.bool, device=dev)
|
| 405 |
+
task_target_valid = torch.ones((batch_size, n), dtype=torch.bool, device=dev)
|
| 406 |
+
for index in requested_targets:
|
| 407 |
+
is_task_target[:, index] = True
|
| 408 |
+
if n == 1:
|
| 409 |
+
edge_count = 1
|
| 410 |
+
edge_valid = torch.zeros((batch_size, 8, edge_count), dtype=torch.bool, device=dev)
|
| 411 |
+
sender_values = [0]
|
| 412 |
+
receiver_values = [0]
|
| 413 |
+
relation_values = [0]
|
| 414 |
+
else:
|
| 415 |
+
edge_count = 6
|
| 416 |
+
sender_values = [relation % n for relation in range(6)]
|
| 417 |
+
receiver_values = [(relation + 1) % n for relation in range(6)]
|
| 418 |
+
relation_values = list(range(6))
|
| 419 |
+
edge_valid = torch.ones((batch_size, 8, edge_count), dtype=torch.bool, device=dev)
|
| 420 |
+
edge_sender = (
|
| 421 |
+
torch.tensor(sender_values, dtype=torch.int64, device=dev)
|
| 422 |
+
.view(1, 1, -1)
|
| 423 |
+
.repeat(batch_size, 8, 1)
|
| 424 |
+
)
|
| 425 |
+
edge_receiver = (
|
| 426 |
+
torch.tensor(receiver_values, dtype=torch.int64, device=dev)
|
| 427 |
+
.view(1, 1, -1)
|
| 428 |
+
.repeat(batch_size, 8, 1)
|
| 429 |
+
)
|
| 430 |
+
edge_relation_id = (
|
| 431 |
+
torch.tensor(relation_values, dtype=torch.int64, device=dev)
|
| 432 |
+
.view(1, 1, -1)
|
| 433 |
+
.repeat(batch_size, 8, 1)
|
| 434 |
+
)
|
| 435 |
+
edge_payload = torch.randn(
|
| 436 |
+
(batch_size, 8, edge_count, 12), generator=generator, dtype=torch.float32
|
| 437 |
+
).to(dev)
|
| 438 |
+
edge_payload_valid = edge_valid.unsqueeze(-1).expand(-1, -1, -1, 12).clone()
|
| 439 |
+
edge_payload = edge_payload * edge_valid.unsqueeze(-1).to(edge_payload.dtype)
|
| 440 |
+
actions = torch.randn((batch_size, 8, 12), generator=generator, dtype=torch.float32).to(dev)
|
| 441 |
+
action_valid = torch.ones((batch_size, 8), dtype=torch.bool, device=dev)
|
| 442 |
+
window_hashes = tuple(
|
| 443 |
+
sha256(f"synthetic-window|{seed}|{row}|{n}".encode("utf-8")).hexdigest()
|
| 444 |
+
for row in range(batch_size)
|
| 445 |
+
)
|
| 446 |
+
geometry_bytes = tuple(
|
| 447 |
+
f"synthetic-v1-geometry|{seed}|{row}|{n}".encode("utf-8") for row in range(batch_size)
|
| 448 |
+
)
|
| 449 |
+
geometry_hashes = tuple(sha256(value).hexdigest() for value in geometry_bytes)
|
| 450 |
+
batch = ModelBatch(
|
| 451 |
+
slot_id=slot_id,
|
| 452 |
+
family_id=family_id,
|
| 453 |
+
family_valid=family_valid,
|
| 454 |
+
static_flags=static_flags,
|
| 455 |
+
static_flags_valid=static_flags_valid,
|
| 456 |
+
pose=pose,
|
| 457 |
+
pose_valid=pose_valid,
|
| 458 |
+
articulation=articulation,
|
| 459 |
+
views=views,
|
| 460 |
+
view_state=view_state,
|
| 461 |
+
node_valid=node_valid,
|
| 462 |
+
is_task_target=is_task_target,
|
| 463 |
+
task_target_valid=task_target_valid,
|
| 464 |
+
ordered_route_valid=ordered_route_valid_from_anchor(node_valid[:, 7]),
|
| 465 |
+
edge_sender=edge_sender,
|
| 466 |
+
edge_receiver=edge_receiver,
|
| 467 |
+
edge_relation_id=edge_relation_id,
|
| 468 |
+
edge_valid=edge_valid,
|
| 469 |
+
edge_payload=edge_payload,
|
| 470 |
+
edge_payload_valid=edge_payload_valid,
|
| 471 |
+
actions=actions,
|
| 472 |
+
action_valid=action_valid,
|
| 473 |
+
natural_window_sha256=window_hashes,
|
| 474 |
+
nested_v1_geometry_bytes=geometry_bytes,
|
| 475 |
+
nested_v1_geometry_sha256=geometry_hashes,
|
| 476 |
+
geometry_receipt_sha256=geometry_hashes,
|
| 477 |
+
pre_geometry_source_sha256=tuple(
|
| 478 |
+
sha256(f"synthetic-pre-geometry|{seed}|{row}|{n}".encode("utf-8")).hexdigest()
|
| 479 |
+
for row in range(batch_size)
|
| 480 |
+
),
|
| 481 |
+
outer_manifest_row_sha256=tuple(
|
| 482 |
+
sha256(f"synthetic-manifest-row|{seed}|{row}|{n}".encode("utf-8")).hexdigest()
|
| 483 |
+
for row in range(batch_size)
|
| 484 |
+
),
|
| 485 |
+
dataset_sidecar_sha256=tuple(
|
| 486 |
+
sha256(f"synthetic-sidecar|{seed}|{row}|{n}".encode("utf-8")).hexdigest()
|
| 487 |
+
for row in range(batch_size)
|
| 488 |
+
),
|
| 489 |
+
source_split=("outer_train",) * batch_size,
|
| 490 |
+
source_paths=tuple(f"/synthetic/outer_train/{row}.zip" for row in range(batch_size)),
|
| 491 |
+
declared_model_fields=_default_declared_fields(),
|
| 492 |
+
)
|
| 493 |
+
batch.validate()
|
| 494 |
+
return batch
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
def permute_batch(batch: ModelBatch, permutation: Tensor) -> ModelBatch:
|
| 498 |
+
if permutation.dtype != torch.int64 or permutation.ndim != 1:
|
| 499 |
+
raise BatchContractError("PERMUTATION_DTYPE_OR_SHAPE")
|
| 500 |
+
n = batch.n_nodes
|
| 501 |
+
if sorted(int(value) for value in permutation.tolist()) != list(range(n)):
|
| 502 |
+
raise BatchContractError("INVALID_PERMUTATION")
|
| 503 |
+
permutation = permutation.to(batch.slot_id.device)
|
| 504 |
+
inverse = torch.empty_like(permutation)
|
| 505 |
+
inverse[permutation] = torch.arange(n, device=permutation.device)
|
| 506 |
+
node_dim_one = {
|
| 507 |
+
"slot_id": batch.slot_id[:, permutation],
|
| 508 |
+
"family_id": batch.family_id[:, permutation],
|
| 509 |
+
"family_valid": batch.family_valid[:, permutation],
|
| 510 |
+
"static_flags": batch.static_flags[:, permutation],
|
| 511 |
+
"static_flags_valid": batch.static_flags_valid[:, permutation],
|
| 512 |
+
"is_task_target": batch.is_task_target[:, permutation],
|
| 513 |
+
"task_target_valid": batch.task_target_valid[:, permutation],
|
| 514 |
+
}
|
| 515 |
+
history_nodes = {
|
| 516 |
+
"pose": batch.pose[:, :, permutation],
|
| 517 |
+
"pose_valid": batch.pose_valid[:, :, permutation],
|
| 518 |
+
"articulation": batch.articulation[:, :, permutation],
|
| 519 |
+
"views": batch.views[:, :, permutation],
|
| 520 |
+
"view_state": batch.view_state[:, :, permutation],
|
| 521 |
+
"node_valid": batch.node_valid[:, :, permutation],
|
| 522 |
+
}
|
| 523 |
+
moved = replace(
|
| 524 |
+
batch,
|
| 525 |
+
**node_dim_one,
|
| 526 |
+
**history_nodes,
|
| 527 |
+
ordered_route_valid=ordered_route_valid_from_anchor(history_nodes["node_valid"][:, 7]),
|
| 528 |
+
edge_sender=inverse[batch.edge_sender],
|
| 529 |
+
edge_receiver=inverse[batch.edge_receiver],
|
| 530 |
+
)
|
| 531 |
+
moved.validate()
|
| 532 |
+
return moved
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
__all__ = [
|
| 536 |
+
"BatchContractError",
|
| 537 |
+
"FORBIDDEN_MODEL_FIELDS",
|
| 538 |
+
"ModelBatch",
|
| 539 |
+
"canonical_pair_index",
|
| 540 |
+
"make_synthetic_batch",
|
| 541 |
+
"ordered_route_index",
|
| 542 |
+
"ordered_route_valid_from_anchor",
|
| 543 |
+
"permute_batch",
|
| 544 |
+
]
|
gwam_active13_gwam_training_v3_20260801/model_v2_0_4/config.py
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from collections.abc import Iterable
|
| 4 |
+
from dataclasses import asdict, dataclass
|
| 5 |
+
from typing import Literal
|
| 6 |
+
|
| 7 |
+
MODEL_VERSION = "2.0.4"
|
| 8 |
+
MODEL_ID = "graphpacket_slim_target_compact_velocity_free_v2_0_4"
|
| 9 |
+
MODEL_PROFILE_ID = "active13_target_physical_v2"
|
| 10 |
+
INPUT_FEATURE_PROFILE_ID = "pose_qpos_action_target_views_edges_no_raw_velocity_v2_0_4"
|
| 11 |
+
LOCKED_RELATION_REGISTRY_SHA256 = "b2e807e5fdc642012d20f19921bb7315f3e422915b665d02d3f38da7c61f8cf8"
|
| 12 |
+
LOCKED_TARGET_RESOLVER_SHA256 = "db316b0730fbb42584995ba558d728824fb87069173cc0fac7250cdefc0c139c"
|
| 13 |
+
ALLOWED_RELATION_IDS = (0, 1, 2, 3, 4, 5)
|
| 14 |
+
RELATION_TO_GROUP = {0: 0, 1: 0, 2: 1, 3: 1, 4: 2, 5: 3}
|
| 15 |
+
TRAINING_SEEDS = (20260732, 20260733, 20260734)
|
| 16 |
+
RUN_NAMES = (
|
| 17 |
+
"candidate_correct_target",
|
| 18 |
+
"candidate_all_unknown_target",
|
| 19 |
+
"candidate_valid_wrong_target",
|
| 20 |
+
"action_blind_correct_target",
|
| 21 |
+
"node_only_correct_target",
|
| 22 |
+
"same_information_relation_set_correct_target",
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class ConfigError(ValueError):
|
| 27 |
+
"""Fail-closed model configuration error."""
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@dataclass(frozen=True, slots=True)
|
| 31 |
+
class ArchitectureConfig:
|
| 32 |
+
d_model: int = 384
|
| 33 |
+
edge_dim: int = 192
|
| 34 |
+
attention_heads: int = 8
|
| 35 |
+
edge_bases: int = 8
|
| 36 |
+
relation_groups: int = 4
|
| 37 |
+
encoder_blocks: int = 5
|
| 38 |
+
transition_blocks: int = 4
|
| 39 |
+
decoder_blocks: int = 3
|
| 40 |
+
ff_hidden: int = 1536
|
| 41 |
+
pair_rank: int = 64
|
| 42 |
+
graph_tokens: int = 16
|
| 43 |
+
deterministic_tokens: int = 8
|
| 44 |
+
learned_tokens: int = 8
|
| 45 |
+
history: int = 8
|
| 46 |
+
horizon: int = 8
|
| 47 |
+
geometry_topk: int = 8
|
| 48 |
+
pair_chunk: int = 4096
|
| 49 |
+
dropout: float = 0.0
|
| 50 |
+
activation_checkpointing: bool = True
|
| 51 |
+
moe: bool = False
|
| 52 |
+
|
| 53 |
+
def as_dict(self) -> dict[str, object]:
|
| 54 |
+
return asdict(self)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
ARCHITECTURE = ArchitectureConfig()
|
| 58 |
+
|
| 59 |
+
TargetIntervention = Literal["correct", "all_unknown", "valid_wrong"]
|
| 60 |
+
Topology = Literal["typed", "node_only", "relation_set"]
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
@dataclass(frozen=True, slots=True)
|
| 64 |
+
class RunConfig:
|
| 65 |
+
name: str
|
| 66 |
+
model_id: str
|
| 67 |
+
model_profile_id: str
|
| 68 |
+
target_intervention: TargetIntervention
|
| 69 |
+
topology: Topology
|
| 70 |
+
action_blind: bool
|
| 71 |
+
seed: int
|
| 72 |
+
architecture_key: str
|
| 73 |
+
initialization_key: str
|
| 74 |
+
optimizer_schedule_key: str
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
_RUN_MAPPING: dict[str, tuple[TargetIntervention, Topology, bool]] = {
|
| 78 |
+
"candidate_correct_target": ("correct", "typed", False),
|
| 79 |
+
"candidate_all_unknown_target": ("all_unknown", "typed", False),
|
| 80 |
+
"candidate_valid_wrong_target": ("valid_wrong", "typed", False),
|
| 81 |
+
"action_blind_correct_target": ("correct", "typed", True),
|
| 82 |
+
"node_only_correct_target": ("correct", "node_only", False),
|
| 83 |
+
"same_information_relation_set_correct_target": (
|
| 84 |
+
"correct",
|
| 85 |
+
"relation_set",
|
| 86 |
+
False,
|
| 87 |
+
),
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def validate_model_profile(profile_id: str, relation_ids: Iterable[int]) -> None:
|
| 92 |
+
if profile_id != MODEL_PROFILE_ID:
|
| 93 |
+
raise ConfigError(f"MODEL_PROFILE_INELIGIBLE:{profile_id}")
|
| 94 |
+
ids = tuple(int(value) for value in relation_ids)
|
| 95 |
+
if any(value not in ALLOWED_RELATION_IDS for value in ids):
|
| 96 |
+
raise ConfigError(f"MODEL_RELATION_ID_INELIGIBLE:{ids}")
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def make_run_config(name: str, seed: int = TRAINING_SEEDS[0]) -> RunConfig:
|
| 100 |
+
try:
|
| 101 |
+
intervention, topology, action_blind = _RUN_MAPPING[name]
|
| 102 |
+
except KeyError as exc:
|
| 103 |
+
raise ConfigError(f"RUN_CONFIG_INELIGIBLE:{name}") from exc
|
| 104 |
+
if seed not in TRAINING_SEEDS:
|
| 105 |
+
raise ConfigError(f"TRAINING_SEED_INELIGIBLE:{seed}")
|
| 106 |
+
architecture_key = (
|
| 107 |
+
f"{MODEL_ID}|{MODEL_PROFILE_ID}|{INPUT_FEATURE_PROFILE_ID}|d384-e192-h8-b8-g4-enc5-trans4-dec3-ff1536-r64-t16-L8-H8"
|
| 108 |
+
)
|
| 109 |
+
initialization_key = f"fresh|{MODEL_ID}|seed={seed}"
|
| 110 |
+
optimizer_schedule_key = "adamw-v2|fixed-4608|microbatch1"
|
| 111 |
+
return RunConfig(
|
| 112 |
+
name=name,
|
| 113 |
+
model_id=(
|
| 114 |
+
MODEL_ID
|
| 115 |
+
if topology == "typed" and not action_blind
|
| 116 |
+
else (
|
| 117 |
+
"action_blind_v2"
|
| 118 |
+
if action_blind
|
| 119 |
+
else "node_only_v2"
|
| 120 |
+
if topology == "node_only"
|
| 121 |
+
else "same_information_relation_set_v2"
|
| 122 |
+
)
|
| 123 |
+
),
|
| 124 |
+
model_profile_id=MODEL_PROFILE_ID,
|
| 125 |
+
target_intervention=intervention,
|
| 126 |
+
topology=topology,
|
| 127 |
+
action_blind=action_blind,
|
| 128 |
+
seed=seed,
|
| 129 |
+
architecture_key=architecture_key,
|
| 130 |
+
initialization_key=initialization_key,
|
| 131 |
+
optimizer_schedule_key=optimizer_schedule_key,
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def all_run_configs(seed: int = TRAINING_SEEDS[0]) -> tuple[RunConfig, ...]:
|
| 136 |
+
return tuple(make_run_config(name, seed) for name in RUN_NAMES)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
__all__ = [
|
| 140 |
+
"ALLOWED_RELATION_IDS",
|
| 141 |
+
"ARCHITECTURE",
|
| 142 |
+
"ArchitectureConfig",
|
| 143 |
+
"ConfigError",
|
| 144 |
+
"LOCKED_RELATION_REGISTRY_SHA256",
|
| 145 |
+
"LOCKED_TARGET_RESOLVER_SHA256",
|
| 146 |
+
"INPUT_FEATURE_PROFILE_ID",
|
| 147 |
+
"MODEL_ID",
|
| 148 |
+
"MODEL_PROFILE_ID",
|
| 149 |
+
"MODEL_VERSION",
|
| 150 |
+
"RELATION_TO_GROUP",
|
| 151 |
+
"RUN_NAMES",
|
| 152 |
+
"RunConfig",
|
| 153 |
+
"TRAINING_SEEDS",
|
| 154 |
+
"all_run_configs",
|
| 155 |
+
"make_run_config",
|
| 156 |
+
"validate_model_profile",
|
| 157 |
+
]
|
gwam_active13_gwam_training_v3_20260801/model_v2_0_4/controls.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import gc
|
| 4 |
+
from dataclasses import dataclass
|
| 5 |
+
from fractions import Fraction
|
| 6 |
+
|
| 7 |
+
from torch import nn
|
| 8 |
+
|
| 9 |
+
from .config import RunConfig, make_run_config
|
| 10 |
+
from .model import CompactTargetConditionedGNN, build_model
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def parameter_count(model: nn.Module) -> int:
|
| 14 |
+
seen: set[tuple[int, int, int]] = set()
|
| 15 |
+
total = 0
|
| 16 |
+
for parameter in model.parameters():
|
| 17 |
+
storage = parameter.untyped_storage()
|
| 18 |
+
identity = (storage.data_ptr(), storage.nbytes(), parameter.storage_offset())
|
| 19 |
+
if identity in seen:
|
| 20 |
+
continue
|
| 21 |
+
seen.add(identity)
|
| 22 |
+
total += int(parameter.numel())
|
| 23 |
+
return total
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def _adapter_total(width: int) -> int:
|
| 27 |
+
return 5 * (1154 * width + 384)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@dataclass(frozen=True, slots=True)
|
| 31 |
+
class CompensationDecision:
|
| 32 |
+
topology: str
|
| 33 |
+
candidate_parameter_count: int
|
| 34 |
+
fixed_parameter_count: int
|
| 35 |
+
raw_width_numerator: int
|
| 36 |
+
raw_width_denominator: int
|
| 37 |
+
width: int
|
| 38 |
+
final_parameter_count: int
|
| 39 |
+
method: str
|
| 40 |
+
evaluated_widths: tuple[int, ...]
|
| 41 |
+
|
| 42 |
+
@property
|
| 43 |
+
def raw_width(self) -> Fraction:
|
| 44 |
+
return Fraction(self.raw_width_numerator, self.raw_width_denominator)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
@dataclass(frozen=True, slots=True)
|
| 48 |
+
class TopologyControlBuild:
|
| 49 |
+
model: CompactTargetConditionedGNN
|
| 50 |
+
compensation_width: int
|
| 51 |
+
decision: CompensationDecision
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
@dataclass(frozen=True, slots=True)
|
| 55 |
+
class ArmParityReport:
|
| 56 |
+
names: tuple[str, ...]
|
| 57 |
+
parameter_counts: tuple[int, ...]
|
| 58 |
+
initialization_digests: tuple[str, ...]
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _nearest_positive_multiple_of_eight_half_tie_lower(numerator: int, denominator: int) -> int:
|
| 62 |
+
if numerator <= 0 or denominator <= 0:
|
| 63 |
+
raise ValueError("NONPOSITIVE_COMPENSATION_RAW_WIDTH")
|
| 64 |
+
unit_denominator = denominator * 8
|
| 65 |
+
lower_units, remainder = divmod(numerator, unit_denominator)
|
| 66 |
+
lower_units = max(1, lower_units)
|
| 67 |
+
upper_units = lower_units + 1
|
| 68 |
+
lower_distance = abs(numerator - lower_units * unit_denominator)
|
| 69 |
+
upper_distance = abs(upper_units * unit_denominator - numerator)
|
| 70 |
+
chosen_units = lower_units if lower_distance <= upper_distance else upper_units
|
| 71 |
+
return 8 * chosen_units
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def one_shot_compensation_width(
|
| 75 |
+
candidate_parameter_count: int, topology: str
|
| 76 |
+
) -> CompensationDecision:
|
| 77 |
+
if topology not in {"node_only", "relation_set"}:
|
| 78 |
+
raise ValueError(f"UNKNOWN_TOPOLOGY:{topology}")
|
| 79 |
+
name = (
|
| 80 |
+
"node_only_correct_target"
|
| 81 |
+
if topology == "node_only"
|
| 82 |
+
else "same_information_relation_set_correct_target"
|
| 83 |
+
)
|
| 84 |
+
# Width eight is a bookkeeping scaffold used solely to subtract the exact
|
| 85 |
+
# adapter formula and recover P_fixed,c. It is never evaluated as a model
|
| 86 |
+
# alternative and is not returned as a candidate width.
|
| 87 |
+
scaffold = build_model(make_run_config(name), compensation_width=8)
|
| 88 |
+
scaffold_count = parameter_count(scaffold)
|
| 89 |
+
fixed_count = scaffold_count - _adapter_total(8)
|
| 90 |
+
del scaffold
|
| 91 |
+
gc.collect()
|
| 92 |
+
numerator = candidate_parameter_count - fixed_count - 5 * 384
|
| 93 |
+
denominator = 5 * 1154
|
| 94 |
+
width = _nearest_positive_multiple_of_eight_half_tie_lower(numerator, denominator)
|
| 95 |
+
final_count = fixed_count + _adapter_total(width)
|
| 96 |
+
return CompensationDecision(
|
| 97 |
+
topology=topology,
|
| 98 |
+
candidate_parameter_count=candidate_parameter_count,
|
| 99 |
+
fixed_parameter_count=fixed_count,
|
| 100 |
+
raw_width_numerator=numerator,
|
| 101 |
+
raw_width_denominator=denominator,
|
| 102 |
+
width=width,
|
| 103 |
+
final_parameter_count=final_count,
|
| 104 |
+
method="nearest_positive_multiple_of_8_half_tie_lower",
|
| 105 |
+
evaluated_widths=(width,),
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def build_topology_control(
|
| 110 |
+
run_config: RunConfig, candidate_parameter_count: int
|
| 111 |
+
) -> TopologyControlBuild:
|
| 112 |
+
if run_config.topology not in {"node_only", "relation_set"}:
|
| 113 |
+
raise ValueError(f"NOT_A_TOPOLOGY_CONTROL:{run_config.name}")
|
| 114 |
+
decision = one_shot_compensation_width(candidate_parameter_count, run_config.topology)
|
| 115 |
+
model = build_model(run_config, compensation_width=decision.width)
|
| 116 |
+
actual = parameter_count(model)
|
| 117 |
+
if actual != decision.final_parameter_count:
|
| 118 |
+
raise RuntimeError(
|
| 119 |
+
f"CONTROL_LEDGER_MISMATCH:expected={decision.final_parameter_count}:actual={actual}"
|
| 120 |
+
)
|
| 121 |
+
if abs(actual - candidate_parameter_count) / candidate_parameter_count > 0.01:
|
| 122 |
+
raise RuntimeError("CONTROL_PARAMETER_PARITY_EXCEEDS_ONE_PERCENT")
|
| 123 |
+
# This attribute is non-parameter metadata and makes the selected one-shot
|
| 124 |
+
# width inspectable without changing the module ledger.
|
| 125 |
+
model.compensation_width = decision.width # type: ignore[attr-defined]
|
| 126 |
+
return TopologyControlBuild(
|
| 127 |
+
model=model,
|
| 128 |
+
compensation_width=decision.width,
|
| 129 |
+
decision=decision,
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def verify_arm_parameter_parity(candidate: nn.Module) -> ArmParityReport:
|
| 134 |
+
from .ledger import initialization_digest
|
| 135 |
+
|
| 136 |
+
names = (
|
| 137 |
+
"candidate_correct_target",
|
| 138 |
+
"candidate_all_unknown_target",
|
| 139 |
+
"candidate_valid_wrong_target",
|
| 140 |
+
"action_blind_correct_target",
|
| 141 |
+
)
|
| 142 |
+
counts: list[int] = []
|
| 143 |
+
digests: list[str] = []
|
| 144 |
+
for index, name in enumerate(names):
|
| 145 |
+
model = candidate if index == 0 else build_model(make_run_config(name))
|
| 146 |
+
counts.append(parameter_count(model))
|
| 147 |
+
digests.append(initialization_digest(model))
|
| 148 |
+
if index:
|
| 149 |
+
del model
|
| 150 |
+
gc.collect()
|
| 151 |
+
if len(set(counts)) != 1:
|
| 152 |
+
raise RuntimeError(f"ARM_PARAMETER_COUNT_MISMATCH:{counts}")
|
| 153 |
+
if len(set(digests)) != 1:
|
| 154 |
+
raise RuntimeError("ARM_INITIALIZATION_MISMATCH")
|
| 155 |
+
return ArmParityReport(
|
| 156 |
+
names=names, parameter_counts=tuple(counts), initialization_digests=tuple(digests)
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
__all__ = [
|
| 161 |
+
"ArmParityReport",
|
| 162 |
+
"CompensationDecision",
|
| 163 |
+
"TopologyControlBuild",
|
| 164 |
+
"build_topology_control",
|
| 165 |
+
"one_shot_compensation_width",
|
| 166 |
+
"parameter_count",
|
| 167 |
+
"verify_arm_parameter_parity",
|
| 168 |
+
]
|
gwam_active13_gwam_training_v3_20260801/model_v2_0_4/geometry.py
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import hashlib
|
| 4 |
+
import hmac
|
| 5 |
+
import json
|
| 6 |
+
from dataclasses import dataclass
|
| 7 |
+
from typing import TYPE_CHECKING, Any
|
| 8 |
+
|
| 9 |
+
if TYPE_CHECKING:
|
| 10 |
+
from .batch import ModelBatch
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
GEOMETRY_ARM_PROVENANCE_SCHEMA = "graphpacket_slim_v2_0_4_geometry_arm_provenance_v1"
|
| 14 |
+
|
| 15 |
+
REQUIRED_GEOMETRY_ARM_NAMES = (
|
| 16 |
+
"candidate_correct_target",
|
| 17 |
+
"candidate_all_unknown_target",
|
| 18 |
+
"candidate_valid_wrong_target",
|
| 19 |
+
"action_blind_correct_target",
|
| 20 |
+
"node_only_correct_target",
|
| 21 |
+
"same_information_relation_set_correct_target",
|
| 22 |
+
"action_correct",
|
| 23 |
+
"action_reversed",
|
| 24 |
+
"action_null",
|
| 25 |
+
"action_far_same_task_cross_window",
|
| 26 |
+
"token_correct",
|
| 27 |
+
"token_all_zero",
|
| 28 |
+
"token_different_group_replacement",
|
| 29 |
+
"token_future_horizon_permutation",
|
| 30 |
+
"edge_correct",
|
| 31 |
+
"edge_all_messages_off",
|
| 32 |
+
"edge_relation_preserving_degree_matched_rewire",
|
| 33 |
+
"target_correct",
|
| 34 |
+
"target_all_unknown",
|
| 35 |
+
"target_valid_wrong",
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
_PROVENANCE_ROOT_KEYS = frozenset({"arm_name", "batch_cardinality", "rows", "schema"})
|
| 39 |
+
_PROVENANCE_ROW_KEYS = frozenset({"row_index", "source_identity"})
|
| 40 |
+
_SOURCE_IDENTITY_KEYS = frozenset(
|
| 41 |
+
{
|
| 42 |
+
"dataset_sidecar_sha256",
|
| 43 |
+
"geometry_receipt_sha256",
|
| 44 |
+
"model_profile_id",
|
| 45 |
+
"natural_window_sha256",
|
| 46 |
+
"nested_v1_geometry_sha256",
|
| 47 |
+
"outer_manifest_row_sha256",
|
| 48 |
+
"pre_geometry_source_sha256",
|
| 49 |
+
"relation_registry_sha256",
|
| 50 |
+
"source_path",
|
| 51 |
+
"source_split",
|
| 52 |
+
"target_resolver_sha256",
|
| 53 |
+
}
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class GeometryBindingError(ValueError):
|
| 58 |
+
"""Fail-closed nested-v1 geometry or arm-provenance binding error."""
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _require_digest(value: str, name: str) -> None:
|
| 62 |
+
if type(value) is not str or len(value) != 64 or any(
|
| 63 |
+
character not in "0123456789abcdef" for character in value
|
| 64 |
+
):
|
| 65 |
+
raise GeometryBindingError(f"INVALID_{name}:{value}")
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _canonical_json_bytes(value: Any) -> bytes:
|
| 69 |
+
try:
|
| 70 |
+
return (
|
| 71 |
+
json.dumps(
|
| 72 |
+
value,
|
| 73 |
+
sort_keys=True,
|
| 74 |
+
separators=(",", ":"),
|
| 75 |
+
ensure_ascii=False,
|
| 76 |
+
allow_nan=False,
|
| 77 |
+
).encode("utf-8")
|
| 78 |
+
+ b"\n"
|
| 79 |
+
)
|
| 80 |
+
except (TypeError, ValueError) as exc:
|
| 81 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_JSON_VALUE") from exc
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def _load_canonical_provenance(value: bytes) -> dict[str, Any]:
|
| 85 |
+
if type(value) is not bytes:
|
| 86 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_BYTES_TYPE")
|
| 87 |
+
try:
|
| 88 |
+
decoded = value.decode("utf-8")
|
| 89 |
+
payload = json.loads(decoded)
|
| 90 |
+
except (UnicodeDecodeError, json.JSONDecodeError) as exc:
|
| 91 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_JSON") from exc
|
| 92 |
+
if type(payload) is not dict:
|
| 93 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_ROOT_TYPE")
|
| 94 |
+
if _canonical_json_bytes(payload) != value:
|
| 95 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_NONCANONICAL")
|
| 96 |
+
return payload
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def _row_source_identity(batch: "ModelBatch", row: int) -> dict[str, object]:
|
| 100 |
+
return {
|
| 101 |
+
"dataset_sidecar_sha256": batch.dataset_sidecar_sha256[row],
|
| 102 |
+
"geometry_receipt_sha256": batch.geometry_receipt_sha256[row],
|
| 103 |
+
"model_profile_id": batch.model_profile_id,
|
| 104 |
+
"natural_window_sha256": batch.natural_window_sha256[row],
|
| 105 |
+
"nested_v1_geometry_sha256": batch.nested_v1_geometry_sha256[row],
|
| 106 |
+
"outer_manifest_row_sha256": batch.outer_manifest_row_sha256[row],
|
| 107 |
+
"pre_geometry_source_sha256": batch.pre_geometry_source_sha256[row],
|
| 108 |
+
"relation_registry_sha256": batch.relation_registry_sha256,
|
| 109 |
+
"source_path": batch.source_paths[row],
|
| 110 |
+
"source_split": batch.source_split[row],
|
| 111 |
+
"target_resolver_sha256": batch.target_resolver_sha256,
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
@dataclass(frozen=True, slots=True)
|
| 116 |
+
class GeometryBinding:
|
| 117 |
+
object_bytes: bytes
|
| 118 |
+
object_sha256: str
|
| 119 |
+
geometry_receipt_sha256: str
|
| 120 |
+
pre_geometry_source_sha256: str
|
| 121 |
+
|
| 122 |
+
def validate(self) -> None:
|
| 123 |
+
if type(self.object_bytes) is not bytes:
|
| 124 |
+
raise GeometryBindingError("GEOMETRY_BYTES_TYPE")
|
| 125 |
+
_require_digest(self.object_sha256, "OBJECT_SHA256")
|
| 126 |
+
_require_digest(self.geometry_receipt_sha256, "GEOMETRY_RECEIPT_SHA256")
|
| 127 |
+
_require_digest(self.pre_geometry_source_sha256, "PRE_GEOMETRY_SOURCE_SHA256")
|
| 128 |
+
actual = hashlib.sha256(self.object_bytes).hexdigest()
|
| 129 |
+
if actual != self.object_sha256:
|
| 130 |
+
raise GeometryBindingError(
|
| 131 |
+
f"GEOMETRY_OBJECT_DIGEST_MISMATCH:expected={self.object_sha256}:actual={actual}"
|
| 132 |
+
)
|
| 133 |
+
if self.geometry_receipt_sha256 != self.object_sha256:
|
| 134 |
+
raise GeometryBindingError("GEOMETRY_RECEIPT_OBJECT_DIGEST_MISMATCH")
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
@dataclass(frozen=True, slots=True)
|
| 138 |
+
class GeometryArmBindingResult:
|
| 139 |
+
arm_names: tuple[str, ...]
|
| 140 |
+
byte_length: int
|
| 141 |
+
object_sha256: str
|
| 142 |
+
geometry_receipt_sha256: str
|
| 143 |
+
pre_geometry_source_sha256: str
|
| 144 |
+
memcmp_equal: bool
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
@dataclass(frozen=True, slots=True)
|
| 148 |
+
class GeometryArmInput:
|
| 149 |
+
"""One runtime arm plus an independently supplied canonical provenance receipt."""
|
| 150 |
+
|
| 151 |
+
arm_name: str
|
| 152 |
+
batch: "ModelBatch"
|
| 153 |
+
provenance_bytes: bytes
|
| 154 |
+
provenance_sha256: str
|
| 155 |
+
|
| 156 |
+
def validate(self) -> dict[str, Any]:
|
| 157 |
+
from .batch import ModelBatch
|
| 158 |
+
|
| 159 |
+
if type(self.batch) is not ModelBatch:
|
| 160 |
+
raise GeometryBindingError("GEOMETRY_ARM_INPUT_BATCH_TYPE")
|
| 161 |
+
if self.arm_name not in REQUIRED_GEOMETRY_ARM_NAMES:
|
| 162 |
+
raise GeometryBindingError(f"GEOMETRY_ARM_INPUT_NAME:{self.arm_name}")
|
| 163 |
+
self.batch.validate()
|
| 164 |
+
_require_digest(self.provenance_sha256, "GEOMETRY_ARM_PROVENANCE_SHA256")
|
| 165 |
+
actual_digest = hashlib.sha256(self.provenance_bytes).hexdigest()
|
| 166 |
+
if not hmac.compare_digest(actual_digest, self.provenance_sha256):
|
| 167 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_DIGEST_MISMATCH")
|
| 168 |
+
payload = _load_canonical_provenance(self.provenance_bytes)
|
| 169 |
+
if set(payload) != _PROVENANCE_ROOT_KEYS:
|
| 170 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_ROOT_FIELDS")
|
| 171 |
+
if payload.get("schema") != GEOMETRY_ARM_PROVENANCE_SCHEMA:
|
| 172 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_SCHEMA")
|
| 173 |
+
if payload.get("arm_name") != self.arm_name:
|
| 174 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_NAME_MISMATCH")
|
| 175 |
+
if type(payload.get("batch_cardinality")) is not int or payload[
|
| 176 |
+
"batch_cardinality"
|
| 177 |
+
] != self.batch.batch_size:
|
| 178 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_BATCH_CARDINALITY")
|
| 179 |
+
rows = payload.get("rows")
|
| 180 |
+
if type(rows) is not list or len(rows) != self.batch.batch_size:
|
| 181 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_ROW_CARDINALITY")
|
| 182 |
+
for row, entry in enumerate(rows):
|
| 183 |
+
if type(entry) is not dict or set(entry) != _PROVENANCE_ROW_KEYS:
|
| 184 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_ROW_FIELDS")
|
| 185 |
+
if type(entry["row_index"]) is not int or entry["row_index"] != row:
|
| 186 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_ROW_INDEX")
|
| 187 |
+
identity = entry["source_identity"]
|
| 188 |
+
if type(identity) is not dict or set(identity) != _SOURCE_IDENTITY_KEYS:
|
| 189 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_SOURCE_FIELDS")
|
| 190 |
+
if identity != _row_source_identity(self.batch, row):
|
| 191 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_SOURCE_MISMATCH")
|
| 192 |
+
return payload
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
@dataclass(frozen=True, slots=True)
|
| 196 |
+
class GeometryForwardGuard:
|
| 197 |
+
"""Immutable row-level C4 binding plus explicit per-arm provenance."""
|
| 198 |
+
|
| 199 |
+
arm_names: tuple[str, ...]
|
| 200 |
+
rows_by_arm: tuple[tuple[GeometryBinding, ...], ...]
|
| 201 |
+
arm_provenance_bytes: tuple[bytes, ...]
|
| 202 |
+
arm_provenance_sha256: tuple[str, ...]
|
| 203 |
+
|
| 204 |
+
def verify(self, arm_name: str, batch: "ModelBatch") -> None:
|
| 205 |
+
_verify_complete_guard_matrix(self.arm_names, self.rows_by_arm)
|
| 206 |
+
try:
|
| 207 |
+
arm_index = self.arm_names.index(arm_name)
|
| 208 |
+
except ValueError as exc:
|
| 209 |
+
raise GeometryBindingError(f"GEOMETRY_ARM_UNBOUND:{arm_name}") from exc
|
| 210 |
+
GeometryArmInput(
|
| 211 |
+
arm_name=arm_name,
|
| 212 |
+
batch=batch,
|
| 213 |
+
provenance_bytes=self.arm_provenance_bytes[arm_index],
|
| 214 |
+
provenance_sha256=self.arm_provenance_sha256[arm_index],
|
| 215 |
+
).validate()
|
| 216 |
+
expected_rows = self.rows_by_arm[arm_index]
|
| 217 |
+
if len(expected_rows) != batch.batch_size:
|
| 218 |
+
raise GeometryBindingError("GEOMETRY_FORWARD_BATCH_CARDINALITY")
|
| 219 |
+
for row, expected in enumerate(expected_rows):
|
| 220 |
+
actual = GeometryBinding(
|
| 221 |
+
object_bytes=batch.nested_v1_geometry_bytes[row],
|
| 222 |
+
object_sha256=batch.nested_v1_geometry_sha256[row],
|
| 223 |
+
geometry_receipt_sha256=batch.geometry_receipt_sha256[row],
|
| 224 |
+
pre_geometry_source_sha256=batch.pre_geometry_source_sha256[row],
|
| 225 |
+
)
|
| 226 |
+
bind_geometry_across_arms({"frozen": expected, "forward": actual})
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def bind_geometry_across_arms(
|
| 230 |
+
bindings: dict[str, GeometryBinding],
|
| 231 |
+
) -> GeometryArmBindingResult:
|
| 232 |
+
if not bindings:
|
| 233 |
+
raise GeometryBindingError("GEOMETRY_ARM_SET_EMPTY")
|
| 234 |
+
ordered = tuple(sorted(bindings.items()))
|
| 235 |
+
for _, binding in ordered:
|
| 236 |
+
binding.validate()
|
| 237 |
+
reference_name, reference = ordered[0]
|
| 238 |
+
for name, binding in ordered[1:]:
|
| 239 |
+
if len(binding.object_bytes) != len(reference.object_bytes):
|
| 240 |
+
raise GeometryBindingError(f"GEOMETRY_BYTES_MISMATCH:{reference_name}:{name}:length")
|
| 241 |
+
if not hmac.compare_digest(binding.object_bytes, reference.object_bytes):
|
| 242 |
+
raise GeometryBindingError(f"GEOMETRY_BYTES_MISMATCH:{reference_name}:{name}:memcmp")
|
| 243 |
+
if (
|
| 244 |
+
binding.object_sha256 != reference.object_sha256
|
| 245 |
+
or binding.geometry_receipt_sha256 != reference.geometry_receipt_sha256
|
| 246 |
+
or binding.pre_geometry_source_sha256 != reference.pre_geometry_source_sha256
|
| 247 |
+
):
|
| 248 |
+
raise GeometryBindingError(f"GEOMETRY_BINDING_MISMATCH:{reference_name}:{name}")
|
| 249 |
+
return GeometryArmBindingResult(
|
| 250 |
+
arm_names=tuple(name for name, _ in ordered),
|
| 251 |
+
byte_length=len(reference.object_bytes),
|
| 252 |
+
object_sha256=reference.object_sha256,
|
| 253 |
+
geometry_receipt_sha256=reference.geometry_receipt_sha256,
|
| 254 |
+
pre_geometry_source_sha256=reference.pre_geometry_source_sha256,
|
| 255 |
+
memcmp_equal=True,
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def _verify_complete_guard_matrix(
|
| 260 |
+
arm_names: tuple[str, ...],
|
| 261 |
+
rows_by_arm: tuple[tuple[GeometryBinding, ...], ...],
|
| 262 |
+
) -> None:
|
| 263 |
+
required = set(REQUIRED_GEOMETRY_ARM_NAMES)
|
| 264 |
+
actual = set(arm_names)
|
| 265 |
+
if len(arm_names) != len(actual) or actual != required:
|
| 266 |
+
missing = tuple(sorted(required - actual))
|
| 267 |
+
extra = tuple(sorted(actual - required))
|
| 268 |
+
raise GeometryBindingError(
|
| 269 |
+
f"GEOMETRY_ARM_MATRIX_INCOMPLETE:missing={missing}:extra={extra}"
|
| 270 |
+
)
|
| 271 |
+
if len(rows_by_arm) != len(arm_names):
|
| 272 |
+
raise GeometryBindingError("GEOMETRY_ARM_MATRIX_CARDINALITY")
|
| 273 |
+
batch_sizes = {len(rows) for rows in rows_by_arm}
|
| 274 |
+
if len(batch_sizes) != 1 or not batch_sizes or next(iter(batch_sizes)) < 1:
|
| 275 |
+
raise GeometryBindingError("GEOMETRY_ARM_BATCH_CARDINALITY")
|
| 276 |
+
batch_size = next(iter(batch_sizes))
|
| 277 |
+
for row in range(batch_size):
|
| 278 |
+
bind_geometry_across_arms(
|
| 279 |
+
{arm_name: rows_by_arm[index][row] for index, arm_name in enumerate(arm_names)}
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
def geometry_guard_for_batches(inputs: tuple[GeometryArmInput, ...]) -> GeometryForwardGuard:
|
| 284 |
+
"""Bind all runtime arms from canonical identity/provenance receipts."""
|
| 285 |
+
|
| 286 |
+
if type(inputs) is not tuple or not inputs:
|
| 287 |
+
raise GeometryBindingError("GEOMETRY_ARM_INPUT_TYPE")
|
| 288 |
+
if any(type(value) is not GeometryArmInput for value in inputs):
|
| 289 |
+
raise GeometryBindingError("GEOMETRY_ARM_INPUT_TYPE")
|
| 290 |
+
validated = tuple((value, value.validate()) for value in inputs)
|
| 291 |
+
ordered = tuple(sorted(validated, key=lambda item: item[0].arm_name))
|
| 292 |
+
arm_names = tuple(value.arm_name for value, _ in ordered)
|
| 293 |
+
required = set(REQUIRED_GEOMETRY_ARM_NAMES)
|
| 294 |
+
actual = set(arm_names)
|
| 295 |
+
if len(arm_names) != len(actual) or actual != required:
|
| 296 |
+
missing = tuple(sorted(required - actual))
|
| 297 |
+
extra = tuple(sorted(actual - required))
|
| 298 |
+
raise GeometryBindingError(
|
| 299 |
+
f"GEOMETRY_ARM_MATRIX_INCOMPLETE:missing={missing}:extra={extra}"
|
| 300 |
+
)
|
| 301 |
+
batch_sizes = {value.batch.batch_size for value, _ in ordered}
|
| 302 |
+
if len(batch_sizes) != 1:
|
| 303 |
+
raise GeometryBindingError("GEOMETRY_ARM_BATCH_CARDINALITY")
|
| 304 |
+
reference_rows = ordered[0][1]["rows"]
|
| 305 |
+
if any(payload["rows"] != reference_rows for _, payload in ordered[1:]):
|
| 306 |
+
raise GeometryBindingError("GEOMETRY_ARM_PROVENANCE_CROSS_ARM_MISMATCH")
|
| 307 |
+
rows_by_arm = tuple(
|
| 308 |
+
tuple(
|
| 309 |
+
GeometryBinding(
|
| 310 |
+
object_bytes=value.batch.nested_v1_geometry_bytes[row],
|
| 311 |
+
object_sha256=value.batch.nested_v1_geometry_sha256[row],
|
| 312 |
+
geometry_receipt_sha256=value.batch.geometry_receipt_sha256[row],
|
| 313 |
+
pre_geometry_source_sha256=value.batch.pre_geometry_source_sha256[row],
|
| 314 |
+
)
|
| 315 |
+
for row in range(value.batch.batch_size)
|
| 316 |
+
)
|
| 317 |
+
for value, _ in ordered
|
| 318 |
+
)
|
| 319 |
+
result = GeometryForwardGuard(
|
| 320 |
+
arm_names=arm_names,
|
| 321 |
+
rows_by_arm=rows_by_arm,
|
| 322 |
+
arm_provenance_bytes=tuple(value.provenance_bytes for value, _ in ordered),
|
| 323 |
+
arm_provenance_sha256=tuple(value.provenance_sha256 for value, _ in ordered),
|
| 324 |
+
)
|
| 325 |
+
_verify_complete_guard_matrix(result.arm_names, result.rows_by_arm)
|
| 326 |
+
return result
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
__all__ = [
|
| 330 |
+
"GEOMETRY_ARM_PROVENANCE_SCHEMA",
|
| 331 |
+
"GeometryArmBindingResult",
|
| 332 |
+
"GeometryArmInput",
|
| 333 |
+
"GeometryBinding",
|
| 334 |
+
"GeometryBindingError",
|
| 335 |
+
"GeometryForwardGuard",
|
| 336 |
+
"REQUIRED_GEOMETRY_ARM_NAMES",
|
| 337 |
+
"bind_geometry_across_arms",
|
| 338 |
+
"geometry_guard_for_batches",
|
| 339 |
+
]
|
gwam_active13_gwam_training_v3_20260801/model_v2_0_4/interventions.py
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import hashlib
|
| 4 |
+
import hmac
|
| 5 |
+
import json
|
| 6 |
+
from dataclasses import dataclass, fields
|
| 7 |
+
from typing import Any
|
| 8 |
+
|
| 9 |
+
import torch
|
| 10 |
+
from torch import Tensor
|
| 11 |
+
|
| 12 |
+
from .batch import ModelBatch
|
| 13 |
+
from .config import RunConfig, make_run_config
|
| 14 |
+
|
| 15 |
+
TARGET_INTERVENTION_RECEIPT_SCHEMA = (
|
| 16 |
+
"graphpacket_slim_v2_0_4_target_intervention_receipt_v1"
|
| 17 |
+
)
|
| 18 |
+
BOOL_TENSOR_DIGEST_SCHEMA = "graphpacket_slim_v2_0_4_bool_tensor_digest_v1"
|
| 19 |
+
|
| 20 |
+
_TARGET_FIELDS = frozenset({"is_task_target", "task_target_valid"})
|
| 21 |
+
_RECEIPT_ROOT_KEYS = frozenset({"arms", "node_count", "row_source_identity", "schema"})
|
| 22 |
+
_RECEIPT_ARM_NAMES = ("correct", "all_unknown", "valid_wrong")
|
| 23 |
+
_RECEIPT_ARM_KEYS = frozenset(
|
| 24 |
+
{
|
| 25 |
+
"is_task_target_sha256",
|
| 26 |
+
"supported",
|
| 27 |
+
"target_cardinality",
|
| 28 |
+
"task_target_valid_sha256",
|
| 29 |
+
"valid_cardinality",
|
| 30 |
+
}
|
| 31 |
+
)
|
| 32 |
+
_SOURCE_IDENTITY_KEYS = frozenset(
|
| 33 |
+
{
|
| 34 |
+
"dataset_sidecar_sha256",
|
| 35 |
+
"geometry_receipt_sha256",
|
| 36 |
+
"model_profile_id",
|
| 37 |
+
"natural_window_sha256",
|
| 38 |
+
"nested_v1_geometry_sha256",
|
| 39 |
+
"outer_manifest_row_sha256",
|
| 40 |
+
"pre_geometry_source_sha256",
|
| 41 |
+
"relation_registry_sha256",
|
| 42 |
+
"source_path",
|
| 43 |
+
"source_split",
|
| 44 |
+
"target_resolver_sha256",
|
| 45 |
+
}
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def _canonical_json_bytes(value: Any) -> bytes:
|
| 50 |
+
try:
|
| 51 |
+
return (
|
| 52 |
+
json.dumps(
|
| 53 |
+
value,
|
| 54 |
+
sort_keys=True,
|
| 55 |
+
separators=(",", ":"),
|
| 56 |
+
ensure_ascii=False,
|
| 57 |
+
allow_nan=False,
|
| 58 |
+
).encode("utf-8")
|
| 59 |
+
+ b"\n"
|
| 60 |
+
)
|
| 61 |
+
except (TypeError, ValueError) as exc:
|
| 62 |
+
raise ValueError("DATASET_INTERVENTION_RECEIPT_JSON_VALUE") from exc
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def canonical_bool_tensor_sha256(row: Tensor) -> str:
|
| 66 |
+
"""Digest one bool row with an explicit schema, dtype, shape, and raw bytes."""
|
| 67 |
+
|
| 68 |
+
if type(row) is not Tensor or row.dtype != torch.bool or row.ndim != 1:
|
| 69 |
+
raise ValueError("DATASET_INTERVENTION_RECEIPT_TENSOR_CONTRACT")
|
| 70 |
+
header = _canonical_json_bytes(
|
| 71 |
+
{
|
| 72 |
+
"dtype": "bool",
|
| 73 |
+
"schema": BOOL_TENSOR_DIGEST_SCHEMA,
|
| 74 |
+
"shape": [int(row.shape[0])],
|
| 75 |
+
}
|
| 76 |
+
)
|
| 77 |
+
raw = bytes(int(value) for value in row.to(torch.uint8).cpu().tolist())
|
| 78 |
+
return hashlib.sha256(header + raw).hexdigest()
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def _require_digest(value: str) -> None:
|
| 82 |
+
if type(value) is not str or len(value) != 64 or any(
|
| 83 |
+
character not in "0123456789abcdef" for character in value
|
| 84 |
+
):
|
| 85 |
+
raise ValueError(f"DATASET_INTERVENTION_RECEIPT_INVALID:{value}")
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def _row_source_identity(batch: ModelBatch, row: int) -> dict[str, object]:
|
| 89 |
+
return {
|
| 90 |
+
"dataset_sidecar_sha256": batch.dataset_sidecar_sha256[row],
|
| 91 |
+
"geometry_receipt_sha256": batch.geometry_receipt_sha256[row],
|
| 92 |
+
"model_profile_id": batch.model_profile_id,
|
| 93 |
+
"natural_window_sha256": batch.natural_window_sha256[row],
|
| 94 |
+
"nested_v1_geometry_sha256": batch.nested_v1_geometry_sha256[row],
|
| 95 |
+
"outer_manifest_row_sha256": batch.outer_manifest_row_sha256[row],
|
| 96 |
+
"pre_geometry_source_sha256": batch.pre_geometry_source_sha256[row],
|
| 97 |
+
"relation_registry_sha256": batch.relation_registry_sha256,
|
| 98 |
+
"source_path": batch.source_paths[row],
|
| 99 |
+
"source_split": batch.source_split[row],
|
| 100 |
+
"target_resolver_sha256": batch.target_resolver_sha256,
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def _load_canonical_receipt(value: bytes) -> dict[str, Any]:
|
| 105 |
+
if type(value) is not bytes:
|
| 106 |
+
raise ValueError("DATASET_INTERVENTION_RECEIPT_BYTES_TYPE")
|
| 107 |
+
try:
|
| 108 |
+
payload = json.loads(value.decode("utf-8"))
|
| 109 |
+
except (UnicodeDecodeError, json.JSONDecodeError) as exc:
|
| 110 |
+
raise ValueError("DATASET_INTERVENTION_RECEIPT_JSON") from exc
|
| 111 |
+
if type(payload) is not dict:
|
| 112 |
+
raise ValueError("DATASET_INTERVENTION_RECEIPT_ROOT_TYPE")
|
| 113 |
+
if _canonical_json_bytes(payload) != value:
|
| 114 |
+
raise ValueError("DATASET_INTERVENTION_RECEIPT_NONCANONICAL")
|
| 115 |
+
return payload
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
@dataclass(frozen=True, slots=True)
|
| 119 |
+
class TargetInterventionBatchBundle:
|
| 120 |
+
correct: ModelBatch
|
| 121 |
+
all_unknown: ModelBatch
|
| 122 |
+
valid_wrong: ModelBatch
|
| 123 |
+
valid_wrong_support: tuple[bool, ...]
|
| 124 |
+
dataset_intervention_receipt_bytes: tuple[bytes, ...]
|
| 125 |
+
dataset_intervention_receipt_sha256: tuple[str, ...]
|
| 126 |
+
|
| 127 |
+
def __iter__(self):
|
| 128 |
+
return iter(_RECEIPT_ARM_NAMES)
|
| 129 |
+
|
| 130 |
+
def __getitem__(self, name: str) -> ModelBatch:
|
| 131 |
+
if name not in _RECEIPT_ARM_NAMES:
|
| 132 |
+
raise KeyError(name)
|
| 133 |
+
return getattr(self, name)
|
| 134 |
+
|
| 135 |
+
def as_dict(self) -> dict[str, ModelBatch]:
|
| 136 |
+
return {name: self[name] for name in _RECEIPT_ARM_NAMES}
|
| 137 |
+
|
| 138 |
+
def geometry_guard(self, arm_inputs):
|
| 139 |
+
"""Validate explicit upstream arm provenance; never synthesize arm identities."""
|
| 140 |
+
|
| 141 |
+
from .geometry import GeometryArmInput, geometry_guard_for_batches
|
| 142 |
+
|
| 143 |
+
if type(arm_inputs) is not tuple or any(
|
| 144 |
+
type(value) is not GeometryArmInput for value in arm_inputs
|
| 145 |
+
):
|
| 146 |
+
raise ValueError("GEOMETRY_ARM_INPUT_REQUIRED")
|
| 147 |
+
by_name = {value.arm_name: value for value in arm_inputs}
|
| 148 |
+
expected = {
|
| 149 |
+
"candidate_correct_target": self.correct,
|
| 150 |
+
"candidate_all_unknown_target": self.all_unknown,
|
| 151 |
+
"candidate_valid_wrong_target": self.valid_wrong,
|
| 152 |
+
}
|
| 153 |
+
for arm_name, batch in expected.items():
|
| 154 |
+
if arm_name not in by_name or by_name[arm_name].batch is not batch:
|
| 155 |
+
raise ValueError(f"TARGET_GEOMETRY_ARM_BINDING:{arm_name}")
|
| 156 |
+
return geometry_guard_for_batches(arm_inputs)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def _verify_receipt_row(
|
| 160 |
+
*,
|
| 161 |
+
row: int,
|
| 162 |
+
receipt_bytes: bytes,
|
| 163 |
+
receipt_sha256: str,
|
| 164 |
+
correct: ModelBatch,
|
| 165 |
+
all_unknown: ModelBatch,
|
| 166 |
+
valid_wrong: ModelBatch,
|
| 167 |
+
valid_wrong_supported: bool,
|
| 168 |
+
) -> None:
|
| 169 |
+
_require_digest(receipt_sha256)
|
| 170 |
+
actual_digest = hashlib.sha256(receipt_bytes).hexdigest()
|
| 171 |
+
if not hmac.compare_digest(actual_digest, receipt_sha256):
|
| 172 |
+
raise ValueError("DATASET_INTERVENTION_RECEIPT_DIGEST_MISMATCH")
|
| 173 |
+
payload = _load_canonical_receipt(receipt_bytes)
|
| 174 |
+
if set(payload) != _RECEIPT_ROOT_KEYS:
|
| 175 |
+
raise ValueError("DATASET_INTERVENTION_RECEIPT_SCHEMA_ROOT_FIELDS")
|
| 176 |
+
if payload.get("schema") != TARGET_INTERVENTION_RECEIPT_SCHEMA:
|
| 177 |
+
raise ValueError("DATASET_INTERVENTION_RECEIPT_SCHEMA")
|
| 178 |
+
if type(payload.get("node_count")) is not int or payload["node_count"] != correct.n_nodes:
|
| 179 |
+
raise ValueError("DATASET_INTERVENTION_RECEIPT_CARDINALITY_MISMATCH:node_count")
|
| 180 |
+
source = payload.get("row_source_identity")
|
| 181 |
+
if type(source) is not dict or set(source) != _SOURCE_IDENTITY_KEYS:
|
| 182 |
+
raise ValueError("DATASET_INTERVENTION_RECEIPT_SCHEMA_SOURCE_FIELDS")
|
| 183 |
+
if source != _row_source_identity(correct, row):
|
| 184 |
+
raise ValueError("DATASET_INTERVENTION_RECEIPT_SOURCE_MISMATCH")
|
| 185 |
+
arms = payload.get("arms")
|
| 186 |
+
if type(arms) is not dict or set(arms) != set(_RECEIPT_ARM_NAMES):
|
| 187 |
+
raise ValueError("DATASET_INTERVENTION_RECEIPT_SCHEMA_ARMS")
|
| 188 |
+
for name, batch, expected_support in (
|
| 189 |
+
("correct", correct, True),
|
| 190 |
+
("all_unknown", all_unknown, True),
|
| 191 |
+
("valid_wrong", valid_wrong, valid_wrong_supported),
|
| 192 |
+
):
|
| 193 |
+
arm = arms[name]
|
| 194 |
+
if type(arm) is not dict or set(arm) != _RECEIPT_ARM_KEYS:
|
| 195 |
+
raise ValueError(f"DATASET_INTERVENTION_RECEIPT_SCHEMA_ARM_FIELDS:{name}")
|
| 196 |
+
if type(arm["supported"]) is not bool or arm["supported"] is not expected_support:
|
| 197 |
+
raise ValueError(f"DATASET_INTERVENTION_RECEIPT_SUPPORT_MISMATCH:{name}")
|
| 198 |
+
target = batch.is_task_target[row]
|
| 199 |
+
valid = batch.task_target_valid[row]
|
| 200 |
+
for key, tensor in (
|
| 201 |
+
("is_task_target_sha256", target),
|
| 202 |
+
("task_target_valid_sha256", valid),
|
| 203 |
+
):
|
| 204 |
+
_require_digest(arm[key])
|
| 205 |
+
if arm[key] != canonical_bool_tensor_sha256(tensor):
|
| 206 |
+
raise ValueError(
|
| 207 |
+
f"DATASET_INTERVENTION_RECEIPT_TENSOR_DIGEST_MISMATCH:{name}:{key}"
|
| 208 |
+
)
|
| 209 |
+
expected_counts = {
|
| 210 |
+
"target_cardinality": int(target.sum().item()),
|
| 211 |
+
"valid_cardinality": int(valid.sum().item()),
|
| 212 |
+
}
|
| 213 |
+
for key, expected in expected_counts.items():
|
| 214 |
+
if type(arm[key]) is not int or arm[key] != expected:
|
| 215 |
+
raise ValueError(
|
| 216 |
+
f"DATASET_INTERVENTION_RECEIPT_CARDINALITY_MISMATCH:{name}:{key}"
|
| 217 |
+
)
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def bind_precomputed_target_intervention_batches(
|
| 221 |
+
*,
|
| 222 |
+
correct: ModelBatch,
|
| 223 |
+
all_unknown: ModelBatch,
|
| 224 |
+
valid_wrong: ModelBatch,
|
| 225 |
+
valid_wrong_support: tuple[bool, ...],
|
| 226 |
+
dataset_intervention_receipt_bytes: tuple[bytes, ...],
|
| 227 |
+
dataset_intervention_receipt_sha256: tuple[str, ...],
|
| 228 |
+
) -> TargetInterventionBatchBundle:
|
| 229 |
+
"""Bind dataset-authored target arms to canonical row receipts."""
|
| 230 |
+
|
| 231 |
+
for batch in (correct, all_unknown, valid_wrong):
|
| 232 |
+
if type(batch) is not ModelBatch:
|
| 233 |
+
raise ValueError("TARGET_INTERVENTION_BATCH_TYPE")
|
| 234 |
+
batch.validate()
|
| 235 |
+
b = correct.batch_size
|
| 236 |
+
if any(batch.batch_size != b or batch.n_nodes != correct.n_nodes for batch in (all_unknown, valid_wrong)):
|
| 237 |
+
raise ValueError("TARGET_INTERVENTION_BATCH_CARDINALITY")
|
| 238 |
+
if len(valid_wrong_support) != b or any(type(value) is not bool for value in valid_wrong_support):
|
| 239 |
+
raise ValueError("VALID_WRONG_SUPPORT_CARDINALITY")
|
| 240 |
+
if type(dataset_intervention_receipt_bytes) is not tuple or len(
|
| 241 |
+
dataset_intervention_receipt_bytes
|
| 242 |
+
) != b:
|
| 243 |
+
raise ValueError("DATASET_INTERVENTION_RECEIPT_BYTES_REQUIRED")
|
| 244 |
+
if type(dataset_intervention_receipt_sha256) is not tuple or len(
|
| 245 |
+
dataset_intervention_receipt_sha256
|
| 246 |
+
) != b:
|
| 247 |
+
raise ValueError("DATASET_INTERVENTION_RECEIPT_REQUIRED")
|
| 248 |
+
verify_same_information_batch_parity(
|
| 249 |
+
{"correct": correct, "all_unknown": all_unknown, "valid_wrong": valid_wrong},
|
| 250 |
+
target_intervention=True,
|
| 251 |
+
)
|
| 252 |
+
if torch.any(all_unknown.is_task_target) or torch.any(all_unknown.task_target_valid):
|
| 253 |
+
raise ValueError("ALL_UNKNOWN_ARM_NOT_ALL_UNKNOWN")
|
| 254 |
+
for row, supported in enumerate(valid_wrong_support):
|
| 255 |
+
if supported:
|
| 256 |
+
if not torch.equal(valid_wrong.task_target_valid[row], correct.task_target_valid[row]):
|
| 257 |
+
raise ValueError("VALID_WRONG_VALIDITY_MISMATCH")
|
| 258 |
+
if torch.any(valid_wrong.is_task_target[row] & correct.is_task_target[row]):
|
| 259 |
+
raise ValueError("VALID_WRONG_NOT_DISJOINT")
|
| 260 |
+
if int(valid_wrong.is_task_target[row].sum()) != int(correct.is_task_target[row].sum()):
|
| 261 |
+
raise ValueError("VALID_WRONG_CARDINALITY_MISMATCH")
|
| 262 |
+
elif torch.any(valid_wrong.is_task_target[row]) or torch.any(
|
| 263 |
+
valid_wrong.task_target_valid[row]
|
| 264 |
+
):
|
| 265 |
+
raise ValueError("VALID_WRONG_UNSUPPORTED_MUST_USE_ALL_UNKNOWN")
|
| 266 |
+
_verify_receipt_row(
|
| 267 |
+
row=row,
|
| 268 |
+
receipt_bytes=dataset_intervention_receipt_bytes[row],
|
| 269 |
+
receipt_sha256=dataset_intervention_receipt_sha256[row],
|
| 270 |
+
correct=correct,
|
| 271 |
+
all_unknown=all_unknown,
|
| 272 |
+
valid_wrong=valid_wrong,
|
| 273 |
+
valid_wrong_supported=supported,
|
| 274 |
+
)
|
| 275 |
+
return TargetInterventionBatchBundle(
|
| 276 |
+
correct=correct,
|
| 277 |
+
all_unknown=all_unknown,
|
| 278 |
+
valid_wrong=valid_wrong,
|
| 279 |
+
valid_wrong_support=valid_wrong_support,
|
| 280 |
+
dataset_intervention_receipt_bytes=dataset_intervention_receipt_bytes,
|
| 281 |
+
dataset_intervention_receipt_sha256=dataset_intervention_receipt_sha256,
|
| 282 |
+
)
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
def select_target_intervention_batch(
|
| 286 |
+
run_config: RunConfig,
|
| 287 |
+
bundle: TargetInterventionBatchBundle,
|
| 288 |
+
) -> ModelBatch:
|
| 289 |
+
"""Fail closed unless a canonical run selects its declared dataset arm."""
|
| 290 |
+
|
| 291 |
+
if type(run_config) is not RunConfig:
|
| 292 |
+
raise ValueError("RUN_CONFIG_TYPE")
|
| 293 |
+
canonical = make_run_config(run_config.name, run_config.seed)
|
| 294 |
+
if run_config != canonical:
|
| 295 |
+
raise ValueError("RUN_CONFIG_NONCANONICAL")
|
| 296 |
+
verify_same_information_batch_parity(bundle)
|
| 297 |
+
return bundle[run_config.target_intervention]
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
def verify_same_information_batch_parity(
|
| 301 |
+
batches: dict[str, ModelBatch] | TargetInterventionBatchBundle,
|
| 302 |
+
*,
|
| 303 |
+
target_intervention: bool | None = None,
|
| 304 |
+
) -> None:
|
| 305 |
+
if isinstance(batches, TargetInterventionBatchBundle):
|
| 306 |
+
target_intervention = True
|
| 307 |
+
batches = batches.as_dict()
|
| 308 |
+
elif target_intervention is None:
|
| 309 |
+
target_intervention = False
|
| 310 |
+
if not batches:
|
| 311 |
+
raise ValueError("SAME_INFORMATION_ARM_SET_EMPTY")
|
| 312 |
+
ordered = tuple(batches.items())
|
| 313 |
+
_, reference = ordered[0]
|
| 314 |
+
reference.validate()
|
| 315 |
+
for arm_name, batch in ordered[1:]:
|
| 316 |
+
batch.validate()
|
| 317 |
+
for field in fields(ModelBatch):
|
| 318 |
+
name = field.name
|
| 319 |
+
if target_intervention and name in _TARGET_FIELDS:
|
| 320 |
+
continue
|
| 321 |
+
left = getattr(reference, name)
|
| 322 |
+
right = getattr(batch, name)
|
| 323 |
+
if isinstance(left, torch.Tensor):
|
| 324 |
+
if not torch.equal(left, right):
|
| 325 |
+
raise ValueError(f"SAME_INFORMATION_PARITY_FAIL:{name}:{arm_name}")
|
| 326 |
+
elif left != right:
|
| 327 |
+
raise ValueError(f"SAME_INFORMATION_PARITY_FAIL:{name}:{arm_name}")
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
__all__ = [
|
| 331 |
+
"BOOL_TENSOR_DIGEST_SCHEMA",
|
| 332 |
+
"TARGET_INTERVENTION_RECEIPT_SCHEMA",
|
| 333 |
+
"TargetInterventionBatchBundle",
|
| 334 |
+
"bind_precomputed_target_intervention_batches",
|
| 335 |
+
"canonical_bool_tensor_sha256",
|
| 336 |
+
"select_target_intervention_batch",
|
| 337 |
+
"verify_same_information_batch_parity",
|
| 338 |
+
]
|