Skip to content

Commit

Permalink
Add documentation about the combined use of $globals and `$runtime_…
Browse files Browse the repository at this point in the history
…params` (#3861)

* Added globals with runtime params example

Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>

* Fixed typos

Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>

* build: use new exclude_also over exclude_lines (#3850)

Signed-off-by: Deepyaman Datta <deepyaman.datta@utexas.edu>

* Removed changes merged by mistake

Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>

* Changed yaml -> yml

Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>

* Removed changes merged by mistake

Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>

* Removed changes merged by mistake

Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>

---------

Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>
Signed-off-by: Deepyaman Datta <deepyaman.datta@utexas.edu>
Co-authored-by: Deepyaman Datta <deepyaman.datta@utexas.edu>
  • Loading branch information
ElenaKhaustova and deepyaman committed May 10, 2024
1 parent daf1c01 commit 9b0195b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
25 changes: 25 additions & 0 deletions docs/source/configuration/advanced_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,31 @@ companies:
```
If the `folder` parameter is not passed through the CLI `--params` option with `kedro run`, the default value `'data/01_raw/'` is used for the `filepath`.

#### How to use `globals` and `runtime_params`

As mentioned above, `runtime_params` are not designed to override `globals` configuration. This is done to avoid unexplicit overrides and to simplify parameter resolutions. Thus, `globals` has only one entry point - the `yaml` file.

However, you can use `globals` and `runtime_params` by specifying `globals` as a default value to be used in case the runtime parameter is not passed.

Consider this `parameters.yml`:
```yaml
model_options:
random_state: "${runtime_params:random, ${globals:my_global_value}}"
```

and this `globals.yml` file:

```yaml
my_global_value: 4
```

This will allow you to pass a runtime parameter named `random` through the CLI to specify the value of `model_options.random_state` in your project's parameters:
```bash
kedro run --params random=3
```

If the `random` parameter is not passed through the CLI `--params` option with `kedro run`, then `my_global_value` from `globals.yml` is used for the `model_options.random_state`.

### How to use resolvers in the `OmegaConfigLoader`
Instead of hard-coding values in your configuration files, you can also dynamically compute them using [`OmegaConf`'s
resolvers functionality](https://omegaconf.readthedocs.io/en/2.3_branch/custom_resolvers.html#resolvers). You use resolvers to define custom
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dynamic = ["readme", "version"]
[project.optional-dependencies]
test = [
"behave==1.2.6",
"coverage>=7.2.0",
"coverage[toml]",
"import-linter==2.0",
"ipylab>=1.0.0",
"ipython>=7.31.1, <8.0; python_version < '3.8'",
Expand Down Expand Up @@ -88,7 +88,7 @@ jupyter = [
"ipylab>=1.0.0",
"notebook>=7.0.0" # requires the new share backend of notebook and labs"
]
all = ["kedro[test,docs,jupyter]"]
all = [ "kedro[test,docs,jupyter]" ]

[project.urls]
Homepage = "https://kedro.org"
Expand Down Expand Up @@ -129,7 +129,7 @@ omit = [
"kedro/runner/parallel_runner.py",
"*/site-packages/*",
]
exclude_also = ["raise NotImplementedError"]
exclude_lines = ["pragma: no cover", "raise NotImplementedError"]

[tool.pytest.ini_options]
addopts="""
Expand Down

0 comments on commit 9b0195b

Please sign in to comment.