|
Download docs/hf-datasets.md from Intelligence-Networking-Lab/Channels4World: direct link, hf CLI and curl.
- Browser
- Download file 7.32 kB
-
https://huggingface.co/datasets/Intelligence-Networking-Lab/Channels4World/resolve/main/docs/hf-datasets.md
- Command line
-
hf download hf://datasets/Intelligence-Networking-Lab/Channels4World/docs/hf-datasets.md
-
curl -L -o hf-datasets.md https://huggingface.co/datasets/Intelligence-Networking-Lab/Channels4World/resolve/main/docs/hf-datasets.md
7.32 kB
| # TAR records with HF Datasets | |
| HF Datasets can read the existing TAR member names with its `webdataset` loader. The | |
| examples need `pip install datasets`; `hf://` paths are read through `huggingface_hub`, | |
| which `datasets` installs. | |
| Each core/detail NPZ is one scene × carrier × BS record; each positions NPZ is one | |
| scene record. These are ragged records, not preassembled UE training samples. | |
| Choose and join components before defining samples or batching them. | |
| The [card](../README.md#streaming-archives) shows a short remote/local iteration example. | |
| `streaming=True` returns an iterable; omitting it downloads remote input as needed and | |
| builds an Arrow dataset on disk, even when the TARs are already local. Neither route | |
| extracts a subset root for the channels4world library. Tiny can remain loose throughout. | |
| ## Decoding and array representation | |
| HF's loader already decodes `record["npz"]`; do not pass that mapping to `np.load`. | |
| Its feature inference and NumPy formatting are separate steps: integer widths can | |
| change, and empty arrays need their declared dimensions restored. Direct NumPy NPZ | |
| reads and the channels4world library retain the stored numeric dtypes and shapes; HF's formatted | |
| rows do not promise that representation unchanged. | |
| The explicit features and restoration below follow the release's array schema | |
| (`schema/arrays.json`, summarized in the [schema reference](schema-reference.md)). The | |
| shape comes from each NPZ's embedded JSON `__meta__`. | |
| ```python | |
| import json | |
| import numpy as np | |
| from datasets import Array2D, Features, Sequence, Value, load_dataset | |
| SCHEMAS = { | |
| "core": { | |
| "link_ue_index": ("int32", ("links",)), | |
| "link_path_offsets": ("int64", ("links+1",)), | |
| "path_rank": ("uint8", ("paths",)), | |
| "a_real": ("float32", ("paths",)), "a_imag": ("float32", ("paths",)), | |
| "tau": ("float32", ("paths",)), | |
| "theta_t": ("float32", ("paths",)), "phi_t": ("float32", ("paths",)), | |
| "theta_r": ("float32", ("paths",)), "phi_r": ("float32", ("paths",)), | |
| "interaction_count": ("uint8", ("paths",)), | |
| "interaction_flags": ("uint16", ("paths",)), | |
| }, | |
| "detail": { | |
| "path_interaction_offsets": ("int64", ("paths+1",)), | |
| "interaction_rank": ("uint8", ("interactions",)), | |
| "interaction_type": ("int8", ("interactions",)), | |
| "interaction_vertex": ("float32", ("interactions", 3)), | |
| }, | |
| "positions": { | |
| "bs_positions": ("float32", ("bs", 3)), | |
| "ue_positions": ("float32", ("ues", 3)), | |
| }, | |
| } | |
| def features_for(component): | |
| fields = {"__meta__": Value("string")} | |
| for name, (dtype, axes) in SCHEMAS[component].items(): | |
| fields[name] = (Array2D(shape=(None, 3), dtype=dtype) if len(axes) == 2 | |
| else Sequence(Value(dtype))) | |
| return Features({"__key__": Value("string"), "__url__": Value("string"), "npz": fields}) | |
| def restore_npz(record): | |
| raw = record["npz"] | |
| meta = json.loads(str(raw["__meta__"])) | |
| def size(axis): | |
| if isinstance(axis, int): | |
| return axis | |
| name, _, extra = axis.partition("+") | |
| return meta["dimensions"][name] + (int(extra) if extra else 0) | |
| arrays = { | |
| name: np.asarray(raw[name], dtype=dtype).reshape(tuple(size(a) for a in axes)) | |
| for name, (dtype, axes) in SCHEMAS[meta["identity"]["component"]].items() | |
| } | |
| return meta, arrays | |
| ``` | |
| For example, zero interactions restore `interaction_vertex` to `(0, 3)` rather than | |
| an ambiguous empty vector. Core and detail offsets still have their final sentinel: | |
| an empty core has `link_path_offsets.shape == (1,)`. | |
| ## One chosen link, with remote or local TARs | |
| Stream only the archives of the group that holds the chosen scene (the `group` column of | |
| the `scenes` catalog), then pick records by identity: | |
| ```python | |
| SCENE_ID, BS_ID, UE_ID = "urban_scene_019234", 0, 14 | |
| GROUP = "test-urban-g00000" # from the scenes catalog | |
| base = "hf://datasets/Intelligence-Networking-Lab/Channels4World@v1.0.0/payload" | |
| # For downloaded copies: base = "c4w/payload" | |
| def records(component): | |
| archive = (f"{base}/3.5ghz/core/inc1-small/{GROUP}-3.5ghz-core.tar" if component == "core" | |
| else f"{base}/scene/positions/inc1-small/{GROUP}-positions.tar") | |
| return load_dataset( | |
| "webdataset", streaming=True, features=features_for(component), | |
| data_files={"test": archive}, | |
| )["test"].with_format("numpy") | |
| def identity_of(meta): | |
| i = meta["identity"] | |
| return i["scene_id"], i["bs_index"] | |
| meta, core = next((m, a) for m, a in map(restore_npz, records("core")) | |
| if identity_of(m) == (SCENE_ID, BS_ID)) | |
| positions = next(a for m, a in map(restore_npz, records("positions")) | |
| if m["identity"]["scene_id"] == SCENE_ID) | |
| row = int(np.searchsorted(core["link_ue_index"], UE_ID)) # UE 14's link row | |
| assert row < core["link_ue_index"].size and core["link_ue_index"][row] == UE_ID | |
| start, stop = map(int, core["link_path_offsets"][row:row + 2]) | |
| print(core["tau"][start:stop]) | |
| print(core["a_real"][start:stop] + 1j * core["a_imag"][start:stop]) | |
| print(np.linalg.norm(positions["ue_positions"][UE_ID] - positions["bs_positions"][BS_ID])) | |
| ``` | |
| Archives stream in order, so each iterator reads until it reaches the matching record: | |
| at most one group's archive (800 channel records or 25 scene records). This scene is the | |
| first in its group, so both stop almost at once. To fetch one record without reading the | |
| rest of its archive, use a byte-range read | |
| ([file guide](without-library.md#find-the-byte-location-of-one-record)). For repeated | |
| workloads, index or cache positions rather than rescanning them for every BS. | |
| Core and detail additionally join by carrier and BS and must share `path_axis_sha256`; | |
| their `__key__` values differ by component. Use the identity and dependency metadata, not | |
| only equal array lengths. Restoration itself does not verify content hashes. | |
| ## Optional: stock WebDataset and NumPy | |
| Stock `webdataset`, without calling its decoder, yields NPZ **bytes**. For a downloaded | |
| core TAR, standard NumPy opens those bytes with their stored dtypes and shapes: | |
| ```python | |
| import io | |
| import webdataset as wds | |
| archive = "c4w/payload/3.5ghz/core/inc1-small/test-urban-g00000-3.5ghz-core.tar" | |
| key = "records/scene=urban_scene_019234/band_hz=3500000000/component=core/bs00000" | |
| record = next(r for r in wds.WebDataset(archive, shardshuffle=False) if r["__key__"] == key) | |
| with np.load(io.BytesIO(record["npz"]), allow_pickle=False) as npz: | |
| core = {name: npz[name] for name in npz.files if name != "__meta__"} | |
| meta = json.loads(npz["__meta__"].item()) | |
| ``` | |
| Each WebDataset sample is one member: `__key__` is the member path without its `.npz` | |
| extension. Keep the same UE, scene and component associations as above. | |
| Explicit features avoid relying on types inferred from the first examples, and | |
| restoration makes the stored dtypes and shapes explicit again. Reference behavior: | |
| [HF WebDataset loader](https://github.com/huggingface/datasets/blob/5.1.0/src/datasets/packaged_modules/webdataset/webdataset.py) | |
| and [NumPy formatter](https://github.com/huggingface/datasets/blob/5.1.0/src/datasets/formatting/np_formatter.py). | |
| [Return to card](../README.md) · [Without the library](without-library.md) · [Schema](schema-reference.md) | |