Skip to content

runner_utils

runner_utils

PyAERMOD runner UX helpers.

Additions on top of runner.py / BatchRunner:

  • extract_errmsg / tail_output / summarize_failure: pull useful diagnostics from AERMOD's ERRMSG.TMP and .OUT files when a run fails.
  • ProgressReporter protocol with TqdmProgress (if tqdm is installed) and LoggingProgress / NoOpProgress fallbacks.
  • resume_batch: given a list of input files and an output dir, return which already have valid .out files and which still need to run.
  • RunManifest: JSON-backed batch state for resume / inspection.
  • generate_slurm_script: produce a SLURM job-array template for a directory of .inp files.

ERRMSGInfo dataclass

Parsed contents of AERMOD's ERRMSG.TMP (or equivalent).

NoOpProgress

Silent progress reporter.

LoggingProgress

Progress reporter that emits INFO-level log lines.

TqdmProgress

Progress reporter using tqdm. Only works if tqdm is installed.

RunManifest dataclass

Tracks a batch's per-run state in a JSON file.

Use-cases: - Persist partial batch progress across restarts - Post-hoc inspection of which inputs succeeded / failed

A subclass can store richer entries by setting entry_type to a subclass of :class:RunManifestEntry, as :class:pyaermod.ensemble.EnsembleManifest does. load builds entries of that type and ignores keys it does not know, so a file written with more fields still loads. save replaces the file in one step, so a process killed while saving leaves the previous file whole.

extract_errmsg

extract_errmsg(path: Union[str, Path]) -> Optional[ERRMSGInfo]

Parse an AERMOD ERRMSG.TMP-style file.

Returns None if the file doesn't exist.

tail_output

tail_output(path: Union[str, Path], n_lines: int = 40) -> List[str]

Return the last n_lines of a file as a list of strings.

summarize_failure

summarize_failure(input_file: Union[str, Path], working_dir: Union[str, Path]) -> str

Return a human-readable failure summary.

Gathers ERRMSG.TMP content plus the tail of the .OUT file.

resume_batch

resume_batch(input_files: Sequence[Union[str, Path]], output_dir: Union[str, Path]) -> Dict[str, List[Path]]

Partition input_files into 'done' and 'todo' lists.

An input is 'done' when its <stem>.out in output_dir records a successful run by the rule AERMODRunner.run applies (AERMOD's *** AERMOD Finishes Successfully *** line and no fatal errors in its final message summary), and that .out came from the deck as it is now: the runstream AERMOD copies to the top of the .out must match the deck's text. Everything else is 'todo': no .out, a run that failed or was cut off (killed, timed out), and an .out from before the deck was edited.

Because the check reads content, a script may write every deck again before it resumes: a deck rewritten with the same text stays 'done', whatever the file times say. File times decide only what the copy cannot show. A deck with NO ECHO is 'todo' when it is newer than its .out, and so is a deck whose INCLUDED file (looked up relative to the deck's directory) is newer than its .out. The met files and other inputs a deck names are not checked.

generate_slurm_script

generate_slurm_script(input_files: Sequence[Union[str, Path]], output_dir: Union[str, Path], script_path: Union[str, Path], input_list_path: Union[str, Path], *, aermod_exe: str = 'aermod', job_name: str = 'pyaermod', log_dir: str = 'logs', partition: str = 'general', cpus: int = 1, mem: str = '4G', wallclock: str = '02:00:00', max_concurrent: Optional[int] = None) -> Path

Write a SLURM job-array script + input-list file for a batch.

Returns the path to the generated script.