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 throughLegacyConfigAdapter.- 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 asmigrate_yaml().save – When
True, persist outputs under the config’sout_dir/output/output_dirthe way the CLI does for habitat and ML workflows. Default isFalseso 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:
StudyResultfor habitat train/predict,ModelResultorCVResultfor ML train/K-fold, orWorkflowResultfor comparison and thin-delegation workflows.- Raises:
HABITAPIError – When the workflow cannot be determined or translation fails.
NotImplementedError – When the workflow is not routed by
run_from_yaml.FileNotFoundError – When
config_pathdoes not exist.ValueError – When the translated document or on-disk inputs are invalid.
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 ... )