scaffold.hydra

Submodules

Functions

compose(→ omegaconf.DictConfig)

Alternative for hydra.compose, which differs in the following ways:

initialize(→ Iterator[hydra.core.global_hydra.GlobalHydra])

Context manager, that either uses an existing hydra instance, or initializes one temporarily.

Package Contents

scaffold.hydra.compose(config_name_or_class: str | scaffold.hydra.config_helpers.StructuredConfig, config_dir: str | None = None, overrides: List[str] | None = None, return_hydra_config: bool = False, check_missing: bool | None = False, return_leaf: bool | None = True) omegaconf.DictConfig

Alternative for hydra.compose, which differs in the following ways:

  1. No need to call hydra.initialize before composing a config, since this will use scaffold.hydra.initialize internally, which uses an existing instance if available.

  2. Is able to compose a config from a StructuredConfig class, which does not require the user to know the path in the config store, where the structured config was registered.

  3. Can check for missing values right away, instead of throwing an exception when trying to access them.

  4. Can automatically return the leaf node of the given config. When calling the original hydra.compose(“/my/grouped/config”), this results in a config with the keys config[“my”][“group”][…]. Setting return_leaf=True, scaffold.hydra.compose will automatically return the result of config[“my”][“group”] instead of adding all group keys.

Parameters:
  • config_name_or_class (Union[str, StructuredConfig]) – Path to the config in the config store, or StructuredConfig class. Passing an instance of StructuredConfig has the same effect, but will throw a warning if the instance arguments are not the same as the default ones.

  • config_dir (Optional[str] = None) – Optional absolute config directory to add to the search path.

  • overrides (List[str] = None) – Hydra overrides. See https://hydra.cc/docs/advanced/override_grammar/basic/.

  • return_hydra_config (bool = False) – If True, returns the hydra in the root of the config.

  • check_missing (Optional[bool] = False) – If True, will throw an exception if omegaconf.MISSING or ‘???’ values are present.

  • return_leaf (Optional[bool] = True) – If True, will return the leaf node of the config path inside the config store, so compose(“/my/grouped/config”) will return only the values in the “config” node or yaml, without still containing the group keys in the returned config.

Returns:

Rendered DictConfig.

scaffold.hydra.initialize(config_dir: str | None = None, job_name: str | None = 'app', exists_ok: bool | None = True) Iterator[hydra.core.global_hydra.GlobalHydra]

Context manager, that either uses an existing hydra instance, or initializes one temporarily.

Deprecated since version This: helper is no longer needed in most cases. Use hydra’s own hydra.initialize directly, or define configs with hydra_zen.builds() and hydra_zen.ZenStore which do not require manual initialization. This function will be removed in a future release.

Parameters:
  • config_dir (Optional[str]) – Absolute directory that should be added to the search path.

  • job_name (Optional[str]) – hydra.job.name which should be set.

  • exists_ok (Optional[bool]) – Do not fail if hydra is already initialized and yield GlobalHydra.instance().