Introduction to Structured Configs in Hydra
mainStructured Configs allow you to use Python dataclasses to define your configuration structure and types. This provides runtime type checking during configuration composition or mutation, and enables static type checking when using tools like mypy or PyCharm.
Supported Types
- Primitive types:
int,bool,float,str,Enums,bytes,pathlib.Path. - Nesting: Structured Configs can be nested within each other.
- Containers:
ListandDictcontaining primitives, other Structured Configs, or nested containers. - Optional fields.
Limitations
Uniontypes are only partially supported (refer to OmegaConf documentation for details).- User-defined methods on dataclasses are not supported.
Primary Usage Patterns
- As a config: Using dataclasses in place of traditional YAML configuration files.
- As a config schema: Using dataclasses to validate the structure and types of existing configuration files (recommended for complex use cases).
Both patterns maintain full compatibility with Hydra features like config composition and command-line overrides.