Skip to content

Pipeline specification and execution

A pipeline catalog is a user specification. KgPipe.build() resolves it into a KgPipePlan: concrete files, the port each file was bound to, the parameter values, and a fingerprint of that candidate. The catalog does not itself store the task DAG.

Catalog

The catalog schema version is kgpipe.pipeline/v1, written as the root schema key. That key is not a pipeline. Files that omit it still load as v1. An unknown schema value is rejected. experiments/examples/sample.yaml is a single-pipeline file in this form. experiments/examples/pipeline.conf is a larger catalog of the same dummy tasks (experiments/examples/src/kgpipe_examples/dummy_tasks.py). experiments/moviekg/pipeline.conf is the MovieKG catalog. Each entry declares inputs and output, so a JSON or text source still keeps an N-Triples seed. rdf_base and rdf_alt store their historical thresholds in parameters. The LLM entries keep LLM_MODEL in config because those tasks read DEFAULT_LLM_MODEL_NAME. connect defaults to auto.

schema: kgpipe.pipeline/v1

rdf_base:
    description: "Align source RDF with target KG"
    connect: auto
    inputs:
        source: {role: source, format: nt}
        seed: {role: seed, format: nt}
    output:
        result: {role: result, format: nt}
    parameters:
        entity_matching_threshold: 0.99
        relation_matching_threshold: 0.5
    tasks:
        - paris_entity_matching
        - paris_exchange
        - fusion_first_value
        - type_inference_ontology_simple

schema is the catalog version, not a pipeline. Existing files omit it and still load. A task is either a registry name or a step:

tasks:
    - name: paris_entity_matching
      parameters:
          entity_matching_threshold: 0.99

Load a catalog and run it through the public API:

from kgpipe import Pipeline

pipeline = Pipeline.from_yaml("pipeline.yaml", "rdf_base")
plan = pipeline.plan()
outcome = pipeline.run()

pipeline.validate() is the same load and plan step without run(). Invalid task names, backends, parameter types, and port combinations fail there. The same specification can be written in Python with Pipeline(...) or Pipeline.from_conf(...). Both compile to the plan above. See Python API.

build_from_yaml and validate_pipeline remain the loader Pipeline.from_yaml calls.

build_from_conf is the lower-level form when the files already exist as Data objects:

from kgpipe.generation.loaders import load_pipeline_catalog, build_from_conf
from kgpipe.common.models import Data, DataFormat

catalog = load_pipeline_catalog(path)
conf = catalog.root["rdf_base"]
seed = Data(path="seed.nt", format=DataFormat.RDF_NTRIPLES)
pipe = build_from_conf("rdf_base", conf, seed, data_dir)
plan = pipe.build(source=source, result=result, stable_files=True)

build_from_conf resolves task names through the registry and binds parameters onto each task that declares config_spec. It does not connect ports. That happens in build().

A step may set id, task (or name), parameters, inputs, outputs, backend, and backend_options. backend is python, docker, or remote. If the catalog asks for a backend the registered task does not have, load fails. backend_options is a free-form map for that backend; it is not part of the fingerprint.

Defaults, paths, and environment

Catalog-level defaults and env are reserved keys, not pipelines. Pipeline defaults overlay the catalog. build_from_yaml then overlays function arguments. Relative paths are resolved against the YAML file directory. File paths never enter plan.fingerprint.

schema: kgpipe.pipeline/v1

env:
    KGPIPE_THRESHOLD: "0.99"

defaults:
    data_dir: ./output
    source: ./data/source.nt
    seed: ${SEED_FILE:-./data/seed.nt}
    result: ./output/result.nt
    ontology: ./data/ontology.ttl

seed and target are the same slot. ${VAR} and ${VAR:-default} are expanded when the catalog loads. Bare $source, $seed, and $result are port refs and are not expanded. A missing variable without a default is an error. load_pipeline_catalog(..., environ=...) supplies the map; the default is os.environ overlaid on the catalog env block.

Auto-connect

connect: auto keeps a catalog that starts as [source, seed]. For each task, in input_spec order:

  • A port named kg is bound to the last catalog entry. Outputs are prepended, so that entry stays the seed.
  • Every other port takes the first entry whose format matches and that this task has not already used.
  • Outputs are new files in data_dir. The last task's output is result when build() was given one.
  • Those outputs are prepended, so the next task sees the newest artifact first.

The resolved plan records a ref for every port: $source, $seed, $result, or step_id.port. For rdf_base that is:

Step Inputs Output
paris_entity_matching source=$source, kg=$seed output=paris_entity_matching.output (paris.csv)
paris_exchange input=paris_entity_matching.output output=paris_exchange.output (er.json)
fusion_first_value source=$source, kg=$seed, matches1=paris_exchange.output output=fusion_first_value.output (nt)
type_inference_ontology_simple source=fusion_first_value.output result=$result

kg is part of the algorithm. fusion_first_value has two N-Triples inputs, and format matching alone cannot tell source from seed. Two inputs of the same format are bound newest-first: aggregate_2matches assigns json1 the newer er.json and json2 the older one.

kgpipe plan pipeline.conf rdf_base prints this wiring and the candidate fingerprint. kgpipe run pipeline.conf rdf_base --dry-run registers that plan in the system graph.

Explicit ports

The same refs can be written in the catalog. This is the form to use when auto-connect is ambiguous, or when the resolved plan is dumped back out. Bindings on a step require connect: explicit.

rdf_base:
    description: "Align source RDF with target KG"
    connect: explicit
    tasks:
        - id: match
          task: paris_entity_matching
          inputs: {source: $source, kg: $seed}
          outputs: {output: match.output}
        - id: exchange
          task: paris_exchange
          inputs: {input: match.output}
          outputs: {output: exchange.output}
        - id: fuse
          task: fusion_first_value
          inputs: {source: $source, kg: $seed, matches1: exchange.output}
          outputs: {output: fuse.output}
        - id: types
          task: type_inference_ontology_simple
          inputs: {source: fuse.output}
          outputs: {result: $result}

build() checks that every port exists on the task, that each ref is $source, $seed, $result, or an earlier step_id.port, and that the formats agree. $result is only valid on the last step.

Fingerprint

plan.fingerprint is a sha256 of the schema version, step id, task name, port refs, and resolved parameter values. Paths are not included, so the same candidate run in two directories has one fingerprint. Changing a parameter or a port ref changes it.

Search candidates

A parameter-search candidate is the same catalog entry. The search still samples a list of live KgTask objects and a ConfigurationProfile per task. build_candidate() writes that into a kgpipe.pipeline/v1 PipelineConf before build(). Task order is the task list. Parameter values are the profile bindings. connect stays auto.

from kgpipe.generation.loaders import build_candidate

pipe, conf = build_candidate(name, tasks, profiles, seed, data_dir)
plan = pipe.build(source=source, result=result, stable_files=True, configCatalog=pipe.config_catalog)

dump_pipeline_catalog() writes that entry as YAML, and load_pipeline_catalog() reads it back. pipeline_conf_from_plan() writes the resolved port refs as connect: explicit. Rebuilding either form produces the same task order, port refs, parameter values, and fingerprint.

The sampled RDF runs in data/kgpipe-experiment-results/parameter_search/rdf_sampled keep the older {task_keys, profiles} JSON beside the resolved plan. Those plans record the files that were wired together. Rebuilding the candidate from the JSON reproduces that wiring as $source, $seed, $result, and step_id.port, and it reproduces the cache filename of each intermediate file. The task tmp files themselves are not in this checkout.

Command line

validate, plan, and exec are the CLI for one catalog entry. They call Pipeline.validate, Pipeline.plan, and Pipeline.run. A file with one pipeline does not need a name. Repeat --package or --module-path to import the tasks that entry names. --input / --source, --seed / --target, --result, --output / --data-dir, and --ontology override the catalog paths.

kgpipe validate experiments/examples/sample.yaml \
  --module-path experiments/examples/src/kgpipe_examples/dummy_tasks.py

kgpipe plan experiments/examples/pipeline.conf dummy_auto \
  --module-path experiments/examples/src/kgpipe_examples/dummy_tasks.py

kgpipe exec experiments/examples/sample.yaml \
  --module-path experiments/examples/src/kgpipe_examples/dummy_tasks.py \
  --input ./data/source.nt --seed ./data/seed.nt \
  --result ./output/result.nt --data-dir ./output

kgpipe exec experiments/examples/sample.yaml --dry-run \
  --module-path experiments/examples/src/kgpipe_examples/dummy_tasks.py

--dry-run resolves the plan and does not run tasks. --force runs a task again when its outputs are already on disk.

Relative paths in the catalog, and relative --input, --seed, --result, --output / --data-dir, and --ontology values, resolve against the catalog file. The same command works from any working directory, and a path written in the YAML means the same file as the same path passed on the command line. Pipeline.from_yaml uses that directory as base_dir. An absolute path is used as given.

stdout is the requested result. In the default text format that is the status, fingerprint, attempt id, report path, ports, and one line per task report. --format json and --format yaml print only that document. stderr is progress: one line per task (Running sample match dummy_match) and a status line (exec: sample success). The first word after Running is the pipeline, so parallel jobs stay distinct. --quiet hides progress and the success line. Errors stay on stderr. --verbose adds resolved paths, discovery notes, and tracebacks.

The durable result is not stdout. Each attempt writes report.json (kgpipe.execution/v1), summary.txt, plan.json, and artifacts.json under <data-dir>/runs/<attempt-id>/. fingerprint is the resolved configuration. run_id and attempt_id identify this execution and are different values. The same candidate run twice has one fingerprint and two attempt ids. artifacts.json lists file URIs and sha256 checksums for the inputs, outputs, logs, and the report itself. discover_artifacts reads those files.

A task whose outputs are already on disk is not run again. Both streams mark that as cached (Skipping sample match dummy_match cached, and skipped sample cached on stdout). --force ignores the cache. Importing KGpipe does not configure the root logger or create a log file. Each task that runs writes logs/<step-id>.log inside that attempt directory, including Docker stdout and stderr and the traceback on failure. The report's log field is that path. A cached task does not write a new log. A failed or interrupted attempt still leaves its directory. The report is running until the attempt finishes, so a hard stop leaves that directory in place.

Exit Meaning
0 The plan resolved, or execution succeeded or skipped
1 A task failed, or execution stopped
2 The catalog, task name, parameters, or ports are invalid

kgpipe run PIPELINE_FILE --dry-run still registers the plan in the system graph. Execution is kgpipe exec.

Execution

run() executes plan.steps in order. Each task receives the files build() chose. A task is skipped when its output files already exist, unless stable_files_override=True. A skipped report has reason == "cached". A task that runs sets log_path to logs/<step-id>.log inside the attempt directory (data_dir/runs/<attempt_id>/, or run_dir when that argument is set). The returned PipelineRun includes the execution report. load_report(outcome.report_path) reads it back. Optimization and orchestration use the same schema with kind set to optimization or orchestration; parent_run_id links a pipeline attempt to that parent.

reports = pipe.run()
for report in reports:
    print(report.task_name, report.status, report.duration)

Replacing pipe.tasks[i] requires another build() before run(). The new plan re-resolves the ports.

Independent jobs

execute_jobs runs pipelines that do not depend on each other. Steps inside one pipeline stay in order. A search strategy that picks the next candidate from earlier scores submits one job at a time. A strategy that already chose an independent set — a random sample, an initial population, or a fixture list with one directory per candidate — can submit that set together.

Each job is a JobSpec: a PipelineConf, the files it reads and writes, and its own data_dir. Tasks are registry names. modules or module_paths imports them before the job runs. The worker cap defaults to parallel_jobs in the KGpipe config, which is 1, so the batch runs in the current process. A cap above 1, a wall-clock timeout, a CPU-time limit, or a CancelToken runs each job in a spawned process. Parallel jobs must use different data directories. A shared directory is rejected before any task runs. Attempt logs stay under that job's runs/<attempt-id>/.

A batch of more than one job writes an orchestration report (kind is orchestration) and sets parent_run_id on each pipeline attempt. The report records limits (max_workers, and timeout_s or cpu_time_s when set) and provenance.backend (local or local-process). A task or process failure is failed with error_type. A wall-clock timeout is failed with TimeoutError. Cancelling the batch marks jobs that have not finished as interrupted and leaves a finished job unchanged. Results come back in submission order.

from kgpipe.execution import JobSpec, execute_jobs
from kgpipe.generation.spec import PipelineConf

jobs = [
    JobSpec(
        name="one",
        conf=PipelineConf(description="one", tasks=["copy_triples"]),
        source="one/source.nt",
        seed="one/seed.nt",
        result="one/result.nt",
        data_dir="one/work",
        module_paths=["pkg/tasks.py"],
    ),
]
batch = execute_jobs(jobs, max_workers=2)
print(batch.runs[0].status, batch.runs[0].report_path)

A search candidate uses the same job. pipeline_conf_from_candidate builds the PipelineConf, and the job points it at an isolated data directory.

Search and kgpipe search run a parameter domain this way. One catalog and one --parameter domain replace a catalog copy per value. The search report is kind: optimization. Each assignment's attempt sets parent_run_id to that search. See Parameters.