Created
March 24, 2023 19:25
-
-
Save noklam/45e32c6a60264a20fff2d8fdbe21dda0 to your computer and use it in GitHub Desktop.
An example to understand how merging work with omegaconf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Experiment 2 - Simplified Merge Config Case | |
%%writefile base.yml | |
# conf/local/parameters.yaml | |
client: | |
url: http://${host}:${server.port}/ | |
server_port: ${server.port} | |
%%writefile local.yml | |
server: | |
host: localhost | |
port: 80 | |
env_config = OmegaConf.load('base.yml') | |
base_config = OmegaConf.load('local.yml') | |
# Roughly what happens in `load_and_merge_dir_config` | |
env_config = dict(env_config) | |
base_config = dict(base_config) | |
config = base_config.copy() | |
config.update(env_config) | |
config | |
config["client"]._parent # It can't see the other keys merge from the dictionary | |
config["client"].host | |
%%writefile test.yml | |
server: | |
host: localhost | |
port: 80 | |
client: | |
url: http://${server.host}:${server.port}/ | |
server_port: ${server.port} | |
one_config = OmegaConf.load("test.yml") | |
one_config["client"]._parent | |
OmegaConf.to_container(one_config, resolve=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment