slurm-workflows: HPC workflow helpers for Slurm clusters
slurm-workflows lets you run Python functions on a Slurm cluster
without sbatch scripts written by hand.
It provides an interface inspired by
concurrent.futures.
The interface launches long-lived pilot workers.
It then dispatches tasks to those workers.
You pay Slurm's queue latency once per worker, not once per task.
Use it in three cases:
- You have many Python tasks to run on one cluster allocation.
- A sweep or a calibration has to spread across a pool of nodes.
- Per-worker state is expensive, and you want it to stay warm between tasks.
Installation
A run needs:
- Python >= 3.12
- Access to a Slurm cluster (
sbatch,squeue,scancelonPATH) - A running
ds-serviceserver
pip install -U slurm-workflows
To set up on UVA's Rivanna cluster, read How to install slurm-workflows on Rivanna.
Usage
from ds_service_client import DsServiceServer
from slurm_workflows import SlurmPilotExecutor
def square(x):
return x * x
SETUP_SCRIPT = """
module load gcc/14.2.0
conda activate my-env
"""
with DsServiceServer(interface="ib0") as ds_service:
ds_service.wait_until_ready()
with SlurmPilotExecutor("my-run", ds_service.address) as executor:
# 1. Describe a kind of worker. This submits nothing.
executor.define_worker(
name="cpu",
sbatch_args=["-A my_alloc", "-p standard", "-t 01:00:00"],
setup_script=SETUP_SCRIPT,
)
# 2. Launch 4 pilot jobs of that kind.
executor.scale_workers("cpu", 4)
# 3. Submit tasks to a named queue. Workers of that group pull from it.
tasks = [executor.submit("cpu", square, i) for i in range(100)]
# 4. Block until every result is in.
executor.wait(tasks, desc="squaring")
# The executor canceled every pilot job at the end of the block.
print(sum(task.output for task in tasks))
328350
Tasks can be submitted before the workers exist. They wait on the queue until a pilot job starts and takes them.
Documentation
| Document | What it covers |
|---|---|
| Computing pi on a Slurm cluster | The main features of slurm-workflows, by creating a worker pool to compute $\pi$. |
| Computing pi with a Sobol' QMC sweep | Using ExploreSpaceSobolQMC to create a space filling design and evaluate it. |
| Optimizing Himmelblau's function | Using OptimizeSpaceBotorch to run a calibration / optimization task. |
| How to install slurm-workflows on Rivanna | Installing the package and the ds-service binary on Rivanna. |
| How to run the task-queue server | Starting a ds-service server from the driver and binding it where workers can reach it. |
| How to keep per-worker state with actors | Loading an expensive model or connection once per worker instead of once per task. |
| How to fold results across workers | Using mapreduce to run one function over a whole collection and bring back a single value. |
How to watch a run with swtop |
Following a live run from another shell, and keeping a record of one. |
| How to troubleshoot a failing run | Finding the right log, and what each RuntimeError means. |
| How to resume a search | Carrying an optimization on across a walltime limit. |
SlurmPilotExecutor |
The coordinator, Task, RaiseOnError, worker group options, what a run publishes, and the logs. |
ExploreSpaceSobolQMC |
The Sobol' sweep, the objective contract, and the results file. |
OptimizeSpaceBotorch |
The batch Bayesian search, its task fields, and its stopping rule. |
| Search spaces | IntRange, FloatRange and CategoricalRange. |
swtop |
The CLI, the blocks on screen, and what the host and job readings measure. |
| About the pilot-job model | Why pilot workers, the three processes, where the coordinator runs, and which class to reach for. |
| About batch Bayesian optimization | Why a search has rounds, where the fit runs, and when it is worth the overhead. |
| About what a run publishes | Why a run is observable from outside itself, and the limits of that. |
For contributors
| Document | What it covers |
|---|---|
| Developer notes | The layout of the code, where each kind of documentation goes, and the conventions a change is held to. |
| How to run the tests | Running the suite, what it mocks, and what it runs for real. |
License
MIT. See LICENSE.
Release files for slurm-workflows 2.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| slurm_workflows-2.2.0.tar.gz | 46.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| slurm_workflows-2.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 99.7 kB
Release files / slurm_workflows-2.2.0.tar.gz
| Download URL | slurm_workflows-2.2.0.tar.gz |
|---|---|
| Size | 46.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e7ae5da7ce4aa33b28a3f0d4c299b8ae3a2896820eb6a950113ac6606889a4b7
|
|
BLAKE2b-256 checksum How to use checksums |
fa90f8d5ee5e2948d07d4c02da64fb2a968a22f669b61cabcf3276fba98f40d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / slurm_workflows-2.2.0-py3-none-any.whl
| Download URL | slurm_workflows-2.2.0-py3-none-any.whl |
|---|---|
| Size | 53.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e767ec475092123ec072edfddfe4e50d392a68c994bd570e76a4c3adf48bbea6
|
|
BLAKE2b-256 checksum How to use checksums |
a953c1821eec044e038c756277382145e264e7818838e53d7fd281010e281e47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|