Skip to main content

No project description provided

Project description

slurmbatcher

Easily create sbatch scripts for running jobs on a cluster.

Installation

pip install slurmbatcher

Configuration

Create a configuration file in toml format. The configuration file must contain a command_template and a matrix.parameters section. The command_template is a string that will be used to generate the sbatch script. The matrix.parameters section contains the parameters that will be used to generate the cartesian product of all possible parameter combinations. Additional parameters can be added to the sbatch.parameters section to specify sbatch parameters.

command_template mini language

You can use placeholders in the command_template string to insert parameters from the matrix.parameters section. Placeholders are enclosed in curly braces that contain the name of the parameter to be inserted. You can also use the special **parameters placeholder to insert all parameters as keyword arguments. The **parameters placeholder will insert all parameters as keyword arguments in the form --parameter-name value.

You can use format specifiers to format the inserted values. The format specifier is a colon followed by a format string. The format string is passed to the python format method. For example, {seed:04d} will format the seed parameter as a zero-padded 4-digit integer. Additionally the following format specifiers are available:

  • :value: gets replaced with the value of the parameter in the current matrix configuration (same as no format specifier)
  • :name: gets replaced with the name of the parameter
  • :option: gets replaces with a keyword argument in the form --name value

Example:

running slurmbatcher example.toml with the following example.toml:

command_template="""\
    echo --cwd {workdir} \
    python $HOME/evoprompt/main.py --task {task} {evaluation-strategy:option} --{seed:name}={seed} {**parameters}\
"""
[sbatch.parameters]
partition = "gpu"
gpus = 1
mail-type = "END,FAIL"
mail-user = "griesshaber@hdm-stuttgart.de"
cpus-per-task = 4


[matrix.parameters]
task = ["sst2", "sst5"]
seed = 42
evaluation-strategy = ["simple", "fast"]

will generate the following sbatch script and submit it to the cluster (use --dry-run to only print the script):

#!/bin/bash
#SBATCH --partition=gpu
#SBATCH --gpus=1
#SBATCH --mail-type=END,FAIL
#SBATCH --mail-user=griesshaber@hdm-stuttgart.de
#SBATCH --cpus-per-task=4
#SBATCH --nodelist=tars
#SBATCH --array=0-15

task=( 'sst2' 'sst5' )
workdir='$HOME/evoprompt'
rest=( '1' '2' )
seed='42'
evaluation_strategy=( 'simple' 'early-stopping' 'shortest-first' 'hardest-first' )

echo --cwd ${workdir} python $HOME/evoprompt/main.py --task ${task[$(( (SLURM_ARRAY_TASK_ID / 1) % 2 ))]} --evaluation-strategy ${evaluation_strategy[$(( (SLURM_ARRAY_TASK_ID / 4) % 4 ))]} --seed ${seed} --rest=${rest[$(( (SLURM_ARRAY_TASK_ID / 2) % 2 ))]}

which will run the following commands on the cluster:

echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy simple --seed 42 --rest=1
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy shortest-first --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst5 --evaluation-strategy shortest-first --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy hardest-first --seed 42 --rest=1
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst5 --evaluation-strategy hardest-first --seed 42 --rest=1
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy hardest-first --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst5 --evaluation-strategy hardest-first --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst5 --evaluation-strategy simple --seed 42 --rest=1
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy simple --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst5 --evaluation-strategy simple --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy early-stopping --seed 42 --rest=1
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst5 --evaluation-strategy early-stopping --seed 42 --rest=1
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy early-stopping --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst5 --evaluation-strategy early-stopping --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy shortest-first --seed 42 --rest=1
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst5 --evaluation-strategy shortest-first --seed 42 --rest=1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slurmbatcher-0.3.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

slurmbatcher-0.3.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file slurmbatcher-0.3.1.tar.gz.

File metadata

  • Download URL: slurmbatcher-0.3.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.1 Darwin/24.0.0

File hashes

Hashes for slurmbatcher-0.3.1.tar.gz
Algorithm Hash digest
SHA256 50f46dfb93bb227cf7290ba774a9f46d1752d761f4c9123e3eb7a6809c593b3f
MD5 36e4d50142604af1195550b68442ac90
BLAKE2b-256 8fca8570318d8a67b9eb1a85e1a4283d96e90838a33e18378b82044bad8e72bc

See more details on using hashes here.

File details

Details for the file slurmbatcher-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: slurmbatcher-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.1 Darwin/24.0.0

File hashes

Hashes for slurmbatcher-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce6eebbd678c59ea7c397feaf4eabfb9a44ef840b9f0df546b37abf7760ff001
MD5 6e4c237b32b1605b6001be632b33c114
BLAKE2b-256 eb387ff01786e6a3355c9678fb738dc8f1c98bd461ef1abf6f243390d393e6d7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page