SBatchJob

Provides a simple interface to formatting SLURM files so that they can be submitted to sbatch. The hope is that this can be subclassed codify options for different HPC paritions and whatnot.

slurm_keys: list
default_opts: dict
sbatch_opt_template: str
sbatch_template: str
sbatch_enter_command: str
sbatch_exit_command: str

 

__init__(self, description=None, job_name=None, account=None, partition=None, mem=None, nodes=None, ntasks_per_node=None, chdir=None, output=None, steps=(), precall=None, environment=None, **opts): 

LLM Docstring

Build a SLURM batch job from the common #SBATCH options plus any additional ones, the job steps, and optional environment/precall hooks.

  • description: str | None

    a human-readable description echoed into the script

  • job_name: str | None

    the SLURM job name

  • account: str | None

    the SLURM account

  • partition: str | None

    the SLURM partition

  • mem: Any

    the memory request

  • nodes: Any

    the node count

  • ntasks_per_node: Any

    tasks per node

  • chdir: str | None

    the working directory

  • output: str | None

    the output-file pattern

  • steps: tuple | str

    the job steps (shell commands)

  • precall: Callable | None

    a callable run before writing the file

  • environment: dict | None

    environment variables to export

  • opts: Any

    additional #SBATCH options

 

clean_opts(self, opts): 

Makes sure opt names are clean. Does no validation of the values sent in.

  • opts: Any
  • :returns: _

 

format_opt_block(self): 

Formats block of options

  • :returns: _

 

format(self): 

Formats an SBATCH file from the held options

  • call_steps: Any
  • :returns: _

 

write(self, file, output_dir=None, mode='w+', **kwargs): 

LLM Docstring

Write the formatted SLURM script to a file, optionally within a working directory (into which any precall hook is run).

  • file: str | IO

    an open stream or a file path

  • output_dir: str | None

    directory to write into (split from file if omitted)

  • mode: str

    the file mode when a path is given

  • kwargs: Any

    extra arguments for open

  • :returns: str | IO

    the path (or stream) written

 

run(self, file=None, output_dir=None, sbatch_function='sbatch', delete=True, text=True, capture_output=True, *args, **kwargs): 

LLM Docstring

Write the SLURM script and submit it with sbatch (via subprocess.run), optionally deleting the script afterward.

  • file: str | None

    the script file name (a temporary name is generated if omitted)

  • output_dir: str | None

    directory to write the script into

  • sbatch_function: str

    the submission command

  • delete: bool

    remove the script file after submission

  • text: bool

    run the subprocess in text mode

  • capture_output: bool

    capture the subprocess output

  • args: Any

    extra positional arguments passed to sbatch

  • kwargs: Any

    extra flags passed to sbatch

  • :returns: subprocess.CompletedProcess

    the completed-process result


Feedback

Examples

Templates

Documentation