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.2.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

slurmbatcher-0.2.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: slurmbatcher-0.2.0.tar.gz
  • Upload date:
  • Size: 4.4 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.2.0.tar.gz
Algorithm Hash digest
SHA256 8f18f526b5de1da0f19c520c3344ba33f99d123bfd05b43f782d7113af7adbdf
MD5 f8a48191b2d92efbcbffc61fa571ce0a
BLAKE2b-256 d69cf7e3e56cc5c8e12ab661a94b1714dee4987388a7f64c9adf5203d0a3e9d1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: slurmbatcher-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a41bc91643ad5dbb8dccd98dfe1db7e51370fa930e446ad3d54b56774e209aaf
MD5 2292b81c03b78a0fb0da7a40fdfacc57
BLAKE2b-256 8936a14434eabe4a48bcdde14710d00dfbf20b582e1fc9edc84a62b0a9054543

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