slurm-workflows: HPC workflow helpers for Slurm clusters
slurm-workflows lets you run Python functions on a Slurm cluster
without hand-written sbatch scripts.
It provides an interface
inspired by concurrent.futures.
The interface launches long-lived workers inside pilot jobs.
It then dispatches tasks to those workers.
You pay Slurm's scheduling latency once per pilot job, not once per task.
Use it in three cases:
- You have many Python tasks to run on one cluster allocation.
- An exploration or a search has to spread across a pool of workers.
- 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) - The
ds-servicebinary onPATH
pip install -U slurm-workflows
# For OptimizeSpaceBotorch:
pip install -U "slurm-workflows[botorch]"
To set up on UVA's Rivanna cluster, read How to install slurm-workflows on Rivanna.
Usage
Replace the Slurm account (-A), the partition (-p)
and the setup script with the ones for your cluster.
The driver must run on a node with the ib0 interface.
For another interface, read
How to run the ds-service server.
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 job group. This submits nothing.
executor.define_job_group(
name="cpu",
sbatch_args=["-A my_alloc", "-p standard", "-t 01:00:00"],
setup_script=SETUP_SCRIPT,
)
# 2. Launch 4 pilot jobs of that job group.
executor.scale_jobs("cpu", 4)
# 3. Submit tasks to a named queue. That job group's workers claim them.
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))
work directory: '/home/<user>/.cache/slurm-workflows/my-run/<timestamp>'
328350
You can submit tasks before the workers exist. They wait on the queue until a worker starts and claims them.
Documentation
| Document | What it covers |
|---|---|
| Computing pi on a Slurm cluster | The main features of slurm-workflows, by creating a pool of workers to compute $\pi$. |
| Computing pi with a Sobol' QMC exploration | Using ExploreSpaceSobolQMC to create a space-filling design and evaluate it. |
| Optimizing Himmelblau's function | Using OptimizeSpaceBotorch to run a batch Bayesian search. |
| How to install slurm-workflows on Rivanna | Installing the package and the ds-service binary on Rivanna. |
How to run the ds-service 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, or map to bring back every value. |
How to watch a run with swtop |
Following a live run from another shell, and keeping a record of one. |
How to embed swtop in a Textual app |
Putting the swtop tabs, summary line, progress bar and error line in your own Textual app. |
| How to troubleshoot a failing run | Finding the right log, and what each RuntimeError means. |
| How to resume a search | Carrying a search on across a Slurm time limit. |
| How to update worker code without resubmitting | Restarting the workers in running pilot jobs, so they run new code without a second wait in Slurm's queue. |
SlurmPilotExecutor |
The executor, Task, RaiseOnError, the job group options, restarting workers, and the worker entry point. |
mapreduce |
Mapping an iterable across the pool, the fold contract, and what the call creates on the server. |
map |
Mapping an iterable across the pool and getting every value back in order. |
| What a run publishes | The keys and time series a run writes, and the logs. |
ExploreSpaceSobolQMC |
The Sobol' exploration, its study fields, and the results file. |
OptimizeSpaceBotorch |
The batch Bayesian search, its study fields, and its stopping rule. |
| Search spaces | IntRange, FloatRange and CategoricalRange. |
| The objective | The contract an objective function meets, and what a failed evaluation does to a run. |
swtop |
The CLI, the keys, the blocks on screen, what the host and job readings measure, and the widgets an app can embed. |
| The pilot-job model | Why pilot jobs, the three processes, where the driver runs, and which class to reach for. |
| Batch Bayesian optimization | Why a search has rounds, where the fit runs, and when it is worth the overhead. |
| The trail a run leaves | 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 must follow. |
| Terminology | The word this project uses for each concept, in prose and in identifiers, and where each word comes from. |
| How to run the tests | Running the suite, what it mocks, and what it runs for real. |
License
MIT. See LICENSE.
Metadata
Release files for slurm-workflows 4.5.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 | Provenance | Actions |
|---|---|---|---|---|
| slurm_workflows-4.5.0.tar.gz | 65.1 kB | Without provenance | Details for slurm_workflows-4.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| slurm_workflows-4.5.0-py3-none-any.whl | Python 3 | none | any | Details for slurm_workflows-4.5.0-py3-none-any.whl |
Total release size: 137.8 kB
Release files / slurm_workflows-4.5.0.tar.gz
| Download URL | slurm_workflows-4.5.0.tar.gz |
|---|---|
| Size | 65.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a72ac527e7a9e5a29df9e0ce3d2442647f367974857bac20f45e2fe64c124cdf
|
|
BLAKE2b-256 checksum How to use checksums |
524f88ebb83158e8a345cfd4f3b722777119e7234199ea414d70cdda2c079d40
|
| 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-4.5.0-py3-none-any.whl
| Download URL | slurm_workflows-4.5.0-py3-none-any.whl |
|---|---|
| Size | 72.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b2310ba47090dad25f67d0f5de99a79d085703f8911cf8429440cdc7ebef5edb
|
|
BLAKE2b-256 checksum How to use checksums |
c55efb6e99dbb6ec19bc0736a1d92e7e77b4cdf7f7e05077c86fcf823d4cbe40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Security for slurm-workflows 4.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.