# hydra_compose()

Compose a validation configuration with Hydra.

Usage

[Source](https://github.com/posit-dev/pointblank/blob/main/pointblank/hydra.py#L312-L409)

``` python
hydra_compose(
    config=None,
    overrides=None,
    config_dir=None,
)
```

## Parameters

`config: str | Path | None = None`  
The path to a YAML file to compose. Its `defaults:` list selects options from config groups, which are looked up in the file's directory, in `config_dir=`, and in the config trees that installed packages have put on the Hydra search path. Without a file, the configuration is made up of the groups selected in `overrides=`.

`overrides: Iterable[str] | None = None`  
Hydra overrides, such as `"pointblank/thresholds=strict"` to select a group option or `"thresholds.warning=0.2"` to set a value. These take precedence over the file.

`config_dir: str | Path | None = None`  
A directory to add to the search path.

## Returns

`dict`  
A configuration with the same keys as a plain YAML configuration. A mapping with a `_target_` key is left as it is, so nothing in the configuration is imported or run.

## Raises

`ImportError`  
If neither `hydra-core` nor `lerna` is installed.

`YAMLValidationError`  
If the configuration can't be composed, or the result isn't a valid configuration.

## Examples

Let's write a check collection and a configuration that selects it to a temporary directory. The configuration also selects the `small_table` dataset and the `strict` thresholds, which are options that come with Pointblank.

``` python
import pointblank as pb
import tempfile
from pathlib import Path

config_dir = Path(tempfile.mkdtemp())
(config_dir / "pointblank" / "checks").mkdir(parents=True)

(config_dir / "pointblank" / "checks" / "ids.yaml").write_text('''
# @package checks.ids
steps:
- col_vals_not_null:
    columns: ${vars.id_column}
''')

(config_dir / "small_table.yaml").write_text('''
defaults:
- override /pointblank/tbl: small_table
- override /pointblank/thresholds: strict
- override /pointblank/checks:
    - ids
- _self_

vars:
  id_column: a

steps:
- rows_distinct
''')

pb.hydra_compose(config_dir / "small_table.yaml")
```

    {'tbl': 'small_table',
     'thresholds': {'warning': 0.01, 'error': 0.05, 'critical': 0.1},
     'steps': [{'col_vals_not_null': {'columns': 'a'}}, 'rows_distinct']}

The result has the keys of a plain YAML configuration. The step of the collection comes before the step of the configuration, and `${vars.id_column}` has been replaced.

An override selects a different option of a group, or sets a value:

``` python
pb.hydra_compose(
    config_dir / "small_table.yaml",
    overrides=["pointblank/thresholds=lenient", "vars.id_column=b"],
)
```

    {'tbl': 'small_table',
     'thresholds': {'warning': 0.1, 'error': 0.25, 'critical': 0.35},
     'steps': [{'col_vals_not_null': {'columns': 'b'}}, 'rows_distinct']}

The thresholds are now those of the `lenient` preset, and the step of the collection checks column `b`. A composed configuration can be saved as a plain YAML file, or run with [`hydra_interrogate()`](../reference/hydra_interrogate.md#pointblank.hydra_interrogate).
