fl4health.utils.config module

exception InvalidConfigError[source]

Bases: ValueError

check_config(config)[source]

Check if Configuration Dictionary is valid

Return type:

None

load_config(config_path)[source]

Load Configuration Dictionary

Return type:

dict[str, Any]

make_dict_with_epochs_or_steps(local_epochs=None, local_steps=None)[source]

Given two optional variables, this function will determine which, if any, are not None and create a dictionary from the value. If both are not None, it will prioritize local_epochs. If both are None, then the dictionary is empty.

Parameters:
  • local_epochs (int | None, optional) – Number of local epochs of training to perform in FL. Defaults to None.

  • local_steps (int | None, optional) – Number of local steps of training to perform in FL. Defaults to None.

Returns:

Dictionary with at most one of the non-none values, keyed by the name of the non-none variable

Return type:

dict[str, int]

narrow_dict_type(dictionary, key, narrow_type_to)[source]

Checks if a key exists in dictionary and if so, verify it is of type narrow_type_to.

Parameters:
  • dictionary (dict[str, Any]) – A dictionary with string keys.

  • key (str) – The key to check dictionary for.

  • narrow_type_to (type[T]) – The expected type of dictionary[key]

Returns:

The type-checked value at dictionary[key]

Return type:

T

Raises:

ValueError – If dictionary[key] is not of type narrow_type_to or if the key is not present in dictionary.

narrow_dict_type_and_set_attribute(self, dictionary, dictionary_key, attribute_name, narrow_type_to, func=None)[source]

Checks a key exists in dictionary, verify its type and sets the corresponding attribute. Optionally, passes narrowed value to function prior to setting attribute. If key is not present in dictionary or dictionary[dictionary_key] has the wrong type, a ValueError is thrown.

Parameters:
  • self (object) – The object to set attribute to dictionary[dictionary_key].

  • dictionary (dict[str, Any]) – A dictionary with string keys.

  • dictionary_key (str) – The key to check dictionary for.

  • narrow_type_to (type[T]) – The expected type of dictionary[key].

Raises:

ValueError – If dictionary[key] is not of type narrow_type_to or if the key is not present in dictionary.

Return type:

None