Skip to content

declearn.main.utils.aggregate_clients_data_info

Validate and aggregate clients' data-info dictionaries.

This functions wraps declearn.data_info.aggregate_data_info, catches KeyError and ValueError and runs further analysis to identify their cause and raise a custom AggregationError that stores a general error message and client-wise ones in order to report on failure causes.

Parameters:

Name Type Description Default
clients_data_info Dict[str, Dict[str, Any]]

Client-wise data-info dict that are to be aggregated.

required
required_fields Set[str]

Optional set of fields to target among provided information. If set, raise if a field is missing from any client, and use only these fields in the returned dict.

required

Raises:

Type Description
AggregationError

In case any error is raised when calling aggregate_data_info on the input arguments.

Returns:

Name Type Description
data_info dict[str, any]

Aggregated data specifications derived from individual ones, with required_fields as keys.

Source code in declearn/main/utils/_data_info.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
def aggregate_clients_data_info(
    clients_data_info: Dict[str, Dict[str, Any]],
    required_fields: Set[str],
) -> Dict[str, Any]:
    """Validate and aggregate clients' data-info dictionaries.

    This functions wraps `declearn.data_info.aggregate_data_info`,
    catches KeyError and ValueError and runs further analysis to
    identify their cause and raise a custom AggregationError that
    stores a general error message and client-wise ones in order
    to report on failure causes.

    Parameters
    ----------
    clients_data_info: dict[str, dict[str, any]]
        Client-wise data-info dict that are to be aggregated.
    required_fields: set[str]
        Optional set of fields to target among provided information.
        If set, raise if a field is missing from any client, and use
        only these fields in the returned dict.

    Raises
    ------
    AggregationError
        In case any error is raised when calling `aggregate_data_info`
        on the input arguments.

    Returns
    -------
    data_info: dict[str, any]
        Aggregated data specifications derived from individual ones,
        with `required_fields` as keys.
    """
    try:
        return aggregate_data_info(
            list(clients_data_info.values()), required_fields
        )
    except KeyError as exc:
        _raise_on_missing_fields(clients_data_info, required_fields)
        _raise_aggregation_fails(clients_data_info, exc)
    except ValueError as exc:
        _raise_on_invalid_fields(clients_data_info, required_fields)
        _raise_incompatible_fields(clients_data_info, exc)
    except Exception as exc:  # re-raise; pylint: disable=broad-except
        _raise_aggregation_fails(clients_data_info, exc)