Skip to content

Commit

Permalink
Document Hydra default OmegaConf resolver (#780)
Browse files Browse the repository at this point in the history
* Add doc for Hydra default OmegaConf resolvers

* Address comments

* Update website/docs/configure_hydra/Intro.md

Co-authored-by: Omry Yadan <[email protected]>

Co-authored-by: Omry Yadan <[email protected]>
  • Loading branch information
jieru-hu and omry authored Jul 22, 2020
1 parent 959f14d commit 650cfc8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions hydra/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def register(name: str, f: Any) -> None:
# calling it again in no_workers mode will throw. safe to ignore.
pass

# please add documentation when you add a new resolver
register("now", lambda pattern: strftime(pattern, localtime()))
register(
"hydra",
Expand Down
23 changes: 23 additions & 0 deletions website/docs/configure_hydra/Intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,26 @@ You can see the full Hydra config using `--cfg hydra`:
- *hydra.runtime.version*: Hydra's version
- *hydra.runtime.cwd*: Original working directory the app was executed from

## Hydra resolvers

Hydra supports [several OmegaConf resolvers](https://github.com/facebookresearch/hydra/blob/master/hydra/core/utils.py) by default.

### `now`
Creates a string representing the current time using [strftime](https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior).
For example, for formatting the time you can use something like`${now:%H-%M-%S}`.

### `hydra`
Interpolates into the `hydra` config node.
For example, use `${hydra:job.name}` to get the Hydra job name.

### `python_version`
Return a string representing the runtime python version by calling `sys.version_info`.
You can pass in a parameter to specify level of version returned. By default, the resolver returns the major and minor version.
```yaml
python_version: ${python_version:} # runtime python version, eg: 3.8
major_version: ${python_version:major} # runtime python major version, eg: 3
minor_version: ${python_version:minor} # runtime python version in the format major.minor, eg: 3.8
micro_version: ${python_version:micro} # runtime python version in the format major.minor.micro, eg: 3.8.2
```

You can learn more about OmegaConf <a class="external" href="https://omegaconf.readthedocs.io/en/latest/usage.html#access-and-manipulation" target="_blank">here</a>.

0 comments on commit 650cfc8

Please sign in to comment.