Skip to content

feat(nextflow): compile, run and import workflows on a Nextflow DSL2 target - #569

Closed
vjaganat90 wants to merge 350 commits into
masterfrom
feat/nf-support
Closed

vjaganat90 wants to merge 350 commits into
masterfrom
feat/nf-support

Conversation

@vjaganat90

Copy link
Copy Markdown
Member

What

  • Merge the Nextflow backend into master: everything on feat/nf-support, from feat: compile Sophios workflows to Nextflow IR #378 to chore(nextflow): rebase the backend onto master #568. The branch already holds master through 3f14788b (chore(nextflow): rebase the backend onto master #568), so the merge has no conflicts and changes nothing master has; the diff is the backend alone, 92 files, +24,167 −318.
  • Nextflow DSL2 becomes a second compile target beside CWL. CWL stays the canonical representation: the target lowers the graph the compiler has already inferred, and fails closed, so a CWL field, type, requirement or hint it does not consume is rejected by name before anything is written. docs/nextflow.md is the user guide, with what the target does with each field; design_docs/sophios_nextflow_backend.md is the design.
    • Compile: sophios --yaml workflow.wic --target nextflow, or workflow.compile(target="nextflow"), which returns a CompiledNextflowWorkflow whose write() writes the four files.
    • Run: --run_local, --check and --generate_run_script under --target nextflow, and run(), start() and run_async() with target="nextflow", as one nextflow run on this machine.
    • Import: sophios.api.python.nextflow.import_nextflow(directory) reads a pipeline Sophios wrote back into a Workflow.
    • Error codes wic046 to wic054: a CUDA field the pipeline does not check (a note), and the import's refusals.
  • What changes for a CWL user:
    • --target (default cwl) and target=. Each CLI option is declared under the target it belongs to, and an option of the other target, set away from its default, is an error.
    • A value bound on a workflow's own input, flow.inputs.x = v, is the job's value of x in compile(), run() and a compute request; an inputs file passed to run() still wins. Master drops it.
    • A port name may start with _.
  • CI: the Nextflow Backend lane (.github/workflows/nextflow.yml, Nextflow 26.04.2 on Java 17) runs the runtime, Docker and pure suites, and Run Workflows also runs the corpus under Nextflow on a push. The packaging lanes leave out the tests that need Nextflow; tests/core/test_ci_coverage.py checks both.

Why
The backend was built and reviewed one PR at a time on feat/nf-support, merging master in as it moved (#379, #469, #536, #563, #568). This brings it to master.

Merge this with a merge commit: a squash would fold the backend's 350 commits into one and leave feat/nf-support's history apart from master's.

Known gaps

Checked

  • git merge-tree --write-tree master feat/nf-support gives feat/nf-support's own tree: no conflicts.
  • That tree is the one chore(nextflow): rebase the backend onto master #568's head 0140534f had, and every lane passed on it: Lint And Test, Nextflow Backend, Run Workflows and Build and Test Wheel.

Vasu Jaganath and others added 30 commits September 30, 2026 00:49
Sophios declares it for every when, so rejecting it at workflow level made
conditional steps inside subworkflows unreachable; the declaration is not the
use of JavaScript.
An optional reference is T-or-null and appears only beside null. Single-input
scatter gathers only once it carries an index. A non-integral int binding
fails the task as a divergence from cwltool, and inference, directives, and
REST each need a successor design.
A whole-field $( … ) valueFrom on an argument or scalar input binding is
parsed against the safe JavaScript subset into typed nodes and lowered to a
computed command token (schema version 10). Each node renders through one
fixed Groovy idiom over double: an exact Math.round, a finite check on every
numeric subexpression that names the expression and its inputs, and number
text matching cwltool's printing. Optional bindings and separate: false
beside a computed value are rejected.
…ration

A field of two projections is a template, not a subset expression. A hydrated
computed token re-checks each operator, arity, and literal, and a number
literal is a strict-mode ASCII decimal. Math.pow renders as StrictMath.pow.
A CommandLineTool step's when lowers to NfProcess.condition (executable
schema version 11): a safe-subset boolean expression over the step's own
bound val inputs. Rendering combines the process's input channels into
one tuple, branches on the rendered predicate, calls the process on the
run branch, and mixes each output with the skip branch mapped to the
existing absent-optional [] sentinel, so a skipped invocation still
emits one element per output and downstream channels never hang.

A possibly-null output is admitted only at a workflow output or an
optional val input whose use the absent-optional lowering already
admits; every other consumer (non-optional port, path consumer,
array-typed output outside scatter) is rejected by name, as is when on
a scattered step or a step whose run is a workflow. pickValue was
already rejected by the generic unconsumed-field diagnostic.

Rendering uses synthetic closure parameter names rather than the port
names themselves, since Groovy rejects a closure parameter shadowing an
already-declared take: variable of the same name.
…r when

Sophios declares InlineJavascriptRequirement on every workflow containing a
when, and the workflow-level closed world rejected it, so a condition inside
an inlined subworkflow could never lower. The declaration is now consumed as
inert, like the scatter and subworkflow feature requirements. Also pins that
a workflow with computed arguments reads back and promotes.
An absent optional input reaches Nextflow as the reserved [] sentinel, not
null, and a skipped conditional step emits the same sentinel. A null
equality rendered as a literal null comparison was therefore false for an
absent input and !== null was true, so inputs.x === null skipped the step
where CWL runs it and !== null ran it where CWL skips, with nothing
failing. A null check now tests for either null or the sentinel.
A step with a when and a tool that declares no inputs lowered to an
executable IR that render_nextflow could not write: the branch/mix skip
needs an input channel to gate on. NfProcess now rejects a condition on a
process with no inputs, so no hydrated or constructed model reaches the
renderer in that shape, and the CWL front end reports it as a finding
naming the step beside the other when rejections. The render-time check
is unreachable and is removed.
The n-ary merge with a closure is not callable once any channel after the
first is a queue channel, as a process output is: Nextflow fails the run
with "Missing process or function merge". A conditional step with three or
more inputs, one of them a process output, therefore lowered and then
failed at launch. The inputs are now merged pairwise, which accepts every
mix of value and queue channels and passes list items such as an array
input or the [] sentinel through unchanged.
Two or more scattered workflow-input arrays under dotproduct are paired by
index from the whole arrays; unequal lengths fail the run naming each input
and its length, and empty inputs produce zero invocations. Each invocation
carries a hidden index through the scattered process, and its outputs are
gathered to workflow outputs in index order. Unscattered inputs broadcast.
The executable schema moves to version 12.
… the IR

A process with a condition and dotproduct-adapted inputs passed
validation, but the conditional rendering merges one channel per input
port while the dotproduct ports share one tuple channel, so
render_nextflow indexed past the end of its channel list (and, where it
did not, called the process with mismatched channels and a [] skip
sentinel carrying no index for the gather to sort on). The CWL front end
already blocks when with scatter; the IR now refuses the shape too, so no
hydrated or constructed model reaches the renderer in it.
…red process

Every output of a dotproduct-scattered process carries the hidden scatter
index, and only the gather into a workflow output strips it. A process
connection out of one validated and rendered NEXT(PAIR.out.f), so NEXT's
path input would have received [index, file] tuples. The CWL front end
already rejects scattered process-to-process edges; the IR now does too,
whichever order the connections are listed in.
The duplicate import tripped pylint reimported (W0404), and the list is
now in alphabetical order.
Two or more scattered workflow-input arrays under flat_crossproduct run every
combination, first declared input outermost as CWL orders them, reusing the
hidden invocation index and index-ordered gather. The method is a new
adapter value, gated at executable schema version 13. nested_crossproduct
over two or more inputs stays rejected.
…hods

The source collector, channel renderer and per-process bookkeeping now serve
flat_crossproduct as well as dotproduct, so the dotproduct names read as if
the other method were handled elsewhere. Rename them to match
_multi_input_method. The IR guards on a multi-input-scattered process name
the method in use instead of always saying dotproduct.
The channel renderer's docstring described only dotproduct and claimed
unequal lengths fail the run, and the multi-input scatter paragraph of the
user docs applied dotproduct's pairing and length check to flat_crossproduct,
which runs every combination and compares no lengths. Say which method does
what, and name both methods where the adapter and its schema gate are
documented.
…ards

The version-13 gate on the flat_crossproduct adapter, its hydration round
trip, the two-or-more input check, and the rejections of a conditional
process and of a process connection out of a scattered process were only
exercised through dotproduct. Run those tests over both multi-input methods,
with the gate case for flat_crossproduct at version 12, the newest version
that still lacks it.
…er-invocation when

A multi-input scatter's outputs now feed later steps: into an unscattered
array-typed input they are gathered once in invocation order, each file
staged in its own numbered directory so same-named outputs never collide,
and a gathered array may be a later multi-input scatter's whole-array
source. The edge carries this as a process-connection adapter (gather, or
the downstream scatter method), gated at executable schema version 14.
A multi-input scattered step may carry a when, evaluated per invocation;
skipped positions gather as the null sentinel. Gathering or conditioning a
single-input scatter stays rejected, since it carries no invocation index.
…tered consumer

The stageAs: 'gather*/*' policy was rendered only for a process without
a multi-input scatter. A gathered File array feeding an unscattered port
of a multi-input-scattered step still rendered as a flat `path files`, so
every task of that step received N copies of the same basename and
Nextflow failed with an input file name collision. The scattered
consumer's other ports now get the same staging, for dotproduct and
flat_crossproduct alike.

Nextflow numbers the directories per port, so one shared pattern still
collided when a process took two gathered ports whose files share a
basename. The pattern now carries the port name, gather_<port>_*/*.
…ge check

A multi-input-scattered producer is always taken by the first branch of
the check, so the negated producer test on the last branch could never be
false.
…scatter

The rejection had no test. It is also why only a multi-input-scattered
consumer can receive a gathered array and need the numbered-directory
staging: a single-input-scattered step is refused on every port.
nested_crossproduct runs flat_crossproduct's invocations, records each
scattered input's length, and regroups the index-sorted results into one
array dimension per input at the workflow output, so an empty dimension
keeps its outer shape. A nested result feeding a later step is rejected by
name in lowering and in the executable model. The method is a new adapter
value, gated at executable schema version 15.
… arrays

The nested set and the helper gate counted workflow-input connections
only, but a gathered array rescattered by nested_crossproduct arrives as
a process connection. When every scattered input was gathered, the
workflow output fell through to the flat branch and a rank-2 result
arrived flat with no error. Both now count either connection kind.
The deferral branch that used it is gone.
When the adjacent executable model renders to the source byte for byte, the
renderer's determinism accounts for every construct, so the model supplies
the structural document and nothing is opaque. Without the model the DSL2
reader alone applies and unrecognized syntax stays opaque.
parse_nf_file now takes the structural document from the adjacent
executable model whenever that model renders to the source byte for byte and
the text parse alone is incomplete or fails. Export followed by import is
the identity for every generated pattern: single-input and multi-input
scatter under all three methods, computed arguments, conditional steps,
per-invocation when, and gather into a later scatter. Text-only reads are
unchanged.
Vasu Jaganath and others added 27 commits October 27, 2026 22:21
…the line

A hole of the idiom table held any text unless the table named its kind,
and the reader went back into a hole to try a shorter text whenever a
later part of the form failed, so a long line that nearly matched a form
with several such holes took time cubic in its length: a line of 11 KB
after a merge took seconds, and one of 28 KB minutes. Each hole is now
read once: it holds the longest text that the form's text up to the next
hole follows, and the reader never goes back into it, so a line is read,
or refused, in time linear in its length. The renderer writes every form
so that it reads back this way but a conditional output's channel,
ch_<process>_<emit>, which splits more than one way when a name holds an
_: the reader already fills that form and looks the name up, and the
statement that defines the channel now takes the name as one hole.
…ear in the line

A hole the idiom table names no kind for compiled to .*, and the regex
engine went back into every hole to try each other split of a line, so
a long line that nearly matched a form took time polynomial in its
length: cubic for MERGE_NEXT, which the reader tries on the line after
each merge (6 s at 11 KB on the review's line), and for SHAPE, which it
tries on every statement of main: (11 s at 16 KB); quadratic for
BRANCH, COMBINE, MERGE, SCATTER and STEP_INPUT, and, through an
identifier hole, for ELEMENT and MIX.

Idiom now compiles each hole into one atomic group with the form's text
up to the next hole, so the hole holds the longest text that this text
follows and matching never goes back into it. The review's line is
refused in a tenth of a millisecond at 108 KB. MIX read
ch_{process}_{emit} by going back, as an emit may hold an _; it now
takes the channel as one hole, which the renderer fills with
CONDITIONAL_OUTPUT, so every case renders byte for byte as before. The
reader never read those holes, and the line is still compared with its
rendering, so an edited channel name stops the import at its line with
wic053 where it stopped with wic048.

test_every_hole_is_read_once holds every form in the table to opening
an atomic group at each hole. A new test gives the import the review's
line after a merge and a statement that nearly shapes a scatter, each
tens of KB: each stops with wic048 at its line within seconds, where
they took three minutes and 11 s. The crossproduct case's conditional
output is now o_txt, so the fixed point reads a channel whose emit holds
an _.
…hich the bundle leaves to an inputs file

The path-agreement property drew no workflow-level input, so a value
bound on one in Python, which compile() puts in its job and write_wic
does not write, sat in its declared blind spot while the two front ends
compiled it to different jobs. The generator now also gives join its
name through a workflow input holding the drawn value, and the property
says how the two then agree: the bundle compiled from the file leaves
that input open, and with the value merged in as an inputs file merges it, its
job is the one compile() returns, at IDENTICAL as before. The blind spot
names what is still not drawn.
…ns, and the .wic write_wic writes leaves it open

docs/inputs-and-values.md said a value bound on a workflow input in
Python was given in every run, but write_wic writes the workflow without
it, so the .wic it wrote, run from the command line, asked for the
input. The chapter now says the value is in the job compile() returns
and so in a run from Python, and that the .wic write_wic writes leaves
the input open for an inputs file, in a paragraph of its own, so the one
it interrupted reads as before. converting.md lists the value among what
write_wic does not write, and the Workflow.write_wic docstring says the
same; partial-failures.md gives such values in an inputs file when the
written .wic runs on the command line; nextflow.md says write_wic leaves
the input open, where it said a .wic file holds no values, which a !ii
value contradicts.

The path-agreement property in test_canonical_path.py pins it.
…s a model or stops with a code

read_nextflow promises SophiosError or OSError, but some text escaped as a
plain exception: a byte that is not UTF-8 in any of the three files raised
UnicodeDecodeError; _skip recursed once per bracket, so about 1000 nested
parentheses in a call or in a string's interpolation raised RecursionError,
as did a condition or params JSON nested as deep; and an integer longer
than Python converts raised ValueError. A byte that is not UTF-8 now stops
the read with its file's code at its line, _skip and the reader's folded
calls count their brackets instead of recursing, the params file is refused
past the nesting Sophios writes, and a condition too deep to build or
render stops at its workflow.

A property test corrupts the files of two compiled cases, cutting them
short or inserting such bytes, digits or nesting, and checks the read
returns a model or raises SophiosError or OSError; the edit test pins each
concrete case at its line.
…closing ones is free, as is a def's indentation

The reader took a script's or stub's closing quotes only on a line of
their own, so a comment or spaces after them stopped the import, at times
at a later line; it took the opening quotes only after indentation, so a
block comment before them stopped it too; and it took a helper's def only
at the first column. Groovy reads all of these as layout, outside the
string. What follows the closing quotes on their line is now read as
code, so a comment there is dropped and code stops at that line; only
layout may come before the opening quotes; and a def may be indented.

The layout property gains the rewrite the test's line model left out: a
block comment before each opening quote, a comment or trailing spaces
after each closing one, and each helper's def indented. nextflow lint
accepts the rewritten pipeline.
…keeps its notes

§4.3: compile(target="nextflow") returns CompiledNextflowWorkflow, which
holds the executable IR as nextflow_workflow and every note the compile
made, the core compile's then the lowering's, in diagnostics.
write(path=None) writes the four artifacts into one directory, the
current one by default, as CompiledWorkflow.write() does, returns it and
compiles nothing again; it removes nothing first, where the CLI and a run
do. to_nextflow() leaves the surface.

§6 GPUs and §4.4: a compile collects its notes and a run warns with them;
the CLI prints them.
…w, which writes itself

CompiledNextflowWorkflow, beside CompiledWorkflow in
api/python/_compiled.py, holds the executable IR as nextflow_workflow,
lang_version, and diagnostics: the core compile's notes, then the
lowering's, rendered as CompiledWorkflow renders its own. write(path=None)
writes nextflow_workflow.json, workflow.nf, nextflow.config and
nextflow_params.json into the directory path, the current one by default,
through write_nextflow_artifacts, returns that directory, and compiles
nothing again. It removes nothing first; the CLI and a run still remove
the four files before writing.

What breaks:

- Workflow.to_nextflow() and _workflow_runtime.write_nextflow_workflow()
  are deleted, with no alias.
    before: paths = workflow.to_nextflow("out")
    after:  workflow.compile(target="nextflow").write("out")
- compile(target="nextflow") returns CompiledNextflowWorkflow, not the IR.
    before: ir = workflow.compile(target="nextflow")
    after:  ir = workflow.compile(target="nextflow").nextflow_workflow
- compile(target="nextflow") raises no UserWarning; every note, wic046
  included, is in diagnostics. run(), start() and run_async() still warn
  with the lowering's notes and the CLI still prints them, so importing a
  GPU pipeline no longer warns.
- sophios.api.python.workflow exports CompiledNextflowWorkflow in place of
  ExecutableNextflowWorkflow, which stays in sophios.api.python.nextflow;
  that module no longer exports write_nextflow_artifacts, render_nextflow,
  render_nextflow_config or render_nextflow_params. With every caller now
  inside Sophios and typed, render_nextflow_params is folded into the
  writer, and the renderers no longer raise TypeError for a value that is
  not an ExecutableNextflowWorkflow.
- A rejected Python compile leaves the files an earlier write() left;
  only the CLI and a run remove them first.

The tests, docs/nextflow.md, docs/cli-reference.md and the API reference
use the new surface; the stale-file guarantee is tested on the CLI path.
# Conflicts:
#	docs/cli-reference.md
#	src/sophios/api/python/_workflow_runtime.py
#	src/sophios/main.py
chore(nextflow): rebase the backend onto master
… only as CWL does, and never at the input's own staged name; the import writes it with .path
…ference only as CWL does, never at the input's own staged name, and the import writes it with .path
…ectory input, never its own staged name, and the import's .path
# Conflicts:
#	src/sophios/api/python/_workflow_runtime.py
#	tests/core/test_canonical_path.py
…ritten on a step is

The merge brings the backend's _with_bound_values under master's
service_document, so a compute request now carries flow.inputs.x = v,
where master sent no inputs for it. Neither side tests that path:
master's compute tests bind only step inputs, and the backend's bound
values are checked through compile() alone.
chore(nextflow): rebase the backend onto master
@vjaganat90

Copy link
Copy Markdown
Member Author

Replaced by #570, which merges the same commit from the fork.

@vjaganat90 vjaganat90 closed this Nov 2, 2026
@vjaganat90
vjaganat90 deleted the feat/nf-support branch November 2, 2026 18:20
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.

1 participant