run_from_yaml

Note

This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the Habitat Guide and Python API guide (v2.0) for usage.

run_from_yaml(config_path: str | Path, *, workflow: str | None = None, save: bool = False, logger: Logger | None = None) → Any[source]

Run a YAML configuration document through the matching recipe.

This is the programmatic twin of the CLI. The document version is detected automatically: v1 documents (version: '1.0') are read directly for the habitat train/predict and ML train/cv workflows, while v0.1 documents are first translated through LegacyConfigAdapter.

Parameters:
  • config_path – Path to the YAML file. In v0.1 documents, relative paths inside the file resolve against the file’s directory; v1 documents use paths as written (current working directory).

  • workflow – Workflow alias (habitat, model, cv, compare, preprocess, icc, extract, radiomics, sort-dicom). When omitted, guessed from the path/name the same way as migrate_yaml().

  • save – When True, persist outputs under the config’s out_dir / output / output_dir the way the CLI does for habitat and ML workflows. Default is False so callers keep results in memory. Thin-delegation workflows (preprocess, icc, extract, radiomics, compare) always write through the v0.1 engines regardless of this flag.

  • logger – Optional logger forwarded to delegated v0.1 API paths.

Returns:

StudyResult for habitat train/predict, ModelResult or CVResult for ML train/K-fold, or WorkflowResult for comparison and thin-delegation workflows.

Raises:

Examples

Run the shipped v1 two-step demo exactly as the CLI would, writing outputs under the document’s output.out_dir:

>>> import habit.recipes as recipes
>>> result = recipes.run_from_yaml(  
...     "config/habitat/config_habitat_two_step_v1.yaml",
...     workflow="habitat",  # optional when the path names the workflow
...     save=True,
... )
>>> result.habitat_model.n_habitats >= 2  
True

A v0.1 document runs through the same call; it is translated to a v1 spec first:

>>> result = recipes.run_from_yaml(  
...     "config/habitat/config_habitat_two_step.yaml",
...     save=False,  # keep the StudyResult in memory
... )

Examples using habit.recipes.run_from_yaml

Quickstart: YAML

Quickstart: YAML