RecordSet¶
- class RecordSet(parameters_records: dict[str, ParametersRecord] | None = None, metrics_records: dict[str, MetricsRecord] | None = None, configs_records: dict[str, ConfigsRecord] | None = None)[source]¶
Bases:
object
RecordSet stores groups of parameters, metrics and configs.
A
RecordSet
is the unified mechanism by which parameters, metrics and configs can be either stored as part of a flwr.common.Context in your apps or communicated as part of a flwr.common.Message between your apps.- Parameters:
parameters_records (Optional[Dict[str, ParametersRecord]]) – A dictionary of
ParametersRecords
that can be used to record and communicate model parameters and high-dimensional arrays.metrics_records (Optional[Dict[str, MetricsRecord]]) – A dictionary of
MetricsRecord
that can be used to record and communicate scalar-valued metrics that are the result of performing and action, for example, by aClientApp
.configs_records (Optional[Dict[str, ConfigsRecord]]) – A dictionary of
ConfigsRecord
that can be used to record and communicate configuration values to an entity (e.g. to aClientApp
) for it to adjust how an action is performed.
Examples
A
RecordSet
can hold three types of records, each designed with an specific purpose. What is common to all of them is that they are Python dictionaries designed to ensure that each key-value pair adheres to specified data types.Let’s see an example.
>>> from flwr.common import RecordSet >>> from flwr.common import ConfigsRecord, MetricsRecord, ParametersRecord >>> >>> # Let's begin with an empty record >>> my_recordset = RecordSet() >>> >>> # We can create a ConfigsRecord >>> c_record = ConfigsRecord({"lr": 0.1, "batch-size": 128}) >>> # Adding it to the record_set would look like this >>> my_recordset.configs_records["my_config"] = c_record >>> >>> # We can create a MetricsRecord following a similar process >>> m_record = MetricsRecord({"accuracy": 0.93, "losses": [0.23, 0.1]}) >>> # Adding it to the record_set would look like this >>> my_recordset.metrics_records["my_metrics"] = m_record
Adding a
ParametersRecord
follows the same steps as above but first, the array needs to be serialized and represented as aflwr.common.Array
. If the array is aNumPy
array, you can use the built-in utility function array_from_numpy. It is often possible to convert an array first toNumPy
and then use the aforementioned function.>>> from flwr.common import array_from_numpy >>> # Creating a ParametersRecord would look like this >>> arr_np = np.random.randn(3, 3) >>> >>> # You can use the built-in tool to serialize the array >>> arr = array_from_numpy(arr_np) >>> >>> # Finally, create the record >>> p_record = ParametersRecord({"my_array": arr}) >>> >>> # Adding it to the record_set would look like this >>> my_recordset.configs_records["my_config"] = c_record
For additional examples on how to construct each of the records types shown above, please refer to the documentation for
ConfigsRecord
,MetricsRecord
andParametersRecord
.Methods
Attributes
Dictionary holding ConfigsRecord instances.
Dictionary holding MetricsRecord instances.
Dictionary holding ParametersRecord instances.
- property configs_records: TypedDict[str, ConfigsRecord]¶
Dictionary holding ConfigsRecord instances.
- property metrics_records: TypedDict[str, MetricsRecord]¶
Dictionary holding MetricsRecord instances.
- property parameters_records: TypedDict[str, ParametersRecord]¶
Dictionary holding ParametersRecord instances.