🐛 Bug: AssertionError when configuring hydra from top-level dataclass
Description
Using a dataclass at the top-level would be convenient (as it eliminates the need for yaml files), but the below usage pattern results in an AssertionError.
To reproduce
# repro.py
from dataclasses import dataclass, field
from typing import Any, Dict
import hydra
from hydra.core.config_store import ConfigStore
@dataclass
class MyAppConfig:
req_int: int
opt_str: str = "Default String"
opt_float: float = 3.14
hydra: Dict[str, Any] = field(default_factory=lambda: {"job": {"chdir": False}})
cs = ConfigStore.instance()
# Registering the Config class with the name 'base_config'.
cs.store(name="base_config", node=MyAppConfig)
@hydra.main(version_base=None, config_name="base_config")
def my_app(cfg: MyAppConfig) -> None:
print(cfg)
if __name__ == "__main__":
my_app()
$ python repro.py
Traceback (most recent call last):
File "/home/rig1/dev/hydra/hydra/_internal/utils.py", line 217, in run_and_report
return func()
File "/home/rig1/dev/hydra/hydra/_internal/utils.py", line 457, in <lambda>
lambda: hydra.run(
File "/home/rig1/dev/hydra/hydra/_internal/hydra.py", line 115, in run
assert cfg.hydra.mode == RunMode.RUN
AssertionError
System information
Python version : 3.10
Hydra version : main branch HEAD (commit 98a051d36a)
Additional context
The assertion error in the traceback happens because the value of cfg.hydra.mode is the string "RUN", which is not equal to the enum member RunMode.RUN.
There might be an underlying OmegaConf issue here.
🐛 Bug: AssertionError when configuring hydra from top-level dataclass
Description
Using a dataclass at the top-level would be convenient (as it eliminates the need for yaml files), but the below usage pattern results in an
AssertionError
.To reproduce
System information
main
branch HEAD (commit 98a051d36a)Additional context
The assertion error in the traceback happens because the value of
cfg.hydra.mode
is the string"RUN"
, which is not equal to the enum memberRunMode.RUN
. There might be an underlying OmegaConf issue here.Thanks to Omry for reporting this one.