Updates items in the configuration file. The configuration dict should only be composed of primitive Python types (dict, list and values). This is the case when reading the file using `read_config_as_dict`. Args: config: the configuration dict to update updates: the
(config: dict, updates: dict, copy_original: bool = True)
| 117 | |
| 118 | |
| 119 | def update_config(config: dict, updates: dict, copy_original: bool = True) -> dict: |
| 120 | """Updates items in the configuration file. |
| 121 | |
| 122 | The configuration dict should only be composed of primitive Python types |
| 123 | (dict, list and values). This is the case when reading the file using |
| 124 | `read_config_as_dict`. |
| 125 | |
| 126 | Args: |
| 127 | config: the configuration dict to update |
| 128 | updates: the updates to make to the configuration dict |
| 129 | copy_original: whether to copy the original dict before updating it |
| 130 | |
| 131 | Returns: |
| 132 | the updated dictionary |
| 133 | """ |
| 134 | if copy_original: |
| 135 | config = copy.deepcopy(config) |
| 136 | |
| 137 | for k, v in updates.items(): |
| 138 | if k in config and isinstance(config[k], dict) and isinstance(v, dict): |
| 139 | if k in ("optimizer", "scheduler") and config["type"] != v["type"]: |
| 140 | # if changing the optimizer or scheduler type, update all values |
| 141 | config[k] = v |
| 142 | else: |
| 143 | config[k] = update_config(config[k], v, copy_original=False) |
| 144 | else: |
| 145 | config[k] = copy.deepcopy(v) |
| 146 | return config |
| 147 | |
| 148 | |
| 149 | def update_config_by_dotpath(config: dict, updates: dict, copy_original: bool = True) -> dict: |