flwr-nightly 1.22.0.dev20250915__py3-none-any.whl → 1.22.0.dev20250916__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.
@@ -22,6 +22,9 @@ from .dp_fixed_clipping import (
22
22
  from .fedadagrad import FedAdagrad
23
23
  from .fedadam import FedAdam
24
24
  from .fedavg import FedAvg
25
+ from .fedavgm import FedAvgM
26
+ from .fedmedian import FedMedian
27
+ from .fedtrimmedavg import FedTrimmedAvg
25
28
  from .fedxgb_bagging import FedXgbBagging
26
29
  from .fedyogi import FedYogi
27
30
  from .result import Result
@@ -33,6 +36,9 @@ __all__ = [
33
36
  "FedAdagrad",
34
37
  "FedAdam",
35
38
  "FedAvg",
39
+ "FedAvgM",
40
+ "FedMedian",
41
+ "FedTrimmedAvg",
36
42
  "FedXgbBagging",
37
43
  "FedYogi",
38
44
  "Result",
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
  from collections.abc import Iterable
19
- from logging import INFO
19
+ from logging import INFO, WARNING
20
20
  from typing import Callable, Optional
21
21
 
22
22
  from flwr.common import (
@@ -67,7 +67,7 @@ class FedAvg(Strategy):
67
67
  arrayrecord_key : str (default: "arrays")
68
68
  Key used to store the ArrayRecord when constructing Messages.
69
69
  configrecord_key : str (default: "config")
70
- Key used to store the ConfigRecord when constructing Messages.
70
+ Key used to store the ConfigRecord when constructing Messages.
71
71
  train_metrics_aggr_fn : Optional[callable] (default: None)
72
72
  Function with signature (list[RecordDict], str) -> MetricRecord,
73
73
  used to aggregate MetricRecords from training round replies.
@@ -111,6 +111,20 @@ class FedAvg(Strategy):
111
111
  evaluate_metrics_aggr_fn or aggregate_metricrecords
112
112
  )
113
113
 
114
+ if self.fraction_evaluate == 0.0:
115
+ self.min_evaluate_nodes = 0
116
+ log(
117
+ WARNING,
118
+ "fraction_evaluate is set to 0.0. "
119
+ "Federated evaluation will be skipped.",
120
+ )
121
+ if self.fraction_train == 0.0:
122
+ self.min_train_nodes = 0
123
+ log(
124
+ WARNING,
125
+ "fraction_train is set to 0.0. Federated training will be skipped.",
126
+ )
127
+
114
128
  def summary(self) -> None:
115
129
  """Log summary configuration of the strategy."""
116
130
  log(INFO, "\t├──> Sampling:")
@@ -150,6 +164,9 @@ class FedAvg(Strategy):
150
164
  self, server_round: int, arrays: ArrayRecord, config: ConfigRecord, grid: Grid
151
165
  ) -> Iterable[Message]:
152
166
  """Configure the next round of federated training."""
167
+ # Do not configure federated train if fraction_train is 0.
168
+ if self.fraction_train == 0.0:
169
+ return []
153
170
  # Sample nodes
154
171
  num_nodes = int(len(list(grid.get_node_ids())) * self.fraction_train)
155
172
  sample_size = max(num_nodes, self.min_train_nodes)
@@ -259,6 +276,10 @@ class FedAvg(Strategy):
259
276
  self, server_round: int, arrays: ArrayRecord, config: ConfigRecord, grid: Grid
260
277
  ) -> Iterable[Message]:
261
278
  """Configure the next round of federated evaluation."""
279
+ # Do not configure federated evaluation if fraction_evaluate is 0.
280
+ if self.fraction_evaluate == 0.0:
281
+ return []
282
+
262
283
  # Sample nodes
263
284
  num_nodes = int(len(list(grid.get_node_ids())) * self.fraction_evaluate)
264
285
  sample_size = max(num_nodes, self.min_evaluate_nodes)
@@ -0,0 +1,198 @@
1
+ # Copyright 2025 Flower Labs GmbH. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ==============================================================================
15
+ """Federated Averaging with Momentum (FedAvgM) [Hsu et al., 2019] strategy.
16
+
17
+ Paper: arxiv.org/pdf/1909.06335.pdf
18
+ """
19
+
20
+
21
+ from collections import OrderedDict
22
+ from collections.abc import Iterable
23
+ from logging import INFO
24
+ from typing import Callable, Optional
25
+
26
+ from flwr.common import (
27
+ Array,
28
+ ArrayRecord,
29
+ ConfigRecord,
30
+ Message,
31
+ MetricRecord,
32
+ NDArrays,
33
+ RecordDict,
34
+ log,
35
+ )
36
+ from flwr.server import Grid
37
+
38
+ from ..exception import AggregationError
39
+ from .fedavg import FedAvg
40
+
41
+
42
+ class FedAvgM(FedAvg):
43
+ """Federated Averaging with Momentum strategy.
44
+
45
+ Implementation based on https://arxiv.org/abs/1909.06335
46
+
47
+ Parameters
48
+ ----------
49
+ fraction_train : float (default: 1.0)
50
+ Fraction of nodes used during training. In case `min_train_nodes`
51
+ is larger than `fraction_train * total_connected_nodes`, `min_train_nodes`
52
+ will still be sampled.
53
+ fraction_evaluate : float (default: 1.0)
54
+ Fraction of nodes used during validation. In case `min_evaluate_nodes`
55
+ is larger than `fraction_evaluate * total_connected_nodes`,
56
+ `min_evaluate_nodes` will still be sampled.
57
+ min_train_nodes : int (default: 2)
58
+ Minimum number of nodes used during training.
59
+ min_evaluate_nodes : int (default: 2)
60
+ Minimum number of nodes used during validation.
61
+ min_available_nodes : int (default: 2)
62
+ Minimum number of total nodes in the system.
63
+ weighted_by_key : str (default: "num-examples")
64
+ The key within each MetricRecord whose value is used as the weight when
65
+ computing weighted averages for both ArrayRecords and MetricRecords.
66
+ arrayrecord_key : str (default: "arrays")
67
+ Key used to store the ArrayRecord when constructing Messages.
68
+ configrecord_key : str (default: "config")
69
+ Key used to store the ConfigRecord when constructing Messages.
70
+ train_metrics_aggr_fn : Optional[callable] (default: None)
71
+ Function with signature (list[RecordDict], str) -> MetricRecord,
72
+ used to aggregate MetricRecords from training round replies.
73
+ If `None`, defaults to `aggregate_metricrecords`, which performs a weighted
74
+ average using the provided weight factor key.
75
+ evaluate_metrics_aggr_fn : Optional[callable] (default: None)
76
+ Function with signature (list[RecordDict], str) -> MetricRecord,
77
+ used to aggregate MetricRecords from training round replies.
78
+ If `None`, defaults to `aggregate_metricrecords`, which performs a weighted
79
+ average using the provided weight factor key.
80
+ server_learning_rate: float (default: 1.0)
81
+ Server-side learning rate used in server-side optimization.
82
+ server_momentum: float (default: 0.0)
83
+ Server-side momentum factor used for FedAvgM.
84
+ """
85
+
86
+ def __init__( # pylint: disable=R0913, R0917
87
+ self,
88
+ fraction_train: float = 1.0,
89
+ fraction_evaluate: float = 1.0,
90
+ min_train_nodes: int = 2,
91
+ min_evaluate_nodes: int = 2,
92
+ min_available_nodes: int = 2,
93
+ weighted_by_key: str = "num-examples",
94
+ arrayrecord_key: str = "arrays",
95
+ configrecord_key: str = "config",
96
+ train_metrics_aggr_fn: Optional[
97
+ Callable[[list[RecordDict], str], MetricRecord]
98
+ ] = None,
99
+ evaluate_metrics_aggr_fn: Optional[
100
+ Callable[[list[RecordDict], str], MetricRecord]
101
+ ] = None,
102
+ server_learning_rate: float = 1.0,
103
+ server_momentum: float = 0.0,
104
+ ) -> None:
105
+ super().__init__(
106
+ fraction_train=fraction_train,
107
+ fraction_evaluate=fraction_evaluate,
108
+ min_train_nodes=min_train_nodes,
109
+ min_evaluate_nodes=min_evaluate_nodes,
110
+ min_available_nodes=min_available_nodes,
111
+ weighted_by_key=weighted_by_key,
112
+ arrayrecord_key=arrayrecord_key,
113
+ configrecord_key=configrecord_key,
114
+ train_metrics_aggr_fn=train_metrics_aggr_fn,
115
+ evaluate_metrics_aggr_fn=evaluate_metrics_aggr_fn,
116
+ )
117
+ self.server_learning_rate = server_learning_rate
118
+ self.server_momentum = server_momentum
119
+ self.server_opt: bool = (self.server_momentum != 0.0) or (
120
+ self.server_learning_rate != 1.0
121
+ )
122
+ self.current_arrays: Optional[ArrayRecord] = None
123
+ self.momentum_vector: Optional[NDArrays] = None
124
+
125
+ def summary(self) -> None:
126
+ """Log summary configuration of the strategy."""
127
+ opt_status = "ON" if self.server_opt else "OFF"
128
+ log(INFO, "\t├──> FedAvgM settings:")
129
+ log(INFO, "\t|\t├── Server optimization: %s", opt_status)
130
+ log(INFO, "\t|\t├── Server learning rate: %s", self.server_learning_rate)
131
+ log(INFO, "\t|\t└── Server Momentum: %s", self.server_momentum)
132
+ super().summary()
133
+
134
+ def configure_train(
135
+ self, server_round: int, arrays: ArrayRecord, config: ConfigRecord, grid: Grid
136
+ ) -> Iterable[Message]:
137
+ """Configure the next round of federated training."""
138
+ if self.current_arrays is None:
139
+ self.current_arrays = arrays
140
+ return super().configure_train(server_round, arrays, config, grid)
141
+
142
+ def aggregate_train(
143
+ self,
144
+ server_round: int,
145
+ replies: Iterable[Message],
146
+ ) -> tuple[Optional[ArrayRecord], Optional[MetricRecord]]:
147
+ """Aggregate ArrayRecords and MetricRecords in the received Messages."""
148
+ # Call FedAvg aggregate_train to perform validation and aggregation
149
+ aggregated_arrays, aggregated_metrics = super().aggregate_train(
150
+ server_round, replies
151
+ )
152
+
153
+ # following convention described in
154
+ # https://pytorch.org/docs/stable/generated/torch.optim.SGD.html
155
+ if self.server_opt and aggregated_arrays is not None:
156
+ # The initial parameters should be set in `start()` method already
157
+ if self.current_arrays is None:
158
+ raise AggregationError(
159
+ "No initial parameters set for FedAvgM. "
160
+ "Ensure that `configure_train` has been called before aggregation."
161
+ )
162
+ ndarrays = self.current_arrays.to_numpy_ndarrays()
163
+ aggregated_ndarrays = aggregated_arrays.to_numpy_ndarrays()
164
+
165
+ # Preserve keys for arrays in ArrayRecord
166
+ array_keys = list(aggregated_arrays.keys())
167
+ aggregated_arrays.clear()
168
+
169
+ # Remember that updates are the opposite of gradients
170
+ pseudo_gradient = [
171
+ old - new for new, old in zip(aggregated_ndarrays, ndarrays)
172
+ ]
173
+ if self.server_momentum > 0.0:
174
+ if self.momentum_vector is None:
175
+ # Initialize momentum vector in the first round
176
+ self.momentum_vector = pseudo_gradient
177
+ else:
178
+ self.momentum_vector = [
179
+ self.server_momentum * mv + pg
180
+ for mv, pg in zip(self.momentum_vector, pseudo_gradient)
181
+ ]
182
+
183
+ # No nesterov for now
184
+ pseudo_gradient = self.momentum_vector
185
+
186
+ # SGD and convert back to ArrayRecord
187
+ updated_array_list = [
188
+ Array(old - self.server_learning_rate * pg)
189
+ for old, pg in zip(ndarrays, pseudo_gradient)
190
+ ]
191
+ aggregated_arrays = ArrayRecord(
192
+ OrderedDict(zip(array_keys, updated_array_list))
193
+ )
194
+
195
+ # Update current weights
196
+ self.current_arrays = aggregated_arrays
197
+
198
+ return aggregated_arrays, aggregated_metrics
@@ -0,0 +1,71 @@
1
+ # Copyright 2025 Flower Labs GmbH. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ==============================================================================
15
+ """Federated Median (FedMedian) [Yin et al., 2018] strategy.
16
+
17
+ Paper: arxiv.org/pdf/1803.01498v1.pdf
18
+ """
19
+
20
+
21
+ from collections.abc import Iterable
22
+ from typing import Optional, cast
23
+
24
+ import numpy as np
25
+
26
+ from flwr.common import Array, ArrayRecord, Message, MetricRecord
27
+
28
+ from .fedavg import FedAvg
29
+
30
+
31
+ class FedMedian(FedAvg):
32
+ """Federated Median (FedMedian) strategy.
33
+
34
+ Implementation based on https://arxiv.org/pdf/1803.01498v1
35
+ """
36
+
37
+ def aggregate_train(
38
+ self,
39
+ server_round: int,
40
+ replies: Iterable[Message],
41
+ ) -> tuple[Optional[ArrayRecord], Optional[MetricRecord]]:
42
+ """Aggregate ArrayRecords and MetricRecords in the received Messages."""
43
+ # Call FedAvg aggregate_train to perform validation and aggregation
44
+ valid_replies, _ = self._check_and_log_replies(replies, is_train=True)
45
+
46
+ if not valid_replies:
47
+ return None, None
48
+
49
+ # Aggregate ArrayRecords using median
50
+ # Get the key for the only ArrayRecord from the first Message
51
+ record_key = list(valid_replies[0].content.array_records.keys())[0]
52
+ # Preserve keys for arrays in ArrayRecord
53
+ array_keys = list(valid_replies[0].content[record_key].keys())
54
+
55
+ # Compute median for each layer and construct ArrayRecord
56
+ arrays = ArrayRecord()
57
+ for array_key in array_keys:
58
+ # Get the corresponding layer from each client
59
+ layers = [
60
+ cast(ArrayRecord, msg.content[record_key]).pop(array_key).numpy()
61
+ for msg in valid_replies
62
+ ]
63
+ # Compute median and save as Array in ArrayRecord
64
+ arrays[array_key] = Array(np.median(np.stack(layers), axis=0))
65
+
66
+ # Aggregate MetricRecords
67
+ metrics = self.train_metrics_aggr_fn(
68
+ [msg.content for msg in valid_replies],
69
+ self.weighted_by_key,
70
+ )
71
+ return arrays, metrics
@@ -0,0 +1,176 @@
1
+ # Copyright 2025 Flower Labs GmbH. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ==============================================================================
15
+ """Federated Averaging with Trimmed Mean [Dong Yin, et al., 2021].
16
+
17
+ Paper: arxiv.org/abs/1803.01498
18
+ """
19
+
20
+
21
+ from collections.abc import Iterable
22
+ from logging import INFO
23
+ from typing import Callable, Optional, cast
24
+
25
+ import numpy as np
26
+
27
+ from flwr.common import Array, ArrayRecord, Message, MetricRecord, NDArray, RecordDict
28
+ from flwr.common.logger import log
29
+
30
+ from ..exception import AggregationError
31
+ from .fedavg import FedAvg
32
+
33
+
34
+ class FedTrimmedAvg(FedAvg):
35
+ """Federated Averaging with Trimmed Mean [Dong Yin, et al., 2021].
36
+
37
+ Implemented based on: https://arxiv.org/abs/1803.01498
38
+
39
+ Parameters
40
+ ----------
41
+ fraction_train : float (default: 1.0)
42
+ Fraction of nodes used during training. In case `min_train_nodes`
43
+ is larger than `fraction_train * total_connected_nodes`, `min_train_nodes`
44
+ will still be sampled.
45
+ fraction_evaluate : float (default: 1.0)
46
+ Fraction of nodes used during validation. In case `min_evaluate_nodes`
47
+ is larger than `fraction_evaluate * total_connected_nodes`,
48
+ `min_evaluate_nodes` will still be sampled.
49
+ min_train_nodes : int (default: 2)
50
+ Minimum number of nodes used during training.
51
+ min_evaluate_nodes : int (default: 2)
52
+ Minimum number of nodes used during validation.
53
+ min_available_nodes : int (default: 2)
54
+ Minimum number of total nodes in the system.
55
+ weighted_by_key : str (default: "num-examples")
56
+ The key within each MetricRecord whose value is used as the weight when
57
+ computing weighted averages for both ArrayRecords and MetricRecords.
58
+ arrayrecord_key : str (default: "arrays")
59
+ Key used to store the ArrayRecord when constructing Messages.
60
+ configrecord_key : str (default: "config")
61
+ Key used to store the ConfigRecord when constructing Messages.
62
+ train_metrics_aggr_fn : Optional[callable] (default: None)
63
+ Function with signature (list[RecordDict], str) -> MetricRecord,
64
+ used to aggregate MetricRecords from training round replies.
65
+ If `None`, defaults to `aggregate_metricrecords`, which performs a weighted
66
+ average using the provided weight factor key.
67
+ evaluate_metrics_aggr_fn : Optional[callable] (default: None)
68
+ Function with signature (list[RecordDict], str) -> MetricRecord,
69
+ used to aggregate MetricRecords from training round replies.
70
+ If `None`, defaults to `aggregate_metricrecords`, which performs a weighted
71
+ average using the provided weight factor key.
72
+ beta : float (default: 0.2)
73
+ Fraction to cut off of both tails of the distribution.
74
+ """
75
+
76
+ def __init__( # pylint: disable=R0913, R0917
77
+ self,
78
+ fraction_train: float = 1.0,
79
+ fraction_evaluate: float = 1.0,
80
+ min_train_nodes: int = 2,
81
+ min_evaluate_nodes: int = 2,
82
+ min_available_nodes: int = 2,
83
+ weighted_by_key: str = "num-examples",
84
+ arrayrecord_key: str = "arrays",
85
+ configrecord_key: str = "config",
86
+ train_metrics_aggr_fn: Optional[
87
+ Callable[[list[RecordDict], str], MetricRecord]
88
+ ] = None,
89
+ evaluate_metrics_aggr_fn: Optional[
90
+ Callable[[list[RecordDict], str], MetricRecord]
91
+ ] = None,
92
+ beta: float = 0.2,
93
+ ) -> None:
94
+ super().__init__(
95
+ fraction_train=fraction_train,
96
+ fraction_evaluate=fraction_evaluate,
97
+ min_train_nodes=min_train_nodes,
98
+ min_evaluate_nodes=min_evaluate_nodes,
99
+ min_available_nodes=min_available_nodes,
100
+ weighted_by_key=weighted_by_key,
101
+ arrayrecord_key=arrayrecord_key,
102
+ configrecord_key=configrecord_key,
103
+ train_metrics_aggr_fn=train_metrics_aggr_fn,
104
+ evaluate_metrics_aggr_fn=evaluate_metrics_aggr_fn,
105
+ )
106
+ self.beta = beta
107
+
108
+ def summary(self) -> None:
109
+ """Log summary configuration of the strategy."""
110
+ log(INFO, "\t├──> FedTrimmedAvg settings:")
111
+ log(INFO, "\t|\t└── beta: %s", self.beta)
112
+ super().summary()
113
+
114
+ def aggregate_train(
115
+ self,
116
+ server_round: int,
117
+ replies: Iterable[Message],
118
+ ) -> tuple[Optional[ArrayRecord], Optional[MetricRecord]]:
119
+ """Aggregate ArrayRecords and MetricRecords in the received Messages."""
120
+ # Call FedAvg aggregate_train to perform validation and aggregation
121
+ valid_replies, _ = self._check_and_log_replies(replies, is_train=True)
122
+
123
+ if not valid_replies:
124
+ return None, None
125
+
126
+ # Aggregate ArrayRecords using trimmed mean
127
+ # Get the key for the only ArrayRecord from the first Message
128
+ record_key = list(valid_replies[0].content.array_records.keys())[0]
129
+ # Preserve keys for arrays in ArrayRecord
130
+ array_keys = list(valid_replies[0].content[record_key].keys())
131
+
132
+ # Compute trimmed mean for each layer and construct ArrayRecord
133
+ arrays = ArrayRecord()
134
+ for array_key in array_keys:
135
+ # Get the corresponding layer from each client
136
+ layers = [
137
+ cast(ArrayRecord, msg.content[record_key]).pop(array_key).numpy()
138
+ for msg in valid_replies
139
+ ]
140
+ # Compute trimmed mean and save as Array in ArrayRecord
141
+ try:
142
+ arrays[array_key] = Array(trim_mean(np.stack(layers), self.beta))
143
+ except ValueError as e:
144
+ raise AggregationError(
145
+ f"Trimmed mean could not be computed. "
146
+ f"Likely cause: beta={self.beta} is too large."
147
+ ) from e
148
+
149
+ # Aggregate MetricRecords
150
+ metrics = self.train_metrics_aggr_fn(
151
+ [msg.content for msg in valid_replies],
152
+ self.weighted_by_key,
153
+ )
154
+ return arrays, metrics
155
+
156
+
157
+ def trim_mean(array: NDArray, cut_fraction: float) -> NDArray:
158
+ """Compute trimmed mean along axis=0.
159
+
160
+ It is based on the scipy implementation:
161
+
162
+ https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.trim_mean.html
163
+ """
164
+ axis = 0
165
+ nobs = array.shape[0]
166
+ lowercut = int(cut_fraction * nobs)
167
+ uppercut = nobs - lowercut
168
+ if lowercut > uppercut:
169
+ raise ValueError("Fraction too big.")
170
+
171
+ atmp = np.partition(array, (lowercut, uppercut - 1), axis)
172
+
173
+ slice_list = [slice(None)] * atmp.ndim
174
+ slice_list[axis] = slice(lowercut, uppercut)
175
+ result: NDArray = np.mean(atmp[tuple(slice_list)], axis=axis)
176
+ return result
@@ -16,12 +16,20 @@
16
16
 
17
17
 
18
18
  from collections import OrderedDict
19
+ from unittest.mock import Mock
19
20
 
20
21
  import numpy as np
21
22
  import pytest
22
23
  from parameterized import parameterized
23
24
 
24
- from flwr.common import Array, ArrayRecord, ConfigRecord, MetricRecord, RecordDict
25
+ from flwr.common import (
26
+ Array,
27
+ ArrayRecord,
28
+ ConfigRecord,
29
+ Message,
30
+ MetricRecord,
31
+ RecordDict,
32
+ )
25
33
  from flwr.serverapp.exception import InconsistentMessageReplies
26
34
 
27
35
  from .strategy_utils import (
@@ -32,6 +40,17 @@ from .strategy_utils import (
32
40
  )
33
41
 
34
42
 
43
+ def create_mock_reply(arrays: ArrayRecord, num_examples: float) -> Message:
44
+ """Create a mock reply Message with default keys."""
45
+ message = Mock(spec=Message)
46
+ message.content = RecordDict(
47
+ {"arrays": arrays, "metrics": MetricRecord({"num-examples": num_examples})}
48
+ )
49
+ message.has_error.side_effect = lambda: False
50
+ message.has_content.side_effect = lambda: True
51
+ return message
52
+
53
+
35
54
  def test_config_to_str() -> None:
36
55
  """Test that items of types bytes are masked out."""
37
56
  config = ConfigRecord({"a": 123, "b": [1, 2, 3], "c": b"bytes"})
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: flwr-nightly
3
- Version: 1.22.0.dev20250915
3
+ Version: 1.22.0.dev20250916
4
4
  Summary: Flower: A Friendly Federated AI Framework
5
5
  License: Apache-2.0
6
6
  Keywords: Artificial Intelligence,Federated AI,Federated Analytics,Federated Evaluation,Federated Learning,Flower,Machine Learning
@@ -102,25 +102,15 @@ Meet the Flower community on [flower.ai](https://flower.ai)!
102
102
 
103
103
  Flower's goal is to make federated learning accessible to everyone. This series of tutorials introduces the fundamentals of federated learning and how to implement them in Flower.
104
104
 
105
- 0. **What is Federated Learning?**
105
+ 0. **[What is Federated Learning?](https://flower.ai/docs/framework/main/en/tutorial-series-what-is-federated-learning.html)**
106
106
 
107
- [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/adap/flower/blob/main/framework/docs/source/tutorial-series-what-is-federated-learning.ipynb) (or open the [Jupyter Notebook](https://github.com/adap/flower/blob/main/framework/docs/source/tutorial-series-what-is-federated-learning.ipynb))
107
+ 1. **[An Introduction to Federated Learning](https://flower.ai/docs/framework/main/en/tutorial-series-get-started-with-flower-pytorch.html)**
108
108
 
109
- 1. **An Introduction to Federated Learning**
109
+ 2. **[Using Strategies in Federated Learning](https://flower.ai/docs/framework/main/en/tutorial-series-use-a-federated-learning-strategy-pytorch.html)**
110
110
 
111
- [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/adap/flower/blob/main/framework/docs/source/tutorial-series-get-started-with-flower-pytorch.ipynb) (or open the [Jupyter Notebook](https://github.com/adap/flower/blob/main/framework/docs/source/tutorial-series-get-started-with-flower-pytorch.ipynb))
111
+ 3. **[Customize a Flower Strategy](https://flower.ai/docs/framework/main/en/tutorial-series-build-a-strategy-from-scratch-pytorch.html)**
112
112
 
113
- 2. **Using Strategies in Federated Learning**
114
-
115
- [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/adap/flower/blob/main/framework/docs/source/tutorial-series-use-a-federated-learning-strategy-pytorch.ipynb) (or open the [Jupyter Notebook](https://github.com/adap/flower/blob/main/framework/docs/source/tutorial-series-use-a-federated-learning-strategy-pytorch.ipynb))
116
-
117
- 3. **Building Strategies for Federated Learning**
118
-
119
- [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/adap/flower/blob/main/framework/docs/source/tutorial-series-build-a-strategy-from-scratch-pytorch.ipynb) (or open the [Jupyter Notebook](https://github.com/adap/flower/blob/main/framework/docs/source/tutorial-series-build-a-strategy-from-scratch-pytorch.ipynb))
120
-
121
- 4. **Custom Clients for Federated Learning**
122
-
123
- [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/adap/flower/blob/main/framework/docs/source/tutorial-series-customize-the-client-pytorch.ipynb) (or open the [Jupyter Notebook](https://github.com/adap/flower/blob/main/framework/docs/source/tutorial-series-customize-the-client-pytorch.ipynb))
113
+ 4. **[Communicate Custom Messages](https://flower.ai/docs/framework/main/en/tutorial-series-customize-the-client-pytorch.html)**
124
114
 
125
115
  Stay tuned, more tutorials are coming soon. Topics include **Privacy and Security in Federated Learning**, and **Scaling Federated Learning**.
126
116
 
@@ -332,18 +332,21 @@ flwr/server/workflow/secure_aggregation/secaggplus_workflow.py,sha256=DkayCsnlAy
332
332
  flwr/serverapp/__init__.py,sha256=ZujKNXULwhWYQhFnxOOT5Wi9MRq2JCWFhAAj7ouiQ78,884
333
333
  flwr/serverapp/dp_fixed_clipping.py,sha256=wbP4W7CaUHXdll8ZSVUnTBSEWrnWM00CGk63rOR-Q2s,12133
334
334
  flwr/serverapp/exception.py,sha256=5cuH-2AafvihzosWDdDjuMmHdDqZ1XxHvCqZXNBVklw,1334
335
- flwr/serverapp/strategy/__init__.py,sha256=0ldxlooz4a5yewUbQJGVrW9awrrIcFDIrNR4yZgpfKw,1292
335
+ flwr/serverapp/strategy/__init__.py,sha256=MHrU_tz_myWqzG3h4gZdIpt2DDN-JdNK-HHIcrz1-Ns,1448
336
336
  flwr/serverapp/strategy/dp_fixed_clipping.py,sha256=wbP4W7CaUHXdll8ZSVUnTBSEWrnWM00CGk63rOR-Q2s,12133
337
337
  flwr/serverapp/strategy/fedadagrad.py,sha256=fD65P6OEERa_pxq847e1UZpA083AcWR44XavYB0naGM,6343
338
338
  flwr/serverapp/strategy/fedadam.py,sha256=s3xPIqhopy6yPTeFxevSPnc7a6BcKnKsvo2AaO6Z_xs,7138
339
- flwr/serverapp/strategy/fedavg.py,sha256=53L06lZLkbGV0TRZrUWvPaocvFTT1PAhTvu9UkKq1zE,11294
339
+ flwr/serverapp/strategy/fedavg.py,sha256=Bq_nlmngzJbjqX1fF1mevXGVN6-pwglHv-6yNrs6lkA,12035
340
+ flwr/serverapp/strategy/fedavgm.py,sha256=VlByltWzUYCoiVIWPFRqsqLKNWjlOlO2INK8SUxEjzk,8327
341
+ flwr/serverapp/strategy/fedmedian.py,sha256=b31Dk0LQBbQxi_f-jeSbWHI7iOBugcuBSN2Az-_a75E,2596
340
342
  flwr/serverapp/strategy/fedopt.py,sha256=kqT0uV2IUE93O72XEVa1JJo61dcwbZEoT9KmYTjR2tE,8477
343
+ flwr/serverapp/strategy/fedtrimmedavg.py,sha256=4-QxgAQGo_7vB_L7qDYy28d95OBt9MeDa92yaTRMHqk,7166
341
344
  flwr/serverapp/strategy/fedxgb_bagging.py,sha256=ktDjzov4y0BRecioq788umCEtcuwElou9olBizQKOnM,3282
342
345
  flwr/serverapp/strategy/fedyogi.py,sha256=1Ripr4Hi2cdeTOLiFOXtMKvOxR3BsUQwc7bbTrXN4LM,6653
343
346
  flwr/serverapp/strategy/result.py,sha256=E0Hl2VLnZAgQJjE2GDoKsK7JX-kPPU2KXc47Axt6hGw,4295
344
347
  flwr/serverapp/strategy/strategy.py,sha256=8uJGGm1ROLZERQ_dkRS7Z_rs-yK6XCE0UxXtIdFiEWk,10789
345
348
  flwr/serverapp/strategy/strategy_utils.py,sha256=hiwS7k-Hx6_c4NZXoKpHucS5CBKb7f8GppXRBSMt3Us,10851
346
- flwr/serverapp/strategy/strategy_utils_tests.py,sha256=o32XHujd9PLCB-YZMI2AttWLlvUXHe9yuxgiCrCkpgU,10209
349
+ flwr/serverapp/strategy/strategy_utils_tests.py,sha256=_adS23Lrv1QA6V_3oZ7P_csMd8RqDObFeIhOkFnNtTg,10690
347
350
  flwr/simulation/__init__.py,sha256=Gg6OsP1Z-ixc3-xxzvl7j7rz2Fijy9rzyEPpxgAQCeM,1556
348
351
  flwr/simulation/app.py,sha256=LbGLMvN9Ap119yBqsUcNNmVLRnCySnr4VechqcQ1hpA,10401
349
352
  flwr/simulation/legacy_app.py,sha256=nMISQqW0otJL1-2Kfd94O6BLlGS2IEmEPKTM2WGKrIs,15861
@@ -404,7 +407,7 @@ flwr/supernode/servicer/__init__.py,sha256=lucTzre5WPK7G1YLCfaqg3rbFWdNSb7ZTt-ca
404
407
  flwr/supernode/servicer/clientappio/__init__.py,sha256=7Oy62Y_oijqF7Dxi6tpcUQyOpLc_QpIRZ83NvwmB0Yg,813
405
408
  flwr/supernode/servicer/clientappio/clientappio_servicer.py,sha256=nIHRu38EWK-rpNOkcgBRAAKwYQQWFeCwu0lkO7OPZGQ,10239
406
409
  flwr/supernode/start_client_internal.py,sha256=Y9S1-QlO2WP6eo4JvWzIpfaCoh2aoE7bjEYyxNNnlyg,20777
407
- flwr_nightly-1.22.0.dev20250915.dist-info/METADATA,sha256=FBo-ub8Rc1rRhLrioWMroybBDcoP9t7v6vBqdE9U3do,15967
408
- flwr_nightly-1.22.0.dev20250915.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
409
- flwr_nightly-1.22.0.dev20250915.dist-info/entry_points.txt,sha256=hxHD2ixb_vJFDOlZV-zB4Ao32_BQlL34ftsDh1GXv14,420
410
- flwr_nightly-1.22.0.dev20250915.dist-info/RECORD,,
410
+ flwr_nightly-1.22.0.dev20250916.dist-info/METADATA,sha256=5fd7FMKBNE9N1UWd12_xAPWowIbjr948mx-erdTIBBM,14559
411
+ flwr_nightly-1.22.0.dev20250916.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
412
+ flwr_nightly-1.22.0.dev20250916.dist-info/entry_points.txt,sha256=hxHD2ixb_vJFDOlZV-zB4Ao32_BQlL34ftsDh1GXv14,420
413
+ flwr_nightly-1.22.0.dev20250916.dist-info/RECORD,,