plaid.storage.common.writer¶
plaid.storage.common.writer
¶
Common storage writer utilities.
This module provides common utilities for writing dataset metadata, problem definitions, and other auxiliary files to disk or uploading them to Hugging Face Hub. It handles serialization of infos, problem definitions, and dataset tree structures.
plaid.storage.common.writer.save_infos_to_disk
¶
Save dataset infos as a YAML file to disk.
Parameters:
-
path(Union[str, Path]) –The directory path where
infos.yamlwill be saved. -
infos(Infos) –Dataset infos to write.
Source code in plaid/storage/common/writer.py
plaid.storage.common.writer.save_problem_definitions_to_disk
¶
Save ProblemDefinitions to disk.
Parameters:
-
path(Union[str, Path]) –The directory path for saving.
-
pb_defs(dict[str, ProblemDefinition]) –Mapping from problem definition identifiers to definitions.
Source code in plaid/storage/common/writer.py
plaid.storage.common.writer.save_constants_to_disk
¶
Write constant features to disk under
For each split in flat_cst this creates a directory
Behavior
- Numeric constants are written as their C-order bytes.
- String constants support two cases:
- CGNS string scalar: a 1-element array of Python str -> written as ASCII bytes, shape recorded as [len].
- CGNS char array: multi-char arrays -> converted to fixed-width bytes and written.
- If a schema entry's dtype is None, the layout entry is set to None and no bytes are written.
Parameters:
-
path(str | Path) –Root dataset directory where "constants" will be created.
-
constant_schema(dict) –Mapping split -> {constant_name: {'dtype': str | None, 'ndim': int, ...}}.
-
flat_cst(dict) –Mapping split -> {constant_name: numpy array | None} containing values to save.
Returns:
-
None(None) –This function does not return a value.
Raises:
-
AssertionError–if a numeric array does not match the expected ndim.
-
OSError / IOError–on file system write errors.
Source code in plaid/storage/common/writer.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
plaid.storage.common.writer.save_metadata_to_disk
¶
Save the structure of a dataset tree to disk.
This function writes the constant part of the tree and its key mappings to files in the specified directory. The constant part is serialized as a pickle file, while the key mappings are saved in YAML format.
Parameters:
-
path(Union[str, Path]) –Directory path where the tree structure files will be saved.
-
flat_cst(dict) –Dictionary containing the constant part of the tree.
-
variable_schema(dict) –Dictionary containing the variable schema.
-
constant_schema(dict) –Dictionary containing the constant schema.
-
cgns_types(dict) –Dictionary containing CGNS types.
Returns:
-
None–None
Source code in plaid/storage/common/writer.py
plaid.storage.common.writer.push_infos_to_hub
¶
Upload dataset infos.yaml to a Hugging Face dataset repository.
Serializes the provided infos to YAML using :class:Infos and uploads
it as infos.yaml to the target repo_id using the HfApi.
Parameters:
-
repo_id(str) –Hugging Face dataset repository identifier (e.g. "user/repo").
-
infos(Infos) –Dataset infos to upload.
Raises:
-
ValueError–If
infosis an empty mapping. -
OSError / IOError–If the upload fails due to I/O errors or network problems.
Source code in plaid/storage/common/writer.py
plaid.storage.common.writer.push_local_problem_definitions_to_hub
¶
Upload local ProblemDefinitions to a Hugging Face dataset repository.
This function uploads the entire local problem_definitions/ directory
located under path to the target Hugging Face dataset repository using
HfApi.upload_folder.
Expected local layout:
<path>/
problem_definitions/
<name_1>
<name_2>
...
Each problem definition is assumed to already be serialized on disk
(e.g. via ProblemDefinition.save_to_file). The function performs a
directory-level upload and does not inspect, validate, or re-serialize
individual problem definitions.
Parameters:
-
repo_id(str) –Hugging Face dataset repository identifier (e.g.
"username/dataset_name"). -
path(Union[Path, str]) –Root dataset directory containing the
problem_definitions/folder.
Notes
- Upload is atomic at the folder level.
- Existing files in
problem_definitions/on the Hub may be overwritten. - Uses
repo_type="dataset". - Not covered by unit tests (
pragma: no cover).
Raises:
-
OSError / IOError–If the local folder does not exist or an upload error occurs.
Source code in plaid/storage/common/writer.py
plaid.storage.common.writer.push_local_metadata_to_hub
¶
Upload locally stored dataset metadata to a Hugging Face dataset repository.
This function uploads the structural metadata of a PLAID dataset from disk to a Hugging Face Hub dataset repository. The upload consists of:
-
The
constants/directory, containing:data.mmapfiles with concatenated constant values,layout.jsonfiles describing byte offsets and shapes,constant_schema.yamlfiles describing constant dtypes and dimensions, organized per dataset split.
-
variable_schema.yaml, describing the schema of variable (sample-dependent) features. -
cgns_types.yaml, describing CGNS node types associated with dataset paths.
All metadata files are assumed to have been previously generated on disk
(e.g. via save_metadata_to_disk). This function performs no validation,
transformation, or serialization; it strictly uploads existing files.
Expected local layout::
<path>/
constants/
<split>/
data.mmap
layout.json
constant_schema.yaml
variable_schema.yaml
cgns_types.yaml
Parameters:
-
repo_id(str) –Hugging Face dataset repository identifier (e.g.
"username/dataset_name"). -
path(Union[Path, str]) –Root dataset directory containing the metadata files.
Notes
- Uploads use
repo_type="dataset". - Folder uploads may overwrite existing files on the Hub.
- The operation is atomic per uploaded artifact
(
constants/folder, individual YAML files). - Not covered by unit tests (
pragma: no cover).
Raises:
-
OSError / IOError–If required local files are missing or if an upload error occurs.
Source code in plaid/storage/common/writer.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |