class EpsilonPolicyConfig(PolicyConfig): epsilon_greedy: float = 0.1 # Parameters to tune epsilon over epochs eps_start: float = SI("${policy.epsilon_greedy}") eps_final: float = SI("${policy.epsilon_greedy}") eps_steps: int = 10000 initial_collect_steps: int = 3000
class Interpolation: x: int = 100 y: int = 200 # The real type of y is int, cast the interpolation string # to help static type checkers to see this truth z1: int = II("x") z2: str = SI("${x}_${y}")
class ProjectConfig: application_name: str = MISSING tensorboard_path: str = MISSING dm_storage_path: str = MISSING version: str = "v1" log_interval: int = 200 summary_interval: int = SI("${project.log_interval}")
class Config: """ Top-level Hydra config class. """ defaults: List[Any] = field(default_factory=lambda: [ { 'experiment': 'cnn' }, { 'lightning': 'default' }, { 'optim': 'adam' }, { 'override hydra/job_logging': 'rich' }, { 'override hydra/hydra_logging': 'rich' }, ]) # Path settings data_dir: str = SI("${oc.env:DATA_DIR}") output_dir: str = SI("${oc.env:RUN_DIR}") # Runtime configuration hydra: Hydra = Hydra() # Experiment settings --> experiment/*.yaml experiment: ExperimentSettings = MISSING # Lightning settings --> lightning/*.yaml lightning: LightningSettings = MISSING # Optimizer & scheduler settings --> optim/*.yaml optim: OptimSettings = MISSING # wandb metadata notes: Optional[str] = None tags: Optional[List[str]] = None
class Package: name: str = II("parent_key:") module: str = II(".name") path: str = MISSING version_type: VersionType = VersionType.FILE version_file: str = SI("${.module}/__init__.py")
class RelativeInterpolation: x: int = 100 y: int = 200 z1: int = II(".x") z2: str = SI("${.x}_${.y}")
def test_type_validation_error_no_throw() -> None: cfg = OmegaConf.structured(User(name="Bond", age=SI("${name}"))) bad_node = cfg._get_node("age") assert bad_node._dereference_node(throw_on_resolution_failure=False) is None
x_node = cfg._get_node("x") assert isinstance(x_node, Node) assert x_node._dereference_node(throw_on_resolution_failure=False) is None def test_none_value_in_quoted_string(restore_resolvers: Any) -> None: OmegaConf.register_new_resolver("test", lambda x: x) cfg = OmegaConf.create({"x": "${test:'${missing}'}", "missing": None}) assert cfg.x == "None" @mark.parametrize( ("cfg", "key", "expected_value", "expected_node_type"), [ param( User(name="Bond", age=SI("${cast:int,'7'}")), "age", 7, IntegerNode, id="expected_type", ), param( # This example specifically test the case where intermediate resolver results # cannot be cast to the same type as the key. User(name="Bond", age=SI("${cast:int,${drop_last:${drop_last:7xx}}}")), "age", 7, IntegerNode, id="intermediate_type_mismatch_ok", ), param(