From 650cfc8ae2ac124e43cf78fff9f0d90daed8c74b Mon Sep 17 00:00:00 2001 From: Jieru Hu Date: Wed, 22 Jul 2020 02:14:48 -0700 Subject: [PATCH] Document Hydra default OmegaConf resolver (#780) * Add doc for Hydra default OmegaConf resolvers * Address comments * Update website/docs/configure_hydra/Intro.md Co-authored-by: Omry Yadan Co-authored-by: Omry Yadan --- hydra/core/utils.py | 1 + website/docs/configure_hydra/Intro.md | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/hydra/core/utils.py b/hydra/core/utils.py index 4f2447630fb..ea9dffdaf4b 100644 --- a/hydra/core/utils.py +++ b/hydra/core/utils.py @@ -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", diff --git a/website/docs/configure_hydra/Intro.md b/website/docs/configure_hydra/Intro.md index 1246619476c..3de0e33290f 100644 --- a/website/docs/configure_hydra/Intro.md +++ b/website/docs/configure_hydra/Intro.md @@ -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 here.