Execution#

Most users only need project.run(), project.submit(), or runtraj run (Running). The functions below do the work underneath.

  • run() is what project.run() calls. It finds the releases with missing results, runs them, and waits until they finish. task=(i, n) runs share i of n here (task_share()), which is what runtraj run --task i/n does.

  • submit() is what project.submit() calls. It writes a job array script (job_script()) whose tasks each run runtraj run --task, submits it with sbatch, and returns the job id at once. With backend: kubernetes it makes an indexed Job instead (job_manifest()) and creates it with kubectl.

  • schedule_job() is what runtraj schedule calls: a CronJob (cron_job_manifest()) whose pod each hour runs runtraj tick, which adds the hours now due (add_due_releases()) and runs them.

  • run_result() runs the transport model for one Simulation and writes its particles and log.

  • run_stages() runs the stages of the variants that share those particles: each stage file that is missing, in the order the stages read one another, and each again when what it reads was made again. run_stage() runs one, which writes its own file.

  • run_release() runs every variant of one release, skipping what exists. Variants that share particles run the transport model once and run their stages on the particles in memory. A failure is recorded with the simulation (runtraj.Simulation.failure). Workers are always handed releases.

  • run_releases() runs a list of releases, in this process or in a process pool.

On Slurm each task of the job array runs one share of the releases (task_share()) with runtraj run --task. A local run happens in this process. A program that starts the tasks itself, on another scheduler, writes pending() to the releases.txt each task reads (runtraj run --releases); wait() waits for a Slurm job array by its id.

Running#

runtraj.execution.run

Run every simulation of a project that has not finished, and wait for it.

runtraj.execution.submit

Submit every simulation of a project that has not finished to Slurm or Kubernetes.

runtraj.execution.pending

Return the ids of the releases a run would run, each once, in project order.

runtraj.execution.wait

Wait until every task of a Slurm job array has ended, and return how each ended.

runtraj.execution.task_share

Return task task's share of release_ids, split n_tasks ways.

Workers#

Internal: importable from their modules, and free to change.

runtraj.execution.runner.resolve_compute_root

Return the compute root of project: the directory its workdirs are made in.

runtraj.execution.worker.run_result

Run the transport model for a simulation and write its result to the output directory.

runtraj.execution.worker.run_stage

Run one stage of a simulation, which writes its file to the output directory.

runtraj.execution.worker.run_stages

Run the stages of the simulations of one release that share particles, and return what failed.

runtraj.execution.worker.run_release

Run every simulation of one release, and return what did not complete.

runtraj.execution.worker.run_releases

Run a list of releases, in this process or in a process pool.

Slurm job arrays#

runtraj.execution.job_script

Return the sbatch script of a job array whose tasks each run a share of the releases.

runtraj.execution.fetch_script

Return the sbatch script of the job that gets the met files before a job array.

Kubernetes indexed Jobs#

runtraj.execution.kubernetes.job_manifest

Return the indexed Job that runs a project in n_tasks pods, as a Kubernetes manifest.

runtraj.execution.kubernetes.submit_job

Make the indexed Job that runs pending releases, and return its name.

runtraj.execution.kubernetes.project_jobs

Return the summaries of a project's Jobs on the cluster, oldest first (job_summary()).

runtraj.execution.kubernetes.job_summary

Return what runtraj status shows of one Job, from kubectl get jobs -o json.

runtraj.execution.runner.fetch_shared

Get the met files of every unfinished simulation, one task at a time, before this task's share runs.

runtraj.execution.inputs.push

Copy a project's inputs to url.

runtraj.execution.inputs.pull

Copy a project's inputs from url into directory, the reverse of push().

runtraj.execution.inputs.hash_inputs

Return a content hash of a project folder's config.yaml and releases.csv.

Running every hour#

runtraj.execution.kubernetes.schedule_job

Make the CronJob that runs a project every hour, for the sites in its sites.csv, and return its name.

runtraj.execution.kubernetes.cron_job_manifest

Return the CronJob that runs runtraj tick for a project every hour.

runtraj.execution.kubernetes.cron_job_name

Return the name of a project's CronJob: runtraj-<name>-<hash>.

runtraj.execution.schedule.add_due_releases

Add the releases now due to a project's releases.csv, and return the ids of all that are due.

runtraj.execution.schedule.due_hours

Return the hours a tick at now covers, oldest first, in UTC.

runtraj.execution.schedule.read_sites

Return the sites in a project's sites.csv.

runtraj.execution.schedule.hourly_releases

Return a release at each site at each hour, hour by hour.

runtraj.execution.schedule.check_now

Return now in UTC without a time zone, or the clock's time when it is None.

runtraj.execution.inputs.lock

Hold a lock on the file name at url while the with block runs.

runtraj.execution.inputs.get

Copy one file from url into a project folder, the reverse of put().

runtraj.execution.inputs.put

Copy one file of a project folder to url, such as a releases.csv that grew.

Transport model#

The worker runs a simulation through the transport model its settings name. HYSPLIT is the one built in, and CONTRIBUTING describes how to add another, named by its import path. A model fails a run that its meteorology does not cover, as MET_COVERAGE. Particles that all leave the met’s domain before the end of the run are a complete run. Use check_model() in the tests of a model of your own.

runtraj.models.TransportModel

A transport model that follows particles from a release.

runtraj.models.BatchedTransportModel

A transport model that runs many releases in one call, such as an emulator on a GPU.

runtraj.models.TransportConfig

The base of every transport model's config.

runtraj.models.ModelRun

What one model run produced.

runtraj.models.get_model

Return the transport model name names.

runtraj.models.run_model

Run the transport model called name for one release, and finish its result.

runtraj.models.run_model_many

Run a batched transport model once for many releases, and finish each one's particles.

runtraj.models.open_met

Return the met files of a run of the transport model name as runtraj.sampling reads them.

runtraj.models.check_model

Check that model keeps the promises runtraj relies on, for one config.

runtraj.models.hysplit.HysplitModel

HYSPLIT as a transport model, the object get_model("hysplit") returns.

Stages#

A stage makes one file per release from a simulation’s results, after the transport model runs. PYSTILT’s footprint is one (stilt.footprint.FootprintStage). A stages block of config.yaml names its stage’s class by import path, so a stage in a package of your own needs no registration, and CONTRIBUTING describes how to write one. Use check_stage() in its tests.

runtraj.stages.Stage

What is made from each simulation's results: one file per release.

runtraj.stages.get_stage

Return the stage whose class is at the import path path, made with no arguments.

runtraj.stages.ordered

Return the names of stages in the order they run: each after the stages it reads.

runtraj.stages.check_stage

Check that stage keeps the promises the worker and the output directory rely on, for one config.