omegaconf | The last one | Configuration Management library
kandi X-RAY | omegaconf Summary
kandi X-RAY | omegaconf Summary
OmegaConf is a hierarchical configuration system, with support for merging configurations from multiple sources (YAML config files, dataclasses/objects and CLI arguments) providing a consistent API regardless of how the configuration was created.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Update the value of a key in the cfg
- Parse the given value into a grammar rule
- Split a key into a list
- Merge multiple configs together
- Merge this container with other
- Return the type of the given class or object
- Parse a config value
- Convert a Config object to a dict
- Return the content of the configuration
- Return a tuple containing the value of a key
- Convert a Config object into a dictionary
- Dereference the node
- Insert an item into the list
- Removes a value from the config
- Safely merge two configs
- Update a key in a nested dict
- Mark a key as deprecated
- Visit the interpolation node
- Merge two configurations
- Clean up files and directories
- Sort the list
- Removes the value at index
- Visit interpolation resolver
- Return the resolver name as a string
- Test notebook on Python 3
- Convert a configuration object into a python object
- Convert a Config object into a dict
- Invalidate flags cache
- Decode the given expression into a Python value
- Gets a value from the list
- Test whether a key is in the config file
- Merge this container into another container
omegaconf Key Features
omegaconf Examples and Code Snippets
import torch
from unittest import mock
from typing import List
import pytorch_lightning.cli as pl_cli
from pytorch_lightning import LightningModule, LightningDataModule, Trainer, Callback
class NoFitTrainer(Trainer):
def fit(self, *_, **__):
from monet_pytorch import Monet
monet = Monet.from_config(model='monet')
from monet_pytorch import Monet
monet = Monet.from_config(model='monet', dataset='tetrominoes')
from monet_pytorch import Monet
monet = Monet.from_config(model='monet', dat
python my_scripy.py MY_PATHS="[a,b,c]"
conf = OmegaConf.structured(ConfDef())
cli_conf = OmegaConf.from_cli()
conf = OmegaConf.merge(conf, cli_conf)
print("\n\nCONFIGURATION:")
print(OmegaConf.to_yaml(conf), end="\
# config.yaml
arg1: numpy.float32 # note: use "numpy" here, not "np"
arg2: tensorflow.float16
# python code
...
from hydra.utils import get_class
arg1 = get_class(config.arg1)
arg2 = get_class(config.arg2)
with initialize(config_path="conf", job_name="test_app"):
cfg = compose(config_name="config", overrides=["db=mysql", "db.user=me"])
from typing import List, Optional
import typer
from omegaconf import OmegaCon
# conf.yaml
_target_: app.ClassA
foo: bar
model:
_target_: app.ClassB
hello: world
modelconf: "${remove_target: ${.model}}"
# app.py
import hydra
from omegaconf import DictConfig, OmegaConf
class ClassB:
var1: 42
var2: ${oc.decode:${oc.env:PROJECT_NUMBER}}
# my_app.py
import hydra
from pprint import pprint
from hydra.core.hydra_config import HydraConfig
from omegaconf import OmegaConf
@hydra.main(config_path=".", config_name="config")
def main(config):
hydra_cfg = HydraConfig.get()
# my_app.py
import hydra
import hydra.utils as hu
from omegaconf import OmegaConf
def resolve_tuple(*args):
return tuple(args)
OmegaConf.register_new_resolver('as_tuple', resolve_tuple)
@hydra.main(config_path='conf', config_name='
Community Discussions
Trending Discussions on omegaconf
QUESTION
I am using OmegaConf to read a .yaml configuration file (file path is given through hydra). After I edit it, I want to save the file again. Possibly using:
...ANSWER
Answered 2022-Mar-30 at 12:36This is not supported. Hydra abstracts away the config files it loads. In fact - those config files may exist inside Python packages, the file system or arbitrary locations backed by specialized plugins.
QUESTION
So, I have a hydra model config (autoencoder.yaml) defined as:
...ANSWER
Answered 2022-Feb-25 at 18:03When modifying the defaults list, use a slash ('/'
) instead of a period ('.'
) as the separator for path components:
QUESTION
I am using OmegaConf
's structured config system in order to get a convenient, strongly typed way of configuring my Python application, since it takes very few lines of code and allows merging confs from source, filesystem and CLI. This is defined through a ConfDef
class like the one below.
Now, I want to provide a parameter as a collection of, say, strings. While the OmegaConf
documentation addresses how should the ConfDef
look like, no details about the CLI interaction are provided. Hence the question:
I am using Ubuntu20.04, but generic approaches if existing would be preferred.
...ANSWER
Answered 2022-Feb-21 at 23:12QUESTION
Hydra provides a way to dynamically create a hierarchical configuration by composition and override it through config files and the command line, leveraging OmegaConf. I look for a recommended way to document the parameters but I could not find (a documented) one. What are best practices for that? Coming from argparse, I like the way of documenting the parameter inline, i.e. close to the code.
...ANSWER
Answered 2022-Feb-15 at 02:47Excellent question! The answer is: parameter-by-parameter documentation is not yet implemented (as of Hydra v1.1, OmegaConf v2.1).
The future plans are:
- in OmegaConf, expose an API allowing users to attach documentation (and other metadata) to each field of a structured config. See this open OmegaConf issue.
- Once the above is complete, implement a Hydra feature allowing a parameter-specific help messages to be printed based on the parameter's metadata. See this open Hydra issue.
For now, the best we can do is to customize the general application help message (i.e. the --help
command line flag).
QUESTION
Recently I have started to use hydra to manage the configs in my application. I use Structured Configs to create schema for .yaml config files. Structured Configs in Hyda uses dataclasses for type checking. However, I also want to use some kind of validators for some of the parameter I specify in my Structured Configs (something like this).
Do you know if it is somehow possible to use Pydantic for this purpose? When I try to use Pydantic, OmegaConf complains about it:
...ANSWER
Answered 2022-Jan-10 at 05:58See pydantic.dataclasses.dataclass, which are a drop-in replacement for the standard-library dataclasses with some extra type-checking.
QUESTION
nodes:
node1: 1
node2: 2
node3: 3
selected_node: ${subfield:${nodes},node1}
...ANSWER
Answered 2022-Feb-09 at 16:38I managed to solve this using the implementation below.
It would be better to avoid importing the private interface omegaconf._impl
, but I haven't yet found a way to do that.
QUESTION
I have a simple Typer application:
...ANSWER
Answered 2022-Jan-24 at 09:28The compose
function accepts an optional list of override strings:
QUESTION
How do I set up a my hydra config to accept a custom enum? Specifically I followed the Structured Config Schema tutorial.
I have a dataclass config:
...ANSWER
Answered 2021-Dec-16 at 17:46Note the error message: Invalid value 'enum1', expected one of [ENUM1, ENUM2]
.
This is to say, in your data/config.yaml
file, you should be using ENUM1
instead of enum1
.
QUESTION
ModuleNotFoundError Traceback (most recent call last)
in
16 from omegaconf import OmegaConf
17 from PIL import Image
---> 18 from taming.models import cond_transformer, vqgan
19 import taming.modules
20 import torch
ModuleNotFoundError: No module named 'taming'
...ANSWER
Answered 2021-Dec-16 at 12:20Try the following command:
QUESTION
In my project, I'm setting an environment variables using python-dotenv.
I then reference it in my YAML using the co.env
OmegaConf resolver.
ANSWER
Answered 2021-Nov-24 at 01:31You can use oc.decode to decode to get it as a number.
Something like:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install omegaconf
You can use omegaconf like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page