Queue Submission and MPI
Running jobs on HPC clusters with queue templates, and configuring MPI
This page explains how to run pipeliner jobs on HPC clusters using queue submission, and how to configure MPI parallelism. Queue submission is controlled per-job through each job's do_queue option — the queue settings (template, command, queue name) define how a job is submitted, not whether it is. MPI is configured through the mpirun_command setting, whose default seeds each job's own mpi_command option. Understanding these two orthogonal mechanisms lets you build pipelines that run locally during development and submit to a scheduler in production without changing job logic.
Before configuring queue submission and MPI you need:
ccpem-pipelinerinstalled in a Python ≥ 3.9 environment (pip install ccpem-pipeliner)- A pipeliner project directory (created with
PipelinerProject(make_new_project=True)or by runningpipeliner --new_project) - (Optional) An HPC cluster scheduler such as SLURM or SGE, with a
qsub-compatible submission command - (Optional) An MPI runtime such as OpenMPI, with
mpirunonPATH - Familiarity with the pipeliner job option system (
job.joboptions[key].value = x)
If you are running jobs locally only, the queue-submission settings can be left at their defaults (queue use is off by default).
All queue and MPI settings are read from the pipeliner settings file (ccpem-pipeliner-settings.json, stored in ~/.config/ccpem/pipeliner/ on Linux or ~/Library/Application Support/ccpem/pipeliner/ on macOS) or from environment variables. Environment variables are re-read on every getter call and always take precedence over file values.
MPI settings
| Setting key | Environment variable(s) | Default | Effect |
|---|---|---|---|
mpirun_command | PIPELINER_MPIRUN_COMMAND | mpirun -n XXXmpinodesXXX | Sets the default value of each new job's mpi_command job option. XXXmpinodesXXX is substituted with the job's MPI process count at run time. |
default_nrmpi | PIPELINER_DEFAULT_NRMPI, RELION_QSUB_NRMPI | 1 | Default value for the Number of MPI procs: job option on jobs that support MPI. |
default_nrthreads | PIPELINER_DEFAULT_NRTHREADS, RELION_QSUB_NRTHREADS | 1 | Default value for the threads job option. |
mpi_max | PIPELINER_MPI_MAX, RELION_MPI_MAX | None | Maximum MPI process count exposed in the GUI. |
thread_max | PIPELINER_THREAD_MAX, RELION_THREAD_MAX | None | Maximum thread count exposed in the GUI. |
minimum_dedicated | PIPELINER_MINIMUM_DEDICATED, RELION_MINIMUM_DEDICATED | None | Minimum dedicated cores per node (used in the qsub template as XXXdedicatedXXX). |
warning_local_mpi | PIPELINER_WARNING_LOCAL_MPI, RELION_WARNING_LOCAL_MPI | None | Warn when a local (non-queued) job is launched with more than this many MPI processes. |
Important: mpirun_command sets the default value of each job's per-job mpi_command option. It is not a global MPI runtime switch. Jobs must explicitly prepend self.get_mpi_command() in their get_commands() implementation to actually invoke MPI. If XXXmpinodesXXX is absent from mpi_command, the command runs as written without substitution and no error is raised.
qsub templates must not contain an mpirun or mpiexec call. MPI is always controlled per-job via the mpi_command job option.
Queue submission settings
| Setting key | Environment variable(s) | Default | Effect |
|---|---|---|---|
queue_use | PIPELINER_QUEUE_USE, RELION_QUEUE_USE | false | Sets the default value of each new job's do_queue option. Accepts yes, true, y, or 1 (case-insensitive) as true; all other values are false. |
qsub_command | PIPELINER_QSUB_COMMAND, RELION_QSUB_COMMAND | qsub | The command used to submit the generated qsub script to the scheduler. |
qsub_template | PIPELINER_QSUB_TEMPLATE, RELION_QSUB_TEMPLATE | "" (empty string) | Path to the qsub script template file. Sets the default of each new job's Standard submission script: (qsubscript) option. If a job with do_queue set to Yes has an empty or missing template, run_job raises ValueError: Job cannot be run because: ... and no job is created. |
queue_name | PIPELINER_QUEUE_NAME, RELION_QUEUE_NAME | openmpi | Substituted into the template as XXXqueueXXX and used as the default value of each job's queuename option. |
qsub_extra_count | PIPELINER_QSUB_EXTRA_COUNT, RELION_QSUB_EXTRA_COUNT | 0 | Number of extra substitution variables (XXXextra1XXX…XXXextraNXXX) that your template uses. Each requires a corresponding qsub_extra<N> name setting. |
Per-job behaviour: queue_use only sets the default of each job's do_queue option at job creation time. Whether any individual job is actually submitted to the queue is determined by that job's do_queue value, read at submission time. Changing PIPELINER_QUEUE_USE after a job has been created does not affect jobs already written to disk.
When queue_use is false (the default), jobs run locally. Set it to true (or set PIPELINER_QUEUE_USE=true) to make new jobs default to queue submission. You can also override do_queue for a specific job by editing its run.job or job.star file before running:
Submit to queue? == Yes
qsub template placeholders
Your qsub script template may contain any of the following XXX...XXX placeholders, which pipeliner substitutes before submission:
| Placeholder | Substituted value |
|---|---|
XXXnameXXX | Job output directory |
XXXmpinodesXXX | Number of MPI processes |
XXXcoresXXX | MPI processes × threads per process |
XXXdedicatedXXX | Minimum dedicated cores per node |
XXXthreadsXXX | Threads per MPI process |
XXXqueueXXX | Queue name |
XXXcommandXXX | The job runner command |
XXXerrfileXXX | Path for stderr output |
XXXoutfileXXX | Path for stdout output |
XXXextra1XXX … XXXextraNXXX | Values of each job's qsub_extra_1 … qsub_extra_N options |
Unrecognised placeholders (including misspelled known ones) trigger a RuntimeWarning from evaluate_qsub_template. XXXextraNXXX placeholders beyond qsub_extra_count also trigger a warning.
qsub_extra settings
When your cluster template needs site-specific variables (e.g. a project account code or memory request), use qsub_extra<N> settings. For each N from 1 to qsub_extra_count:
| Setting key | Primary env var | Fallback env var | Purpose |
|---|---|---|---|
qsub_extra<N> | PIPELINER_QSUB_EXTRA<N> | RELION_QSUB_EXTRA<N> | Label shown to the user for this extra field |
qsub_extra<N>_default | PIPELINER_QSUB_EXTRA<N>_DEFAULT | RELION_QSUB_EXTRA<N>_DEFAULT | Default value substituted into XXXextraNXXX |
qsub_extra<N>_help | PIPELINER_QSUB_EXTRA<N>_HELP | RELION_QSUB_EXTRA<N>_HELP | Help text shown to the user |
Each qsub_extra<N> maps to a per-job option named qsub_extra_<N> (e.g. qsub_extra_1). The value of that option is substituted into XXXextra1XXX in the template at submission time.
Enabling queue submission for a job
Queue submission is opt-in per job. The simplest way to enable it for a new job is to set PIPELINER_QUEUE_USE=true in your environment before creating the project or running jobs — this makes the do_queue option default to Yes for every new job.
Alternatively, edit the job's run.job file before running and set:
Submit to queue? == Yes
Queue submit command: == qsub
Queue name: == openmpi
Then run the job with:
pipeliner --run_job <your_run.job file>
If do_queue is Yes and the job's submission script (its qsubscript option, which defaults to qsub_template) is empty or the file does not exist, run_job raises ValueError (Job cannot be run because: File <path> not found) and no job is created. If the script cannot be read when an already-scheduled job is launched, the job fails with Error starting job <dir> (cause: Error reading template submission script in: <path>) and is marked Failed.
Using run_in_foreground with queue submission
Passing run_in_foreground=True to PipelinerProject.run_job() only bypasses queue submission when do_queue is No. If the job has do_queue == Yes and you also pass run_in_foreground=True, pipeliner raises:
ValueError: Cannot wait for completion when submitting jobs to a queue
To run a queued job locally, change do_queue to No in the job's run.job or job.star file rather than using run_in_foreground=True.
MPI job submission via the Python API
Jobs that support MPI expose nr_mpi (label: Number of MPI procs:) and mpi_command job options, added by calling get_runtab_options(mpi=True) in the job class. The mpi_command option defaults to the value of user_settings.get_mpirun_command() (default: mpirun -n XXXmpinodesXXX).
Set the MPI process count per-job through the job options dictionary:
from pipeliner.api.manage_project import PipelinerProject
from pipeliner.api.api_utils import write_default_runjob, edit_jobstar, write_default_jobstar
# Generate a default job.star template for motion correction
write_default_jobstar("relion.motioncorr.own")
# Edit parameters including MPI count
edit_jobstar(
fn_template="relion_motioncorr_own_job.star",
params_to_change={
"input_star_mics": "Import/job001/movies.star",
"nr_mpi": "4",
"dose_per_frame": "1.0",
},
out_fn="motioncorr_run.star",
)
# Run the job
proj = PipelinerProject()
job = proj.run_job("motioncorr_run.star", run_in_foreground=True)
Queue submission via the Python API
To run a job via the queue, set do_queue to Yes in the parameters. Make sure qsub_template points to a valid script template before doing this:
import os
from pipeliner.api.manage_project import PipelinerProject
from pipeliner.api.api_utils import write_default_jobstar, edit_jobstar
os.environ["PIPELINER_QSUB_TEMPLATE"] = "/etc/pipeliner/slurm_template.sh"
os.environ["PIPELINER_QSUB_COMMAND"] = "sbatch"
write_default_jobstar("relion.ctffind.ctffind4")
edit_jobstar(
fn_template="relion_ctffind_ctffind4_job.star",
params_to_change={
"input_star_mics": "MotionCorr/job002/corrected_micrographs.star",
"nr_mpi": "8",
"do_queue": "Yes",
"queuename": "long",
},
out_fn="ctf_queue_run.star",
)
proj = PipelinerProject()
job = proj.run_job("ctf_queue_run.star")
The job is submitted to the scheduler and run_job() returns immediately. Use proj.wait_for_job_to_finish(job) if you need to block until it completes.
Overriding MPI and queue settings per-job in a run.job file
The run.job file format uses <option label> == <value> lines. Labels must match exactly those printed by pipeliner --default_runjob <jobtype>. For example, to override the MPI command for a single job, generate the template and edit it:
Number of MPI procs: == 4
MPI run command: == srun -n XXXmpinodesXXX
Submit to queue? == Yes
Queue name: == gpu
Then run:
pipeliner --run_job relion_motioncorr_own_run.job
Example 1 — Generate a run.job file and check queue/MPI defaults
Generate a default run.job file for the RELION motion correction job to inspect the queue and MPI option labels before editing:
pipeliner --default_runjob relion.motioncorr.own
This writes relion_motioncorr_own_run.job in the current directory. Open it to see lines such as:
job_type == relion.motioncorr.own
is_continue == false
is_tomo == false
Input movies STAR file: ==
Number of MPI procs: == 1
MPI run command: == mpirun -n XXXmpinodesXXX
Submit to queue? == No
Queue name: == openmpi
Queue submit command: == qsub
Edit the values as needed, then run:
pipeliner --run_job relion_motioncorr_own_run.job
Example 2 — Python API: schedule and run a job with MPI via the queue
This example uses the Python API to configure and submit a CTF-finding job to a cluster scheduler with 8 MPI processes and a custom queue name. The qsub_template environment variable must point to a valid submission script.
import os
from pipeliner.api.manage_project import PipelinerProject
from pipeliner.api.api_utils import write_default_jobstar, edit_jobstar
# Point to your site's qsub template
os.environ["PIPELINER_QSUB_TEMPLATE"] = "/shared/templates/slurm_pipeliner.sh"
os.environ["PIPELINER_QSUB_COMMAND"] = "sbatch"
# Generate a default job.star for CTF finding
write_default_jobstar("relion.ctffind.ctffind4")
# Edit parameters: set input, MPI count, and enable queue submission
edit_jobstar(
fn_template="relion_ctffind_ctffind4_job.star",
params_to_change={
"input_star_mics": "MotionCorr/job002/corrected_micrographs.star",
"nr_mpi": "8",
"do_queue": "Yes",
"queuename": "long",
},
out_fn="ctf_cluster_run.star",
)
# Open project and run the job (returns immediately; job runs on cluster)
proj = PipelinerProject()
job = proj.run_job("ctf_cluster_run.star")
# Optionally wait for completion
final_status = proj.wait_for_job_to_finish(job)
print(f"Job finished with status: {final_status}")
Example 3 — Python API: inspect and override mpirun_command for a scheduled job
This example shows how to read the current mpirun_command setting and schedule a job with a custom per-job mpi_command.
from pipeliner import user_settings
from pipeliner.api.manage_project import PipelinerProject
from pipeliner.api.api_utils import write_default_jobstar, edit_jobstar
# Inspect the global default
default_mpi_cmd = user_settings.get_mpirun_command()
# default_mpi_cmd is 'mpirun -n XXXmpinodesXXX'
# Generate and edit a motion correction job.star
write_default_jobstar("relion.motioncorr.own")
edit_jobstar(
fn_template="relion_motioncorr_own_job.star",
params_to_change={
"input_star_mics": "Import/job001/movies.star",
"nr_mpi": "4",
# Override per-job MPI command (e.g. for SLURM srun)
"mpi_command": "srun -n XXXmpinodesXXX",
"dose_per_frame": "1.2",
},
out_fn="mc_srun.star",
)
proj = PipelinerProject()
# Schedule without running immediately
scheduled_job = proj.schedule_job("mc_srun.star")
# Later, run the scheduled job
proj.run_scheduled_job(scheduled_job, run_in_foreground=True)
Job fails immediately with Error starting job <dir>
Symptom: A job with do_queue == Yes that was already scheduled fails when it is started (for example with run_scheduled_job). The job is marked Failed and no processing output appears.
Likely cause: The job's submission script template (its Standard submission script: option, whose default comes from the qsub_template setting) no longer exists. When the template cannot be read, pipeliner raises ValueError: Error reading template submission script in: <path> and wraps it in RuntimeError: Error starting job <dir>. The same RuntimeError is raised if the queue submit command fails (cause: Command '...' failed with return code <n>). A new job run with an empty or missing template never gets this far: run_job raises ValueError: Job cannot be run because: ... not found and no job is created.
Fix: Set the Standard submission script: option in the job's run.job or job.star file to the absolute path of a valid submission script template and run it as a new job. Setting PIPELINER_QSUB_TEMPLATE or qsub_template in ~/.config/ccpem/pipeliner/ccpem-pipeliner-settings.json only changes the default for job files generated afterwards. Verify the file exists before re-running the job.
ValueError: Cannot wait for completion when submitting jobs to a queue
Symptom: Calling proj.run_job(..., run_in_foreground=True) raises this error from the Python API.
Likely cause: The job has do_queue == Yes set and you also passed run_in_foreground=True. These options are mutually exclusive.
Fix: Either set do_queue to No in the job's run.job or job.star file to run locally, or remove run_in_foreground=True and use proj.wait_for_job_to_finish(job) after submission if you need to block.
RuntimeWarning about unrecognised placeholder in qsub template
Symptom: A RuntimeWarning is emitted from evaluate_qsub_template when a job is submitted, mentioning an unrecognised XXX...XXX placeholder.
Likely cause: Your template contains a misspelled placeholder (e.g. XXXmpinodeXXX instead of XXXmpinodesXXX), or it references XXXextraNXXX for an N greater than qsub_extra_count.
Fix: Check your template against the supported placeholder list (XXXnameXXX, XXXmpinodesXXX, XXXcoresXXX, XXXdedicatedXXX, XXXthreadsXXX, XXXqueueXXX, XXXcommandXXX, XXXerrfileXXX, XXXoutfileXXX, and XXXextra1XXX…XXXextraNXXX). Correct any typos and ensure qsub_extra_count matches the number of XXXextraNXXX slots in your template.
MPI jobs run with only 1 process despite nr_mpi being set higher
Symptom: Jobs appear to run sequentially; no MPI parallelism is observed even though nr_mpi is set to a value greater than 1.
Likely cause 1: The job class does not call self.get_mpi_command() in its get_commands() implementation. Setting nr_mpi alone is not sufficient; the job must explicitly prepend the MPI command.
Likely cause 2: XXXmpinodesXXX is absent from the mpi_command option value. In this case get_mpi_command() runs the command as written without substituting the process count, and no error is raised.
Fix: For built-in RELION jobs (e.g. relion.motioncorr.own, relion.ctffind.ctffind4), MPI is handled correctly by the job class. For custom jobs, ensure get_commands() prepends self.get_mpi_command() when nr_mpi > 1. Also verify that mpi_command contains XXXmpinodesXXX.
qsub_extra warning: expected settings missing
Symptom: At startup, pipeliner logs a warning such as CCP-EM Pipeliner found N qsub_extra variables have been specified in the 'qsub_extra_count' setting, but the expected settings for the following names are missing: qsub_extra1.
Likely cause: qsub_extra_count is set to a non-zero value in the settings file or via PIPELINER_QSUB_EXTRA_COUNT, but the corresponding qsub_extra<N> name settings are not defined.
Fix: For each N from 1 to qsub_extra_count, set PIPELINER_QSUB_EXTRA<N> (e.g. PIPELINER_QSUB_EXTRA1) to a non-empty label string, or add qsub_extra<N> entries to your settings file. If you do not need extra substitution variables, set qsub_extra_count back to 0.