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.
Features
- Pilot workers - pay Slurm's queue latency once per worker, then dispatch tasks to them.
- Dynamic scaling - grow or shrink a pool of workers at runtime.
- Stateful actors - keep expensive per-worker state (loaded models, database connections) warm across many tasks.
- Transparent serialization - cloudpickle serializes functions, arguments, and return values.
- Live monitoring tool -
swtop, a terminal UI that shows the tasks, workers, nodes and jobs for a running workflow. - Bayesian optimization - an optimizer built on botorch for optimization and calibration workflows.
Requirements
- Python >= 3.12
- Access to a Slurm cluster (
sbatch,squeue,scancelonPATH) - A running
ds-serviceserver, v5.1.0 or later
Installation
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))
The executor passes sbatch_args straight through to sbatch.
As a result, any Slurm option works.
You can submit tasks before the workers exist.
The tasks wait on the queue until a pilot job starts and takes them.
Documentation
Tutorials
| 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 guides
| Document | What it covers |
|---|---|
| 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 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. |
Reference
| Document | What it covers |
|---|---|
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. |
Explanation
| Document | What it covers |
|---|---|
| About the pilot-job model | Why pilot workers, the three processes, 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 | Notes for anyone working on slurm-workflows itself. |
| How to run the tests | Organization of the unit tests and instructions for running them. |
License
MIT - see LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file slurm_workflows-2.0.0.tar.gz.
File metadata
- Download URL: slurm_workflows-2.0.0.tar.gz
- Upload date:
- Size: 43.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9be13757e40a0d72dc4e4288c5cf33f8f99e63e98d4cf7ddc0072887bd72d3eb
|
|
| MD5 |
4795472f88a581ae605e3c43ff7ee9bc
|
|
| BLAKE2b-256 |
4fd062c8fe5c7bb969b883587e47a41d6ccb7d25e7bd238bcc4a6cdbcbf03726
|
File details
Details for the file slurm_workflows-2.0.0-py3-none-any.whl.
File metadata
- Download URL: slurm_workflows-2.0.0-py3-none-any.whl
- Upload date:
- Size: 50.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
432fc53a3e23c03cc07620da2d70496d156c379cb60b1bd1d83ba2f267833057
|
|
| MD5 |
74f9f8d82b3e70e2f3defe808941b917
|
|
| BLAKE2b-256 |
534f3aa2cf9fe5d6f729e443b53c74879fdf345e1160ad6131bd6ca47029c40c
|