GOOD.utils.config_reader

A project configuration module that reads config argument from a file; set automatic generated arguments; and overwrite configuration arguments by command arguments.

Functions

args2config(config, args)

Overwrite config by assigned arguments.

config_summoner(args)

A config loading and postprocessing function.

load_config(path[, previous_includes, ...])

Config loader.

merge_dicts(dict1, dict2)

Recursively merge two dictionaries.

process_configs(config)

Process loaded configs.

search_tap_args(args, query)

Search a key in command line arguments.

GOOD.utils.config_reader.args2config(config: Union[CommonArgs, Munch], args: CommonArgs)[source]

Overwrite config by assigned arguments. If an argument is not None, this argument has the highest priority; thus, it will overwrite the corresponding config.

Parameters
  • config (Union[CommonArgs, Munch]) – Loaded configs.

  • args (CommonArgs) – Command line arguments.

Returns

Overwritten configs.

GOOD.utils.config_reader.config_summoner(args: CommonArgs) Union[CommonArgs, Munch][source]

A config loading and postprocessing function.

Parameters

args (CommonArgs) – Command line arguments.

Returns

Processed configs.

GOOD.utils.config_reader.load_config(path: str, previous_includes: list = [], skip_include=False) dict[source]

Config loader. Loading configs from a config file.

Parameters
  • path (str) – The path to your yaml configuration file.

  • previous_includes (list) – Included configurations. It is for the include configs used for recursion. Please leave it blank when call this function outside.

Returns

config dictionary loaded from the given yaml file.

Return type

config (dict)

GOOD.utils.config_reader.merge_dicts(dict1: dict, dict2: dict)[source]

Recursively merge two dictionaries. Values in dict2 override values in dict1. If dict1 and dict2 contain a dictionary as a value, this will call itself recursively to merge these dictionaries. This does not modify the input dictionaries (creates an internal copy). Additionally returns a list of detected duplicates. Adapted from https://github.com/TUM-DAML/seml/blob/master/seml/utils.py :param dict1: First dict. :type dict1: dict :param dict2: Second dict. Values in dict2 will override values from dict1 in case they share the same key. :type dict2: dict

Returns

return_dict – Merged dictionaries.

Return type

dict

GOOD.utils.config_reader.process_configs(config: Union[CommonArgs, Munch])[source]

Process loaded configs. This process includes setting storage places for datasets, tensorboard logs, logs, and checkpoints. In addition, we also set random seed for each experiment round, checkpoint saving gap, and gpu device. Finally, we connect the config with two components GOOD.utils.metric.Metric and GOOD.utils.train.TrainHelper for easy and unified accesses.

Parameters

config (Union[CommonArgs, Munch]) – Loaded configs.

Returns

Configs after setting.

GOOD.utils.config_reader.search_tap_args(args: CommonArgs, query: str)[source]

Search a key in command line arguments.

Parameters
  • args (CommonArgs) – Command line arguments.

  • query (str) – The query for the target argument.

Returns

A found or not flag and the target value if found.