Workflows and Slurm jobs
How workflows and Slurm jobs are configured in slurm-config.ini, how to add existing or new workflows, and how data moves to and from Slurm.
Recommended for new workflows: package the workflow as a container described by a
Bilayers config.yaml, with OME-Zarr as input and output format.
BIOMERO supports Bilayers workflows, including Zarr and HCS plate workflows, directly. The
older BIAFLOWS descriptor.json with TIFF folders is still supported so that existing workflows keep
working, but we discourage it for new work; see Legacy: BIAFLOWS descriptor.json.
This page covers the BIOMERO library mechanics. The NL-BIOMERO documentation covers the workflow developer side in more depth:
Bilayers workflows in BIOMERO: descriptor mapping, I/O directories, parameter choices, unsupported Bilayers features
Developing OME-Zarr workflows: the Zarr data contract for images, labels and plates
Example workflows
These Bilayers-based workflows are the examples to start from:
Workflow |
What it is |
|---|---|
GPU instance segmentation (Cellpose 3, Cellpose-SAM, Stardist, Spotiflow, InstanSeg) for OME-Zarr images and HCS plates |
|
GPU deconvolution for widefield and confocal images, with OME-Zarr input and output |
|
bilayers-auto-container (no release yet) |
Template plus agent skill. Give an agent a source workflow URL with the create-bilayers-container skill and it creates a new repository from the template, with a Bilayers |
Cellpose 4 (Cellpose-SAM), built from the auto-container template; writes an RO-Crate per run |
If you want to wrap your own tool, start with the create-bilayers-container agent skill in the bilayers-auto-container repository (see the table above).
For example, this slurm-config.ini entry adds cisegmentation (the sample in resources/slurm-config.ini has it too):
[WORKFLOWS]
cisegmentation=cisegmentation
# _use_gpu takes the global gpu_partition/gpu_gres/gpu_gpus from [SLURM]: fill them in for your cluster, or set cisegmentation_job_partition/_job_gres directly
cisegmentation_use_gpu=true
cisegmentation_repo=https://github.com/Cellular-Imaging-Amsterdam-UMC/cisegmentation/tree/v0.7.0
cisegmentation_job=jobs/cisegmentation.sh
cisegmentation_job_time=08:00:00
Pin _repo to a release tag, as here, so the workflow does not change under you. How to add an existing workflow explains each key and the Zarr and plate modes in the admin UI.
slurm-config.ini
The slurm-config.ini file is a configuration file used by the biomero Python package to specify various settings related to SSH and Slurm. Here is a brief description of its contents:
[SSH]: This section contains SSH settings, including the alias for the SLURM SSH connection (host). Additional SSH configuration can be specified in the user’s SSH config file or in /etc/fabric.yml.
[SLURM]: This section includes settings specific to Slurm. It defines the paths on the SLURM entrypoint for storing data files (slurm_data_path), container image files (slurm_images_path), converter images (slurm_converters_path), and Slurm job scripts (slurm_script_path). It also includes optional behavior flags and overrides such as slurm_data_bind_path, slurm_conversion_partition, sacct_start_time, sacct_days_ago, env_file_submission, inject_gpu_flag, gpu_partition, gpu_gres, slurm_zip_cmd, slurm_lock_cmd, and the advanced slurm_script_repo setting.
[WORKFLOWS]: This section defines the workflows ([MODELS] is accepted as the older name). Each workflow has a unique key and requires corresponding values for <key>_repo (the repository, at a version tag, with the workflow descriptor: a Bilayers config.yaml or a legacy descriptor.json; it describes the parameters and where to find the image), and <key>_job (jobscript path: the location in the slurm_script_repo, or, when BIOMERO generates the scripts, the path under slurm_script_path where it writes the script). The sample slurm-config.ini has a Bilayers entry (cisegmentation) first, followed by legacy BIAFLOWS-era entries; see also the cisegmentation snippet in Example workflows above and NL-BIOMERO’s web/slurm-config.ini.
Note also that you can override the default Slurm job values using this workflow configuration, like memory, GPU, time limit, etc. All values for sbatch can be applied (see e.g. here) and will be forwarded to the job command.
For example
# Run cisegmentation Slurm with 10 GB GPU
cisegmentation_job_gres=gpu:1g.10gb:1
# Run cisegmentation Slurm with 15 GB CPU memory
cisegmentation_job_mem=15GB
The slurm-config.ini file allows users to configure paths, repositories, and other settings specific to their Slurm cluster and the biomero package, providing flexibility and customization options. See the configuration reference for every option.
Time Limit on Slurm
An important Slurm job config is the time limit: SBATCH --time=00:45:00 is the default in BIOMERO (max 45 minutes per job).
The format is d-hh:mm:ss
WARNING: After this time, the job will timeout and this scenario is not handled by BIOMERO (yet)! You will lose your processing progress.
You can change this timeout value:
For ALL workflows, in the job_template.sh (e.g.
#SBATCH --time=08:00:00for 8 hours)For ONE workflow, in the slurm-config.ini (e.g.
cisegmentation_job_time=08:00:00for 8 hours)Per specific run, provide it in the OMERO script UI in the Slurm Run Workflow script UI (SLURM_Run_Workflow.py)
Note that it might take longer for Slurm to schedule your job if you put the time very high, or possibly even make it wait indefinitely (see –time explanation in https://slurm.schedmd.com/sbatch.html). We will work on smart timing, but for now it is hardcoded and configurable.
How to add an existing workflow
To add an existing (containerized) workflow, add it to the slurm-config.ini file like in our example:
[WORKFLOWS]
# -------------------------------------
# CISEGMENTATION (Bilayers, OME-Zarr)
# -------------------------------------
# The path to store the container on the slurm_images_path
cisegmentation=cisegmentation
# The (e.g. github) repository, at a version tag, with the config.yaml file
cisegmentation_repo=https://github.com/Cellular-Imaging-Amsterdam-UMC/cisegmentation/tree/v0.7.0
# The jobscript path: required. With generated scripts (no slurm_script_repo), BIOMERO writes the script here, under slurm_script_path
cisegmentation_job=jobs/cisegmentation.sh
Here,
the name referenced for this workflow is
cisegmentationthe location of the container on slurm will be
<slurm_images_path>/cisegmentationthe code repository is
https://github.com/Cellular-Imaging-Amsterdam-UMC/cisegmentationthe specific version we want is
v0.7.0the container image and its parameters are found through the metadata file in the repository at that version: config.yaml (its
docker_imageentry names the image on Docker Hub)the jobscript on slurm will be
jobs/cisegmentation.shunderslurm_script_path._jobis required, also when jobs are generated.With a
slurm_script_repo, this path must match a script in that git repo,without one, it is where the library writes the generated jobscript
cisegmentation_job_<param>lines (such as_job_time) must come after the_jobline
Then run Slurm Init to pull the container and generate the job script. For a Bilayers config.yaml, the Zarr and plate requirements come from the descriptor; an administrator can additionally enable modes in the OMERO.biomero admin UI and choose Zarr v2 or v3. For a legacy BIAFLOWS descriptor.json, which declares neither, the administrator marks a Zarr workflow manually there (see the NL-BIOMERO admin guide). In slurm-config.ini you can also point <key>_repo straight at one descriptor file, see Slurm configuration.
Workflow metadata via config.yaml (Bilayers)
A lot of the automation in this library is based on metadata of the workflow, provided in the source code of the workflow. The recommended format is the Bilayers config.yaml, for example cisegmentation’s.
For example, the OMERO script UI is generated automatically from this descriptor, and so is the Slurm job script. The descriptor also declares what data the workflow takes and returns (image, file, … with accepted formats such as tiff and omezarr), which is what lets BIOMERO run Zarr and HCS plate workflows. See Bilayers workflows in BIOMERO for how each field is interpreted and which Bilayers features BIOMERO ignores.
BIOMERO converts both Bilayers and BIAFLOWS descriptors to its own intermediate schema, biomero-schema, so other formats could follow. We do not strictly validate the descriptor; we read the expected fields.
Multiple versions
Note that while it is possible to have multiple versions of the same workflow on Slurm (and select the desired one in OMERO), it is not possible to configure this yet. We assume for now you only want one version to start with. You can always update this config to download a new version to Slurm.
I/O
Bilayers workflows decide themselves which command-line flags receive the input and output folders; BIOMERO reads these from the config.yaml and passes the Slurm paths, so you do not configure them:
Required
inputsentries receive$DATA_PATH/data/inoutputsentries (and parameters withoutput_dir_set: True) receive$DATA_PATH/data/out, the folder whose contents are copied back to OMERO
With OME-Zarr as the input and output format, the workflow receives a conventional OME-Zarr (or a Zarr HCS plate) and returns derived masks in the labels/ hierarchy of the result Zarr. The workflow needs no BIOMERO-specific logic. See Developing OME-Zarr workflows for the data contract. For TIFF-only tools, the bilayers-auto-container template converts Zarr to TIFF and back inside the container.
Legacy: BIAFLOWS descriptor.json
BIOMERO still supports workflows described by a BIAFLOWS / Cytomine descriptor.json, so existing BIAFLOWS workflows keep running. We discourage it for new workflows: it describes only one fixed pattern (a folder of TIFF images in, a folder of TIFF results out), so it cannot express Zarr input, HCS plates or Zarr output, and standard BIAFLOWS workflows are not compatible with the Zarr modes. Use a Bilayers config.yaml instead; the bilayers-auto-container template can draft one from a BIAFLOWS descriptor (bilayers-auto from-biaflows).
To add an existing BIAFLOWS workflow, use the same slurm-config.ini entries, for example:
[WORKFLOWS]
# The path to store the container on the slurm_images_path
cellpose=cellpose
# The (e.g. github) repository with the descriptor.json file
cellpose_repo=https://github.com/TorecLuik/W_NucleiSegmentation-Cellpose/tree/v1.2.7
# The jobscript in the 'slurm_script_repo'
cellpose_job=jobs/cellpose.sh
The container is found under the path given in the metadata file: descriptor.json.
Workflow metadata via descriptor.json
This metadata scheme is (based on) Cytomine / BIAFLOWS, and you can find details of it and how to create one yourself on their website, e.g. the BIAFLOWS dev-guide.
NOTE! We do not require the cytomine_<...> authentication parameters. They are not mandatory. In fact, we ignore them. But it might be beneficial to make your workflow compatible with Cytomine as well.
We use the cytomine-0.1 schema. We do not strictly validate it, we just read the expected fields from the descriptor.json.
I/O of BIAFLOWS workflows
Unless you change the Slurm job, the input is expected to be:
The
infolderparameterpointing to a folder with multiple input files/images
The
gtfolderparameter (Optional)pointing to a
ground-truthinput files, generally not needed for prediction / processing purposes.
The
outfolderparameterwhere you write all your output files (to get copied back to OMERO)
Wrapper.py
Note that you can also use the wrapper.py setup from BIAFLOWS to handle the I/O for you:
with BiaflowsJob.from_cli(argv) as bj:
# Change following to the actual problem class of the workflow
...
# 1. Prepare data for workflow
in_imgs, gt_imgs, in_path, gt_path, out_path, tmp_path = prepare_data(problem_cls, bj, is_2d=True, **bj.flags)
# 2. Run image analysis workflow
bj.job.update(progress=25, statusComment="Launching workflow...")
# Add here the code for running the analysis script
# 3. Upload data to BIAFLOWS
...
# 4. Compute and upload metrics
...
# 5. Pipeline finished
...
This wrapper handles the input parameters for you, providing the input images as in_imgs, et cetera. Then you add your commandline call between point 2 and 3, and possibly some preprocessing between point 1 and 2:
#add here the code for running the analysis script
For example, from Cellpose container workflow:
...
# 2. Run image analysis workflow
bj.job.update(progress=25, statusComment="Launching workflow...")
# Add here the code for running the analysis script
prob_thresh = bj.parameters.prob_threshold
diameter = bj.parameters.diameter
cp_model = bj.parameters.cp_model
use_gpu = bj.parameters.use_gpu
print(f"Chosen model: {cp_model} | Channel {nuc_channel} | Diameter {diameter} | Cell prob threshold {prob_thresh} | GPU {use_gpu}")
cmd = ["python", "-m", "cellpose", "--dir", tmp_path, "--pretrained_model", f"{cp_model}", "--save_tif", "--no_npy", "--chan", "{:d}".format(nuc_channel), "--diameter", "{:f}".format(diameter), "--cellprob_threshold", "{:f}".format(prob_thresh)]
if use_gpu:
print("Using GPU!")
cmd.append("--use_gpu")
status = subprocess.run(cmd)
if status.returncode != 0:
print("Running Cellpose failed, terminate")
sys.exit(1)
# Crop to original shape
for bimg in in_imgs:
shape = resized.get(bimg.filename, None)
if shape:
img = imageio.imread(os.path.join(tmp_path,bimg.filename_no_extension+"_cp_masks.tif"))
img = img[0:shape[0], 0:shape[1]]
imageio.imwrite(os.path.join(out_path,bimg.filename), img)
else:
shutil.copy(os.path.join(tmp_path,bimg.filename_no_extension+"_cp_masks.tif"), os.path.join(out_path,bimg.filename))
# 3. Upload data to BIAFLOWS
We get the commandline parameters from bj.parameters (biaflows job) and provide that the cmd commandline string. Then we run it with subprocess.run(cmd) and check the status.
We use a tmp_path to store both input and output, then move the output to the out_path after the processing is done.
Also note that some preprocessing is done in step 1:
# Make sure all images have at least 224x224 dimensions
# and that minshape / maxshape * minshape >= 224
# 0 = Grayscale (if input RGB, convert to grayscale)
# 1,2,3 = rgb channel
nuc_channel = bj.parameters.nuc_channel
resized = {}
for bfimg in in_imgs:
...
imageio.imwrite(os.path.join(tmp_path, bfimg.filename), img)
Another example is this imageJ wrapper:
...
# 3. Call the image analysis workflow using the run script
nj.job.update(progress=25, statusComment="Launching workflow...")
command = "/usr/bin/xvfb-run java -Xmx6000m -cp /fiji/jars/ij.jar ij.ImageJ --headless --console " \
"-macro macro.ijm \"input={}, output={}, radius={}, min_threshold={}\"".format(in_path, out_path, nj.parameters.ij_radius, nj.parameters.ij_min_threshold)
return_code = call(command, shell=True, cwd="/fiji") # waits for the subprocess to return
if return_code != 0:
err_desc = "Failed to execute the ImageJ macro (return code: {})".format(return_code)
nj.job.update(progress=50, statusComment=err_desc)
raise ValueError(err_desc)
Once again, just a commandline --headless call to ImageJ, wrapped in this Python script and this container.
How to add your new custom workflow
Building workflows like this will make them more FAIR (also for software) and uses best practices like code versioning and containerization!
Also take a look at our in-depth tutorial on adding a Cellprofiler pipeline as a workflow to BIOMERO.
Here is a shorter version. Say you have a tool or script and you want to make it available on OMERO and Slurm.
Option A (recommended): bilayers-auto-container. The bilayers-auto-container template wraps your tool in a container with a Bilayers config.yaml, converts OME-Zarr to and from the formats your tool reads, and writes a Workflow RO-Crate (provenance, the run’s parameters and outputs) next to the results. Its repository includes an agent skill (create-bilayers-container, written for Claude Code) that sets up the container for an existing workflow repository. The template has no release yet: use it from its repository. bilayers_Cellpose is a finished example. Then:
Test the container locally (
bilayers-auto container-testruns it like the Slurm client does).Publish the repository with a release tag (e.g. v1.0.0), and the container on a registry such as Docker Hub with the same tag. Please use a tag that equals your repository version, instead of
latest. This improves reproducibility.Follow How to add an existing workflow: add the entry to
slurm-config.ini(or in the OMERO.biomero admin UI) and run Slurm Init.
Option B: write the container yourself. For a workflow that natively reads and writes OME-Zarr, follow the Zarr workflow data contract, and the Bilayers workflows page for the config.yaml. cisegmentation and cideconvolve are full examples. The steps are:
Make your script headless: executable on the commandline, with parameters as command-line flags, reading from and writing to the folders that the descriptor declares (
data/in,data/out).Describe the inputs, outputs and parameters in a Bilayers
config.yaml, including thedocker_image(see How to add an existing workflow).Describe the requirements / environment of your script, with pinned versions for future reproducibility (e.g. a
requirements.txt, like this).Package your script in a Docker container. E.g. like this. Please watch out for the pitfalls of reproducibility with Dockerfiles: Always version your packages!.
Publish your source code, Dockerfile and
config.yamlto a Github repository (free for public repositories), and publish a version of it (e.g. v1.0.0), like this.Publish your container on Dockerhub (free for public repositories), using the same version as the source code, like this.
Follow How to add an existing workflow: add details to
slurm-config.iniand run Slurm Init (orSlurmClient.from_config(init_slurm=True)).
Existing BIAFLOWS workflows need none of this: add them as described under Legacy: BIAFLOWS descriptor.json.
Slurm jobs
Generating jobs
By default, biomero will generate basic slurm jobs for each workflow, based on the workflow descriptor (config.yaml, or a legacy descriptor.json) and a job template.
It will replace $PARAMS with the (non-cytomine_) parameters given in the descriptor. See also the Parameters section below.
How to add your own Slurm job
The recommended path is to change the job template
and regenerate jobs by running SlurmClient.from_config(init_slurm=True)
(or slurmClient.update_slurm_scripts(generate_jobs=True)).
You can also point BIOMERO at an external scripts repository through
slurm_script_repo, but this is an advanced option. BIOMERO does not maintain
an always-up-to-date public scripts repository for operators, and external
repositories can drift out of sync with newer BIOMERO releases.
If you still want to maintain your own scripts repository, reference it in
slurm-config.ini, both in the field slurm_script_repo and every
<workflow>_job:
# -------------------------------------
# REPOSITORIES
# -------------------------------------
# A (github) repository to pull the slurm scripts from.
#
# Note:
# If you provide no repository, we will generate scripts instead!
# Based on the job_template and the workflow descriptor
#
slurm_script_repo=https://github.com/<org>/<your-slurm-scripts>
[WORKFLOWS]
# -------------------------------------
# Workflow settings (also accepted as [MODELS] for backward compatibility)
# -------------------------------------
# ...
# -------------------------------------
# CISEGMENTATION
# -------------------------------------
# The path to store the container on the slurm_images_path
cisegmentation=cisegmentation
# The (e.g. github) repository with the workflow descriptor (config.yaml)
cisegmentation_repo=https://github.com/Cellular-Imaging-Amsterdam-UMC/cisegmentation/tree/v0.7.0
# The jobscript in the 'slurm_script_repo'
cisegmentation_job=jobs/cisegmentation.sh
You can update those external jobs by calling slurmClient.update_slurm_scripts(),
which will pull the repository’s default branch.
This is only recommended when you explicitly want to own and maintain custom job scripts. For most users, descriptor-driven BIOMERO script generation is the safer and less maintenance-heavy option.
Parameters
The library will provide the parameters from your descriptor as environment variables to the call. E.g. set DIAMETER=0; sbatch ....
Other environment variables provided are:
DATA_PATHMade of
<slurm_data_path>/<input_folder>. The base dir for data folders for this execution. We expect it to containdata/in(inputs) anddata/out(results) folders in our template and data transfer setup.
IMAGE_PATHMade of
<slurm_images_path>/<model_path>, as described inslurm-config.ini
IMAGE_VERSIONSINGULARITY_IMAGEAlready uses the
IMAGE_VERSIONabove, as<container_name>_<IMAGE_VERSION>.sif
We (potentially) override the following Slurm job settings programmatically:
--mail-user={email}(optional)--time={time}(optional)--output=omero-%4j.log(mandatory)
We could add more overrides in the future, and perhaps make them available as global configuration variables in slurm-config.ini.
Batching
We can simply use Slurm for running your workflow 1:1, so 1 job to 1 workflow. This could speed up your workflow already, as Slurm servers are likely equipped with strong CPU and GPU.
However, Slurm is also built for parallel processing on multiple (or the same) servers. We can accomplish this by running multiple jobs for 1 workflow. This is simple for embarrassingly parallel tasks, like segmenting multiple images: just provide each job with a different set of input images. If you have 100 images, you could run 10 jobs on 10 images and (given enough resources available for you on Slurm) that could be 10x faster. In theory, you could run 1 job per image, but at some point you run into the overhead cost of Slurm (and OMERO) and it might actually slow down again (as you incur this cost a 100 times instead of 10 times).
Using the GPU on Slurm
Note, the default Slurm job script will not request any GPU resources by itself.
This is because GPU resources are expensive and some programs do not work with GPU.
We can instead enable the use of GPU for a workflow, with <key>_use_gpu=true together with the GPU partition and resources (gpu_partition, gpu_gres or gpu_gpus) and the inject_gpu_flag option; see Slurm configuration for how these combine. You can also provide your own Slurm job scripts, or set an override value per workflow in slurm-config.ini:
# -------------------------------------
# CISEGMENTATION
# -------------------------------------
# The path to store the container on the slurm_images_path
cisegmentation=cisegmentation
# The (e.g. github) repository with the config.yaml file
cisegmentation_repo=https://github.com/Cellular-Imaging-Amsterdam-UMC/cisegmentation/tree/v0.7.0
# The jobscript in the 'slurm_script_repo'
cisegmentation_job=jobs/cisegmentation.sh
# Override the default job values for this workflow
# Or add a job value to this workflow
# If you don't want to override, comment out / delete the line.
# Run cisegmentation Slurm with 10 GB GPU
cisegmentation_job_gres=gpu:1g.10gb:1
In fact, any ..._job_...=... configuration value will be forwarded to the Slurm commandline.
Slurm commandline parameters override those in the script, so the above one requests 1 10GB gpu for cisegmentation.
E.g. you could also set the time limit higher:
# Run with longer time limit
cisegmentation_job_time=00:30:00
Now the cisegmentation job should run for maximum of 30 minutes, instead of the default.
Transfering data
We have added methods to this library to help with transferring data to the Slurm cluster, using the same SSH connection (via SCP or SFTP).
slurmClient.transfer_data(...)Transfer data to the Slurm cluster
slurmClient.unpack_data(...)Unpack zip file on the Slurm cluster
slurmClient.zip_data_on_slurm_server(...)Zip data on the Slurm cluster
slurmClient.copy_zip_locally(...)Transfer (zip) data from the Slurm cluster
slurmClient.get_logfile_from_slurm(...)Transfer logfile from the Slurm cluster
And more; see the docstring of SlurmClient and example OMERO scripts.