Dataset API¶
In-Memory Dataset¶
OPFDataset
¶
Bases: InMemoryDataset
The heterogeneous OPF data from the "Large-scale Datasets for AC
Optimal Power Flow with Topological Perturbations"
<https://arxiv.org/abs/2406.07234>_ paper.
:class:OPFDataset is a large-scale dataset of solved optimal power flow
problems, derived from the
pglib-opf <https://github.com/power-grid-lib/pglib-opf>_ dataset.
The physical topology of the grid is represented by the :obj:"bus" node
type, and the connecting AC lines and transformers. Additionally,
:obj:"generator", :obj:"load", and :obj:"shunt" nodes are connected
to :obj:"bus" nodes using a dedicated edge type each, e.g.,
:obj:"generator_link".
Edge direction corresponds to the properties of the line, e.g.,
:obj:b_fr is the line charging susceptance at the :obj:from
(source/sender) bus.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str
|
Root directory where the dataset should be saved. |
required |
case_name
|
str
|
The name of the original pglib-opf case.
(default: :obj: |
'pglib_opf_case14_ieee'
|
group_id
|
int
|
The specific group to load. Each group
contains 15,000 samples. Valid values are [0, 19].
(default: :obj: |
0
|
transform
|
callable
|
A function/transform that takes in
a :obj: |
None
|
pre_transform
|
callable
|
A function/transform that takes
in a :obj: |
None
|
pre_filter
|
callable
|
A function that takes in a
:obj: |
None
|
force_reload
|
bool
|
Whether to re-process the dataset.
(default: :obj: |
False
|
keep_temp
|
bool
|
Whether to keep the temporary files
after processing. (default: :obj: |
False
|
n_jobs
|
int
|
The number of jobs to use for parallel
processing. If set to :obj: |
-1
|
local_raw_folder
|
str
|
Local folder to look for raw files.
If :obj: |
None
|
Examples:
>>> from lumina.dataset.opf.opf_dataset import OPFDataset
>>> dataset = OPFDataset(root='./data', case_name='pglib_opf_case14_ieee')
>>> # By default, only first group (i.e., group 0) is loaded, if you want to load multiple groups,
>>> # please use OPFMultiDataset instead:
>>> dataset = OPFMultiDataset.from_case_groups(root='./data', case_name='pglib_opf_case14_ieee', group_ids=[0,1,2])
Source code in lumina/dataset/opf/opf_dataset.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 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 | |
raw_dir: str
property
¶
Raw data folder
processed_dir: str
property
¶
Processed data folder.
tmp_dir: str
property
¶
Temporary data folder.
raw_file_names: List[str]
property
¶
Raw file names, which are stored locally.
processed_file_names: List[str]
property
¶
Processed file names, which are stored locally.
download() -> None
¶
Download .tar.gz files
Source code in lumina/dataset/opf/opf_dataset.py
download_and_extract(name: str) -> None
¶
Download and extract a .tar.gz file.
process() -> None
¶
Process the raw files into a single file.
Source code in lumina/dataset/opf/opf_dataset.py
process_json_group(group_id: int)
¶
Process a single group of files, save processed data to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_id
|
int
|
Group id. |
required |
Source code in lumina/dataset/opf/opf_dataset.py
combine_datasets(file_paths: List[str]) -> List[HeteroData]
¶
Combine datasets from multiple files.
Notes
- deprecated, kept for reference, please use
OPFMultiDatasetinstead.
Source code in lumina/dataset/opf/opf_dataset.py
merge_group_files() -> None
¶
Merge group files into single train/val/test based on groups options.
Notes
- deprecated, kept for reference, please use
OPFMultiDatasetinstead.
Source code in lumina/dataset/opf/opf_dataset.py
metadata()
¶
Returns the metadata of the dataset.
Source code in lumina/dataset/opf/opf_dataset.py
process_hdf5_group(group_id: int)
¶
Process a single group of HDF5 files, save processed data to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_id
|
int
|
Group id. |
required |
Source code in lumina/dataset/opf/opf_dataset.py
__repr__() -> str
¶
OPFHomogeneousDataset
¶
Bases: OPFDataset
OPFDataset variant that converts heterogeneous graphs to homogeneous during preprocessing.
Wraps each HeteroData sample through :class:OPFHomoWrapper before saving,
producing homogeneous Data objects with optional one-hot node/edge type
indicators. Non-finite target values are sanitized and a y_mask is stored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Positional arguments forwarded to :class: |
()
|
|
add_node_type
|
bool
|
Append one-hot node type features to |
True
|
add_edge_type
|
bool
|
Append one-hot edge type features to |
True
|
attach_full_edge_attr
|
bool
|
Attach the full concatenated edge attribute
tensor as |
False
|
sanitize_targets
|
bool
|
Replace non-finite target values with zero.
(default: :obj: |
True
|
log_bad_targets
|
bool
|
Log a warning when non-finite targets are found.
(default: :obj: |
True
|
max_bad_target_logs
|
int
|
Maximum number of bad-target warnings to emit.
(default: :obj: |
1
|
processed_suffix
|
str
|
Suffix appended to the release name for the
processed directory. (default: :obj: |
'homo'
|
**kwargs
|
Additional keyword arguments forwarded to :class: |
{}
|
Source code in lumina/dataset/opf/opf_dataset.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
OPFMultiDataset
¶
Bases: ConcatDataset
Multi-group OPF dataset that combines multiple OPFDataset instances using ConcatDataset.
This class allows combining multiple groups from the same case or different cases to create larger datasets for training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasets
|
List[OPFDataset]
|
List of OPFDataset instances to combine. |
required |
Examples:
>>> # For different cases
>>> d1 = OPFDataset(root, case_name="pglib_opf_case14_ieee", group_id=0)
>>> d2 = OPFDataset(root, case_name="pglib_opf_case30_ieee", group_id=0)
>>> multi_dataset = OPFMultiDataset([d1, d2])
>>> # For same case, multiple groups
>>> datasets = []
>>> for group_id in range(5):
... ds = OPFDataset(root, case_name="pglib_opf_case14_ieee", group_id=group_id)
... datasets.append(ds)
>>> multi_dataset = OPFMultiDataset(datasets)
>>> # Mixed: multiple groups from multiple cases
>>> case_mapping = {
... "pglib_opf_case14_ieee": [0, 1, 2],
... "pglib_opf_case30_ieee": [0, 1]
... }
>>> mixed_dataset = OPFMultiDataset.from_mixed_cases(root, case_mapping)
Source code in lumina/dataset/opf/opf_dataset.py
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 | |
from_case_groups(root: str, case_name: str, group_ids: List[int], dataset_cls=OPFDataset, **kwargs)
classmethod
¶
Create OPFMultiDataset from multiple groups of the same case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str
|
Root directory where the dataset should be saved. |
required |
case_name
|
str
|
The name of the original pglib-opf case. |
required |
group_ids
|
List[int]
|
List of group IDs to load. |
required |
dataset_cls
|
Dataset class to instantiate for each group. |
OPFDataset
|
|
**kwargs
|
Additional arguments passed to OPFDataset constructor. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
OPFMultiDataset |
Combined dataset from multiple groups. |
Source code in lumina/dataset/opf/opf_dataset.py
from_multiple_cases(root: str, case_configs: List[Dict], dataset_cls=OPFDataset, **kwargs)
classmethod
¶
Create OPFMultiDataset from multiple cases with their respective group IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str
|
Root directory where the dataset should be saved. |
required |
case_configs
|
List[Dict]
|
List of dictionaries, each containing 'case_name' and 'group_id' keys. |
required |
dataset_cls
|
Dataset class to instantiate for each case. |
OPFDataset
|
|
**kwargs
|
Additional arguments passed to OPFDataset constructor. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
OPFMultiDataset |
Combined dataset from multiple cases. |
Example
configs = [ ... {"case_name": "pglib_opf_case14_ieee", "group_id": 0}, ... {"case_name": "pglib_opf_case30_ieee", "group_id": 1}, ... ] multi_dataset = OPFMultiDataset.from_multiple_cases(root, configs)
Source code in lumina/dataset/opf/opf_dataset.py
from_mixed_cases(root: str, case_group_mapping: Dict[str, List[int]], dataset_cls=OPFDataset, **kwargs)
classmethod
¶
Create OPFMultiDataset from multiple groups across different cases.
This method allows loading multiple groups from multiple cases in a single call, which is useful when you want to combine several groups from different cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str
|
Root directory where the dataset should be saved. |
required |
case_group_mapping
|
Dict[str, List[int]]
|
Dictionary mapping case names to lists of group IDs to load for each case. |
required |
dataset_cls
|
Dataset class to instantiate for each group. |
OPFDataset
|
|
**kwargs
|
Additional arguments passed to OPFDataset constructor. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
OPFMultiDataset |
Combined dataset from multiple groups across multiple cases. |
Example
Load 3 groups from case14 and 2 groups from case30¶
case_mapping = { ... "pglib_opf_case14_ieee": [0, 1, 2], ... "pglib_opf_case30_ieee": [0, 1] ... } multi_dataset = OPFMultiDataset.from_mixed_cases(root, case_mapping)
Source code in lumina/dataset/opf/opf_dataset.py
On-Disk Dataset¶
OPFOnDiskDataset
¶
Bases: OnDiskDataset
On-disk OPF dataset backed by SQLite or RocksDB.
Stores individual HeteroData samples in a database so that the full
dataset need not reside in CPU memory. Supports the same cases and
group structure as :class:OPFDataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str
|
Root directory where the dataset should be saved. |
required |
case_name
|
str
|
Name of the pglib-opf case.
(default: :obj: |
'pglib_opf_case14_ieee'
|
group_id
|
int
|
Group to load (each group has 15,000 samples).
(default: :obj: |
0
|
transform
|
callable
|
Per-access transform applied to each
sample. (default: :obj: |
None
|
pre_transform
|
callable
|
Transform applied once before
writing to the database. (default: :obj: |
None
|
pre_filter
|
callable
|
Predicate; samples that return
|
None
|
force_reload
|
bool
|
Re-process even if the database already exists.
(default: :obj: |
False
|
keep_temp
|
bool
|
Keep extracted JSON temp files after processing.
(default: :obj: |
False
|
n_jobs
|
int
|
Number of parallel workers for processing.
(default: :obj: |
-1
|
local_raw_folder
|
str
|
Local folder containing raw archives;
skips download when set. (default: :obj: |
None
|
backend
|
str
|
Database backend, |
'sqlite'
|
schema
|
object
|
PyG schema for the stored data type. |
object
|
log
|
bool
|
Enable logging. (default: :obj: |
True
|
write_batch_size
|
int
|
Number of samples to batch per DB write.
(default: :obj: |
128
|
sqlite_timeout_sec
|
float
|
SQLite connection timeout in seconds.
(default: :obj: |
600.0
|
sqlite_busy_timeout_ms
|
Optional[int]
|
SQLite busy timeout in ms. |
None
|
sqlite_journal_mode
|
Optional[str]
|
SQLite journal mode PRAGMA.
(default: :obj: |
'WAL'
|
sqlite_synchronous
|
Optional[str]
|
SQLite synchronous PRAGMA.
(default: :obj: |
'NORMAL'
|
Source code in lumina/dataset/opf/opf_on_disk_dataset.py
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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 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 | |
download() -> None
¶
download_and_extract(name: str) -> None
¶
Download a tar.gz archive by name and extract it to the raw directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Filename of the archive to download. |
required |
Source code in lumina/dataset/opf/opf_on_disk_dataset.py
process() -> None
¶
Process raw JSON files and write samples into the on-disk database.
Source code in lumina/dataset/opf/opf_on_disk_dataset.py
process_json_group(group_id: int) -> None
¶
Parse all JSON files for a group and insert them into the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_id
|
int
|
Group identifier to process. |
required |
Source code in lumina/dataset/opf/opf_on_disk_dataset.py
metadata()
¶
Return node and edge feature dimensionality metadata from the first sample.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dictionary with |
Source code in lumina/dataset/opf/opf_on_disk_dataset.py
OPFOnDiskHomogeneousDataset
¶
Bases: OPFOnDiskDataset
On-disk OPF dataset that converts to homogeneous graphs before storing.
Each HeteroData sample is converted to a homogeneous Data object via
:class:OPFHomoWrapper, optionally pruned and cast to a compact dtype for
storage. On retrieval the data is restored to float32 if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Positional arguments forwarded to :class: |
()
|
|
add_node_type
|
bool
|
Append one-hot node type features.
(default: :obj: |
True
|
add_edge_type
|
bool
|
Append one-hot edge type features.
(default: :obj: |
True
|
sanitize_targets
|
bool
|
Replace non-finite targets with zero.
(default: :obj: |
True
|
log_bad_targets
|
bool
|
Log warnings for non-finite targets.
(default: :obj: |
True
|
max_bad_target_logs
|
int
|
Maximum bad-target warnings to emit.
(default: :obj: |
1
|
processed_suffix
|
str
|
Suffix for the processed directory name.
(default: :obj: |
'homo'
|
attach_full_edge_attr
|
bool
|
Store full concatenated edge attributes
as |
False
|
prune_homo
|
bool
|
Remove extraneous attributes from the homogeneous
data before writing. (default: :obj: |
True
|
storage_dtype
|
Optional[str]
|
Dtype for on-disk storage of floating
point tensors, e.g. |
'float16'
|
restore_fp32
|
bool
|
Cast tensors back to float32 on retrieval.
(default: :obj: |
True
|
**kwargs
|
Additional keyword arguments forwarded to
:class: |
{}
|
Source code in lumina/dataset/opf/opf_on_disk_dataset.py
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 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | |
Sharded Dataset¶
OPFShardedIterableDataset
¶
Bases: IterableDataset
Iterable dataset that streams OPF samples from sharded .pt files.
Shards are distributed across DDP ranks and DataLoader workers so that each global worker processes a disjoint subset. Shard order can be shuffled per epoch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shards
|
Iterable[ShardInfo]
|
Shard descriptors to iterate over. |
required |
shuffle_shards
|
bool
|
Shuffle shard order each epoch.
(default: :obj: |
False
|
seed
|
int
|
Base random seed for shard shuffling.
(default: :obj: |
0
|
transform
|
Optional[Callable]
|
Per-sample transform applied on
iteration. (default: :obj: |
None
|
Source code in lumina/dataset/opf/opf_sharded_dataset.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 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 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |
set_epoch(epoch: int) -> None
¶
Set the current epoch for deterministic shard shuffling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epoch
|
int
|
Current training epoch number. |
required |
peek()
¶
Return the first sample from the first shard without iterating all data.
Returns:
| Type | Description |
|---|---|
|
The first data sample from the dataset. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no shards are available. |
Source code in lumina/dataset/opf/opf_sharded_dataset.py
metadata()
¶
Return node and edge feature dimensionality metadata from the first sample.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dictionary with |
Source code in lumina/dataset/opf/opf_sharded_dataset.py
load_shard_manifest(path: str) -> Dict
¶
Load a shard manifest JSON file and annotate it with its source path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the manifest JSON file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Parsed manifest dictionary with an added |
Source code in lumina/dataset/opf/opf_sharded_dataset.py
build_shard_infos(manifest: Dict) -> List[ShardInfo]
¶
Build a list of ShardInfo objects from a parsed manifest dictionary.
Resolves relative shard paths against the manifest's base directory and
infers num_samples from the shard file when not specified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
Dict
|
Parsed shard manifest containing a |
required |
Returns:
| Type | Description |
|---|---|
List[ShardInfo]
|
List[ShardInfo]: Ordered list of shard descriptors. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the manifest is missing the |
Source code in lumina/dataset/opf/opf_sharded_dataset.py
Processing Functions¶
process_json_file(json_file)
¶
Process a single json file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_file
|
str
|
Path to the json file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
data |
HeteroData
|
Processed single data object. |
Source code in lumina/dataset/opf/opf_dataset.py
build_heterodata_from_grid(grid: Dict, metadata: Dict, solution: Optional[Dict] = None)
¶
Build a single HeteroData graph from OPFData grid and metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
Dict
|
Grid payload from an OPFData object. |
required |
metadata
|
Dict
|
Metadata payload from an OPFData object. |
required |
solution
|
Dict
|
Solution payload from an OPFData object. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
data |
HeteroData
|
Processed single data object. |
Source code in lumina/dataset/opf/opf_dataset.py
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 | |
process_hdf5_scenario(scenario, scenario_key: str) -> Union[Optional[HeteroData], List[HeteroData]]
¶
Process a single HDF5 scenario group into a HeteroData graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenario
|
An open HDF5 group containing |
required | |
scenario_key
|
str
|
Key identifying the scenario within the HDF5 file. |
required |
Returns:
| Type | Description |
|---|---|
Union[Optional[HeteroData], List[HeteroData]]
|
Union[Optional[HeteroData], List[HeteroData]]: The constructed
HeteroData object, or |
Source code in lumina/dataset/opf/opf_dataset.py
Schema¶
OPFSchemaModel
¶
Bases: BaseModel
Base Pydantic model defining a column-ordered feature schema for OPF data.
Subclasses declare fields whose order defines the canonical column layout of the corresponding numpy feature array. Provides utilities for schema introspection, cross-schema alignment, and numpy conversion.
Source code in lumina/dataset/opf/schema.py
get_feature_names() -> List[str]
classmethod
¶
Return the ordered list of feature field names.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: Field names in declaration order. |
get_field_indices() -> Dict[str, int]
classmethod
¶
Return a mapping from field names to their column indices.
Returns:
| Type | Description |
|---|---|
Dict[str, int]
|
Dict[str, int]: |
Source code in lumina/dataset/opf/schema.py
get_alignment_map(other: type[OPFSchemaModel]) -> Dict[int, int]
classmethod
¶
Compute a column index mapping from this schema to another.
Only fields present in both schemas are included.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
type[OPFSchemaModel]
|
Target schema class. |
required |
Returns:
| Type | Description |
|---|---|
Dict[int, int]
|
Dict[int, int]: |
Source code in lumina/dataset/opf/schema.py
from_numpy(data: np.ndarray) -> OPFSchemaModel
classmethod
¶
Create a model instance from a 1-D numpy array of feature values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Array whose elements correspond to schema fields in declaration order. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
OPFSchemaModel |
OPFSchemaModel
|
Populated model instance. |
Source code in lumina/dataset/opf/schema.py
to_numpy() -> np.ndarray
¶
Convert this model instance to a 1-D numpy array of feature values.
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Feature values in declaration order. |
Source code in lumina/dataset/opf/schema.py
JSONBus
¶
Bases: OPFSchemaModel
Bus features in JSON format.
Source code in lumina/dataset/opf/schema.py
JSONGenerator
¶
Bases: OPFSchemaModel
Generator features in JSON format.
Source code in lumina/dataset/opf/schema.py
H5Bus
¶
Bases: OPFSchemaModel
Bus features in HDF5 format.
Source code in lumina/dataset/opf/schema.py
H5Generator
¶
Bases: OPFSchemaModel
Generator features in HDF5 format.
Source code in lumina/dataset/opf/schema.py
Case Tagging¶
CaseTaggedDataset
¶
Bases: Dataset
Map-style dataset wrapper that attaches a case_id to every sample.
Delegates all attribute access to the wrapped dataset, adding only the
case_id tensor to each retrieved sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Underlying map-style dataset. |
required | |
case_id
|
Integer case identifier attached to every sample. |
required |
Source code in lumina/dataset/opf/case_id.py
attach_case_id(sample, case_id)
¶
Attach a case_id tensor to a PyG Data or HeteroData sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
A PyG data object (or |
required | |
case_id
|
Integer case identifier to store as a scalar |
required |
Returns:
| Type | Description |
|---|---|
|
The input sample with |
|
|
sample if it is |
Source code in lumina/dataset/opf/case_id.py
Staging¶
opf_release(processed_suffix: Optional[str] = None) -> str
¶
Build the release directory name, optionally appending a suffix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
processed_suffix
|
Optional[str]
|
Suffix to append (e.g. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Release string such as |
Source code in lumina/dataset/opf/staging.py
stage_on_disk_group(source_root: str, stage_root: str, case_name: str, group_id: int, backend: str, processed_suffix: Optional[str] = None, log: bool = True) -> str
¶
Copy an on-disk database from the source root to a local staging root.
Skips the copy if source and destination are the same path or if the destination already exists with the same file size. Also copies SQLite sidecar files (WAL, SHM, journal) when present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_root
|
str
|
Root directory containing the source database. |
required |
stage_root
|
str
|
Local staging root to copy into. |
required |
case_name
|
str
|
Name of the pglib-opf case. |
required |
group_id
|
int
|
Group identifier. |
required |
backend
|
str
|
Database backend ( |
required |
processed_suffix
|
Optional[str]
|
Release directory suffix. |
None
|
log
|
bool
|
Enable copy logging. (default: :obj: |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The effective root directory to use (either stage_root or source_root if staging was skipped). |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the source database does not exist. |
Source code in lumina/dataset/opf/staging.py
stage_sharded_case(source_root: str, stage_root: str, case_name: str, processed_suffix: Optional[str] = None, manifest_name: str = 'manifest.json', log: bool = True) -> str
¶
Copy an entire sharded case directory from source to a staging root.
Skips the copy if source and destination are the same path or if the destination manifest already exists with the same file size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_root
|
str
|
Root directory containing the source sharded data. |
required |
stage_root
|
str
|
Local staging root to copy into. |
required |
case_name
|
str
|
Name of the pglib-opf case. |
required |
processed_suffix
|
Optional[str]
|
Release directory suffix. |
None
|
manifest_name
|
str
|
Manifest filename.
(default: :obj: |
'manifest.json'
|
log
|
bool
|
Enable copy logging. (default: :obj: |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The effective root directory to use (either stage_root or source_root if staging was skipped). |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the source sharded directory does not exist. |