Skip to content

feat(sites): run Nextflow on a Slurm cluster - #590

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

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

Conversation

@vjaganat90

@vjaganat90 vjaganat90 commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

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

What
The last of four PRs for Sites (design_docs/sites-design.md): target='nextflow' on sophios.sites.Slurm, each task a Slurm job of its own, GPU tasks included. Every runner of the target table now runs on both sites, or is refused there with its code. It also makes sophios.sites a package.

from sophios.sites import Slurm

hpc = Slurm('me@cluster', root='/project/me/cp', bin='/project/me/envs/run/bin')
run = hpc.submit(workflow, target='nextflow')   # Nextflow, each task a Slurm job of its own
status = run.wait()
  • What a site sets for Nextflow is a block it appends to the run's copy of nextflow.config (decision 25), from one function, _nextflow. The backend has Nextflow read that one file (-C), so the block is the one place a site sets anything of Nextflow's; backends.py is unchanged, and the Nextflow backend knows nothing about sites. On a Machine the block is executor { queueSize = <max_parallel> } (S2). On Slurm it adds:

    process {
        executor = 'slurm'
        queue = '<partition>'
        time = '<steps' time in seconds>s'
        clusterOptions = '--comment=sophios:<id> --account=<account>'
    }

    time is left out when the steps have no limit; the clusterOptions text comes from the same helper as Toil's --slurmArgs=. Why a configuration and not flags, measured with Nextflow 26.04.2 and again with 26.10.5, which feat: one table of targets, and nf-s codes for Nextflow refusals #586 now pins: a -process.* flag gives every task the same value (a closure passed as -process.queue reaches the task as its text, and a withName: selector on the command line is ignored), and the backend's -C silently ignores a second file given to run -c.

  • GPU steps. Nextflow's Slurm executor ignores accelerator (measured with 26.04.2 and 26.10.5: no --gres). So for a workflow with GPU steps, queue and clusterOptions are closures on task.accelerator: a task with one goes to the GPU partition with --gres=gpu:<count>, every other to the run's partition. The GPU partition is found as for Toil (gpu_partition=, else the one partition with GPUs), so where a step goes no longer depends on its runner, and _place no longer takes the runner. Every task keeps the one steps' time (decision 24). The Nextflow target gives Docker no --gpus; that is the target's own follow-up, here and locally alike.

  • The steps' time is given in seconds. Nextflow refuses 2-00:00:00 and 30:00 ("Not a valid time value", measured with 26.04.2 and 26.10.5), and turns 172800s into #SBATCH -t 48:00:00.

  • Your SBATCH_ variables, and Nextflow's task headers. Nextflow writes each task's options as #SBATCH lines: -J, -o, --no-requeue, --signal, -c, -t, --mem, -p, and clusterOptions' comment, account and a GPU task's --gres (measured against the fake Slurm, with 26.04.2 and 26.10.5).

    • A login profile's SBATCH_ variables beat those lines (sbatch(1)), and the leader's bash -l sets them again from the profile.
    • So before Nextflow starts, the job unsets the variables of each of those options, SBATCH_GRES among them, and SBATCH_ERROR: Nextflow writes -o alone, so a task's stdout and stderr go to one log.
    • This is the rule submit already follows for the leader's header. One table maps each option to its variables for both, and it gains those of -c, --mem, --signal and --gres.
    • Your other variables, such as SBATCH_QOS, still reach every task. Toil is not affected: it passes every option it sets on sbatch's command line, which beats the variables.
  • check on Slurm refuses each process that has a container, by name, when the site's container_engine is not docker (wic065; Slurm's default is singularity).

  • sophios.sites is a package of five modules, each under the 750-line limit (owner, 2026-11-10): _ssh (the transport and the scripts' shell functions), _states (a run's states, Appendix B), _runners (the runner-by-scheduler table and the leader script's parts), _site (Machine, Slurm and the reading of the workflow) and _run (Run). Each definition moved as it was. sophios.sites still exports Machine, Slurm and Run, and the too-many-lines exemption is gone. The tests patch the module that holds each name they replace (_ssh._transport, _site._call, _site.lowered_for_site, _run.POLL).

  • Design: design_docs/sites-design.md §19 records what S4 found, in the design: commit. The exception in design_docs/sophios_nextflow_backend.md, which S2 wrote, already names what S4 sets, so S4 changes no word of it.

What changes for callers
Nothing for a local run or for a Machine. Slurm(...).submit(workflow, target='nextflow') now runs instead of raising wic067, GPU steps included. On Slurm, check refuses a Nextflow process with a container unless container_engine='docker' (wic065). Inside the package, sophios.sites is a package; its public names are unchanged.

Deleted

  • S3's refusal of Nextflow on Slurm: the None entry in ON_SLURM, the branch in _prepare that returned the refusal, and the test's assert that the entry is not None. The test that walks targets.TARGETS across both sites has no refusal branch left.
  • The runner argument of _place, and the runner column of its test table.

Why
Decision 17, as decisions 26 and 27 leave it: every target of the target table runs on every site. This PR fills the last cell of the Slurm column, GPU steps included (decision 25).

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 the three commits above #589 (d33c4004..443b0b4a). The split into sophios.sites is a pure move: line by line, the only new lines are imports, the _nextflow block, _steps_options, _TASK_VARIABLES and the unset, and _place without the runner. _gpu_steps and the Nextflow lowering read the same inherited cwltool:CUDARequirement, so the steps sent to the GPU partition are the tasks that carry accelerator. tests/core/test_sites.py passes in WSL Ubuntu 24.04 with Nextflow 26.04.2 (75 passed, the Slurm x Nextflow walk included). The task headers show -p gpu ... --gres=gpu:1 for the GPU step, -p normal for the other, and -t 48:00:00 from 172800s. One non-blocking comment, inline.

#: of `error`, which it leaves to `-o`, sending both streams to one file. The leader's login shell sets them again
#: from your profile, so its job unsets them before Nextflow starts. Toil gives each option it sets on `sbatch`'s
#: command line, which beats them.
_TASK_VARIABLES: Final = tuple(name for option in ('job-name', 'output', 'error', 'no-requeue', 'signal',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nextflow writes --mem (and -c) only for a task that declares them. In the Slurm x Nextflow walk, the copy step's .command.run has -J, -o, --no-requeue, --signal, -t, -p and clusterOptions, but no --mem and no -c. Because this line unsets SBATCH_MEM_PER_NODE/_CPU/_GPU for every task, a tool with no ramMin runs with the cluster's DefMemPerCPU. Under Toil the same step gets --defaultMemory 4Gi and a wic065 note. A user who sets SBATCH_MEM_PER_CPU in their profile to work around a low default also loses it for Nextflow tasks, and docs/sites.md lists "memory" among the options Nextflow always writes.

The unset is still needed for tasks that do declare memory, since the variable would beat their --mem line. So this could be handled by giving Nextflow a default when the tool declares none, as Toil gets 4 GiB, or by extending the wic065 note to Nextflow on Slurm and correcting the docs sentence. Not blocking.

@vjaganat90
vjaganat90 force-pushed the feat/sites-nextflow-slurm branch 4 times, most recently from f4dabee to dc7b3c1 Compare November 24, 2026 03:27
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.
@vjaganat90
vjaganat90 force-pushed the feat/sites-nextflow-slurm branch from dc7b3c1 to 56043ca Compare November 24, 2026 06:36
Vasu Jaganath added 6 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.
S4 runs Nextflow on Slurm, and sites-design.md §19 records what it found.
What a site sets for Nextflow is a block it appends to the run's copy of
the generated nextflow.config (decision 25), which the exception S2 wrote
already names. Nextflow reads no Slurm time, so the block gives the steps'
time in seconds, and no time when the steps have no limit. Nextflow's
Slurm executor reads no accelerator, so for a workflow with GPU steps the
block's queue and clusterOptions are closures on task.accelerator: a GPU
task goes to the partition with GPUs, asking for them with --gres, as
Toil's step does, and where a step goes no longer depends on its runner.
The pinned Nextflow verifies the block by a run against the fake Slurm.
Nextflow writes each task's options as #SBATCH lines, which the SBATCH_
variables a login profile sets again in every job would beat, so
Nextflow's job on Slurm first unsets the variables of every option
Nextflow writes, --gres's among them, and SBATCH_ERROR, since Nextflow
sends a task's two streams to one file, as submit does for the leader's
header. §11's wic067, the tests and Appendix A follow.
Vasu Jaganath added 2 commits November 24, 2026 02:14
A Slurm site runs target='nextflow': each task a Slurm job of its own. One
function, _nextflow, writes the block a site appends to the run's copy of
nextflow.config: executor.queueSize with the tasks at once and, on Slurm, the
slurm executor, the run's partition, the steps' time in seconds, none when
they have no limit, and clusterOptions with the run's comment and account,
the text Toil's --slurmArgs= gets from the same helper. For a workflow with
GPU steps, queue and clusterOptions are closures on task.accelerator, so a
GPU task goes to the partition with GPUs with --gres=gpu:<count>; the GPU
partition is found as for Toil, so where a step goes no longer depends on
its runner. The Nextflow backend learns nothing of sites. Before Nextflow
starts, its job on Slurm unsets the SBATCH_ variables of every option
Nextflow writes in a task's header (-J, -o, --no-requeue, --signal, -c, -t,
--mem, -p, the comment, account and --gres), and SBATCH_ERROR, since -o
alone sends both streams to one file: the login profile sets them again in
every job, and they beat those lines. One table maps each option to its
variables, the leader's and the tasks' alike; it gains the variables of -c,
--mem, --signal and --gres. S3's refusal of Nextflow on Slurm goes. check()
refuses each Nextflow process with a container on a site whose engine is
not Docker, Slurm's singularity among them (wic065).

sophios.sites becomes a package of five modules, each under the 750-line
limit: _ssh (the transport and the scripts' shell functions), _states (a
run's states), _runners (the runner-by-scheduler table and the leader
script's parts), _site (Machine and Slurm) and _run (Run). It still
exports Machine, Slurm and Run.

tests/core/test_sites.py: the walk over targets.TARGETS runs Nextflow on
Slurm too, end to end with the pinned Nextflow and the fake Slurm, in Lint
And Test's Nextflow Runtime step (about 20 s more), with a second step that
asks for a GPU, whose task is a job on the partition with GPUs asking for
one. Under a login profile that sets other SBATCH_ values, SBATCH_GRES
among them, the leader and each job a runner submits carry the run's
comment, account, partition and time, Nextflow's tasks get none of the
SBATCH_ variables of their header's options, nor SBATCH_ERROR, while yours,
such as SBATCH_QOS, reach them. The property over Toil's argv reads
Nextflow's block for the same run against what Toil's own parser read; the
package job adds a Slurm row to the check table, and the placement table,
no longer by runner, loses its runner column. fake_slurm.py reads sbatch's
-t and squeue's -t and -p, records each job's account, partition and GRES,
and lets SBATCH_ACCOUNT, _PARTITION and _TIMELIMIT beat a script's name
they replace.
docs/sites.md runs Nextflow on a cluster: an example, the Slurm cell of
the runner table, a GPU step's task on the partition with GPUs, the
containers Slurm's singularity refuses, the comment of Nextflow's task
jobs, the SBATCH_ variables the leader unsets for Nextflow's task headers,
and wic065 on any site; gpu_partition= applies under Nextflow too.
docs/nextflow.md says what a site sets in the run's nextflow.config, and
that a site on Slurm asks for a GPU task's GPUs itself, since Nextflow's
Slurm executor reads no accelerator. The architecture page names
Nextflow's task jobs.
@vjaganat90
vjaganat90 force-pushed the feat/sites-nextflow-slurm branch from 56043ca to 697a7d6 Compare November 24, 2026 07:15
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