enjoy_slurm.sbatch#

enjoy_slurm.sbatch(jobscript=None, dependency=None, kill_on_invalid_dep=None, verbose=False, *args, **kwargs)[source]#

Submit a batch script to Slurm

All of sbatch command line arguments that are not explicitly documented here can still be passed via **kwargs. For example, partition="compute" would be translated into the --partion compute command line argument for sbatch. For all available options, please consult the sbatch manpage. However, some of the most useful argument are also documented here.

Parameters:
  • jobscript (str) – Path to jobscript file. If no jobscript is provided, you can use the wrap keyword to directly pass shell commands.

  • depdendency (str, tuple or list) – A list of jobids this job depends on. This can also an original slurm command as a string, e.g., "afterok:1:2:3". The default dependency type will be afterok which means that this job will only start if all depedending jobs have exit code 0. If depdendency is a tuple, the first entry defines the dependency type and the second will be the list of jobids, e.g., ("afterany", [1, 2, 3]). See also the sbatch manpage for more details.

  • kill_on_invalid_dep (bool or str) – If a job has an invalid dependency and it can never run this parameter tells Slurm to terminate it or not. A terminated job state will be JOB_CANCELLED. If this option is not specified, the system wide behavior applies. By default the job stays pending with reason DependencyNeverSatisfied or if the kill_invalid_depend is specified in slurm.conf the job is terminated.

  • verbose (bool) – Print sbatch command.

Returns:

jobid – Slurm jobid.

Return type:

int

Examples

>>> from enjoy_slurm import sbatch
>>> jobids = [slurm.sbatch(wrap=f"echo Hello World from job {i}") for in range(0,10)]
>>> slurm.sbatch(wrap="All jobs finished", dependency=jobids)