AREPO Dataset Writing
iris.arepo_processing_write
The parallel computing framework for AREPO processing and dataset construction.
Segregates all MPI-based logic for AREPO processing into a separate module from
arepo_processing so that all non-writing functions
are MPI-optional. This is important since when importing mpi4py, Python will
raise an error if an OpenMPI module is not loaded into the cluster environment.
Also imports core functionalities from arepo_processing
so they can be aliased from this module.
Writer
Bases: Processor
A class for writing Dataset objects to the disk.
Handles all CPU multiprocessing/parallelism with MPI via mpi4py.
Depending on the world and node ranks, launches one of three types of processes:
- Manager: The world rank 0 process. Coordinates workers and GPU managers, Acts as a consolidation point for data.
- GPU Manager: The highest node-rank process on any node, if that node contains multiple processes and GPU support is both available and required. Manages access keys for each GPU allocated to its node, and issues these keys to workers, ensuring that only one worker can access the GPU at a time. This prevents memory overflow on the GPU.
- Worker: All other processes. Workers receive and execute tasks from the manager. The first set of tasks is data generation. Each worker works independently to produce one physical tensor and/or observed pair from a snapshot file on the disk. The second set of tasks is data normalization. If applicable, each worker applies the conversion from processing units to IRIS units over its own data points. Upon completion of all tasks, merges its dataset back into the manager dataset.
The manager task first determines which AREPO snapshots will be targeted for data
production. If snapshot_paths is specified, the manager will produce
self.hyper.writer_hyper.points_per_snapshot physical tensors
for each snapshot. If snapshot_directory is specified, the manager will produce
self.hyper.writer_hyper.points_per_snapshot physical tensors
from self.hyper.writer_hyper.total_snapshots snapshots randomly
selected from this directory. In either case, the points_per_snapshot points will
be symmetrically distributed around the galactic center at the vertices of a regular \(n\)-gon
in the galactic disk. If remote_address and local_cache are not None,
will interpret either snapshot_paths or snapshot_directory as a path
on a remote device, and will automatically handle file copy from the remote to the cache
via SCP, as well as deletion of local copies when complete. If ssh_key_path is not None,
will use the key for server access. Otherwise, will use the default SSH behavior of
the current user session, i.e. search for default keys. Only copies one file at a time
and deletes when the worker processes are complete and before copying the next file.
This allows storage of large simulation databases on remote servers and avoids the need
for manual file transfer to the HPC environment. In conjunction with SLURM job arrays,
this system can automate weeks of data generation from snapshots stored on the remote,
while maximizing usage of storage in the HPC environment for processed datasets.
Attributes:
| Name | Type | Description |
|---|---|---|
hyper |
Hyper
|
A hyperparameters object. |
path |
str | Sequence[str]
|
|
dataset |
Dataset | ConcatDataset | None
|
The working dataset object. |
verbose |
bool
|
If |
world_comm |
Intracomm
|
The MPI intracomm used for communicating with all processes. |
node_comm |
Intracomm
|
The MPI intracomm used for communicating with same-node processes. |
rank |
int
|
The world rank of this process. |
world_size |
int
|
The total number of all processes. |
node_rank |
int
|
The node rank of this process. |
node_size |
int
|
The number of processes on this node. |
workers |
list[int]
|
A list of worker processes, identified by world ranks. |
gpu_managers |
list[int]
|
A list of GPU manager processes, identified by world ranks. |
gpu_interpolate |
bool
|
If |
gpu_normalize |
bool
|
If |
snapshot_paths |
list[str] | None
|
A list of paths to AREPO snapshots (HDF5 files) from which to generate data. |
snapshot_directory |
str | None
|
The |
remote_source |
bool
|
Will be set to |
ssh_key_path |
str | None
|
Path, on the local device, to the SSH private key file, for access to the remote server. If none is specified, will search for default keys. |
remote_address |
str | None
|
Address of a remote server, e.g. 'user@remote.server.edu'. If not |
local_cache |
str | None
|
A path to a local cache directory. Will copy snapshots from the remote server
to this cache as temporary files, deleted after data generation is complete.
For best performance, create a RAM directory in |
abundance |
Abundance | None
|
An abundance function to supply to the
|
units_from |
Dataset | ConcatDataset | None
|
If not |
observer_kwargs |
dict
|
Extra keyword args to pass to an observer, if writing a
|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Sets |
required |
snapshot_paths
|
Sequence[str] | None
|
Sets |
None
|
snapshot_directory
|
str | None
|
Sets |
None
|
ssh_key_path
|
str | None
|
Sets |
None
|
remote_address
|
str | None
|
Sets |
None
|
local_cache
|
str | None
|
Sets |
None
|
hyper
|
Hyper | None
|
Sets |
None
|
dataset_type
|
type[Dataset]
|
The type of |
PreObservedDataset
|
abundance
|
Abundance | None
|
Sets |
None
|
units_from
|
Dataset | ConcatDataset | None
|
Sets |
None
|
gpu_interpolate
|
bool
|
Sets |
True
|
gpu_normalize
|
bool
|
Sets |
False
|
verbose
|
bool
|
Sets |
True
|
observer_kwargs
|
any
|
Sets |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If not one and only one of |
Source code in iris/arepo_processing_write.py
47 48 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 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 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 | |
_load_dataset(path, dataset_type)
Loads or makes a dataset for extension or writing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
A free path or a path to an existing dataset directory of the same |
required |
dataset_type
|
type[Dataset]
|
The type of |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no hyperparameters were provided to the |
Source code in iris/arepo_processing_write.py
_manage()
The rank-zero MPI task. Coordinates all task parallelism.
Source code in iris/arepo_processing_write.py
_census_gpu_managers()
Checks if GPU managers have been designated.
Source code in iris/arepo_processing_write.py
_kill_gpu_managers()
Kills GPU manager processes.
Source code in iris/arepo_processing_write.py
_get_processing_units(hyper)
Computes the parsecs per processing length written to self.hyper.WriterHyper._length_parsec_per_processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hyper
|
Hyper
|
The hyperparameters object from which to pull units. |
required |
Source code in iris/arepo_processing_write.py
_get_snapshot_index(path)
staticmethod
Gets the final integer index from an AREPO snapshot filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
The snapshot path whose filename should be inspected. |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
The final integer index from the filename stem, or |
Source code in iris/arepo_processing_write.py
_filter_snapshot_paths_by_index(paths)
Filters snapshot paths by the configured minimum and maximum snapshot index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
Sequence[str | Path]
|
Snapshot paths to filter. |
required |
Returns:
| Type | Description |
|---|---|
list[str | Path]
|
Snapshot paths with final filename indices inside the configured range. If neither |
list[str | Path]
|
range bound is configured, returns all paths as a list. |
Source code in iris/arepo_processing_write.py
_issue_generation_tasks()
Issues data generation tasks to worker processes.
If self.remote_source, copies
single AREPO snapshots at a time from the remote server to the local machine.
If self.snapshot_paths is specified, works through all snapshots one at a time.
If self.snapshot_directory is specified,
randomly chooses one snapshot from the directory at a time until a total of
self.hyper.writer_hyper.total_snapshots snapshots has been reached.
For each snapshot, creates self.hyper.writer_hyper.points_per_snapshot unique
data generation tasks. (A unique observation looking in towards the galactic center
from each vertex of a regular \(n\)-gon centered on the galactic center. Additional
uniqueness is added by the perturbations added by Snapshot.)
Issues each unique task to a different worker process.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If processing from |
RuntimeError
|
If a snapshot download fails. |
Source code in iris/arepo_processing_write.py
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 | |
_receive_datasets()
Collects all worker DatasetChild objects
and merges them into the manager DatasetParent.
Source code in iris/arepo_processing_write.py
_issue_normalization_tasks(iris_processing_units_different)
Informs each worker process that data generation is complete and instructs
each process to convert its Dataset
from processing units to the newly calculated or adopted IRIS units.
If no conversion is necessary, instructs each worker process to skip normalization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iris_processing_units_different
|
bool
|
The |
required |
Source code in iris/arepo_processing_write.py
_manage_gpu(dataset_type)
Manages access keys for each GPU allocated to its node, and issues these keys to workers, ensuring that only one worker can access the GPU at a time.
Prevents memory overflow on the GPU. If GPU support is not available or required, or if the lone process on its node, reverts to a worker process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_type
|
type[Dataset]
|
The type of |
required |
Source code in iris/arepo_processing_write.py
_work(dataset_type)
_generate(dataset_type)
The worker data generation task.
Listens for the task assignment from the manager process. Then reads the task,
creates a Snapshot object, and
makes a physical tensor and adds it or an observed pair to the dataset
by calling make_physical_tensor.
Upon receiving a null task from the manager, transmits its accumulated
Dataset to the manager for merging.
The data tensors for each Dataset are stored on-disk rather than in memory,
so only the Dataset metadata is transmitted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_type
|
type[Dataset]
|
The type of |
required |
Source code in iris/arepo_processing_write.py
_normalize()
The worker normalization task.
Listens for the normalization task from the manager process,
which includes iris_processing_units_different and a
Hyper object containing the IRIS units
computed by the manager process. If iris_processing_units_different,
calls the normalize method of its Dataset.