Skip to content

feat(sites): run a workflow on a Slurm cluster, with the CWL runners - #589

Open
vjaganat90 wants to merge 6 commits into
PolusAI:masterfrom
vjaganat90:feat/sites-slurm
Open

vjaganat90 wants to merge 6 commits into
PolusAI:masterfrom
vjaganat90:feat/sites-slurm

Conversation

@vjaganat90

@vjaganat90 vjaganat90 commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Stacked on #588 ("feat/sites-machine"). Merge that first; this PR's own changes are the commits above it.

What
The third of four PRs for Sites (design_docs/sites-design.md): sophios.sites.Slurm, a cluster's login node you can ssh to, with the CWL runners. Nextflow on Slurm is S4.

from sophios.sites import Slurm

hpc = Slurm('me@cluster', root='/project/me/cp', bin='/project/me/envs/run/bin')
run = hpc.submit(workflow)                     # toil-cwl-runner, each step a Slurm job of its own
status = run.wait()
  • Settings. Slurm(host, *, root, bin, container_engine='singularity', account=None, partition=None, gpu_partition=None, time=None, modules=()). Each is checked against a pattern when the site is made, as a Machine's are. A time whose days are 0 (0-12) is refused: Toil 9.5 reads it as 12 minutes, Slurm as 12 hours. The differential test against Toil's parse_slurm_time found this.

  • check asks, in the same single call as a machine's checks, sbatch, squeue, scancel, sacct (which must answer) and sinfo -a, and reads your SBATCH_ACCOUNT, _PARTITION and _TIMELIMIT. It refuses SBATCH_CLUSTERS and SLURM_CLUSTERS. It then places the run:

    • the partition: partition=, else your variable, else the cluster's default;
    • the leader's time: time=, else SBATCH_TIMELIMIT, else the partition's longest;
    • the steps' time: time=, else the shortest limit of the partitions used;
    • a GPU step goes to gpu_partition=, else the one partition with GPUs.

    Every problem is reported at once as wic067, the one new code. That includes Nextflow, until S4.

  • submit writes the leader's header from Appendix A: the job named after the run, the comment sophios:<id>, --dependency=singleton and --no-requeue, with the claim ln -s "$SLURM_JOB_ID" right after set -euo pipefail. It runs sbatch --parsable, first unsetting the SBATCH_ variables of each option the header writes (sbatch(1)'s; three for --mem, two for --no-requeue). If the submit's answer is lost, it adopts the job named after the run (squeue -n, then sacct --name) or submits the same folder again; the claim keeps one leader.

  • Runners. toil-cwl-runner, which every site runs cwl with, with Toil's Slurm flags exactly as in Appendix A: --batchSystem slurm, --slurmPartition, --slurmTime, --slurmGPUPartition when needed, '--slurmArgs=--comment=sophios:<id> --account=<account>' and --batchLogsDir <run>/batch. No site runs cwltool (decision 22), and a site takes its runner as a value, for the flags it knows (decision 27, feat(sites): run a workflow on a machine of your own over ssh #588). The runner-by-scheduler table is ON_A_MACHINE and ON_SLURM, and the test that walks targets.TARGETS now covers both columns.

  • States, Appendix B, decided by one function, decide, on both sites. The folder decides first; squeue and sacct answer in the call that reads the folder and are read only when the folder has not decided. A failed squeue or sacct raises wic062 and decides, writes and cancels nothing. The 10-minute and 2-minute windows hold. An exit above 128 decides alone once Slurm lists its leader no more.

  • A job Slurm will never start (a per-job limit such as PartitionTimeLimit): status() stops the run as cancel() does, then writes reason, naming the setting to change. After a hard kill, the step jobs still queued with the run's comment are cancelled.

  • cancel() runs scancel -u "$(id -un)" -n <id>, then takes the claim. A scancel that Slurm refuses ends the call, which raises wic062 having written nothing. The same holds for the stop and for the cancel of leftover step jobs, so the next status() decides again. (scancel exits 0 for a job that has already ended and for a name no job has, per Slurm's scancel.c.)

  • tests/core/fake_slurm.py is a fake Slurm of Sophios's own (sbatch, squeue, sacct, scancel, sinfo), enough for real Toil's --batchSystem slurm to run its steps as fake jobs. The compute driver's fake lives in a private repository that Sophios CI may not check out.

  • What S3 found while it was built is recorded in design_docs/sites-design.md §18, in the design: commit:

    • reason decides first;
    • one squeue over the user's jobs with their comment and name;
    • Slurm is asked in the same call as the folder is read, but decides only after it;
    • one decision for both schedulers;
    • a job that ended unclaimed counts as no job after two minutes;
    • the 0-days time;
    • the SBATCH_ variables;
    • SLURM_CLUSTERS;
    • no cwltool on Slurm (decision 22), which replaced its leader's size and GPU refusal;
    • wic067;
    • a stop done before it is recorded;
    • an exit above 128 whose leader Slurm lists no more.

What changes for callers
Nothing for a local run, on the command line or in the Python API, and nothing in what a Machine does. New: sophios.sites.Slurm and the code wic067. Inside sophios.sites:

  • decide returns a Decision, which says what status() must do: claim none, stop, or cancel step jobs;
  • ON_A_MACHINE entries take a fourth argument, the Slurm placement.

Deleted
S2's none claim, written in bash inside the call that reads the folder. It is now decided by decide, as on Slurm, and written by a second call that reads the claim back. The run reports an end only once the claim holds, and reads QUEUED while the claim cannot be written. This also removes a retry that never ended when the claim could not be written.

Why
Decision 1: develop and test on a workstation, then run the same workflow on a cluster as yourself, changing about one line. This PR is the cluster half for CWL.

Verified

@darkclad darkclad left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed this PR's own three commits on top of #588 (585e02f8..d33c4004). The design is careful: the folder decides first; a run is cancelled by scancel before the claim is written, so a refused scancel leaves nothing behind; singleton plus the claim keep a lost-answer resubmit to one leader; and the ON_SLURM table keeps Toil's flags in one place. I checked the Slurm flags against Toil 9.5's slurm.py. --slurmTime 0 for an infinite partition becomes --time=0:0, which Slurm takes as no limit. A GPU step goes to --slurmGPUPartition before Toil's own partition choice. On SIGTERM, Toil's shutdown() cancels the jobs it issued, so a cancel() normally cleans up the step jobs. CI's package job on Ubuntu ran all 73 non-Nextflow cases of test_sites.py, and all passed. One inline comment, on checking the SBATCH_ variables, is non-blocking.

Comment thread src/sophios/sites.py
f'carry: it matches {pattern.pattern}')
for name, value, pattern in (('SBATCH_ACCOUNT', account, _NAME),
('SBATCH_PARTITION', partition, _NAME),
('SBATCH_TIMELIMIT', limit, _TIME))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two cases here refuse a run that would work.

  1. SBATCH_TIMELIMIT is checked against _TIME, which refuses 0 days because Toil misreads them. This value never reaches Toil, though. It only goes on the leader's #SBATCH --time line, and Slurm reads 0-02:00:00 correctly. The steps get time= or the partition's limit. A profile with export SBATCH_TIMELIMIT=0-02:00:00, a form many cluster guides use, gets wic066 saying no job script can carry it. That happens even when time= is given and the variable is unset for sbatch anyway.
  2. The SBATCH_ value is checked even when account=, partition= or time= overrides it. For example, partition='normal' with SBATCH_PARTITION=a,b in the profile is refused, although _leader unsets that variable.

Checked by calling Slurm._place directly with those answers: each case returns wic066 and no queue.

Suggestion: check each variable only when no setting overrides it. For SBATCH_TIMELIMIT, use a pattern that accepts 0 days, since only Slurm reads it. Fine as a follow-up.

S2 builds Machine and Run, and records in sites-design.md §17 what it found:
macOS has no setsid, so the leader takes a process group of its own with
`set -m`; the traps follow the claim at once; Toil's scratch folders are
made before Toil starts, which refuses a --workDir that does not exist; the
guard prints the hash before the script, so a login profile's output is
never read as the script's; the runner versions a site takes; Toil's
single_machine refuses a step that asks for more memory than the machine
has, so check() notes each Toil step that declares no memory on a machine
too, wic066; a run unclaimed ten minutes after its submit is claimed `none`
on a machine too; the codes S2 adds and reuses; a Machine is refused when it
is made on Windows itself; and the known limit of a StepInput default's
path.

Decision 18's exception to the Nextflow design's non-goal lands here, with
the first PR that runs a pipeline on a site and sets one of its settings:
executor.queueSize, in a block the site appends to the run's copy of the
generated nextflow.config (decision 25).

Decision 27 (2026-11-24, the owner's) replaces 26: check() and submit()
take the runner as a value, as Workflow.run does, and a site takes from it
only the flags of one table, Toil's --maxJobs and --clean and Nextflow's
-qs; max_parallel= and clean= are gone.
Vasu Jaganath added 5 commits November 24, 2026 02:07
sophios.sites.Machine(host, root=, bin=) runs a workflow on a computer you
can ssh to, macOS or Linux, as yourself. check() compiles and lowers here
as run() does, by the one function both call, with relative paths read
against root, and judges in one call there each input the backend's needs
names, the runner in bin and its version, the container engine, and the
folders it writes; it writes nothing. A site runs each target with one
runner, toil-cwl-runner for cwl and nextflow for nextflow, so target=
names it, and runner= takes it as a value, as Workflow.run does, for the
flags a site takes from it: Toil's --maxJobs and --clean, Nextflow's -qs.
One function reads the value: another runner, a setting of the value's own
or any other flag is a ValueError, since a site sets every other flag
itself and its engine is its container_engine=. The run's runner is built
with the site's container engine, which the site reads back from it. Under Toil
it notes each step whose tool declares no memory, which Toil gives 4 GiB
there and refuses to start on a machine with less. submit() copies the run's
files into <root>/sophios/runs/<id> and starts job.sh, which claims the run
with its pid, runs the backend's launch from bin with a machine's flags
(Toil's single_machine), and records how it ended. Nextflow takes no flags
of the site's: how many tasks run at once is executor.queueSize, in a block
the site appends to the run's copy of nextflow.config, the one configuration the
backend has Nextflow read. Run follows the run as RunHandle does, with id
and a repr that attaches; its end is the backend's own outcome over what
the run left.

Every call is the user's ssh with the script on its input, run only when
its sha256 matches. On Windows itself a Machine is refused when it is made.
The new codes are wic062 to wic066, of kind machine, wic066 a note;
wic015, wic016, wic021 and api008 cover what they already mean.

tests/core/test_sites.py runs in the package job (about 60 s), with a local
bash for ssh and the real Toil; its Nextflow row runs in Lint And Test's
Nextflow Runtime step, which now names the file (about 15 s), and reads the
capacity Nextflow's log gives its executor. The walk gives each runner as a
value, and reads what it asks in the job, in that capacity and in the run's
record. The site codes' provocations go
through the same local bash; the Windows leg checks that a Machine is
refused there.
docs/sites.md opens with the sites design's first message, then says how
to make a Machine and reach it, which runner runs each target and how (a
Toil step that declares no memory gets 4 GiB there), what check and
submit do, how a run is followed and where its folder is, what cleanup
leaves, and what each code means. It sits under Run and manage, and the
pages that list the kinds of code, api008 and the run path name a site.
S3 builds Slurm with the CWL runners, and sites-design.md §18 records what
it found. The reason status() writes decides first, since it stops a run
Slurm will never start as cancel() does. One squeue lists the user's jobs
with their comment and name, so the run's leaders and Toil's step jobs come
from one call; squeue and sacct are asked with the folder and read only
when it has not decided. A machine's none claim is decided by the same
function and reported only once it is written. A job that ended without
claiming the run counts as no job after two minutes. A time whose days are
0 is refused: Toil 9.5 reads 0-12 as twelve minutes. The SBATCH_ variables
unset are sbatch(1)'s for each option the header writes; SLURM_CLUSTERS is
refused with SBATCH_CLUSTERS; no site runs cwltool (decision 22), so the
leader asks for neither cores nor memory. A stop is done before it is
recorded: on Slurm, cancel() and the stop status() makes scancel first and
claim after, and status() writes reason last, so a scancel Slurm refuses
writes nothing. An exit above 128 decides alone once Slurm lists its leader
no more. The code S3 adds is wic067. Appendix B's table and its squeue line
follow.
sophios.sites.Slurm(host, root=, bin=, account=, partition=,
gpu_partition=, time=) runs a workflow on a cluster's login node over ssh,
as yourself, as one leader job: sbatch --parsable, whose header names the
job after the run, gives it the comment sophios:<id> and
--dependency=singleton, and whose options' SBATCH_ variables are unset for
sbatch. toil-cwl-runner runs cwl there, each step a Slurm job of its own
on the run's partition, or the one with GPUs, with the steps' time, the
run's comment and account. Nextflow on Slurm is refused, wic067, until
S4.

check() asks Slurm's commands (sacct must answer), sinfo -a and your
SBATCH_ settings, refuses SBATCH_CLUSTERS and SLURM_CLUSTERS, and places
the run by its settings, else by Slurm's conventions. When the submit's
answer is lost, submit adopts the job named after the run, or submits the
same folder again; the claim keeps one leader. status() decides by one
function on both sites: the folder first, then squeue and sacct, with the
ten-minute and two-minute windows; a failed squeue or sacct decides
nothing, and an exit above 128 decides alone once Slurm lists its leader
no more. A run one of whose jobs Slurm will never start is stopped, its
reason naming the setting to change, and the step jobs a killed leader left
are cancelled by the run's comment. cancel() scancels the jobs named after
the run, then claims it. A scancel Slurm refuses ends the call, which
raises wic062 having written nothing: status() writes reason only once the
stop is done.

tests/core/fake_slurm.py is a Slurm of Sophios's own (sbatch, squeue,
sacct, scancel, sinfo), enough for Sophios and for Toil's --batchSystem
slurm. tests/core/test_sites.py takes S2's tests to Slurm: the states over
every life on both sites, a leader Slurm lists no more among them; Toil's
argv on Slurm through Toil's own parser and parse_slurm_time; where a run
goes; and, end to end with the real Toil, the runner table's Slurm column,
the ends, a stop and a hard kill's cancel that Slurm refuses, adoption,
singleton and the claim, and a hard kill's step jobs. The package job runs
the file in about 170 s, its status polled every half second (S2's took
about 60 s); the Nextflow Runtime step still runs its machine row of
Nextflow.
docs/sites.md adds a cluster: Slurm's settings and where each comes from
when it is not given, the Slurm column of the runner table, what check()
asks Slurm and refuses, how submit
adopts a job whose answer was lost and keeps one leader, how a run's state
is read from Slurm, a job Slurm will never start, a leader killed hard and
the step jobs it left, and wic067. The checks page, the run path and the
architecture page name Slurm.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants