flwr-nightly 1.17.0.dev20250320__py3-none-any.whl → 1.17.0.dev20250321__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flwr/cli/run/run.py +5 -9
- flwr/client/client_app.py +10 -12
- flwr/client/grpc_client/connection.py +3 -3
- flwr/client/message_handler/message_handler.py +3 -3
- flwr/client/mod/__init__.py +2 -2
- flwr/client/mod/comms_mods.py +16 -22
- flwr/client/mod/secure_aggregation/secaggplus_mod.py +26 -26
- flwr/common/__init__.py +10 -4
- flwr/common/config.py +4 -4
- flwr/common/constant.py +1 -1
- flwr/common/record/__init__.py +6 -3
- flwr/common/record/{parametersrecord.py → arrayrecord.py} +74 -31
- flwr/common/record/{configsrecord.py → configrecord.py} +73 -27
- flwr/common/record/conversion_utils.py +1 -1
- flwr/common/record/{metricsrecord.py → metricrecord.py} +77 -31
- flwr/common/record/recorddict.py +95 -56
- flwr/common/recorddict_compat.py +54 -62
- flwr/common/secure_aggregation/secaggplus_constants.py +1 -1
- flwr/common/serde.py +42 -43
- flwr/common/typing.py +8 -8
- flwr/proto/exec_pb2.py +30 -30
- flwr/proto/exec_pb2.pyi +2 -2
- flwr/proto/recorddict_pb2.py +29 -29
- flwr/proto/recorddict_pb2.pyi +33 -33
- flwr/proto/run_pb2.py +2 -2
- flwr/proto/run_pb2.pyi +2 -2
- flwr/server/compat/grid_client_proxy.py +1 -1
- flwr/server/superlink/fleet/vce/backend/backend.py +2 -2
- flwr/server/superlink/fleet/vce/backend/raybackend.py +2 -2
- flwr/server/superlink/linkstate/in_memory_linkstate.py +4 -4
- flwr/server/superlink/linkstate/linkstate.py +4 -4
- flwr/server/superlink/linkstate/sqlite_linkstate.py +7 -7
- flwr/server/superlink/linkstate/utils.py +9 -9
- flwr/server/superlink/serverappio/serverappio_servicer.py +2 -2
- flwr/server/superlink/simulation/simulationio_servicer.py +2 -2
- flwr/server/workflow/default_workflows.py +27 -34
- flwr/server/workflow/secure_aggregation/secaggplus_workflow.py +32 -34
- flwr/simulation/app.py +2 -2
- flwr/simulation/ray_transport/ray_actor.py +4 -2
- flwr/simulation/run_simulation.py +2 -2
- flwr/superexec/deployment.py +3 -3
- flwr/superexec/exec_servicer.py +2 -2
- flwr/superexec/executor.py +3 -3
- flwr/superexec/simulation.py +2 -2
- {flwr_nightly-1.17.0.dev20250320.dist-info → flwr_nightly-1.17.0.dev20250321.dist-info}/METADATA +1 -1
- {flwr_nightly-1.17.0.dev20250320.dist-info → flwr_nightly-1.17.0.dev20250321.dist-info}/RECORD +49 -49
- {flwr_nightly-1.17.0.dev20250320.dist-info → flwr_nightly-1.17.0.dev20250321.dist-info}/LICENSE +0 -0
- {flwr_nightly-1.17.0.dev20250320.dist-info → flwr_nightly-1.17.0.dev20250321.dist-info}/WHEEL +0 -0
- {flwr_nightly-1.17.0.dev20250320.dist-info → flwr_nightly-1.17.0.dev20250321.dist-info}/entry_points.txt +0 -0
flwr/common/record/recorddict.py
CHANGED
@@ -22,12 +22,12 @@ from textwrap import indent
|
|
22
22
|
from typing import TypeVar, Union, cast
|
23
23
|
|
24
24
|
from ..logger import log
|
25
|
-
from .
|
26
|
-
from .
|
27
|
-
from .
|
25
|
+
from .arrayrecord import ArrayRecord
|
26
|
+
from .configrecord import ConfigRecord
|
27
|
+
from .metricrecord import MetricRecord
|
28
28
|
from .typeddict import TypedDict
|
29
29
|
|
30
|
-
RecordType = Union[
|
30
|
+
RecordType = Union[ArrayRecord, MetricRecord, ConfigRecord]
|
31
31
|
|
32
32
|
T = TypeVar("T")
|
33
33
|
|
@@ -41,10 +41,10 @@ def _check_key(key: str) -> None:
|
|
41
41
|
|
42
42
|
|
43
43
|
def _check_value(value: RecordType) -> None:
|
44
|
-
if not isinstance(value, (
|
44
|
+
if not isinstance(value, (ArrayRecord, MetricRecord, ConfigRecord)):
|
45
45
|
raise TypeError(
|
46
|
-
f"Expected `{
|
47
|
-
f"or `{
|
46
|
+
f"Expected `{ArrayRecord.__name__}`, `{MetricRecord.__name__}`, "
|
47
|
+
f"or `{ConfigRecord.__name__}` but received "
|
48
48
|
f"`{type(value).__name__}` for the value."
|
49
49
|
)
|
50
50
|
|
@@ -58,9 +58,7 @@ class _SyncedDict(TypedDict[str, T]):
|
|
58
58
|
"""
|
59
59
|
|
60
60
|
def __init__(self, ref_recorddict: RecordDict, allowed_type: type[T]) -> None:
|
61
|
-
if not issubclass(
|
62
|
-
allowed_type, (ParametersRecord, MetricsRecord, ConfigsRecord)
|
63
|
-
):
|
61
|
+
if not issubclass(allowed_type, (ArrayRecord, MetricRecord, ConfigRecord)):
|
64
62
|
raise TypeError(f"{allowed_type} is not a valid type.")
|
65
63
|
super().__init__(_check_key, self.check_value)
|
66
64
|
self.recorddict = ref_recorddict
|
@@ -84,27 +82,19 @@ class _SyncedDict(TypedDict[str, T]):
|
|
84
82
|
|
85
83
|
|
86
84
|
class RecordDict(TypedDict[str, RecordType]):
|
87
|
-
"""RecordDict stores groups of
|
85
|
+
"""RecordDict stores groups of arrays, metrics and configs.
|
88
86
|
|
89
|
-
A :class:`RecordDict` is the unified mechanism by which
|
87
|
+
A :class:`RecordDict` is the unified mechanism by which arrays,
|
90
88
|
metrics and configs can be either stored as part of a :class:`Context`
|
91
89
|
in your apps or communicated as part of a :class:`Message` between
|
92
90
|
your apps.
|
93
91
|
|
94
92
|
Parameters
|
95
93
|
----------
|
96
|
-
|
97
|
-
A dictionary
|
98
|
-
|
99
|
-
|
100
|
-
A dictionary of :code:`MetricsRecord` that can be used to record
|
101
|
-
and communicate scalar-valued metrics that are the result of performing
|
102
|
-
and action, for example, by a :code:`ClientApp`.
|
103
|
-
configs_records : Optional[Dict[str, ConfigsRecord]]
|
104
|
-
A dictionary of :code:`ConfigsRecord` that can be used to record
|
105
|
-
and communicate configuration values to an entity (e.g. to a
|
106
|
-
:code:`ClientApp`)
|
107
|
-
for it to adjust how an action is performed.
|
94
|
+
records : Optional[dict[str, RecordType]]
|
95
|
+
A dictionary mapping string keys to record instances, where each value
|
96
|
+
is either a :class:`ParametersRecord`, :class:`MetricsRecord`,
|
97
|
+
or :class:`ConfigsRecord`.
|
108
98
|
|
109
99
|
Examples
|
110
100
|
--------
|
@@ -116,43 +106,41 @@ class RecordDict(TypedDict[str, RecordType]):
|
|
116
106
|
Let's see an example.
|
117
107
|
|
118
108
|
>>> from flwr.common import RecordDict
|
119
|
-
>>> from flwr.common import
|
109
|
+
>>> from flwr.common import ArrayRecord, ConfigRecord, MetricRecord
|
120
110
|
>>>
|
121
111
|
>>> # Let's begin with an empty record
|
122
112
|
>>> my_records = RecordDict()
|
123
113
|
>>>
|
124
|
-
>>> # We can create a
|
125
|
-
>>> c_record =
|
126
|
-
>>> # Adding it to the
|
114
|
+
>>> # We can create a ConfigRecord
|
115
|
+
>>> c_record = ConfigRecord({"lr": 0.1, "batch-size": 128})
|
116
|
+
>>> # Adding it to the RecordDict would look like this
|
127
117
|
>>> my_records["my_config"] = c_record
|
128
118
|
>>>
|
129
|
-
>>> # We can create a
|
130
|
-
>>> m_record =
|
131
|
-
>>> # Adding it to the
|
119
|
+
>>> # We can create a MetricRecord following a similar process
|
120
|
+
>>> m_record = MetricRecord({"accuracy": 0.93, "losses": [0.23, 0.1]})
|
121
|
+
>>> # Adding it to the RecordDict would look like this
|
132
122
|
>>> my_records["my_metrics"] = m_record
|
133
123
|
|
134
|
-
Adding
|
124
|
+
Adding an :code:`ArrayRecord` follows the same steps as above but first,
|
135
125
|
the array needs to be serialized and represented as a :code:`flwr.common.Array`.
|
136
|
-
|
137
|
-
`array_from_numpy <flwr.common.array_from_numpy.html>`_. It is often possible to
|
138
|
-
convert an array first to :code:`NumPy` and then use the aforementioned function.
|
126
|
+
For example:
|
139
127
|
|
140
|
-
>>> from flwr.common import
|
141
|
-
>>> # Creating
|
128
|
+
>>> from flwr.common import Array
|
129
|
+
>>> # Creating an ArrayRecord would look like this
|
142
130
|
>>> arr_np = np.random.randn(3, 3)
|
143
131
|
>>>
|
144
132
|
>>> # You can use the built-in tool to serialize the array
|
145
|
-
>>> arr =
|
133
|
+
>>> arr = Array(arr_np)
|
146
134
|
>>>
|
147
135
|
>>> # Finally, create the record
|
148
|
-
>>>
|
136
|
+
>>> arr_record = ArrayRecord({"my_array": arr})
|
149
137
|
>>>
|
150
|
-
>>> # Adding it to the
|
151
|
-
>>> my_records["my_parameters"] =
|
138
|
+
>>> # Adding it to the RecordDict would look like this
|
139
|
+
>>> my_records["my_parameters"] = arr_record
|
152
140
|
|
153
141
|
For additional examples on how to construct each of the records types shown
|
154
|
-
above, please refer to the documentation for :code:`
|
155
|
-
:code:`
|
142
|
+
above, please refer to the documentation for :code:`ConfigRecord`,
|
143
|
+
:code:`MetricRecord` and :code:`ArrayRecord`.
|
156
144
|
"""
|
157
145
|
|
158
146
|
def __init__(self, records: dict[str, RecordType] | None = None) -> None:
|
@@ -162,35 +150,35 @@ class RecordDict(TypedDict[str, RecordType]):
|
|
162
150
|
self[key] = record
|
163
151
|
|
164
152
|
@property
|
165
|
-
def
|
166
|
-
"""Dictionary holding only
|
167
|
-
synced_dict = _SyncedDict[
|
153
|
+
def array_records(self) -> TypedDict[str, ArrayRecord]:
|
154
|
+
"""Dictionary holding only ArrayRecord instances."""
|
155
|
+
synced_dict = _SyncedDict[ArrayRecord](self, ArrayRecord)
|
168
156
|
for key, record in self.items():
|
169
|
-
if isinstance(record,
|
157
|
+
if isinstance(record, ArrayRecord):
|
170
158
|
synced_dict[key] = record
|
171
159
|
return synced_dict
|
172
160
|
|
173
161
|
@property
|
174
|
-
def
|
175
|
-
"""Dictionary holding only
|
176
|
-
synced_dict = _SyncedDict[
|
162
|
+
def metric_records(self) -> TypedDict[str, MetricRecord]:
|
163
|
+
"""Dictionary holding only MetricRecord instances."""
|
164
|
+
synced_dict = _SyncedDict[MetricRecord](self, MetricRecord)
|
177
165
|
for key, record in self.items():
|
178
|
-
if isinstance(record,
|
166
|
+
if isinstance(record, MetricRecord):
|
179
167
|
synced_dict[key] = record
|
180
168
|
return synced_dict
|
181
169
|
|
182
170
|
@property
|
183
|
-
def
|
184
|
-
"""Dictionary holding only
|
185
|
-
synced_dict = _SyncedDict[
|
171
|
+
def config_records(self) -> TypedDict[str, ConfigRecord]:
|
172
|
+
"""Dictionary holding only ConfigRecord instances."""
|
173
|
+
synced_dict = _SyncedDict[ConfigRecord](self, ConfigRecord)
|
186
174
|
for key, record in self.items():
|
187
|
-
if isinstance(record,
|
175
|
+
if isinstance(record, ConfigRecord):
|
188
176
|
synced_dict[key] = record
|
189
177
|
return synced_dict
|
190
178
|
|
191
179
|
def __repr__(self) -> str:
|
192
180
|
"""Return a string representation of this instance."""
|
193
|
-
flds = ("
|
181
|
+
flds = ("array_records", "metric_records", "config_records")
|
194
182
|
fld_views = [f"{fld}={dict(getattr(self, fld))!r}" for fld in flds]
|
195
183
|
view = indent(",\n".join(fld_views), " ")
|
196
184
|
return f"{self.__class__.__qualname__}(\n{view}\n)"
|
@@ -236,6 +224,9 @@ class RecordSet(RecordDict):
|
|
236
224
|
"""
|
237
225
|
|
238
226
|
_warning_logged = False
|
227
|
+
_warning_logged_params = False
|
228
|
+
_warning_logged_metrics = False
|
229
|
+
_warning_logged_configs = False
|
239
230
|
|
240
231
|
def __init__(self, records: dict[str, RecordType] | None = None) -> None:
|
241
232
|
if not RecordSet._warning_logged:
|
@@ -247,3 +238,51 @@ class RecordSet(RecordDict):
|
|
247
238
|
"Please update your code accordingly.",
|
248
239
|
)
|
249
240
|
super().__init__(records)
|
241
|
+
|
242
|
+
@property
|
243
|
+
def parameters_records(self) -> TypedDict[str, ArrayRecord]:
|
244
|
+
"""Deprecated property.
|
245
|
+
|
246
|
+
Use ``array_records`` instead.
|
247
|
+
"""
|
248
|
+
if not RecordSet._warning_logged_params:
|
249
|
+
RecordSet._warning_logged_params = True
|
250
|
+
log(
|
251
|
+
WARN,
|
252
|
+
"`RecordSet.parameters_records` has been deprecated "
|
253
|
+
"and will be removed in a future release. Please use "
|
254
|
+
"`RecordDict.array_records` instead.",
|
255
|
+
)
|
256
|
+
return self.array_records
|
257
|
+
|
258
|
+
@property
|
259
|
+
def metrics_records(self) -> TypedDict[str, MetricRecord]:
|
260
|
+
"""Deprecated property.
|
261
|
+
|
262
|
+
Use ``metric_records`` instead.
|
263
|
+
"""
|
264
|
+
if not RecordSet._warning_logged_metrics:
|
265
|
+
RecordSet._warning_logged_metrics = True
|
266
|
+
log(
|
267
|
+
WARN,
|
268
|
+
"`RecordSet.metrics_records` has been deprecated "
|
269
|
+
"and will be removed in a future release. Please use "
|
270
|
+
"`RecordDict.metric_records` instead.",
|
271
|
+
)
|
272
|
+
return self.metric_records
|
273
|
+
|
274
|
+
@property
|
275
|
+
def configs_records(self) -> TypedDict[str, ConfigRecord]:
|
276
|
+
"""Deprecated property.
|
277
|
+
|
278
|
+
Use ``config_records`` instead.
|
279
|
+
"""
|
280
|
+
if not RecordSet._warning_logged_configs:
|
281
|
+
RecordSet._warning_logged_configs = True
|
282
|
+
log(
|
283
|
+
WARN,
|
284
|
+
"`RecordSet.configs_records` has been deprecated "
|
285
|
+
"and will be removed in a future release. Please use "
|
286
|
+
"`RecordDict.config_records` instead.",
|
287
|
+
)
|
288
|
+
return self.config_records
|
flwr/common/recorddict_compat.py
CHANGED
@@ -19,10 +19,10 @@ from collections import OrderedDict
|
|
19
19
|
from collections.abc import Mapping
|
20
20
|
from typing import Union, cast, get_args
|
21
21
|
|
22
|
-
from . import Array,
|
22
|
+
from . import Array, ArrayRecord, ConfigRecord, MetricRecord, RecordDict
|
23
23
|
from .typing import (
|
24
24
|
Code,
|
25
|
-
|
25
|
+
ConfigRecordValues,
|
26
26
|
EvaluateIns,
|
27
27
|
EvaluateRes,
|
28
28
|
FitIns,
|
@@ -31,7 +31,7 @@ from .typing import (
|
|
31
31
|
GetParametersRes,
|
32
32
|
GetPropertiesIns,
|
33
33
|
GetPropertiesRes,
|
34
|
-
|
34
|
+
MetricRecordValues,
|
35
35
|
Parameters,
|
36
36
|
Scalar,
|
37
37
|
Status,
|
@@ -40,21 +40,19 @@ from .typing import (
|
|
40
40
|
EMPTY_TENSOR_KEY = "_empty"
|
41
41
|
|
42
42
|
|
43
|
-
def
|
44
|
-
record: ParametersRecord, keep_input: bool
|
45
|
-
) -> Parameters:
|
43
|
+
def arrayrecord_to_parameters(record: ArrayRecord, keep_input: bool) -> Parameters:
|
46
44
|
"""Convert ParameterRecord to legacy Parameters.
|
47
45
|
|
48
46
|
Warnings
|
49
47
|
--------
|
50
|
-
Because `
|
48
|
+
Because `Array`s in `ArrayRecord` encode more information of the
|
51
49
|
array-like or tensor-like data (e.g their datatype, shape) than `Parameters` it
|
52
50
|
might not be possible to reconstruct such data structures from `Parameters` objects
|
53
51
|
alone. Additional information or metadata must be provided from elsewhere.
|
54
52
|
|
55
53
|
Parameters
|
56
54
|
----------
|
57
|
-
record :
|
55
|
+
record : ArrayRecord
|
58
56
|
The record to be conveted into Parameters.
|
59
57
|
keep_input : bool
|
60
58
|
A boolean indicating whether entries in the record should be deleted from the
|
@@ -82,19 +80,17 @@ def parametersrecord_to_parameters(
|
|
82
80
|
return parameters
|
83
81
|
|
84
82
|
|
85
|
-
def
|
86
|
-
|
87
|
-
) -> ParametersRecord:
|
88
|
-
"""Convert legacy Parameters into a single ParametersRecord.
|
83
|
+
def parameters_to_arrayrecord(parameters: Parameters, keep_input: bool) -> ArrayRecord:
|
84
|
+
"""Convert legacy Parameters into a single ArrayRecord.
|
89
85
|
|
90
86
|
Because there is no concept of names in the legacy Parameters, arbitrary keys will
|
91
|
-
be used when constructing the
|
87
|
+
be used when constructing the ArrayRecord. Similarly, the shape and data type
|
92
88
|
won't be recorded in the Array objects.
|
93
89
|
|
94
90
|
Parameters
|
95
91
|
----------
|
96
92
|
parameters : Parameters
|
97
|
-
Parameters object to be represented as a
|
93
|
+
Parameters object to be represented as a ArrayRecord.
|
98
94
|
keep_input : bool
|
99
95
|
A boolean indicating whether parameters should be deleted from the input
|
100
96
|
Parameters object (i.e. a list of serialized NumPy arrays) immediately after
|
@@ -102,8 +98,8 @@ def parameters_to_parametersrecord(
|
|
102
98
|
|
103
99
|
Returns
|
104
100
|
-------
|
105
|
-
|
106
|
-
The
|
101
|
+
ArrayRecord
|
102
|
+
The ArrayRecord containing the provided parameters.
|
107
103
|
"""
|
108
104
|
tensor_type = parameters.tensor_type
|
109
105
|
|
@@ -122,19 +118,19 @@ def parameters_to_parametersrecord(
|
|
122
118
|
ordered_dict[EMPTY_TENSOR_KEY] = Array(
|
123
119
|
data=b"", dtype="", stype=tensor_type, shape=[]
|
124
120
|
)
|
125
|
-
return
|
121
|
+
return ArrayRecord(ordered_dict, keep_input=keep_input)
|
126
122
|
|
127
123
|
|
128
124
|
def _check_mapping_from_recordscalartype_to_scalar(
|
129
|
-
record_data: Mapping[str, Union[
|
125
|
+
record_data: Mapping[str, Union[ConfigRecordValues, MetricRecordValues]]
|
130
126
|
) -> dict[str, Scalar]:
|
131
127
|
"""Check mapping `common.*RecordValues` into `common.Scalar` is possible."""
|
132
128
|
for value in record_data.values():
|
133
129
|
if not isinstance(value, get_args(Scalar)):
|
134
130
|
raise TypeError(
|
135
131
|
"There is not a 1:1 mapping between `common.Scalar` types and those "
|
136
|
-
"supported in `common.
|
137
|
-
"`common.
|
132
|
+
"supported in `common.ConfigRecordValues` or "
|
133
|
+
"`common.ConfigRecordValues`. Consider casting your values to a type "
|
138
134
|
"supported by the `common.RecordDict` infrastructure. "
|
139
135
|
f"You used type: {type(value)}"
|
140
136
|
)
|
@@ -148,14 +144,12 @@ def _recorddict_to_fit_or_evaluate_ins_components(
|
|
148
144
|
) -> tuple[Parameters, dict[str, Scalar]]:
|
149
145
|
"""Derive Fit/Evaluate Ins from a RecordDict."""
|
150
146
|
# get Array and construct Parameters
|
151
|
-
|
147
|
+
array_record = recorddict.array_records[f"{ins_str}.parameters"]
|
152
148
|
|
153
|
-
parameters =
|
154
|
-
parameters_record, keep_input=keep_input
|
155
|
-
)
|
149
|
+
parameters = arrayrecord_to_parameters(array_record, keep_input=keep_input)
|
156
150
|
|
157
151
|
# get config dict
|
158
|
-
config_record = recorddict.
|
152
|
+
config_record = recorddict.config_records[f"{ins_str}.config"]
|
159
153
|
# pylint: disable-next=protected-access
|
160
154
|
config_dict = _check_mapping_from_recordscalartype_to_scalar(config_record)
|
161
155
|
|
@@ -168,10 +162,10 @@ def _fit_or_evaluate_ins_to_recorddict(
|
|
168
162
|
recorddict = RecordDict()
|
169
163
|
|
170
164
|
ins_str = "fitins" if isinstance(ins, FitIns) else "evaluateins"
|
171
|
-
|
172
|
-
recorddict.
|
165
|
+
arr_record = parameters_to_arrayrecord(ins.parameters, keep_input)
|
166
|
+
recorddict.array_records[f"{ins_str}.parameters"] = arr_record
|
173
167
|
|
174
|
-
recorddict.
|
168
|
+
recorddict.config_records[f"{ins_str}.config"] = ConfigRecord(
|
175
169
|
ins.config # type: ignore
|
176
170
|
)
|
177
171
|
|
@@ -181,18 +175,18 @@ def _fit_or_evaluate_ins_to_recorddict(
|
|
181
175
|
def _embed_status_into_recorddict(
|
182
176
|
res_str: str, status: Status, recorddict: RecordDict
|
183
177
|
) -> RecordDict:
|
184
|
-
status_dict: dict[str,
|
178
|
+
status_dict: dict[str, ConfigRecordValues] = {
|
185
179
|
"code": int(status.code.value),
|
186
180
|
"message": status.message,
|
187
181
|
}
|
188
|
-
# we add it to a `
|
189
|
-
# and `str` values aren't supported in `
|
190
|
-
recorddict.
|
182
|
+
# we add it to a `ConfigRecord` because the `status.message` is a string
|
183
|
+
# and `str` values aren't supported in `MetricRecords`
|
184
|
+
recorddict.config_records[f"{res_str}.status"] = ConfigRecord(status_dict)
|
191
185
|
return recorddict
|
192
186
|
|
193
187
|
|
194
188
|
def _extract_status_from_recorddict(res_str: str, recorddict: RecordDict) -> Status:
|
195
|
-
status = recorddict.
|
189
|
+
status = recorddict.config_records[f"{res_str}.status"]
|
196
190
|
code = cast(int, status["code"])
|
197
191
|
return Status(code=Code(code), message=str(status["message"]))
|
198
192
|
|
@@ -216,16 +210,16 @@ def fitins_to_recorddict(fitins: FitIns, keep_input: bool) -> RecordDict:
|
|
216
210
|
def recorddict_to_fitres(recorddict: RecordDict, keep_input: bool) -> FitRes:
|
217
211
|
"""Derive FitRes from a RecordDict object."""
|
218
212
|
ins_str = "fitres"
|
219
|
-
parameters =
|
220
|
-
recorddict.
|
213
|
+
parameters = arrayrecord_to_parameters(
|
214
|
+
recorddict.array_records[f"{ins_str}.parameters"], keep_input=keep_input
|
221
215
|
)
|
222
216
|
|
223
217
|
num_examples = cast(
|
224
|
-
int, recorddict.
|
218
|
+
int, recorddict.metric_records[f"{ins_str}.num_examples"]["num_examples"]
|
225
219
|
)
|
226
|
-
|
220
|
+
config_record = recorddict.config_records[f"{ins_str}.metrics"]
|
227
221
|
# pylint: disable-next=protected-access
|
228
|
-
metrics = _check_mapping_from_recordscalartype_to_scalar(
|
222
|
+
metrics = _check_mapping_from_recordscalartype_to_scalar(config_record)
|
229
223
|
status = _extract_status_from_recorddict(ins_str, recorddict)
|
230
224
|
|
231
225
|
return FitRes(
|
@@ -239,17 +233,15 @@ def fitres_to_recorddict(fitres: FitRes, keep_input: bool) -> RecordDict:
|
|
239
233
|
|
240
234
|
res_str = "fitres"
|
241
235
|
|
242
|
-
recorddict.
|
236
|
+
recorddict.config_records[f"{res_str}.metrics"] = ConfigRecord(
|
243
237
|
fitres.metrics # type: ignore
|
244
238
|
)
|
245
|
-
recorddict.
|
239
|
+
recorddict.metric_records[f"{res_str}.num_examples"] = MetricRecord(
|
246
240
|
{"num_examples": fitres.num_examples},
|
247
241
|
)
|
248
|
-
recorddict.
|
249
|
-
|
250
|
-
|
251
|
-
keep_input,
|
252
|
-
)
|
242
|
+
recorddict.array_records[f"{res_str}.parameters"] = parameters_to_arrayrecord(
|
243
|
+
fitres.parameters,
|
244
|
+
keep_input,
|
253
245
|
)
|
254
246
|
|
255
247
|
# status
|
@@ -278,15 +270,15 @@ def recorddict_to_evaluateres(recorddict: RecordDict) -> EvaluateRes:
|
|
278
270
|
"""Derive EvaluateRes from a RecordDict object."""
|
279
271
|
ins_str = "evaluateres"
|
280
272
|
|
281
|
-
loss = cast(int, recorddict.
|
273
|
+
loss = cast(int, recorddict.metric_records[f"{ins_str}.loss"]["loss"])
|
282
274
|
|
283
275
|
num_examples = cast(
|
284
|
-
int, recorddict.
|
276
|
+
int, recorddict.metric_records[f"{ins_str}.num_examples"]["num_examples"]
|
285
277
|
)
|
286
|
-
|
278
|
+
config_record = recorddict.config_records[f"{ins_str}.metrics"]
|
287
279
|
|
288
280
|
# pylint: disable-next=protected-access
|
289
|
-
metrics = _check_mapping_from_recordscalartype_to_scalar(
|
281
|
+
metrics = _check_mapping_from_recordscalartype_to_scalar(config_record)
|
290
282
|
status = _extract_status_from_recorddict(ins_str, recorddict)
|
291
283
|
|
292
284
|
return EvaluateRes(
|
@@ -300,17 +292,17 @@ def evaluateres_to_recorddict(evaluateres: EvaluateRes) -> RecordDict:
|
|
300
292
|
|
301
293
|
res_str = "evaluateres"
|
302
294
|
# loss
|
303
|
-
recorddict.
|
295
|
+
recorddict.metric_records[f"{res_str}.loss"] = MetricRecord(
|
304
296
|
{"loss": evaluateres.loss},
|
305
297
|
)
|
306
298
|
|
307
299
|
# num_examples
|
308
|
-
recorddict.
|
300
|
+
recorddict.metric_records[f"{res_str}.num_examples"] = MetricRecord(
|
309
301
|
{"num_examples": evaluateres.num_examples},
|
310
302
|
)
|
311
303
|
|
312
304
|
# metrics
|
313
|
-
recorddict.
|
305
|
+
recorddict.config_records[f"{res_str}.metrics"] = ConfigRecord(
|
314
306
|
evaluateres.metrics, # type: ignore
|
315
307
|
)
|
316
308
|
|
@@ -324,7 +316,7 @@ def evaluateres_to_recorddict(evaluateres: EvaluateRes) -> RecordDict:
|
|
324
316
|
|
325
317
|
def recorddict_to_getparametersins(recorddict: RecordDict) -> GetParametersIns:
|
326
318
|
"""Derive GetParametersIns from a RecordDict object."""
|
327
|
-
config_record = recorddict.
|
319
|
+
config_record = recorddict.config_records["getparametersins.config"]
|
328
320
|
# pylint: disable-next=protected-access
|
329
321
|
config_dict = _check_mapping_from_recordscalartype_to_scalar(config_record)
|
330
322
|
|
@@ -335,7 +327,7 @@ def getparametersins_to_recorddict(getparameters_ins: GetParametersIns) -> Recor
|
|
335
327
|
"""Construct a RecordDict from a GetParametersIns object."""
|
336
328
|
recorddict = RecordDict()
|
337
329
|
|
338
|
-
recorddict.
|
330
|
+
recorddict.config_records["getparametersins.config"] = ConfigRecord(
|
339
331
|
getparameters_ins.config, # type: ignore
|
340
332
|
)
|
341
333
|
return recorddict
|
@@ -347,10 +339,10 @@ def getparametersres_to_recorddict(
|
|
347
339
|
"""Construct a RecordDict from a GetParametersRes object."""
|
348
340
|
recorddict = RecordDict()
|
349
341
|
res_str = "getparametersres"
|
350
|
-
|
342
|
+
array_record = parameters_to_arrayrecord(
|
351
343
|
getparametersres.parameters, keep_input=keep_input
|
352
344
|
)
|
353
|
-
recorddict.
|
345
|
+
recorddict.array_records[f"{res_str}.parameters"] = array_record
|
354
346
|
|
355
347
|
# status
|
356
348
|
recorddict = _embed_status_into_recorddict(
|
@@ -365,8 +357,8 @@ def recorddict_to_getparametersres(
|
|
365
357
|
) -> GetParametersRes:
|
366
358
|
"""Derive GetParametersRes from a RecordDict object."""
|
367
359
|
res_str = "getparametersres"
|
368
|
-
parameters =
|
369
|
-
recorddict.
|
360
|
+
parameters = arrayrecord_to_parameters(
|
361
|
+
recorddict.array_records[f"{res_str}.parameters"], keep_input=keep_input
|
370
362
|
)
|
371
363
|
|
372
364
|
status = _extract_status_from_recorddict(res_str, recorddict)
|
@@ -375,7 +367,7 @@ def recorddict_to_getparametersres(
|
|
375
367
|
|
376
368
|
def recorddict_to_getpropertiesins(recorddict: RecordDict) -> GetPropertiesIns:
|
377
369
|
"""Derive GetPropertiesIns from a RecordDict object."""
|
378
|
-
config_record = recorddict.
|
370
|
+
config_record = recorddict.config_records["getpropertiesins.config"]
|
379
371
|
# pylint: disable-next=protected-access
|
380
372
|
config_dict = _check_mapping_from_recordscalartype_to_scalar(config_record)
|
381
373
|
|
@@ -385,7 +377,7 @@ def recorddict_to_getpropertiesins(recorddict: RecordDict) -> GetPropertiesIns:
|
|
385
377
|
def getpropertiesins_to_recorddict(getpropertiesins: GetPropertiesIns) -> RecordDict:
|
386
378
|
"""Construct a RecordDict from a GetPropertiesRes object."""
|
387
379
|
recorddict = RecordDict()
|
388
|
-
recorddict.
|
380
|
+
recorddict.config_records["getpropertiesins.config"] = ConfigRecord(
|
389
381
|
getpropertiesins.config, # type: ignore
|
390
382
|
)
|
391
383
|
return recorddict
|
@@ -394,7 +386,7 @@ def getpropertiesins_to_recorddict(getpropertiesins: GetPropertiesIns) -> Record
|
|
394
386
|
def recorddict_to_getpropertiesres(recorddict: RecordDict) -> GetPropertiesRes:
|
395
387
|
"""Derive GetPropertiesRes from a RecordDict object."""
|
396
388
|
res_str = "getpropertiesres"
|
397
|
-
config_record = recorddict.
|
389
|
+
config_record = recorddict.config_records[f"{res_str}.properties"]
|
398
390
|
# pylint: disable-next=protected-access
|
399
391
|
properties = _check_mapping_from_recordscalartype_to_scalar(config_record)
|
400
392
|
|
@@ -407,7 +399,7 @@ def getpropertiesres_to_recorddict(getpropertiesres: GetPropertiesRes) -> Record
|
|
407
399
|
"""Construct a RecordDict from a GetPropertiesRes object."""
|
408
400
|
recorddict = RecordDict()
|
409
401
|
res_str = "getpropertiesres"
|
410
|
-
recorddict.
|
402
|
+
recorddict.config_records[f"{res_str}.properties"] = ConfigRecord(
|
411
403
|
getpropertiesres.properties, # type: ignore
|
412
404
|
)
|
413
405
|
# status
|