Dask executor
Documentation in dask executor docstrings.
Module executors.dask_executor
Overview
Handles execution of surrogate workflow on Dask. Supports both SLURMCluster and LocalCluster for distributed task execution. SLURMCluster: https://jobqueue.dask.org/en/latest/index.html
Clusters
Local cluster
Can be used for running on a local machine with multiple cores. Useful for testing or small scale runs.
Arguments:
n_workers: 2,
threads_per_worker: 1,
memory_limit: '12GB',
processes: 1
Example configuration: /configs/example_dask_local.yaml
SLURM cluster
Arguments for the SLURM workers.
account: 'project_xxx',
queue: 'medium',
cores: 1,
memory: '12GB',
processes: 1,
walltime: '00:20:00',
config_name: 'slurm',
interface: 'ib0',
Example configuration: /configs/example_dask_slurm.yaml
Notes
Other arguments:
job_script_prologue: ['module load your-modules-here',],
job_extra_directives: [
'-o tmp_path_hm/worker_out_MishkaRunner_1/%x.%j.out',
'-e tmp_path_hm/worker_out_MishkaRunner_1/%x.%j.err'],
DaskExecutor
DaskExecutor(*args, **kwargs)
Bases: Executor
Initializes the DaskExecutor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_run_dir
|
str
|
Base directory for storing run outputs. |
required |
sampler_config
|
dict
|
Arguments for the sampler, including its type. |
required |
runner_config
|
dict
|
Arguments for the runner. |
required |
*args
|
Additional positional arguments. |
()
|
|
**kwargs
|
Additional keyword arguments, including: - type (str): Type of executor. - scale_n_jobs (int): Number of jobs to scale the cluster to. - SLURMcluster_config (dict): Arguments for SLURMCluster. - LocalCluster_config (dict): Arguments for LocalCluster. - block_unitil_cluster_started (bool): Whether to block until the cluster is fully started. |
{}
|
Source code in src/enchanted_surrogates/executors/dask_executor.py
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 | |
clean
clean()
Cleans up resources by shutting down the Dask cluster.
This method is intended to be called when the executor is no longer needed.
Source code in src/enchanted_surrogates/executors/dask_executor.py
447 448 449 450 451 452 453 454 455 456 457 458 | |
execute
execute(input, sampler)
Starts the execution of simulation tasks using the configured Dask cluster.
This method initializes the base run directory, checks for existing data to avoid overwrites, and submits tasks to the Dask cluster in batches. It collects results from completed tasks and writes them to a CSV file.
Raises:
| Type | Description |
|---|---|
FileExistsError
|
If the base run directory contains a file indicating a completed run. |
Source code in src/enchanted_surrogates/executors/dask_executor.py
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 | |
find_line_in_seff_output
find_line_in_seff_output(lines, entry)
Helper function to quickly find the required line in the seff output
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lines
|
list
|
list of lines |
required |
entry
|
str
|
the entry that is being looked for |
required |
Returns: str: time or percentage from the corresponding line, defaults to ""
Source code in src/enchanted_surrogates/executors/dask_executor.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
get_all_dask_job_ids
get_all_dask_job_ids()
Runs squeue to figure out all jobs from the cluster Returns: list: A list of Dask job IDs.
Source code in src/enchanted_surrogates/executors/dask_executor.py
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 | |
get_slurm_usage_info
get_slurm_usage_info(job_id=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
list[int]
|
If you wish to only find the slurm usage info from one specific job pass this |
None
|
Returns: list: dictionary containing the output info from running seff
Source code in src/enchanted_surrogates/executors/dask_executor.py
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 | |
is_running_on_slurm
is_running_on_slurm()
Checks if code is running on slurm or locally. This is done via checking if seff exists. Retuns: bool: true is on slurm false otherwise
Source code in src/enchanted_surrogates/executors/dask_executor.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
shutdown_cluster
shutdown_cluster()
Shuts down the Dask cluster, including the scheduler and workers.
Note
This will also shut down the scheduler, which may not be desired if the scheduler is controlling other clusters. To only shut down the workers, use a different method.
Source code in src/enchanted_surrogates/executors/dask_executor.py
460 461 462 463 464 465 466 467 468 | |
start_cluster
start_cluster()
Starts a Dask cluster using either SLURMCluster or LocalCluster.
If SLURMCluster is used, it sets up SLURM-specific configurations, including output directories for worker logs. If LocalCluster is used, it initializes a local Dask cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slurm_out_dir
|
str
|
Directory for SLURM output logs. Defaults to None. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no workers are successfully started. |
Warning
|
If fewer workers than expected are started. |
Source code in src/enchanted_surrogates/executors/dask_executor.py
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 | |
submit_batch
submit_batch(run_dir_sample_pairs, base_run_dir=None, client=None, include_fut_to_rundir=False)
Submits a batch of simulation tasks to the Dask cluster.
Each task is submitted with its own unique run directory. The tasks are executed asynchronously, and their futures are returned for tracking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_dir_sample_pairs
|
list
|
List of rundir, sample parameters for the simulation tasks. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of futures representing the submitted tasks. |
Source code in src/enchanted_surrogates/executors/dask_executor.py
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 | |
wait_for_all_dask_jobs_running
wait_for_all_dask_jobs_running(poll_interval=1)
Waits for all Dask jobs submitted to SLURM to reach the RUNNING state.
This method repeatedly checks the SLURM job queue for jobs with the prefix 'dask-wor'. If any job is not in the RUNNING state, it waits and retries until all jobs are running.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poll_interval
|
int
|
Time interval (in seconds) between checks. Defaults to 1. |
1
|
Raises:
| Type | Description |
|---|---|
Exception
|
If an error occurs while checking the SLURM queue. |
Source code in src/enchanted_surrogates/executors/dask_executor.py
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 | |