ConfigManager
- class medigan.config_manager.ConfigManager(config_dict: Optional[dict] = None, is_new_download_forced: bool = False)[source]
Bases:
object
ConfigManager class: Downloads, loads and parses medigan’s config json as dictionary.
- Parameters
config_dict (dict) – Optionally provides the config dictionary if already loaded and parsed in a previous process.
is_new_download_forced (bool) – Flags, if True, that a new config file should be downloaded from the config link instead of parsing an existing file.
- config_dict
Optionally provides the config dictionary if already loaded and parsed in a previous process.
- Type
dict
- is_new_download_forced
Flags, if True, that a new config file should be downloaded from the config link instead of parsing an existing file.
- Type
bool
- model_ids
Lists the unique id’s of the generative models specified in the config_dict
- Type
list
- is_config_loaded
Flags if the loading and parsing of the config file was successful (True) or not (False).
- Type
bool
Methods Summary
add_model_to_config
(model_id, metadata[, ...])Adding or updating a model entry in the global metadata.
get_config_by_id
(model_id[, config_key])From config_manager, get and return the part of the config below a config_key for a specific model_id.
is_model_in_config
(model_id)Checking if a model_id is present in the global model metadata file
is_model_metadata_valid
(model_id, metadata)Checking if a model's corresponding metadata is valid.
load_config_file
([is_new_download_forced])Load a config file and return boolean flag indicating success of loading process.
Methods Documentation
- add_model_to_config(model_id: str, metadata: dict, is_local_model: bool = True, overwrite_existing_metadata: bool = False, store_new_config: bool = True) bool [source]
Adding or updating a model entry in the global metadata.
- Parameters
model_id (str) – The generative model’s unique id
metadata (dict) – The model’s corresponding metadata
is_local_model (bool) – flag indicating whether the tested model is a new local user model i.e not yet part of medigan’s official models
overwrite_existing_metadata (bool) – in case of is_local_model, flag indicating whether existing metadata for this model in medigan’s config/global.json should be overwritten.
store_new_config (bool) – flag indicating whether the current model metadata should be stored on disk i.e. in config/
- Returns
Flag indicating whether model metadata update was successfully concluded
- Return type
bool
- get_config_by_id(model_id: str, config_key: Optional[str] = None) dict [source]
From config_manager, get and return the part of the config below a config_key for a specific model_id.
The key param can contain ‘.’ (dot) separations to allow for retrieval of nested config keys such as ‘execution.generator.name’
- Parameters
model_id (str) – The generative model’s unique id
config_key (str) – A key of interest present in the config dict
- Returns
a dictionary from the part of the config file corresponding to model_id and config_key.
- Return type
dict
- is_model_in_config(model_id: str) bool [source]
Checking if a model_id is present in the global model metadata file
- Parameters
model_id (str) – The generative model’s unique id
- Returns
Flag indicating whether a model_id is present in global model metadata
- Return type
bool
- is_model_metadata_valid(model_id: str, metadata: dict, is_local_model: bool = True) bool [source]
Checking if a model’s corresponding metadata is valid.
Specific fields in the model’s metadata are mandatory. It is asserted if these key value pairs are present.
- Parameters
model_id (str) – The generative model’s unique id
metadata (dict) – The model’s corresponding metadata
is_local_model (bool) – flag indicating whether the tested model is a new local user model i.e not yet part of medigan’s official models
- Returns
Flag indicating whether the specific model’s metadata format and fields are valid
- Return type
bool
- load_config_file(is_new_download_forced: bool = False) bool [source]
Load a config file and return boolean flag indicating success of loading process.
If the config file is not present in medigan.CONSTANTS.CONFIG_FILE_FOLDER, it is per default downloaded from the web resource specified in medigan.CONSTANTS.CONFIG_FILE_URL.
- Parameters
is_new_download_forced (bool) – Forces new download of config file even if the file has been downloaded before.
- Returns
a boolean flag indicating true only if the config file was loaded successfully.
- Return type
bool