script_adapter
This module stores the functionality for adapting bash scripts to use schedulers.
Supported schedulers are currently: Flux, LSF, and Slurm.
MerlinFluxScriptAdapter
Bases: MerlinSlurmScriptAdapter
A SchedulerScriptAdapter class for flux blocking parallel launches.
The MerlinFluxScriptAdapter is designed for workflows that execute flux parallel jobs
in a Celery worker. It utilizes non-blocking submits and allows for configuration of the
shell in which scripts are executed.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
A unique identifier for the adapter, set to "merlin-flux". |
_cmd_flags |
Dict[str, str]
|
A dictionary containing command-line flags for the flux command. |
_unsupported |
Set[str]
|
A set of command flags that are not supported by this adapter. |
Methods:
| Name | Description |
|---|---|
get_priority |
Retrieves the priority of the step. |
time_format |
Converts a time format to flux standard designation. |
write_script |
Writes the script for the specified step and returns relevant paths. |
Source code in merlin/study/script_adapter.py
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 | |
__init__(**kwargs)
Initialize an instance of the MerinFluxScriptAdapter.
The MerlinFluxScriptAdapter is the adapter that is used for workflows that
will execute flux parallel jobs in a celery worker. The only configurable aspect to
this adapter is the shell that scripts are executed in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Dict
|
A dictionary with default settings for the adapter. |
{}
|
Source code in merlin/study/script_adapter.py
get_priority(priority)
This is implemented to override the abstract method and fix a pylint error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
priority
|
StepPriority
|
Float or
|
required |
Source code in merlin/study/script_adapter.py
time_format(val)
Convert a time format to Flux Standard Duration (FSD).
This method takes a time value and converts it into a format that is compatible
with Flux's standard time representation. The conversion is performed using the
convert_timestring function with the specified format
method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val
|
Union[str, int]
|
The time value to be converted. This can be a string representing a time duration or an integer representing a time value. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The time formatted according to Flux Standard Duration (FSD). |
Source code in merlin/study/script_adapter.py
write_script(ws_path, step)
This will overwrite the write_script method from Maestro's base ScriptAdapter
class but will eventually call it. This is necessary for the VLAUNCHER to work.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ws_path
|
str
|
The path to the workspace where the scripts will be written. |
required |
step
|
StudyStep
|
The Maestro |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, str, str]
|
A tuple containing:
|
Source code in merlin/study/script_adapter.py
MerlinLSFScriptAdapter
Bases: SlurmScriptAdapter
A SchedulerScriptAdapter class for SLURM blocking parallel launches.
The MerlinLSFScriptAdapter uses non-blocking submits for executing LSF parallel jobs
in a Celery worker.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
A unique key identifier for the adapter. |
_cmd_flags |
Dict[str, str]
|
A dictionary containing command flags for LSF execution. |
_unsupported |
Set[str]
|
A set of parameters that are unsupported by this adapter. |
Methods:
| Name | Description |
|---|---|
get_header |
Generates the header for LSF execution scripts. |
get_parallelize_command |
Generates the LSF parallelization segment of the command line. |
get_priority |
Overrides the abstract method to fix a pylint error. |
write_script |
Overwrites the write_script method from the base ScriptAdapter class. |
Source code in merlin/study/script_adapter.py
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 | |
__init__(**kwargs)
Initialize an instance of the MerinLSFScriptAdapter.
The MerlinLSFScriptAdapter is the adapter that is used for workflows that
will execute LSF parallel jobs in a celery worker. The only configurable aspect to
this adapter is the shell that scripts are executed in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Dict
|
A dictionary with default settings for the adapter. |
{}
|
Source code in merlin/study/script_adapter.py
get_header(step)
Generate the header present at the top of LSF execution scripts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
StudyStep
|
A Maestro StudyStep instance that contains parameters relevant to the execution. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string of the header based on internal batch parameters and the parameter step. |
Source code in merlin/study/script_adapter.py
get_parallelize_command(procs, nodes=None, **kwargs)
Generate the LSF parallelization segment of the command line.
This method constructs a command line segment for parallel execution in LSF. It allows specifying the number of processors and nodes to be allocated for the parallel call, along with additional command flags through keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
procs
|
int
|
Number of processors to allocate to the parallel call. |
required |
nodes
|
int
|
Number of nodes to allocate to the parallel call. Defaults to 1. |
None
|
**kwargs
|
Dict
|
Additional command flags that may be supported by the LSF command. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
A string representing the parallelization command configured using nodes and procs. |
Source code in merlin/study/script_adapter.py
get_priority(priority)
This is implemented to override the abstract method and fix a pylint error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
priority
|
StepPriority
|
Float or
|
required |
Source code in merlin/study/script_adapter.py
write_script(ws_path, step)
This will overwrite the write_script method from Maestro's base ScriptAdapter
class but will eventually call it. This is necessary for the VLAUNCHER to work.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ws_path
|
str
|
The path to the workspace where the scripts will be written. |
required |
step
|
StudyStep
|
The Maestro StudyStep object containing information for the step. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, str, str]
|
A tuple containing:
|
Source code in merlin/study/script_adapter.py
MerlinScriptAdapter
Bases: LocalScriptAdapter
A ScriptAdapter class for interfacing with execution in Merlin.
This class serves as an adapter for executing scripts in a Celery worker environment. It allows for configuration of the execution environment and manages the execution of scripts with appropriate logging and error handling.
Attributes:
| Name | Type | Description |
|---|---|---|
batch_adapter |
ScriptAdapter
|
An instance of a batch adapter used for executing scripts based on the specified batch type. |
batch_type |
str
|
The type of batch processing to be used, derived from the provided keyword arguments. |
key |
str
|
A unique identifier for the adapter, set to "merlin-local". |
Methods:
| Name | Description |
|---|---|
submit |
Executes a workflow step locally. |
write_script |
Writes a script using the batch adapter. |
Source code in merlin/study/script_adapter.py
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 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 | |
__init__(**kwargs)
Initialize an instance of the MerinScriptAdapter.
The MerlinScriptAdapter is the adapter that is used for workflows that
will execute in a celery worker. The only configurable aspect to
this adapter is the shell that scripts are executed in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Dict
|
A dictionary with default settings for the adapter. |
{}
|
Source code in merlin/study/script_adapter.py
submit(step, path, cwd, job_map=None, env=None)
Execute a workflow step locally.
This method runs a specified script in the local environment, allowing for customization of the working directory and environment variables. It handles the execution of the script and logs the results, including any errors or specific return codes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
StudyStep
|
An instance of the StudyStep that contains information about the workflow step being executed. |
required |
path
|
str
|
The file path to the script that is to be executed. |
required |
cwd
|
str
|
The current working directory from which the script will be executed. |
required |
job_map
|
Dict
|
A mapping of workflow step names to their job identifiers. |
None
|
env
|
Dict
|
A dictionary containing environment variables to be set for the execution. |
None
|
Returns:
| Type | Description |
|---|---|
SubmissionRecord
|
An object containing the return code of the command, the process ID of the command, and any additional information about the execution. |
Source code in merlin/study/script_adapter.py
write_script(*args, **kwargs)
Generate a script for execution using the batch adapter.
This method delegates the script writing process to the associated batch adapter and returns the generated script along with a restart script if applicable.
Returns:
| Type | Description |
|---|---|
Tuple[bool, str, str]
|
A tuple containing:
|
Source code in merlin/study/script_adapter.py
MerlinScriptAdapterFactory
This class routes to the correct ScriptAdapter.
The MerlinScriptAdapterFactory is responsible for providing the appropriate
ScriptAdapter based on the specified adapter ID. It maintains a mapping of
available adapters and offers methods to retrieve them.
Attributes:
| Name | Type | Description |
|---|---|---|
factories |
Dict[str, ScriptAdapter]
|
A dictionary mapping adapter IDs (str) to their corresponding
|
Methods:
| Name | Description |
|---|---|
get_adapter |
Returns the appropriate |
get_valid_adapters |
Returns a list of valid adapter IDs that can be used with this factory. |
Source code in merlin/study/script_adapter.py
get_adapter(adapter_id)
classmethod
Returns the appropriate ScriptAdapter to use.
This method retrieves the ScriptAdapter class associated with the given
adapter ID. If the adapter ID is not found in the factory's mapping,
a ValueError is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter_id
|
str
|
The ID of the desired |
required |
Returns:
| Type | Description |
|---|---|
ScriptAdapter
|
The corresponding |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the specified adapter_id is not found in the factories. |
Source code in merlin/study/script_adapter.py
get_valid_adapters()
classmethod
Returns the valid ScriptAdapters.
This method provides a list of all valid adapter IDs that can be used with this factory. The IDs are derived from the keys of the factories dictionary.
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of valid adapter IDs. |
Source code in merlin/study/script_adapter.py
MerlinSlurmScriptAdapter
Bases: SlurmScriptAdapter
A SchedulerScriptAdapter class for SLURM blocking parallel launches.
This class extends the SlurmScriptAdapter to provide support for blocking parallel
launches in SLURM. Unlike the base class, which uses non-blocking submits, this adapter
is designed for workflows that execute SLURM parallel jobs in a Celery worker.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
A unique identifier for the adapter, set to "merlin-slurm". |
_cmd_flags |
Dict[str, str]
|
A dictionary containing command flags for SLURM. |
_unsupported |
Set[str]
|
A set of command flags that are not supported by this adapter. |
Methods:
| Name | Description |
|---|---|
get_header |
Generates the header for SLURM execution scripts. |
get_parallelize_command |
Generates the SLURM parallelization segment of the command line. |
get_priority |
Overrides the abstract method to fix a pylint error. |
time_format |
Converts a timestring to HH:MM:SS format. |
write_script |
Overwrites the write_script method from the base class to ensure VLAUNCHER compatibility. |
Source code in merlin/study/script_adapter.py
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 | |
__init__(**kwargs)
Initialize an instance of the MerinSlurmScriptAdapter.
The MerlinSlurmScriptAdapter is the adapter that is used for workflows that
will execute SLURM parallel jobs in a celery worker. The only configurable aspect to
this adapter is the shell that scripts are executed in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Dict
|
A dictionary with default settings for the adapter. |
{}
|
Source code in merlin/study/script_adapter.py
get_header(step)
Generate the header present at the top of Slurm execution scripts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
StudyStep
|
A Maestro StudyStep instance that contains parameters relevant to the execution. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string of the header based on internal batch parameters and the parameter step. |
Source code in merlin/study/script_adapter.py
get_parallelize_command(procs, nodes=None, **kwargs)
Generate the SLURM parallelization segment of the command line.
This method constructs the command line segment required for parallel execution
in SLURM, including the number of processors and nodes to allocate. It also
incorporates any additional supported command flags provided in kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
procs
|
int
|
The number of processors to allocate for the parallel call. |
required |
nodes
|
int
|
The number of nodes to allocate for the parallel call (default is 1). |
None
|
**kwargs
|
Dict
|
Additional command flags to customize the SLURM command.
Supported flags include 'walltime' and others defined in the
|
{}
|
Returns:
| Type | Description |
|---|---|
str
|
A string representing the SLURM parallelization command, formatted with the specified number of processors, nodes, and any additional flags. |
Source code in merlin/study/script_adapter.py
get_priority(priority)
This is implemented to override the abstract method and fix a pylint error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
priority
|
StepPriority
|
Float or
|
required |
Source code in merlin/study/script_adapter.py
time_format(val)
Convert the input timestring or integer to HH:MM:SS format.
This method utilizes the convert_timestring
function to convert a given timestring or integer (representing seconds)
into a formatted string in the 'hours:minutes:seconds' (HH:MM:SS) format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val
|
Union[str, int]
|
A timestring in the format '[days]:[hours]:[minutes]:seconds' or an integer representing time in seconds. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the input time formatted as 'HH:MM:SS'. |
Source code in merlin/study/script_adapter.py
write_script(ws_path, step)
This will overwrite the write_script method from Maestro's base ScriptAdapter
class but will eventually call it. This is necessary for the VLAUNCHER to work.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ws_path
|
str
|
The path to the workspace where the scripts will be written. |
required |
step
|
StudyStep
|
The Maestro |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, str, str]
|
A tuple containing:
|
Source code in merlin/study/script_adapter.py
setup_vlaunch(step_run, batch_type, gpu_config)
Check for the VLAUNCHER keyword in the step run string and configure VLAUNCHER settings.
This function examines the provided step run command string for the presence of the VLAUNCHER keyword. If found, it replaces the keyword with the LAUNCHER keyword and extracts relevant MERLIN variables such as nodes, processes, and cores per task. It also configures GPU settings based on the provided boolean flag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_run
|
str
|
The step.run command string that may contain the VLAUNCHER keyword. |
required |
batch_type
|
str
|
A string representing the type of batch processing being used. |
required |
gpu_config
|
bool
|
A boolean indicating whether GPUs should be configured. |
required |