batch
This module parses the batch section of the yaml specification.
Currently only the batch worker launch for slurm, lsf or flux are implemented.
batch_check_parallel(batch)
Check for a parallel batch section in the provided batch dictionary.
This function examines the 'batch' section of the given specification to determine whether it is configured for parallel execution. It checks the 'type' attribute within the batch section, defaulting to 'local' if not specified. If the type is anything other than 'local', the function will return True, indicating that parallel processing is enabled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Dict
|
The batch section from either the YAML |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Returns True if the batch type is set to a value other than 'local', indicating that parallel processing is enabled; otherwise, returns False. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the 'batch' section is not present in the specification, an error is logged and an AttributeError is raised. |
Source code in merlin/study/batch.py
batch_worker_launch(batch, com, nodes=None)
Create the worker launch command based on the batch configuration in the workflow specification.
This function constructs a command to launch a worker process using the specified batch configuration. It handles different batch types and integrates any necessary pre-launch commands, launch arguments, and node specifications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Dict
|
The batch section from either the YAML |
required |
com
|
str
|
The command to launch with the batch configuration. |
required |
nodes
|
Union[str, int]
|
The number of nodes to use in the batch launch. If not specified, it will default to the value in the batch configuration. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The constructed worker launch command, ready to be executed. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the batch section is missing in the specification. |
TypeError
|
If the |
Source code in merlin/study/batch.py
check_for_scheduler(scheduler, scheduler_legend)
Check which scheduler (Flux, Slurm, LSF, or PBS) is the main scheduler for the cluster.
This function verifies if the specified scheduler is the main scheduler by executing a command associated with it from the provided scheduler legend. It returns a boolean indicating whether the specified scheduler is active.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scheduler
|
str
|
A string representing the scheduler to check for. Options include 'flux', 'slurm', 'lsf', or 'pbs'. |
required |
scheduler_legend
|
Dict[str, str]
|
A dictionary containing information related to each scheduler,
including the command to check its status and the expected output. See
|
required |
Returns:
| Type | Description |
|---|---|
bool
|
Returns True if the specified scheduler is the main scheduler for the cluster, otherwise returns False. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the command associated with the scheduler cannot be found. |
PermissionError
|
If there are insufficient permissions to execute the command. |
Source code in merlin/study/batch.py
construct_scheduler_legend(parsed_batch, nodes)
Constructs a legend of relevant information needed for each scheduler.
This function generates a dictionary containing configuration details for various job schedulers based on the provided batch configuration. The returned dictionary includes flags for bank, queue, and walltime, as well as commands to check the scheduler and the initial launch command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parsed_batch
|
Dict
|
A dictionary of batch configurations, which must include |
required |
nodes
|
int
|
The number of nodes to use in the launch command. |
required |
Returns:
| Type | Description |
|---|---|
Dict
|
A dictionary containing scheduler-related information, structured as follows:
|
Source code in merlin/study/batch.py
construct_worker_launch_command(parsed_batch, nodes)
Constructs the worker launch command based on the provided batch configuration.
This function generates a launch command for a worker process when no 'worker_launch' command is specified in the batch configuration. It utilizes the scheduler legend to incorporate necessary flags such as bank, queue, and walltime, depending on the workload manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parsed_batch
|
Dict
|
A dictionary of batch configurations, which must include
|
required |
nodes
|
int
|
The number of nodes to use in the batch launch. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The constructed launch command for the worker process. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the PBS scheduler is enabled for a batch type other than 'flux'. |
KeyError
|
If the workload manager is not found in the scheduler legend. |
Source code in merlin/study/batch.py
get_batch_type(scheduler_legend, default=None)
Determine which batch scheduler to use.
This function checks a predefined list of batch schedulers in a specific order to determine which one is available for use. If none of the schedulers are found, it checks the system type environment variable to suggest a default scheduler. If no suitable scheduler is determined, it returns the specified default value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scheduler_legend
|
Dict[str, str]
|
A dictionary storing information related to each
scheduler, including commands and expected outputs for checking their
availability. See |
required |
default
|
str
|
The default batch scheduler to use if a scheduler cannot be determined. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The name of the available batch scheduler. Possible options include 'slurm', 'flux', 'lsf', or 'pbs'. If no scheduler is found, returns the specified default value. |
Source code in merlin/study/batch.py
get_flux_launch(parsed_batch)
Build the Flux launch command based on the batch section of the YAML configuration.
This function constructs the command to launch a Flux job using the parameters specified in the parsed batch configuration. It determines the appropriate execution command for Flux workers and integrates it with the launch command provided in the batch configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parsed_batch
|
Dict
|
A dictionary containing batch configuration parameters.
See |
required |
Returns:
| Type | Description |
|---|---|
str
|
The constructed Flux launch command, ready to be executed. |
Source code in merlin/study/batch.py
get_node_count(parsed_batch, default=1)
Determine a default node count based on the environment.
This function checks the environment and the Flux version to determine the appropriate number of nodes to use for batch processing. It first verifies the Flux version, then attempts to retrieve the node count from the Flux allocation or environment variables specific to Slurm or LSF. If no valid node count can be determined, it returns a specified default value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parsed_batch
|
Dict
|
A dictionary containing parsed batch configurations.
See |
required |
default
|
int
|
The number of nodes to return if a node count from the environment cannot be determined. |
1
|
Returns:
| Type | Description |
|---|---|
int
|
The number of nodes to use for the batch job. This value is determined based on the environment and scheduler specifics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the Flux version is too old (below 0.17.0). |
Source code in merlin/study/batch.py
parse_batch_block(batch)
Parse the batch block of a YAML configuration file.
This function extracts relevant information from the provided batch block dictionary, including paths, execution options, and defaults. It retrieves the Flux executable path and allocation details, and populates a dictionary with the parsed values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Dict
|
A dictionary representing the batch block from the YAML configuration file. |
required |
Returns:
| Type | Description |
|---|---|
Dict
|
A dictionary containing parsed information from the batch block, including:
|