Skip to main content

nb2slurm

Documentation Lint PyPI License

Take a notebook workflow that runs for one subject — one catchment, one region, one number — and run it for many subjects on a SLURM cluster, driven entirely from a notebook. No command line, no rewriting your science into a pipeline DSL.

Pre-1.0. nb2slurm works end to end and is released on PyPI, but it is young: the API can still change in a minor release. Pin the version you depend on.

The problem

Scaling a notebook study to a cluster usually means abandoning notebooks: someone hand-writes a run_*.slurm, a submit_*.sh and a driver script, then keeps them in sync with the notebooks by hand. The scripts drift, the notebooks stop being runnable on a laptop, and the whole thing is one person's private knowledge.

nb2slurm generates those files instead. Your notebooks stay ordinary notebooks — the same ones you open in Jupyter are the ones SLURM executes, with papermill injecting a different subject per job.

Install

pip install nb2slurm

Python 3.9+. You also need rsync locally for the file transfer helpers, and SSH access to a cluster. See Installation for the cluster-side requirements.

Example

import nb2slurm

wf = nb2slurm.Workflow(
    name="myproject",
    notebooks=[
        "notebooks/0_settings.ipynb",       # writes settings.json
        "notebooks/1_computations.ipynb",   # reads settings.json
    ],
    kernel="myenv",                         # a Jupyter kernel on the cluster
    varying=["country", "region"],          # what changes per job
    jobs_json="jobs.json",                  # the jobs, and the output tree
    resources=dict(nodes=1, cpus=2, time="04:00:00"),
    conda_env="myenv",
    concurrency=3,
)

wf.build()                                  # render scripts/ into the project

cfg = nb2slurm.SSHConfig(host="spider.surfsara.nl", user="me",
                         remote_dir="/home/me/myproject")

wf.push(ssh=cfg)        # upload source — never output/
wf.check(ssh=cfg)       # preflight: dir, notebooks, scripts, env, kernel
wf.submit(ssh=cfg)      # one SLURM job per job in jobs.json
wf.status(ssh=cfg)      # parsed squeue
wf.pull(ssh=cfg)        # download results — never your notebooks

Every method works without ssh= too, running locally instead — that is the path when you drive this from a login or Jupyter node on the cluster itself, and dry_run=True prints the exact rsync/sbatch commands without running them.

How it works

  • A package and a scaffolder. The importable nb2slurm holds the logic; bundled Jinja2 templates are rendered by build() into a concrete scripts/ directory you can read, review and commit.
  • jobs.json defines the jobs and the output tree. Each root-to-leaf path in the nested JSON is one SLURM job and one output directory, so the job list and the folder layout cannot drift apart.
  • Transfers are one-directional by design. push never uploads output/, pull never fetches notebooks/. Neither direction can destroy the other side's work.
  • Re-running is cheap. Finished subjects are recorded in done.csv, so re-submitting the whole set only runs what is missing.

Documentation

Full documentation: https://nb2slurm.readthedocs.io

Quickstart the whole cycle in five steps
HPC for notebook users plain-language primer if SLURM and conda are new
The notebook contract the two rules your notebooks must follow
jobs.json the job grid and the output tree
Environments and kernels build one on the cluster, or use what is there
Connecting to the cluster SSH keys, passphrases, test_connection()
Generated files what build() writes, and why
Control notebooks the four-notebook control surface
Monte Carlo π example a complete, runnable workflow
API reference every public class and function

Converting an existing local-only workflow? docs/setup_notebooks.ipynb walks through the in-notebook changes with before/after snippets.

Development

git clone https://github.com/eWaterCycle/nb2slurm
cd nb2slurm
pip install -e ".[dev,docs]"

pytest
ruff check . && ruff format --check .
sphinx-build -b html docs docs/_build/html

Ruff runs in CI on every pull request. Issues and pull requests are welcome.

About

nb2slurm is the reusable generalisation of the eWaterCycle CCI-analysis-seamless project — its hardcoded cci.py, run_cci.slurm and submit_*.sh, turned into something any notebook workflow can use.

Licensed under Apache-2.0.

Metadata

Release files for nb2slurm 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nb2slurm 0.1.1
File Size Uploaded Provenance Actions
nb2slurm-0.1.1.tar.gz 72.5 kB Without provenance Details for nb2slurm-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nb2slurm 0.1.1
File Interpreter ABI Platform Actions
nb2slurm-0.1.1-py3-none-any.whl Python 3 none any Details for nb2slurm-0.1.1-py3-none-any.whl

Total release size: 110.6 kB

Release files / nb2slurm-0.1.1.tar.gz

Download URL nb2slurm-0.1.1.tar.gz
Size 72.5 kB
Tags Source
SHA-256 checksum
How to use checksums
354c3ce5495ee99b4a948239b693ab7207af579d51d83791443588ec2d66f449
BLAKE2b-256 checksum
How to use checksums
ae9a841e9ada5ed6a9863566719bc67478911c066c5a981d3dd5deb946203460
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / nb2slurm-0.1.1-py3-none-any.whl

Download URL nb2slurm-0.1.1-py3-none-any.whl
Size 38.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fadd0ca3b3238013248beac34c475cb2d08552ed6dfd5c5dc9371ad34dabd70d
BLAKE2b-256 checksum
How to use checksums
f5a067bcadbd45ecc2e569d243a0f339d73eb5a1626d2d0624e083d1488ca6f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Security for nb2slurm 0.1.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page