Running, Scheduling and Aborting Jobs
The job lifecycle: scheduling, running, continuing, aborting, status files and logs
This page describes the full lifecycle of a pipeliner job: how jobs are scheduled (assigned a number and directory), run in the foreground or background, monitored via sentinel files and log output, continued or overwritten, and aborted. Understanding this lifecycle is essential for building reliable automated workflows, because every API method and CLI flag maps directly onto one or more lifecycle transitions. The job runner reads the job's job.star file, runs the job's commands, and signals completion by writing one of three sentinel files into the job directory. A background run (the default) launches the job runner as a separate, detached process, or submits it to the queue; with run_in_foreground=True, and for each job in a schedule, the job runner runs in the calling process.
Before working through this page you should already have:
ccpem-pipelinerinstalled and verified (pipeliner.check_setupreports no missing console scripts)- A pipeliner project open in your working directory (
.CCPEM_pipeliner_projectanddefault_pipeline.starpresent) - Python ≥ 3.9
- (
optional) An MPI runtime such as OpenMPI if you intend to submit MPI jobs - (
optional) An HPC cluster scheduler (SLURM, SGE, …) if you intend to use queue submission
See the installation and project-creation guides for setup steps.
The job lifecycle at a glance
A job is Scheduled, then Running, and ends in one of Succeeded, Failed or Aborted (its status can also be reset by hand, see below):
| State | Sentinel file | Meaning |
|---|---|---|
| Scheduled | (none) | Registered in default_pipeline.star; job.star and run.job written |
| Running | (none) | job_runner process is executing commands |
| Succeeded | PIPELINER_JOB_EXIT_SUCCESS | All commands finished with exit code 0 |
| Failed | PIPELINER_JOB_EXIT_FAILED | A required command exited non-zero, or the runner hit an error (for example a program could not be launched, or post-run node creation failed) |
| Aborted | PIPELINER_JOB_EXIT_ABORTED | Abort trigger file was detected |
Job numbers are assigned project-wide from a counter stored in default_pipeline.star, so Import/job001, MotionCorr/job002, CtfFind/job003, and so on — not per-job-type.
Scheduling vs running
PipelinerProject.schedule_job() registers a job in the pipeline graph without running it. PipelinerProject.run_job() calls schedule_job internally and then launches job_runner immediately.
Use schedule_job when you want to queue up several jobs before any of them start (e.g. in a run_schedule workflow). Use run_job for single jobs you want to start right away.
from pipeliner.api.manage_project import PipelinerProject
from pipeliner.api.api_utils import job_default_parameters_dict
proj = PipelinerProject(make_new_project=True)
# Build a parameters dict for the import job
params = job_default_parameters_dict('relion.import.movies')
params['fn_in_raw'] = 'Movies/*.tiff'
params['kV'] = '300'
params['Cs'] = '2.7'
params['Q0'] = '0.1'
params['angpix'] = '0.885'
# Run immediately in the background (default)
job = proj.run_job(params)
print(job.output_dir) # e.g. Import/job001/
run_in_foreground: By default,
run_joblaunches the job runner in the background and returns immediately. To block until the job finishes (useful for chaining dependent jobs in a script), passrun_in_foreground=True. Note that if the job hasdo_queueset toYes,run_in_foreground=TrueraisesValueError('Cannot wait for completion when submitting jobs to a queue'). Setdo_queuetoNoin the parameters dict if you want foreground execution.
Waiting for a job before starting the next one
When chaining dependent jobs in a script, use wait_for_job_to_finish() to block until the upstream job completes:
status = proj.wait_for_job_to_finish(job.output_dir, ping=2.0, timeout=86400.0)
if status != 'Succeeded':
raise RuntimeError(f'Job did not succeed: {status}')
wait_for_job_to_finish returns the final status string ('Succeeded', 'Failed', or 'Aborted'). Pass error_on_fail=True or error_on_abort=True to raise RuntimeError instead.
Generating and editing job parameter files
For CLI-driven workflows, generate a run.job template with pipeliner --default_runjob <jobtype>. The output filename replaces dots with underscores and appends _run.job (e.g. relion.import.movies → relion_import_movies_run.job).
pipeliner --default_runjob relion.motioncorr.own
This produces relion_motioncorr_own_run.job. Edit it using each option's exact label (as written in the generated file). The file format is:
job_type == relion.motioncorr.own
is_continue == false
is_tomo == false
Input movies STAR file: == Import/job001/movies.star
Number of MPI procs: == 4
...
For Python-based editing, generate a STAR template with write_default_jobstar, then edit it with edit_jobstar:
from pipeliner.api.api_utils import write_default_jobstar, edit_jobstar
template = write_default_jobstar('relion.motioncorr.own')
edited = edit_jobstar(
template,
{'input_star_mics': 'Import/job001/movies.star', 'do_save_noDW': 'No'},
'motioncorr_run.star'
)
job = proj.run_job(edited)
Important:
edit_jobstarrequires ajob.starSTAR file as its first argument. Passing arun.jobfile (withlabel == valueformat) raisesValueError("File <name> is not a valid STAR file. ..."), because arun.jobfile can't be parsed as STAR. The failed call may also rewrite therun.jobfile to quote reserved words, saving the original with a.origsuffix. The two file formats are incompatible.
Running a job from the CLI
Create a new job from a run.job or job.star file:
pipeliner --run_job relion_motioncorr_own_run.job
To overwrite an existing job of the same type instead of creating a new one:
pipeliner --run_job relion_motioncorr_own_run.job --overwrite MotionCorr/job002/
To schedule without running immediately:
pipeliner --schedule_job relion_motioncorr_own_run.job
Continuing a job
Continuation resumes a completed job from its last checkpoint, by adding a continuation flag to the underlying command: --only_do_unfinished for motion correction, CTF, picking, extraction, CTF refinement and polishing jobs, and --continue <optimiser file> for optimiser-based jobs. A continue_job.star file is written into the job directory at scheduling time. For optimiser-based jobs (Class2D, Class3D, InitialModel, Refine3D, Multibody), you must set fn_cont to the correct _optimiser.star file in continue_job.star before calling continue_job. get_continuation_job() fills in fn_cont with the latest _optimiser.star file for Class2D, Class3D, InitialModel and Refine3D jobs; it does not do this for MultiBody refinement, where you must still set fn_cont yourself.
Via CLI:
pipeliner --continue_job MotionCorr/job002/
Via Python API:
# Preferred: get_continuation_job prepares the continuation job for you
cont_job = proj.get_continuation_job('MotionCorr/job002/')
proj.run_job(cont_job)
Or, to schedule the continuation without running it immediately:
proj.schedule_continue_job('MotionCorr/job002/')
get_continuation_job()raisesValueErrorif the job status is notSucceeded, andNotImplementedErrorif the job type hascan_continue=False(e.g. allrelion.select.*jobs and all CCP-EM atomic modelling jobs).
Overwriting a job
To delete a job and replace it with a fresh run of the same type:
# Python: pass the existing job name to the overwrite parameter
new_params = job_default_parameters_dict('relion.motioncorr.own')
new_params['input_star_mics'] = 'Import/job001/movies.star'
new_job = proj.run_job(new_params, overwrite='MotionCorr/job002/')
overwrite requires a full job name or full alias. In the Python API a short form like 'job002' or '2' is not found, and run_job silently creates a new job instead of overwriting; use proj.parse_procname() first. The CLI --overwrite option does accept short forms.
Running a named schedule
A schedule runs a list of already-scheduled jobs in sequence. First schedule each job individually, then run them as a group:
j1 = proj.schedule_job(import_params)
j2 = proj.schedule_job(motioncorr_params)
j3 = proj.schedule_job(ctffind_params)
proj.run_schedule(
fn_sched='my_pipeline',
job_ids=[j1.output_dir, j2.output_dir, j3.output_dir],
nr_repeat=1,
minutes_wait=0,
seconds_wait_after=5,
)
run_schedule returns the schedule name fn_sched. To stop a running schedule:
proj.stop_schedule('my_pipeline') # returns True on success
CLI equivalent (requires --name and --jobs):
pipeliner --run_schedule --name my_pipeline --jobs Import/job001/ MotionCorr/job002/ CtfFind/job003/
Aborting a running job
The pipeliner writes PIPELINER_JOB_ABORT_NOW into the job directory. The job runner detects this file, terminates the current subprocess, and writes PIPELINER_JOB_EXIT_ABORTED.
Via CLI:
pipeliner --abort_job MotionCorr/job002/
Via Python API:
proj.abort_job('MotionCorr/job002/')
abort_job raises ValueError if the job name is not found, and RuntimeError if the job is not currently in Running state.
Setting job status manually
You can manually override a job's status with --set_status. This removes any existing PIPELINER_JOB_EXIT_* file and, for success, failed and aborted, writes the matching one (running and scheduled have no sentinel file).
pipeliner --set_status MotionCorr/job002/ success
pipeliner --set_status MotionCorr/job002/ failed
pipeliner --set_status MotionCorr/job002/ aborted
pipeliner --set_status MotionCorr/job002/ scheduled
pipeliner --set_status MotionCorr/job002/ running
Valid status values are substrings of: success, failed, aborted, scheduled, running. The value finished is not valid.
A job with status Running cannot be set to aborted: --set_status raises ValueError ("A running job cannot be marked as aborted..."). Use --abort_job to abort a running job; if the job is definitely not running, set it to success or failed first. Jobs in any other state, except one that is already Aborted, can be set to aborted. Setting a job to the status it already has raises ValueError.
The Python equivalent uses capitalized status strings:
proj.update_job_status('MotionCorr/job002/', 'Succeeded')
Valid values for update_job_status are: 'Succeeded', 'Failed', 'Aborted', 'Running', 'Scheduled'.
Job logs
run.out holds the job runner's timestamped progress messages together with the commands' raw stdout. run.err holds the commands' stderr plus any pipeliner tracebacks. At the start of each run, a timestamped block listing the job's commands, one per line, is appended to note.txt. These three files are your primary diagnostics for a failed job.
MotionCorr/job002/run.out # runner progress messages + command stdout
MotionCorr/job002/run.err # command stderr + pipeliner tracebacks
MotionCorr/job002/note.txt # the commands the job was started with
Example 1 — Run a motion correction job and wait for it to finish
import os
from pipeliner.api.manage_project import PipelinerProject
from pipeliner.api.api_utils import job_default_parameters_dict
os.chdir('/data/my_project') # project directory must be the cwd
proj = PipelinerProject() # open existing project
# Import parameters
import_params = job_default_parameters_dict('relion.import.movies')
import_params['fn_in_raw'] = 'Movies/*.tiff'
import_params['kV'] = '300'
import_params['Cs'] = '2.7'
import_params['Q0'] = '0.1'
import_params['angpix'] = '0.885'
import_job = proj.run_job(import_params, run_in_foreground=True)
# Motion correction depends on import output
motioncorr_params = job_default_parameters_dict('relion.motioncorr.own')
motioncorr_params['input_star_mics'] = import_job.output_dir + 'movies.star'
motioncorr_job = proj.run_job(motioncorr_params)
# Block until motion correction finishes before continuing
status = proj.wait_for_job_to_finish(
motioncorr_job.output_dir,
ping=5.0,
timeout=86400.0,
error_on_fail=True,
)
Example 2 — Schedule a pipeline and run it as a named schedule
from pipeliner.api.manage_project import PipelinerProject
from pipeliner.api.api_utils import job_default_parameters_dict
proj = PipelinerProject()
# Schedule each step without running
import_params = job_default_parameters_dict('relion.import.movies')
import_params['fn_in_raw'] = 'Movies/*.tiff'
import_params['kV'] = '300'
import_params['Cs'] = '2.7'
import_params['Q0'] = '0.1'
import_params['angpix'] = '0.885'
j_import = proj.schedule_job(import_params)
mcc_params = job_default_parameters_dict('relion.motioncorr.own')
mcc_params['input_star_mics'] = j_import.output_dir + 'movies.star'
j_mcc = proj.schedule_job(mcc_params)
ctf_params = job_default_parameters_dict('relion.ctffind.ctffind4')
ctf_params['input_star_mics'] = j_mcc.output_dir + 'corrected_micrographs.star'
# MotionCorr writes float16 micrographs by default, so CTFFIND must use the
# power spectra it saves; without this, schedule_job raises ValueError
ctf_params['use_given_ps'] = 'Yes'
j_ctf = proj.schedule_job(ctf_params)
# Run all three in sequence with a 5-second gap between each
proj.run_schedule(
fn_sched='spa_preprocessing',
job_ids=[j_import.output_dir, j_mcc.output_dir, j_ctf.output_dir],
nr_repeat=1,
minutes_wait=0,
seconds_wait_after=5,
)
Example 3 — Continue a 3D refinement job using get_continuation_job
from pipeliner.api.manage_project import PipelinerProject
proj = PipelinerProject()
# get_continuation_job auto-populates fn_cont with the latest optimiser file
cont_job = proj.get_continuation_job('Refine3D/job008/')
# Optionally adjust a parameter before running. Only options used by the
# continuation command take effect (particle_diameter, for example, does not)
cont_job.joboptions['nr_threads'].value = '4'
result = proj.run_job(cont_job)
print(result.output_dir)
Job can't be run with queue submission enabled: Job cannot be run because: File <path> not found
Symptom: run_job (or pipeliner --run_job) raises ValueError('Job cannot be run because:\nFile <path> not found') and no job is created.
Likely cause: Queue submission is enabled (do_queue == Yes) but the job's submission template option (qsubscript, the Standard submission script: line in a run.job file, whose default comes from the qsub_template setting) is empty or points to a missing file. run_job checks input files, including this template, before it creates the job. RuntimeError('Error starting job <dir>'), caused by ValueError('Error reading template submission script in: <path>'), only happens when a job that was already scheduled is started with run_scheduled_job() and its template can no longer be read; that job is then marked Failed.
Fix: Either provide a valid qsub template path in ~/.config/ccpem/pipeliner/ccpem-pipeliner-settings.json (Linux) or ~/Library/Application Support/ccpem/pipeliner/ccpem-pipeliner-settings.json (macOS) (this sets the default for jobs created afterwards; for an existing job file set qsubscript, or the Standard submission script: line in a run.job file), or set do_queue to No in your job parameters dict (in a run.job file the line is Submit to queue? == No; a do_queue line there is ignored).
ValueError: Cannot wait for completion when submitting jobs to a queue
Symptom: Calling run_job(..., run_in_foreground=True) raises ValueError('Cannot wait for completion when submitting jobs to a queue').
Likely cause: The job has do_queue set to Yes (either explicitly in the parameters dict or via the queue_use default, set by the PIPELINER_QUEUE_USE or RELION_QUEUE_USE environment variable or the settings file).
Fix: Set do_queue to No in the parameters dict before calling run_job, or turn off the queue_use default (unset PIPELINER_QUEUE_USE and RELION_QUEUE_USE, and set "queue_use": false in the settings file) before creating the job. run_in_foreground=True cannot override queue submission.
An edited value in a run.job file has no effect
Symptom: A job created from a run.job file uses a default value instead of the one you edited, or validation reports a required option as missing.
Likely cause: A label in the run.job file was edited and no longer matches the job's registered option label exactly. Lines are matched by label, character-for-character, including colons and capitalisation (e.g. Raw input files: for relion.import.movies input). A line that doesn't match is silently ignored, and the option keeps its default, with a no value for ... using default value warning logged.
Fix: Regenerate the run.job template with pipeliner --default_runjob <jobtype> and copy the exact label strings from the generated file.
ValueError: File <name> is not a valid STAR file
Symptom: edit_jobstar() raises ValueError saying the file is not a valid STAR file.
Likely cause: A run.job file (which uses label == value format) was passed as the fn_template argument instead of a job.star STAR file.
Fix: Use write_default_jobstar(jobtype) to generate a job.star template, then pass that to edit_jobstar. Use write_default_runjob(jobtype) and edit the resulting file manually if you need run.job format.
NotImplementedError when calling get_continuation_job
Symptom: proj.get_continuation_job('Select/job005/') raises NotImplementedError.
Likely cause: The job type does not support continuation (can_continue=False). This applies to all relion.select.* jobs, all relion.import jobs except relion.import.movies, all relion.joinstar.* jobs, and all CCP-EM atomic modelling jobs.
Fix: Rerun the job as a new job using run_job with updated parameters rather than continuing it.
ValueError when setting status to aborted via --set_status
Symptom: pipeliner --set_status MotionCorr/job002/ aborted raises ValueError.
Likely cause: The job is in Running state. A running job cannot be marked as aborted with --set_status; the error reads "ERROR: A running job cannot be marked as aborted. Try to abort the job instead, or if the job is definitely not actually running, set the status as Succeeded or Failed first." Jobs in any other state, except one that is already Aborted, can be set to aborted; setting a job to the status it already has raises ValueError ("Status of <job> is already Aborted").
Fix: Use --abort_job to abort a job that is actively running. If the job is not actually running (for example its process died), set it to success or failed first, then to aborted if needed.
RuntimeError: Trying to open pipeline … could not acquire lock after waiting for 60 seconds
Symptom: A PipelinerProject method or pipeliner CLI command that changes the project (for example run_job, --set_status or --set_alias) raises a lock timeout error after waiting 60 seconds. Read-only operations do not take the lock and still work.
Likely cause: Another process is holding the .relion_lock directory, or a previous process crashed and left the lock behind.
Fix: Run pipeliner.recover_project from the project directory. It removes the stale .relion_lock directory and restores default_pipeline.star from the most recent per-job backup:
pipeliner.recover_project
Or skip the confirmation prompt:
pipeliner.recover_project --assume-yes