tools.slurm

Handy functions for dealing with slurm.

bpreveal.tools.slurm.configSlurm(shellRcFiles, envName, workingDirectory, maxJobs=10)

Generate a configuration dictionary for running jobs with slurm.

Parameters:
  • maxJobs (int) – Maximum number of array jobs to run at once.

  • shellRcFiles (list[str] | str) – shellRcFiles is a list of strings, each one giving the name of a .shrc file in your home directory. These will be sourced, in order, inside the generated script. If shellRcFiles is just a string, it names one and only .shrc file that should be executed.

  • envName (str) – envName is a string, and it gives the name for the environment that should be loaded. if envName is “ml”, then instead of a conda command being used to load bpreveal, the module system on cerebro will be used instead. If you have not installed bpreveal yourself, you should use “ml” for envName.

  • workingDirectory (str) – The directory where your code is based. Slurm scripts will be placed in <workingDirectory>/slurm/<jobName>.slurm, and logs will be in <workingDirectory>/logs/<jobName>.<id>.log.

Returns:

A configuration dictionary.

Return type:

dict

bpreveal.tools.slurm.configSlurmLocal(shellRcFiles, envName, workingDirectory, cpus, memory)

Generate a configuration dictionary for running jobs with slurm.

Parameters:
  • shellRcFiles (list[str] | str) – shellRcFiles is a list of strings, each one giving the name of a .shrc file in your home directory. These will be sourced, in order, inside the generated script. If shellRcFiles is just a string, it names one and only .shrc file that should be executed.

  • envName (str) – The name of the conda environment to activate.

  • workingDirectory (str) – The directory where your code is based. Shell scripts will be placed in <workingDirectory>/slurm/<jobName>.zsh, and logs will be in <workingDirectory>/logs/<jobName>.log.

  • cpus (int) – How many total CPUs are available on this machine?

  • memory (int) – How much memory (in GiB) is available for these jobs, in total?

Returns:

A configuration dictionary.

Return type:

dict

bpreveal.tools.slurm.jobsNonGpu(config, tasks, jobName, ntasks, mem, time, extraHeader='')

Run a job on a non-gpu node.

Parameters:
  • extraHeader (str) – Any additional text to add to the job script.

  • config (dict) – The configuration dict generated by configSlurm.

  • tasks (list[str]) – A list of strings, each giving the commands for one job.

  • jobName (str) – The name of the job for logging and the slurm file.

  • ntasks (int) – How many CPUs should be used?

  • mem (int) – How much memory (in GiB) should be allocated

  • time (str) – How long should the job run, in the format “hh:mm:ss”

Returns:

A string giving the name of the slurm job script that was generated.

Return type:

str

bpreveal.tools.slurm.jobsLocal(config, tasks, jobName, ntasks=None, mem=None, time=None, extraHeader='', parallel=False)

Run a job on a non-gpu node.

Parameters:
  • extraHeader (str) – Any additional text to add to the job script.

  • config (dict) – The configuration dict generated by configSlurm.

  • tasks (list[str]) – A list of strings, each giving the commands for one job.

  • jobName (str) – The name of the job for logging and the slurm file.

  • ntasks (int | None) – If parallel is used, this is how many cores each job will use.

  • mem (int | None) – If parallel is used, this is how much memory each job will use.

  • time (str | None) – Ignored

  • extraHeader – A string that will be appended to the start of the job script.

  • parallel (bool) – Should jobs be run in parallel? Only possible if ntasks and mem are specified.

Returns:

A string giving the name of the slurm job script that was generated.

bpreveal.tools.slurm.jobsGpu(config, tasks, jobName, ntasks, mem, time, extraHeader='')

Run a job on a gpu node.

Parameters:
  • extraHeader (str) – Any additional text to add to the job script.

  • config (dict) – The configuration dict generated by configSlurm.

  • tasks (list[str]) – A list of strings, each giving the commands for one job.

  • jobName (str) – The name of the job for logging and the slurm file.

  • ntasks (int) – How many CPUs should be used?

  • mem (int) – How much memory (in GiB) should be allocated

  • time (str) – How long should the job run, in the format “hh:mm:ss”

Returns:

A string giving the name of the slurm job script that was generated.

bpreveal.tools.slurm.writeDependencyScript(config, jobspecs, wholeJobName, baseJobId=None, local=False, cancelScript=None)

Write a bash script that queues up a set of jobs with a given dependency structure.

Parameters:
  • config (dict) – The configuration dict from configSlurm.

  • jobspecs (list[list[str | list[str]]]) – A jobspec is a tuple of (str, [str,str,str,…]) where the first string is the name of the slurm file to run. The strings after it are the names of the slurm files that the job needs to finish before it can run (i.e., its dependencies).

  • wholeJobName (str) – The name of the script file to generate (excluding extension)

  • baseJobId (int | None) – If provided, make all jobs be dependencies of this job ID.

  • local (bool) – Should this be run locally? If so, just write a shell script that runs all the jobs, with no slurm dependency stuff.

  • cancelScript (str | None) – Name of a script to write that contains commands to cancel all of the jobs in this array (including extension)