Skip to content

generate_run

This module provides functions to generate run files for jobs in different environments (local/Slurm and HTCondor). It includes functions to create shell script snippets for tagging jobs as finished and generating run files with appropriate configurations.

Functions:

Name Description
tag_str

str) -> str:

generate_run_file

str, job_name: str, setup_env_script: str, generation_number: int, tree_path: str, l_keys: list[str], htc: bool = False, additionnal_command: str = "", l_dependencies: list[str] | None = None, name_config: str = "config.yaml") -> str:

_generate_run_file

str, job_name: str, setup_env_script: str, tree_path: str, l_keys: list[str], additionnal_command: str = "") -> str:

_generate_run_file_htc

str, job_name: str, setup_env_script: str, generation_number: int, tree_path: str, l_keys: list[str], additionnal_command: str = "", l_dependencies: list[str] | None = None, name_config: str = "config.yaml") -> str:

generate_run_file(abs_job_folder, job_name, setup_env_script, htc=False, slurm_docker_fix=True, additionnal_command='', **kwargs_htc_run_files)

Generates a run file for a job, either for local/Slurm or HTC environments.

Parameters:

Name Type Description Default
abs_job_folder str

The (absolute) folder where the job is located.

required
job_name str

The name of the job script.

required
setup_env_script str

The script to set up the environment.

required
htc bool

Whether the job shoud be run on HTCondor. Defaults to False.

False
slurm_docker_fix bool

Whether to fix the Docker issue with recovery path on Slurm. Defaults to False.

True
additionnal_command str

Additional command to run. Defaults to "".

''
**kwargs_htc_run_files Any

Additional keyword arguments for the generate_run_files method when submitting HTC jobs.

{}

Returns:

Name Type Description
str str

The generated run file content.

Source code in study_da/submit/generate_run.py
def generate_run_file(
    abs_job_folder: str,
    job_name: str,
    setup_env_script: str,
    htc: bool = False,
    slurm_docker_fix: bool = True,
    additionnal_command: str = "",
    **kwargs_htc_run_files: Any,
) -> str:
    """
    Generates a run file for a job, either for local/Slurm or HTC environments.

    Args:
        abs_job_folder (str): The (absolute) folder where the job is located.
        job_name (str): The name of the job script.
        setup_env_script (str): The script to set up the environment.
        htc (bool, optional): Whether the job shoud be run on HTCondor. Defaults to False.
        slurm_docker_fix (bool, optional): Whether to fix the Docker issue with recovery path on
            Slurm. Defaults to False.
        additionnal_command (str, optional): Additional command to run. Defaults to "".
        **kwargs_htc_run_files (Any): Additional keyword arguments for the generate_run_files method
                when submitting HTC jobs.

    Returns:
        str: The generated run file content.
    """
    if not htc:
        return _generate_run_file(
            abs_job_folder,
            job_name,
            setup_env_script,
            additionnal_command,
            slurm_docker_fix=slurm_docker_fix,
        )
    if kwargs_htc_run_files["l_dependencies"] is None:
        kwargs_htc_run_files["l_dependencies"] = []
    return _generate_run_file_htc(
        abs_job_folder,
        job_name,
        setup_env_script,
        additionnal_command,
        **kwargs_htc_run_files,
    )

tag_str(abs_job_folder)

" Generates a shell script snippet to tag a job as finished if it was successful. Args: abs_job_folder (str): The (absolute) folder where the job is located. Returns: str: A formatted string containing the shell script snippet.

Source code in study_da/submit/generate_run.py
def tag_str(abs_job_folder: str) -> str:
    """ "
    Generates a shell script snippet to tag a job as finished if it was successful.
    Args:
        abs_job_folder (str): The (absolute) folder where the job is located.
    Returns:
        str: A formatted string containing the shell script snippet.
    """
    return f"""
# Ensure job run was successful and tag as finished, or as failed otherwise
if [ $? -eq 0 ]; then
    touch {abs_job_folder}/.finished
else
    touch {abs_job_folder}/.failed
fi\n
"""