step
This module represents all of the logic that goes into a step
MerlinStepRecord
Bases: _StepRecord
This class is a wrapper for the Maestro _StepRecord to remove
a re-submit message and handle status updates.
Attributes:
| Name | Type | Description |
|---|---|---|
condensed_workspace |
str
|
A condensed version of the workspace path. |
elapsed_time |
str
|
The total elapsed time for the step execution. |
jobid |
List[int]
|
A list of job identifiers assigned by the scheduler. |
maestro_step |
StudyStep
|
The StudyStep object associated with this step. |
merlin_step |
Step
|
The Step object associated with this step. |
restart_limit |
int
|
Upper limit on the number of restart attempts. |
restart_script |
str
|
Script to resume record execution (if applicable). |
run_time |
str
|
The run time for the step execution. |
status |
State
|
The current status of the step. |
to_be_scheduled |
bool
|
Indicates if the record needs scheduling. |
workspace |
Variable
|
The output workspace for this step, represented as a Variable. |
Methods:
| Name | Description |
|---|---|
mark_end |
Marks the end of the step with the given state. |
mark_restart |
Increments the restart count for the step. |
mark_running |
Marks the step as running and updates the status file. |
setup_workspace |
Initializes the workspace and status file for the step. |
Source code in merlin/study/step.py
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 | |
condensed_workspace
property
Generate a condensed version of the workspace path for display purposes.
This property constructs a shorter representation of the workspace path by extracting relevant components based on the study name and a timestamp pattern. If a match is found using a regular expression, the workspace path is split to isolate the condensed portion. If no match is found, a fallback method is used to manually create a condensed path based on the step name.
Returns:
| Type | Description |
|---|---|
str
|
A string representing the condensed workspace path, which is easier to read and display. |
__init__(workspace, maestro_step, merlin_step, **kwargs)
Initializes the MerlinStepRecord class which helps track the status of a step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace
|
str
|
The output workspace for this step. |
required |
maestro_step
|
StudyStep
|
The StudyStep object associated with this step. |
required |
merlin_step
|
Step
|
The Step object associated with this step. |
required |
Source code in merlin/study/step.py
mark_end(state, max_retries=False)
Marks the end time of the record with the associated termination state and updates the status file.
This method logs the action of marking the end of the step, maps the provided termination state to a corresponding Maestro state and result, and updates the status file accordingly. If the maximum number of retries has been reached for a soft failure, it appends a message to the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
ReturnCode
|
A ReturnCode object representing the end state of the task. |
required |
max_retries
|
bool
|
A flag indicating whether the maximum number of retries has been reached. |
False
|
Source code in merlin/study/step.py
mark_restart()
Increment the number of restarts we've had for this step and update the status file.
Source code in merlin/study/step.py
mark_running()
Mark the start time of the record and update the status file.
setup_workspace()
Step
This class provides an abstraction for an execution step, which can be
executed by calling the execute method.
Attributes:
| Name | Type | Description |
|---|---|---|
max_retries |
int
|
Returns the maximum number of retries for this step. |
mstep |
_StepRecord
|
The Maestro StepRecord object associated with this step. |
parameter_info |
dict
|
A dictionary containing information about parameters in the study. |
params |
Dict
|
A dictionary containing command parameters for the step, including 'cmd' and 'restart_cmd'. |
restart |
bool
|
Property to get or set the restart status of the step. |
retry_delay |
int
|
Returns the retry delay for the step (default is 1). |
study_name |
str
|
The name of the study this step belongs to. |
Methods:
| Name | Description |
|---|---|
check_if_expansion_needed |
Checks if command expansion is needed based on specified labels. |
clone_changing_workspace_and_cmd |
Produces a deep copy of the current step, with optional command and workspace modifications. |
establish_params |
Pulls parameters from the step parameter map if applicable. |
execute |
Executes the step using the provided adapter configuration. |
get_cmd |
Retrieves the run command text body. |
get_restart_cmd |
Retrieves the restart command text body, or None if not available. |
get_task_queue |
Retrieves the task queue for the step. |
get_task_queue_from_dict |
Static method to get the task queue from a step dictionary. |
get_workspace |
Retrieves the workspace where this step is to be executed. |
name |
Retrieves the name of the step. |
name_no_params |
Gets the original name of the step without parameters or sample labels. |
Source code in merlin/study/step.py
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 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 686 687 688 689 690 | |
max_retries
property
Get the maximum number of retries for this step.
Returns:
| Type | Description |
|---|---|
int
|
The maximum number of retries for the step. |
restart
property
writable
Get the restart property.
Returns:
| Type | Description |
|---|---|
bool
|
True if the step is set to restart, False otherwise. |
retry_delay
property
Get the retry delay for the step.
Returns:
| Type | Description |
|---|---|
int
|
The retry delay in seconds. Defaults to 1 if not specified. |
__init__(maestro_step_record, study_name, parameter_info)
Initializes the Step object which acts as a way to track everything about a step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
maestro_step_record
|
_StepRecord
|
The |
required |
study_name
|
str
|
The name of the study |
required |
parameter_info
|
Dict
|
A dict containing information about parameters in the study |
required |
Source code in merlin/study/step.py
check_if_expansion_needed(labels)
Check if expansion is needed based on commands and labels.
This method determines whether the command associated with the current step requires expansion. It checks for the presence of default keywords or specified sample column labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
List[str]
|
A list of labels to check against the commands. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the command requires expansion, False otherwise. |
Source code in merlin/study/step.py
clone_changing_workspace_and_cmd(new_cmd=None, cmd_replacement_pairs=None, new_workspace=None)
Produces a deep copy of the current step, with optional modifications to the command and workspace, performing variable substitutions as we go.
This method creates a new instance of the Step class by cloning the current step and allowing for modifications to the command text and workspace. It performs variable substitutions in the command based on the provided replacement pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_cmd
|
str
|
If provided, replaces the existing command with this new command. |
None
|
cmd_replacement_pairs
|
List[Tuple[str]]
|
A list of pairs where each pair contains a string to be replaced and its replacement. The method will perform replacements in both the run command and the restart command. |
None
|
new_workspace
|
str
|
If provided, sets this as the workspace for the new step. If not specified, the current workspace will be used. |
None
|
Returns:
| Type | Description |
|---|---|
Step
|
A new Step instance with the modified command and workspace. |
Source code in merlin/study/step.py
establish_params()
Establish parameters for the step from the parameter map.
This method checks if the current step uses parameters by accessing
the step_param_map from parameter_info. If parameters are found
for the current step, it updates the params dictionary with the
corresponding values.
Source code in merlin/study/step.py
execute(adapter_config)
Execute the step with the provided adapter configuration.
This method performs the execution of the step by configuring the necessary parameters and invoking the appropriate adapter. It updates the adapter configuration based on the step's requirements, sets up the workspace, and generates the script for execution. If a dry run is specified, it prepares the workspace without executing any tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter_config
|
dict
|
A dictionary containing configuration for the maestro script adapter, including:
|
required |
Returns:
| Type | Description |
|---|---|
ReturnCode
|
A |
Source code in merlin/study/step.py
get_cmd()
Retrieve the run command text body for the step.
Returns:
| Type | Description |
|---|---|
str
|
The run command text body for the step. |
get_restart_cmd()
Retrieve the restart command text body for the step.
Returns:
| Type | Description |
|---|---|
str
|
The restart command text body for the step, or None if no restart command is available. |
Source code in merlin/study/step.py
get_task_queue()
Retrieve the task queue for the current Step.
Returns:
| Type | Description |
|---|---|
str
|
The name of the task queue for the Step, which may be influenced by the configuration settings. |
Source code in merlin/study/step.py
get_task_queue_from_dict(step_dict)
staticmethod
Get the task queue from a given Maestro step dictionary.
This static method extracts the task queue information from the provided step dictionary. It considers the configuration settings to determine the appropriate queue name, including handling cases where the task queue may be omitted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_dict
|
Dict
|
A dictionary representation of a Maestro step, expected to contain a "run" key with a "task_queue" entry. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The name of the task queue. If the task queue is not specified or is set to "none", it returns the default queue name based on the configuration. |
Source code in merlin/study/step.py
get_workspace()
Get the workspace for the current step.
Returns:
| Type | Description |
|---|---|
str
|
The workspace associated with this step. |
name()
name_no_params()
Get the original name of the step without parameters or sample labels.
This method retrieves the name of the step and removes any parameter labels or sample identifiers that may be included in the name. It ensures that the returned name is clean and free from extraneous characters, such as trailing periods or underscores.
Returns:
| Type | Description |
|---|---|
str
|
The cleaned name of the step, free from parameters and sample labels. |
Source code in merlin/study/step.py
get_current_queue()
Get the queue on the current running task from Celery.
This function retrieves the name of the queue that the current task is associated with. It extracts the routing key from the task's delivery information and removes the queue tag defined in the configuration.
Returns:
| Type | Description |
|---|---|
str
|
The name of the current queue. |
Source code in merlin/study/step.py
get_current_worker()
Get the worker on the current running task from Celery.
This function retrieves the name of the worker that is currently executing the task. It extracts the worker's name from the task's request hostname.
Returns:
| Type | Description |
|---|---|
str
|
The name of the current worker. |