-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24b7699
commit f96cc24
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" | ||
This module defines utility functions for the Hydra configuration system. | ||
""" | ||
# Modules | ||
# ============================================================================= | ||
|
||
# Standard | ||
from copy import deepcopy | ||
|
||
# Third-party | ||
from omegaconf import OmegaConf | ||
|
||
# Local | ||
from .experimentdata.experimentsample import ExperimentSample | ||
|
||
# Authorship & Credits | ||
# ============================================================================= | ||
__author__ = 'Martin van der Schelling ([email protected])' | ||
__credits__ = ['Martin van der Schelling'] | ||
__status__ = 'Alpha' | ||
# ============================================================================= | ||
# | ||
# ============================================================================= | ||
|
||
|
||
def update_config_with_experiment_sample( | ||
config: OmegaConf, experiment_sample: ExperimentSample) -> OmegaConf: | ||
""" | ||
Update the config with the values from the experiment sample | ||
Parameters | ||
---------- | ||
config : OmegaConf | ||
The configuration to update | ||
experiment_sample : ExperimentSample | ||
The experiment sample to update the configuration with | ||
Returns | ||
------- | ||
OmegaConf | ||
The updated configuration | ||
Notes | ||
----- | ||
The function will update the configuration with the values from the | ||
experiment sample. The function will only update the configuration with | ||
values that are present in the experiment sample. If the experiment sample | ||
contains values that are not present in the configuration, they will be | ||
ignored. Keys can be nested using dots, e.g. 'a.b' will update the value | ||
of 'c' in the configuration key 'b'. | ||
The function will return a new configuration object with the | ||
updated values. The original configuration object will not be modified. | ||
""" | ||
cfg = deepcopy(config) | ||
for key, value in experiment_sample.to_dict().items(): | ||
try: | ||
OmegaConf.update(cfg, key, value) | ||
except AttributeError: | ||
continue | ||
|
||
return cfg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
Module for hydra utilities | ||
""" | ||
# Modules | ||
# ============================================================================= | ||
|
||
# Local | ||
from ._src.hydra_utils import update_config_with_experiment_sample | ||
|
||
# Authorship & Credits | ||
# ============================================================================= | ||
__author__ = 'Martin van der Schelling ([email protected])' | ||
__credits__ = ['Martin van der Schelling'] | ||
__status__ = 'Stable' | ||
# ============================================================================= | ||
# | ||
# ============================================================================= | ||
|
||
__all__ = [ | ||
'update_config_with_experiment_sample', | ||
] |