Architecture#
This page says how runtraj is put together: what a project is, how a run
goes from a project to result files, and how runtraj knows which work is
finished. AGENTS.md at the repository root has the same in brief, with
the rules a change must keep.
The design in brief#
There is no index, manifest, or registry. A project is a directory of
inputs (runtraj.Project: config.yaml and releases.csv) and
an output directory (runtraj.output.Output) that config.yaml
names and several projects can share. Its simulations are its releases
crossed with its variants. Each Variant has run
settings, whose hash names its particles folder, and the settings of each
stage it uses, hashed with what the stage reads (runtraj.identity).
Variants with equal run settings share one run per release, and a changed
setting hashes to a new folder (Output Layout).
A project reads; the workers write results. A project writes only its
inputs and knows no scheduler: runtraj.execution.run() and
runtraj.execution.submit() start the workers. The tables a project
gives (project.releases, project.simulations) are plain pandas
DataFrames, and a selection of rows goes back to the project’s methods
(status, incomplete, particles).
A transport model and a stage are classes named by import path.
config.yaml names a model in another package, and each stage, by the
import path of its class, so the config, the settings records, the output
directory and the worker reach them without importing them by name. A
model provides runtraj.models.TransportModel; a stage, which
makes one file per release after the model runs, provides
runtraj.stages.Stage. HYSPLIT is the model built in, and its
package (runtraj.models.hysplit) is the only code that knows
HYSPLIT’s files.
Module map#
src/runtraj/
cli.py the runtraj command
project.py Project: inputs, the simulations table, run and submit, status
check.py what would stop a project's runs, from its inputs
fetch.py gets the met files the unfinished simulations need
output.py Output: the output directory; completed, the completion rule
simulation.py Simulation: a frozen (release, variant, output) value
config.py ProjectConfig and Variant
identity.py settings records and hashes
stages.py the Stage protocol, get_stage, check_stage
releases/ release classes, releases.csv, shared validation
particles/ the particle table and files, release heights, particles.runtraj
models/ the TransportModel and TransportConfig protocols, MODELS, get_model, check_model
hysplit/ config, met, catalog, driver, CONTROL and SETUP.CFG writers, failures
execution/ ExecutionConfig, the runner (plan, local run, Slurm submit), the worker,
kubernetes (the indexed Job, the hourly CronJob), inputs (copies to a bucket, the lock), schedule
transforms/ particle transforms, each multiplying the weight column
sampling.py sample_field, sample_met, calc_pbl_height: fields and met read at points
meteorology.py, spatial.py, visualization.py, exceptions.py
The import contracts in pyproject.toml (just imports) hold this
shape: the modules are in layers, only runtraj.models imports a
transport model’s package (such as HYSPLIT’s, runtraj.models.hysplit),
no model’s package imports another’s, and the project config reads no
results and runs nothing.
How a run goes#
A run (runtraj run, runtraj.Project.run(),
runtraj.Project.submit()) happens in this process or as a Slurm job
array whose tasks each run runtraj run --task i/N. The unit of work is a
release: the worker runs the model once per run-settings hash, then each
missing stage file of the variants that share the particles, a stage after
the ones it reads. A Slurm task rebuilds the project in another process, so
anything a worker needs must be in the project or the output directory.
How runtraj tracks finished work#
Completion is by file. A simulation is complete when the model’s output
file exists, and so does the file of every stage its variant uses.
runtraj.output.completed() is the one rule, read from folder listings.
A failure record (<release id>.failure.yaml in the logs) is a note,
removed when the result is written and never read by completion.
Identity is content. A results folder is named from the settings that made it, so runtraj never deletes or overwrites one: a changed setting makes a new folder beside the old.