meridian_tools.runner
Pipeline orchestration for meridian-tools.
Module: meridian_tools.runner
Functions
run_pipeline
Execute the full meridian-tools staged pipeline.
The pipeline proceeds through the following stages in order:
00_run_metadata— Archive source and resolved configs and writeinput_data_provenance.json.10_validation— Write validation spec (if validation-aware).20_model_fit— Build input data, construct the Meridian model, sample prior and posterior.30_model_assessment— Export diagnostics, model summary, and model selection outputs.40_decomposition— Export summary metrics.60_response_curves— Export response curves (if configured).70_optimisation— Export optimisation results (if configured).
The manifest is written to disk after each stage, so a failure mid-pipeline leaves a readable partial manifest.
Before creating the dated run directory, the runner enforces three separate pre-run checks:
- dependency preflight (
google-meridian[schema], optional plot support) - validation-execution contract checks for incompatible single-run validation combinations
- a narrow wrapper-owned config/data preflight over the resolved input file and authored column mapping
The wrapper-owned preflight checks exactly:
- resolved
data.pathexists and is a regular file - the CSV header row can be read
- the parsed header is non-empty
- no parsed header cell is blank after trimming whitespace
- every authored scalar entry in
data.coord_to_columnsexists in the header - every authored list member in
data.coord_to_columnsexists in the header - every authored key in
media_to_channel,media_spend_to_channel,reach_to_channel,frequency_to_channel,rf_spend_to_channel,organic_reach_to_channel, andorganic_frequency_to_channelexists in the header - authored list-valued coord families are non-empty
- authored mapping fields above are non-empty
- supported media/RF family groups are complete when authored
Header matching is exact and case-sensitive. Anything outside this closed matrix remains Meridian-owned validation.
Parameters:
run_config— APipelineRunConfigspecifying the execution config path, output directory, run name, optional validation spec, and optionalsource_config_pathfor metadata archival.progress_callback— Optional callable invoked on stage lifecycle events. The callback receives keyword arguments:stage_name(str) — stage identifier.event(str) — one of"started","completed","skipped", or"failed".stage_index(int) — 1-based position in the pipeline.stage_count(int) — total number of stages.elapsed_seconds(float) — wall-clock time (present for"completed"and"failed"events).message(str) — human-readable detail (present for"skipped"and"failed"events).
Returns: A PipelineRunResult with the run directory and manifest path.
Raises:
RuntimeErrorif Meridian schema support is unavailable (checked at preflight before the run directory is created).RuntimeErrorifexports.export_plotsistruebutvl-convert-pythonis not installed (also checked at preflight).ValidationExecutionContractErrorif the requested single-run validation execution path is incompatible with the authored config.ConfigPreflightErrorif wrapper-owned config/data preflight fails before run-directory creation.PipelineRunFailureif any exception occurs after the dated run directory already exists.
Example:
Classes
PipelineRunResult
Disk locations for one completed meridian-tools run.
| Attribute | Type | Description |
|---|---|---|
run_dir |
Path |
Absolute path to the run directory. |
manifest_path |
Path |
Absolute path to run_manifest.json. |
ValidationExecutionContractError
Raised when the requested single-run validation execution path is incompatible
with the authored config. Current examples include direct rolling_origin
execution through run_pipeline(...) and combining
PipelineRunConfig.validation_spec with authored
model_spec.kwargs.holdout_id.
ConfigPreflightError
Raised when the wrapper-owned Phase 10 preflight fails before run-directory creation. This covers only the closed wrapper preflight boundary, not full Meridian model validation.
PipelineRunFailure
Raised when a run fails after the dated run directory already exists.
The original underlying exception is preserved via __cause__.
| Attribute | Type | Description |
|---|---|---|
run_dir |
Path |
Absolute failed run directory. |
manifest_path |
Path |
Absolute path to the failed run manifest. |
stage_name |
str | None |
Failing stage name when one is available. |
Constants
Stage names
| Constant | Value |
|---|---|
STAGE_RUN_METADATA |
"00_run_metadata" |
STAGE_VALIDATION |
"10_validation" |
STAGE_MODEL_FIT |
"20_model_fit" |
STAGE_MODEL_ASSESSMENT |
"30_model_assessment" |
STAGE_DECOMPOSITION |
"40_decomposition" |
STAGE_RESPONSE_CURVES |
"60_response_curves" |
STAGE_OPTIMISATION |
"70_optimisation" |
PIPELINE_STAGE_ORDER
The numbering gap at 50 is intentional, reserving space for future stages.