Running#
The same project runs on your computer or on an HPC cluster, and only the
execution section of config.yaml changes. We start every project on
a laptop or one node with a few releases, because a mistake shows up in
minutes there, and move it to Slurm once the results look right.
Where |
Use it when |
Setup |
|---|---|---|
Your computer |
You’re working in a notebook or script, or have up to a few hundred simulations. This is the default. |
Nothing |
You have thousands of simulations and access to an HPC cluster that uses Slurm. |
An |
|
You run many containers at once, such as a Kubernetes Job. |
A volume the containers share, and |
Run a project#
From the command line:
runtraj run ./my_project
From Python or a notebook:
import runtraj
project = runtraj.Project("./my_project")
project.run()
Both run every simulation that isn’t finished yet and return when they are
done. project.run() returns the status table of the simulations it ran,
one row per simulation with a state column. Both read and write the
same project folder, so you can mix them: run with runtraj run and
analyze in a notebook with runtraj.Project("./my_project").
A finished simulation is skipped, so running again only runs what is left.
--no-skip (project.run(skip_existing=False)) runs every simulation
again.
Use several CPU cores#
To run several releases at once, set cpus in the local block of
execution, which holds the settings of a run on this machine:
execution:
backend: local
local:
cpus: 4
or, for one run, runtraj run ./my_project --cpus 4. Each of the cpus
processes runs one release at a time, with all of that release’s
variants. Set it to the number of CPU cores you can spare, because each
HYSPLIT run uses one core. A Slurm run has its own cpus, per array task,
in the slurm block (On An HPC Cluster (Slurm)).
Each process gets its share of the cores as OMP_NUM_THREADS, 4 on a
16-core machine with cpus: 4, so a program that starts a thread per
core does not start 16 in each. To choose another value, export
OMP_NUM_THREADS before the run; runtraj keeps it.
A Python script that calls project.run() with cpus above 1 needs its
code under if __name__ == "__main__":. Python 3.14, macOS, and Windows
start each worker by importing the script again, so anything at the top of the
script runs again in every worker. Project.init there stops with a
FileExistsError because config.yaml exists. Put the run under the guard:
import runtraj
if __name__ == "__main__":
project = runtraj.Project("./my_project")
project.run()
runtraj run --cpus 4 and a cpus of 1 need no guard.
You can stop a run at any time with Ctrl-C (or SIGTERM from kill,
Slurm or Kubernetes). Releases that finished stay finished, and running
again starts the ones that were cut off from the beginning.
If a worker process is killed outright, most often by the kernel’s
out-of-memory killer, the run stops with an error
(WorkerDied) and runtraj run exits with 3. The pool
cannot say which release the worker held, so the error names every release
that was in progress. Nothing is marked failed and what finished stays
finished: run it again and only what is missing runs, with a lower cpus or
more memory per task if memory was the cause. The killed worker’s directory in
the compute root is not removed; clear it by hand.
Save now, run later#
Project.init and project.add_releases() save settings and
releases to the project folder without running anything.
add_releases returns the ids of the releases it added:
project = runtraj.Project("./my_project")
release_ids = project.add_releases(releases)
Any machine that can see the folder can then run the project. To run only the new releases, every variant of each, give their ids:
project.run(releases=release_ids)
runtraj run --releases ids.txt does the same from a file with one id
per line.
Commands#
runtraj check <project>List what would stop the project’s runs, before any run starts, such as met files a release’s run needs that are not there, a release outside the met’s crop, or what a stage finds missing. Nothing is run or downloaded. It exits with 0 when it finds nothing and 1 when it lists anything.
runtraj fetch <project>Get the met files the unfinished simulations need, then exit. A met with
downloaddownloads what is missing, cropped to its subgrid, so the runs that follow download nothing; a met without it is only checked for missing files.--releases FILEand--output DIRare as forruntraj run. It exits with 0 when every file is there, 1 when the archive lacks some, and 3 when it was stopped (Ctrl-C or SIGTERM) or the archive was busy or unreachable (Fetching the meteorology once).runtraj submitandruntraj runfetch first on their own: on Slurm in a job the array waits for (Met files that download), on Kubernetes in each pod in turn withfetch: true(Fetching the meteorology once), and locally before the workers start whencpusis above 1. Runruntraj fetchyourself to see whether the archive has every file before you submit, or before you start tasks withruntraj run --taskfrom another scheduler, which does not fetch first (In Containers (Kubernetes)).runtraj run <project>Run every unfinished simulation and wait until they are done, here or as a Slurm job array. Its options:
--backendand--n-workersoverrideconfig.yamlfor this run.--cpus NrunsNreleases at once. Ctrl-C orSIGTERMstops them all and exits with 3, as does a worker killed for memory.--no-skipreruns every simulation, finished or not.--releases FILEruns only the releases listed inFILE, one id per line.--output DIRuses another output directory thanconfig.yamlnames.--compute-root DIRis the compute root: each run gets a new workdir inDIR, removed after it succeeds. Projects can share one.--task I/Nruns taskIofNhere, as one task of a job array (In Containers (Kubernetes)).
runtraj submit <project>Submit the unfinished simulations to Slurm as a job array, and return as soon as it is submitted (On An HPC Cluster (Slurm)).
runtraj schedule <project>andruntraj tick <project>Run a project every hour on Kubernetes, for the sites in its
sites.csv:schedulemakes the CronJob, andtickis what each hour’s pod runs (Running every hour).runtraj status <project>Count finished and remaining simulations, and the failed ones by reason. List the settings folders in the output directory and which variants use them.
--jsonprints the same as JSON, for a program to read. Withbackend: kubernetes, it lists the project’s Jobs too (Submitting to Kubernetes).
Every command exits with 0 when all went well, 1 when some simulations
failed or runtraj check found something, and 3 when a run was stopped
before it finished, so a script can rerun on 3 (Exit codes lists
every code).
When a simulation fails#
A failed simulation doesn’t stop the others. The worker records why it
failed and goes on, and the next runtraj run tries it again.
runtraj status counts the failures by reason, and sim.failure and
sim.log say what went wrong in one. Checking A Run explains each
reason and what to do about it.