Hyperparameters¶
Functions to handle the definition and manipulation of hyperparameters
- metatrain.utils.hypers.get_hypers_list(hypers_cls: Type[HypersType]) list[str][source]¶
Get the list of hyperparameter names defined in a TypedDict hypers class.
Inheritance of parameters is allowed from parent classes, but make sure that the parent classes only contain hyperparameters as attributes! (i.e., no methods allowed). Private attributes (starting with “_”) are not considered as hyperparameters, so one can have arbitrary private methods or attributes in the class and its parents, although this is not recommended.
- metatrain.utils.hypers.init_with_defaults(hypers_cls: Type[HypersType]) dict[source]¶
Initialize a TypedDict hypers class with its default values.
Inheritance of parameters is allowed from parent classes, but make sure that the parent classes only contain hyperparameters as attributes! (i.e., no methods allowed). Private attributes (starting with “_”) are not considered as hyperparameters, so one can have arbitrary private methods or attributes in the class and its parents, although this is not recommended.
- metatrain.utils.hypers.overwrite_defaults(hypers_cls: Type, new_defaults: dict) None[source]¶
Overwrite the default hyperparameters.
This function does not check that the new defaults correspond to valid hyperparameters of the given hypers class. If the new defaults contain keys that are not hyperparameters of the class, they will simply be ignored.
- metatrain.utils.hypers.get_hypers_diff(old_hypers: Mapping[str, Any], new_hypers: Mapping[str, Any]) dict[str, tuple[Any, Any]][source]¶
Get the difference between two hypers dictionaries.
Only keys present in
new_hypersare compared. Missing keys are treated as “keep the checkpoint value”. Nested mappings are compared the same way, so a partial YAML block such assoap: {max_radial: 4}does not mismatch a checkpoint that also storescutoff.
- metatrain.utils.hypers.raise_hypers_mismatch(hypers_diff: Mapping[str, tuple[Any, Any]]) None[source]¶
Raise an error if the hypers diff is not empty.
The error shows a report of the mismatched hyperparameters.