flwr-nightly 1.8.0.dev20240315__py3-none-any.whl → 1.15.0.dev20250115__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- flwr/cli/app.py +16 -2
- flwr/cli/build.py +181 -0
- flwr/cli/cli_user_auth_interceptor.py +90 -0
- flwr/cli/config_utils.py +343 -0
- flwr/cli/example.py +4 -1
- flwr/cli/install.py +253 -0
- flwr/cli/log.py +182 -0
- flwr/{server/superlink/state → cli/login}/__init__.py +4 -10
- flwr/cli/login/login.py +88 -0
- flwr/cli/ls.py +327 -0
- flwr/cli/new/__init__.py +1 -0
- flwr/cli/new/new.py +210 -66
- flwr/cli/new/templates/app/.gitignore.tpl +163 -0
- flwr/cli/new/templates/app/LICENSE.tpl +202 -0
- flwr/cli/new/templates/app/README.baseline.md.tpl +127 -0
- flwr/cli/new/templates/app/README.flowertune.md.tpl +66 -0
- flwr/cli/new/templates/app/README.md.tpl +16 -32
- flwr/cli/new/templates/app/code/__init__.baseline.py.tpl +1 -0
- flwr/cli/new/templates/app/code/__init__.py.tpl +1 -1
- flwr/cli/new/templates/app/code/client.baseline.py.tpl +58 -0
- flwr/cli/new/templates/app/code/client.huggingface.py.tpl +55 -0
- flwr/cli/new/templates/app/code/client.jax.py.tpl +50 -0
- flwr/cli/new/templates/app/code/client.mlx.py.tpl +73 -0
- flwr/cli/new/templates/app/code/client.numpy.py.tpl +7 -7
- flwr/cli/new/templates/app/code/client.pytorch.py.tpl +30 -21
- flwr/cli/new/templates/app/code/client.sklearn.py.tpl +63 -0
- flwr/cli/new/templates/app/code/client.tensorflow.py.tpl +57 -1
- flwr/cli/new/templates/app/code/dataset.baseline.py.tpl +36 -0
- flwr/cli/new/templates/app/code/flwr_tune/__init__.py +15 -0
- flwr/cli/new/templates/app/code/flwr_tune/client_app.py.tpl +126 -0
- flwr/cli/new/templates/app/code/flwr_tune/dataset.py.tpl +87 -0
- flwr/cli/new/templates/app/code/flwr_tune/models.py.tpl +78 -0
- flwr/cli/new/templates/app/code/flwr_tune/server_app.py.tpl +94 -0
- flwr/cli/new/templates/app/code/flwr_tune/strategy.py.tpl +83 -0
- flwr/cli/new/templates/app/code/model.baseline.py.tpl +80 -0
- flwr/cli/new/templates/app/code/server.baseline.py.tpl +46 -0
- flwr/cli/new/templates/app/code/server.huggingface.py.tpl +38 -0
- flwr/cli/new/templates/app/code/server.jax.py.tpl +26 -0
- flwr/cli/new/templates/app/code/server.mlx.py.tpl +31 -0
- flwr/cli/new/templates/app/code/server.numpy.py.tpl +22 -9
- flwr/cli/new/templates/app/code/server.pytorch.py.tpl +21 -18
- flwr/cli/new/templates/app/code/server.sklearn.py.tpl +36 -0
- flwr/cli/new/templates/app/code/server.tensorflow.py.tpl +29 -1
- flwr/cli/new/templates/app/code/strategy.baseline.py.tpl +1 -0
- flwr/cli/new/templates/app/code/task.huggingface.py.tpl +102 -0
- flwr/cli/new/templates/app/code/task.jax.py.tpl +57 -0
- flwr/cli/new/templates/app/code/task.mlx.py.tpl +102 -0
- flwr/cli/new/templates/app/code/task.numpy.py.tpl +7 -0
- flwr/cli/new/templates/app/code/task.pytorch.py.tpl +29 -24
- flwr/cli/new/templates/app/code/task.sklearn.py.tpl +67 -0
- flwr/cli/new/templates/app/code/task.tensorflow.py.tpl +53 -0
- flwr/cli/new/templates/app/code/utils.baseline.py.tpl +1 -0
- flwr/cli/new/templates/app/pyproject.baseline.toml.tpl +138 -0
- flwr/cli/new/templates/app/pyproject.flowertune.toml.tpl +68 -0
- flwr/cli/new/templates/app/pyproject.huggingface.toml.tpl +46 -0
- flwr/cli/new/templates/app/pyproject.jax.toml.tpl +35 -0
- flwr/cli/new/templates/app/pyproject.mlx.toml.tpl +39 -0
- flwr/cli/new/templates/app/pyproject.numpy.toml.tpl +25 -12
- flwr/cli/new/templates/app/pyproject.pytorch.toml.tpl +29 -14
- flwr/cli/new/templates/app/pyproject.sklearn.toml.tpl +35 -0
- flwr/cli/new/templates/app/pyproject.tensorflow.toml.tpl +29 -14
- flwr/cli/run/__init__.py +1 -0
- flwr/cli/run/run.py +212 -34
- flwr/cli/stop.py +130 -0
- flwr/cli/utils.py +240 -5
- flwr/client/__init__.py +3 -2
- flwr/client/app.py +432 -255
- flwr/client/client.py +1 -11
- flwr/client/client_app.py +74 -13
- flwr/client/clientapp/__init__.py +22 -0
- flwr/client/clientapp/app.py +259 -0
- flwr/client/clientapp/clientappio_servicer.py +244 -0
- flwr/client/clientapp/utils.py +115 -0
- flwr/client/dpfedavg_numpy_client.py +7 -8
- flwr/client/grpc_adapter_client/__init__.py +15 -0
- flwr/client/grpc_adapter_client/connection.py +98 -0
- flwr/client/grpc_client/connection.py +21 -7
- flwr/client/grpc_rere_client/__init__.py +1 -1
- flwr/client/grpc_rere_client/client_interceptor.py +176 -0
- flwr/client/grpc_rere_client/connection.py +163 -56
- flwr/client/grpc_rere_client/grpc_adapter.py +167 -0
- flwr/client/heartbeat.py +74 -0
- flwr/client/message_handler/__init__.py +1 -1
- flwr/client/message_handler/message_handler.py +10 -11
- flwr/client/mod/__init__.py +5 -5
- flwr/client/mod/centraldp_mods.py +4 -2
- flwr/client/mod/comms_mods.py +5 -4
- flwr/client/mod/localdp_mod.py +10 -5
- flwr/client/mod/secure_aggregation/__init__.py +1 -1
- flwr/client/mod/secure_aggregation/secaggplus_mod.py +26 -26
- flwr/client/mod/utils.py +2 -4
- flwr/client/nodestate/__init__.py +26 -0
- flwr/client/nodestate/in_memory_nodestate.py +38 -0
- flwr/client/nodestate/nodestate.py +31 -0
- flwr/client/nodestate/nodestate_factory.py +38 -0
- flwr/client/numpy_client.py +8 -31
- flwr/client/rest_client/__init__.py +1 -1
- flwr/client/rest_client/connection.py +199 -176
- flwr/client/run_info_store.py +112 -0
- flwr/client/supernode/__init__.py +24 -0
- flwr/client/supernode/app.py +321 -0
- flwr/client/typing.py +1 -0
- flwr/common/__init__.py +17 -11
- flwr/common/address.py +47 -3
- flwr/common/args.py +153 -0
- flwr/common/auth_plugin/__init__.py +24 -0
- flwr/common/auth_plugin/auth_plugin.py +121 -0
- flwr/common/config.py +243 -0
- flwr/common/constant.py +135 -1
- flwr/common/context.py +32 -2
- flwr/common/date.py +22 -4
- flwr/common/differential_privacy.py +2 -2
- flwr/common/dp.py +2 -4
- flwr/common/exit_handlers.py +3 -3
- flwr/common/grpc.py +164 -5
- flwr/common/logger.py +230 -12
- flwr/common/message.py +191 -106
- flwr/common/object_ref.py +179 -44
- flwr/common/pyproject.py +1 -0
- flwr/common/record/__init__.py +2 -1
- flwr/common/record/configsrecord.py +58 -18
- flwr/common/record/metricsrecord.py +57 -17
- flwr/common/record/parametersrecord.py +88 -20
- flwr/common/record/recordset.py +153 -30
- flwr/common/record/typeddict.py +30 -55
- flwr/common/recordset_compat.py +31 -12
- flwr/common/retry_invoker.py +123 -30
- flwr/common/secure_aggregation/__init__.py +1 -1
- flwr/common/secure_aggregation/crypto/__init__.py +1 -1
- flwr/common/secure_aggregation/crypto/shamir.py +11 -11
- flwr/common/secure_aggregation/crypto/symmetric_encryption.py +68 -4
- flwr/common/secure_aggregation/ndarrays_arithmetic.py +17 -17
- flwr/common/secure_aggregation/quantization.py +8 -8
- flwr/common/secure_aggregation/secaggplus_constants.py +1 -1
- flwr/common/secure_aggregation/secaggplus_utils.py +10 -12
- flwr/common/serde.py +304 -23
- flwr/common/telemetry.py +65 -29
- flwr/common/typing.py +120 -19
- flwr/common/version.py +17 -3
- flwr/proto/clientappio_pb2.py +45 -0
- flwr/proto/clientappio_pb2.pyi +132 -0
- flwr/proto/clientappio_pb2_grpc.py +135 -0
- flwr/proto/clientappio_pb2_grpc.pyi +53 -0
- flwr/proto/exec_pb2.py +62 -0
- flwr/proto/exec_pb2.pyi +212 -0
- flwr/proto/exec_pb2_grpc.py +237 -0
- flwr/proto/exec_pb2_grpc.pyi +93 -0
- flwr/proto/fab_pb2.py +31 -0
- flwr/proto/fab_pb2.pyi +65 -0
- flwr/proto/fab_pb2_grpc.py +4 -0
- flwr/proto/fab_pb2_grpc.pyi +4 -0
- flwr/proto/fleet_pb2.py +42 -23
- flwr/proto/fleet_pb2.pyi +123 -1
- flwr/proto/fleet_pb2_grpc.py +170 -0
- flwr/proto/fleet_pb2_grpc.pyi +61 -0
- flwr/proto/grpcadapter_pb2.py +32 -0
- flwr/proto/grpcadapter_pb2.pyi +43 -0
- flwr/proto/grpcadapter_pb2_grpc.py +66 -0
- flwr/proto/grpcadapter_pb2_grpc.pyi +24 -0
- flwr/proto/log_pb2.py +29 -0
- flwr/proto/log_pb2.pyi +39 -0
- flwr/proto/log_pb2_grpc.py +4 -0
- flwr/proto/log_pb2_grpc.pyi +4 -0
- flwr/proto/message_pb2.py +41 -0
- flwr/proto/message_pb2.pyi +128 -0
- flwr/proto/message_pb2_grpc.py +4 -0
- flwr/proto/message_pb2_grpc.pyi +4 -0
- flwr/proto/node_pb2.py +2 -2
- flwr/proto/node_pb2.pyi +1 -4
- flwr/proto/recordset_pb2.py +35 -33
- flwr/proto/recordset_pb2.pyi +40 -14
- flwr/proto/run_pb2.py +64 -0
- flwr/proto/run_pb2.pyi +268 -0
- flwr/proto/run_pb2_grpc.py +4 -0
- flwr/proto/run_pb2_grpc.pyi +4 -0
- flwr/proto/serverappio_pb2.py +52 -0
- flwr/proto/{driver_pb2.pyi → serverappio_pb2.pyi} +62 -20
- flwr/proto/serverappio_pb2_grpc.py +410 -0
- flwr/proto/serverappio_pb2_grpc.pyi +160 -0
- flwr/proto/simulationio_pb2.py +38 -0
- flwr/proto/simulationio_pb2.pyi +65 -0
- flwr/proto/simulationio_pb2_grpc.py +239 -0
- flwr/proto/simulationio_pb2_grpc.pyi +94 -0
- flwr/proto/task_pb2.py +7 -8
- flwr/proto/task_pb2.pyi +8 -5
- flwr/proto/transport_pb2.py +8 -8
- flwr/proto/transport_pb2.pyi +9 -6
- flwr/server/__init__.py +2 -10
- flwr/server/app.py +579 -402
- flwr/server/client_manager.py +8 -6
- flwr/server/compat/app.py +6 -62
- flwr/server/compat/app_utils.py +14 -9
- flwr/server/compat/driver_client_proxy.py +25 -59
- flwr/server/compat/legacy_context.py +5 -4
- flwr/server/driver/__init__.py +2 -0
- flwr/server/driver/driver.py +36 -131
- flwr/server/driver/grpc_driver.py +220 -81
- flwr/server/driver/inmemory_driver.py +183 -0
- flwr/server/history.py +28 -29
- flwr/server/run_serverapp.py +15 -126
- flwr/server/server.py +50 -44
- flwr/server/server_app.py +59 -10
- flwr/server/serverapp/__init__.py +22 -0
- flwr/server/serverapp/app.py +256 -0
- flwr/server/serverapp_components.py +52 -0
- flwr/server/strategy/__init__.py +2 -2
- flwr/server/strategy/aggregate.py +37 -23
- flwr/server/strategy/bulyan.py +9 -9
- flwr/server/strategy/dp_adaptive_clipping.py +25 -25
- flwr/server/strategy/dp_fixed_clipping.py +23 -22
- flwr/server/strategy/dpfedavg_adaptive.py +8 -8
- flwr/server/strategy/dpfedavg_fixed.py +13 -12
- flwr/server/strategy/fault_tolerant_fedavg.py +11 -11
- flwr/server/strategy/fedadagrad.py +9 -9
- flwr/server/strategy/fedadam.py +20 -10
- flwr/server/strategy/fedavg.py +16 -16
- flwr/server/strategy/fedavg_android.py +17 -17
- flwr/server/strategy/fedavgm.py +9 -9
- flwr/server/strategy/fedmedian.py +5 -5
- flwr/server/strategy/fedopt.py +6 -6
- flwr/server/strategy/fedprox.py +7 -7
- flwr/server/strategy/fedtrimmedavg.py +8 -8
- flwr/server/strategy/fedxgb_bagging.py +12 -12
- flwr/server/strategy/fedxgb_cyclic.py +10 -10
- flwr/server/strategy/fedxgb_nn_avg.py +6 -6
- flwr/server/strategy/fedyogi.py +9 -9
- flwr/server/strategy/krum.py +9 -9
- flwr/server/strategy/qfedavg.py +16 -16
- flwr/server/strategy/strategy.py +10 -10
- flwr/server/superlink/driver/__init__.py +2 -2
- flwr/server/superlink/driver/serverappio_grpc.py +61 -0
- flwr/server/superlink/driver/serverappio_servicer.py +361 -0
- flwr/server/superlink/ffs/__init__.py +24 -0
- flwr/server/superlink/ffs/disk_ffs.py +108 -0
- flwr/server/superlink/ffs/ffs.py +79 -0
- flwr/server/superlink/ffs/ffs_factory.py +47 -0
- flwr/server/superlink/fleet/__init__.py +1 -1
- flwr/server/superlink/fleet/grpc_adapter/__init__.py +15 -0
- flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py +162 -0
- flwr/server/superlink/fleet/grpc_bidi/__init__.py +1 -1
- flwr/server/superlink/fleet/grpc_bidi/flower_service_servicer.py +4 -2
- flwr/server/superlink/fleet/grpc_bidi/grpc_bridge.py +3 -2
- flwr/server/superlink/fleet/grpc_bidi/grpc_client_proxy.py +1 -1
- flwr/server/superlink/fleet/grpc_bidi/grpc_server.py +5 -154
- flwr/server/superlink/fleet/grpc_rere/__init__.py +1 -1
- flwr/server/superlink/fleet/grpc_rere/fleet_servicer.py +120 -13
- flwr/server/superlink/fleet/grpc_rere/server_interceptor.py +228 -0
- flwr/server/superlink/fleet/message_handler/__init__.py +1 -1
- flwr/server/superlink/fleet/message_handler/message_handler.py +156 -13
- flwr/server/superlink/fleet/rest_rere/__init__.py +1 -1
- flwr/server/superlink/fleet/rest_rere/rest_api.py +119 -81
- flwr/server/superlink/fleet/vce/__init__.py +1 -0
- flwr/server/superlink/fleet/vce/backend/__init__.py +4 -4
- flwr/server/superlink/fleet/vce/backend/backend.py +8 -9
- flwr/server/superlink/fleet/vce/backend/raybackend.py +87 -68
- flwr/server/superlink/fleet/vce/vce_api.py +208 -146
- flwr/server/superlink/linkstate/__init__.py +28 -0
- flwr/server/superlink/linkstate/in_memory_linkstate.py +569 -0
- flwr/server/superlink/linkstate/linkstate.py +376 -0
- flwr/server/superlink/{state/state_factory.py → linkstate/linkstate_factory.py} +19 -10
- flwr/server/superlink/linkstate/sqlite_linkstate.py +1196 -0
- flwr/server/superlink/linkstate/utils.py +399 -0
- flwr/server/superlink/simulation/__init__.py +15 -0
- flwr/server/superlink/simulation/simulationio_grpc.py +65 -0
- flwr/server/superlink/simulation/simulationio_servicer.py +186 -0
- flwr/server/superlink/utils.py +65 -0
- flwr/server/typing.py +2 -0
- flwr/server/utils/__init__.py +1 -1
- flwr/server/utils/tensorboard.py +5 -5
- flwr/server/utils/validator.py +40 -45
- flwr/server/workflow/default_workflows.py +70 -26
- flwr/server/workflow/secure_aggregation/secagg_workflow.py +1 -0
- flwr/server/workflow/secure_aggregation/secaggplus_workflow.py +40 -27
- flwr/simulation/__init__.py +12 -5
- flwr/simulation/app.py +247 -315
- flwr/simulation/legacy_app.py +404 -0
- flwr/simulation/ray_transport/__init__.py +1 -1
- flwr/simulation/ray_transport/ray_actor.py +42 -67
- flwr/simulation/ray_transport/ray_client_proxy.py +37 -17
- flwr/simulation/ray_transport/utils.py +1 -0
- flwr/simulation/run_simulation.py +306 -163
- flwr/simulation/simulationio_connection.py +89 -0
- flwr/superexec/__init__.py +15 -0
- flwr/superexec/app.py +59 -0
- flwr/superexec/deployment.py +188 -0
- flwr/superexec/exec_grpc.py +80 -0
- flwr/superexec/exec_servicer.py +231 -0
- flwr/superexec/exec_user_auth_interceptor.py +101 -0
- flwr/superexec/executor.py +96 -0
- flwr/superexec/simulation.py +124 -0
- {flwr_nightly-1.8.0.dev20240315.dist-info → flwr_nightly-1.15.0.dev20250115.dist-info}/METADATA +33 -26
- flwr_nightly-1.15.0.dev20250115.dist-info/RECORD +328 -0
- flwr_nightly-1.15.0.dev20250115.dist-info/entry_points.txt +12 -0
- flwr/cli/flower_toml.py +0 -140
- flwr/cli/new/templates/app/flower.toml.tpl +0 -13
- flwr/cli/new/templates/app/requirements.numpy.txt.tpl +0 -2
- flwr/cli/new/templates/app/requirements.pytorch.txt.tpl +0 -4
- flwr/cli/new/templates/app/requirements.tensorflow.txt.tpl +0 -4
- flwr/client/node_state.py +0 -48
- flwr/client/node_state_tests.py +0 -65
- flwr/proto/driver_pb2.py +0 -44
- flwr/proto/driver_pb2_grpc.py +0 -169
- flwr/proto/driver_pb2_grpc.pyi +0 -66
- flwr/server/superlink/driver/driver_grpc.py +0 -54
- flwr/server/superlink/driver/driver_servicer.py +0 -129
- flwr/server/superlink/state/in_memory_state.py +0 -230
- flwr/server/superlink/state/sqlite_state.py +0 -630
- flwr/server/superlink/state/state.py +0 -154
- flwr_nightly-1.8.0.dev20240315.dist-info/RECORD +0 -211
- flwr_nightly-1.8.0.dev20240315.dist-info/entry_points.txt +0 -9
- {flwr_nightly-1.8.0.dev20240315.dist-info → flwr_nightly-1.15.0.dev20250115.dist-info}/LICENSE +0 -0
- {flwr_nightly-1.8.0.dev20240315.dist-info → flwr_nightly-1.15.0.dev20250115.dist-info}/WHEEL +0 -0
@@ -0,0 +1,376 @@
|
|
1
|
+
# Copyright 2024 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
|
+
"""Abstract base class LinkState."""
|
16
|
+
|
17
|
+
|
18
|
+
import abc
|
19
|
+
from typing import Optional
|
20
|
+
from uuid import UUID
|
21
|
+
|
22
|
+
from flwr.common import Context
|
23
|
+
from flwr.common.record import ConfigsRecord
|
24
|
+
from flwr.common.typing import Run, RunStatus, UserConfig
|
25
|
+
from flwr.proto.task_pb2 import TaskIns, TaskRes # pylint: disable=E0611
|
26
|
+
|
27
|
+
|
28
|
+
class LinkState(abc.ABC): # pylint: disable=R0904
|
29
|
+
"""Abstract LinkState."""
|
30
|
+
|
31
|
+
@abc.abstractmethod
|
32
|
+
def store_task_ins(self, task_ins: TaskIns) -> Optional[UUID]:
|
33
|
+
"""Store one TaskIns.
|
34
|
+
|
35
|
+
Usually, the ServerAppIo API calls this to schedule instructions.
|
36
|
+
|
37
|
+
Stores the value of the `task_ins` in the link state and, if successful,
|
38
|
+
returns the `task_id` (UUID) of the `task_ins`. If, for any reason,
|
39
|
+
storing the `task_ins` fails, `None` is returned.
|
40
|
+
|
41
|
+
Constraints
|
42
|
+
-----------
|
43
|
+
`task_ins.task.consumer.node_id` MUST be set (not constant.DRIVER_NODE_ID)
|
44
|
+
|
45
|
+
If `task_ins.run_id` is invalid, then
|
46
|
+
storing the `task_ins` MUST fail.
|
47
|
+
"""
|
48
|
+
|
49
|
+
@abc.abstractmethod
|
50
|
+
def get_task_ins(self, node_id: int, limit: Optional[int]) -> list[TaskIns]:
|
51
|
+
"""Get TaskIns optionally filtered by node_id.
|
52
|
+
|
53
|
+
Usually, the Fleet API calls this for Nodes planning to work on one or more
|
54
|
+
TaskIns.
|
55
|
+
|
56
|
+
Constraints
|
57
|
+
-----------
|
58
|
+
Retrieve all TaskIns where
|
59
|
+
|
60
|
+
1. the `task_ins.task.consumer.node_id` equals `node_id` AND
|
61
|
+
2. the `task_ins.task.delivered_at` equals `""`.
|
62
|
+
|
63
|
+
|
64
|
+
If `delivered_at` MUST BE set (not `""`) otherwise the TaskIns MUST not be in
|
65
|
+
the result.
|
66
|
+
|
67
|
+
If `limit` is not `None`, return, at most, `limit` number of `task_ins`. If
|
68
|
+
`limit` is set, it has to be greater zero.
|
69
|
+
"""
|
70
|
+
|
71
|
+
@abc.abstractmethod
|
72
|
+
def store_task_res(self, task_res: TaskRes) -> Optional[UUID]:
|
73
|
+
"""Store one TaskRes.
|
74
|
+
|
75
|
+
Usually, the Fleet API calls this for Nodes returning results.
|
76
|
+
|
77
|
+
Stores the TaskRes and, if successful, returns the `task_id` (UUID) of
|
78
|
+
the `task_res`. If storing the `task_res` fails, `None` is returned.
|
79
|
+
|
80
|
+
Constraints
|
81
|
+
-----------
|
82
|
+
|
83
|
+
`task_res.task.consumer.node_id` MUST be set (not constant.DRIVER_NODE_ID)
|
84
|
+
|
85
|
+
If `task_res.run_id` is invalid, then
|
86
|
+
storing the `task_res` MUST fail.
|
87
|
+
"""
|
88
|
+
|
89
|
+
@abc.abstractmethod
|
90
|
+
def get_task_res(self, task_ids: set[UUID]) -> list[TaskRes]:
|
91
|
+
"""Get TaskRes for the given TaskIns IDs.
|
92
|
+
|
93
|
+
This method is typically called by the ServerAppIo API to obtain
|
94
|
+
results (TaskRes) for previously scheduled instructions (TaskIns).
|
95
|
+
For each task_id provided, this method returns one of the following responses:
|
96
|
+
|
97
|
+
- An error TaskRes if the corresponding TaskIns does not exist or has expired.
|
98
|
+
- An error TaskRes if the corresponding TaskRes exists but has expired.
|
99
|
+
- The valid TaskRes if the TaskIns has a corresponding valid TaskRes.
|
100
|
+
- Nothing if the TaskIns is still valid and waiting for a TaskRes.
|
101
|
+
|
102
|
+
Parameters
|
103
|
+
----------
|
104
|
+
task_ids : set[UUID]
|
105
|
+
A set of TaskIns IDs for which to retrieve results (TaskRes).
|
106
|
+
|
107
|
+
Returns
|
108
|
+
-------
|
109
|
+
list[TaskRes]
|
110
|
+
A list of TaskRes corresponding to the given task IDs. If no
|
111
|
+
TaskRes could be found for any of the task IDs, an empty list is returned.
|
112
|
+
"""
|
113
|
+
|
114
|
+
@abc.abstractmethod
|
115
|
+
def num_task_ins(self) -> int:
|
116
|
+
"""Calculate the number of task_ins in store.
|
117
|
+
|
118
|
+
This includes delivered but not yet deleted task_ins.
|
119
|
+
"""
|
120
|
+
|
121
|
+
@abc.abstractmethod
|
122
|
+
def num_task_res(self) -> int:
|
123
|
+
"""Calculate the number of task_res in store.
|
124
|
+
|
125
|
+
This includes delivered but not yet deleted task_res.
|
126
|
+
"""
|
127
|
+
|
128
|
+
@abc.abstractmethod
|
129
|
+
def delete_tasks(self, task_ins_ids: set[UUID]) -> None:
|
130
|
+
"""Delete TaskIns/TaskRes pairs based on provided TaskIns IDs.
|
131
|
+
|
132
|
+
Parameters
|
133
|
+
----------
|
134
|
+
task_ins_ids : set[UUID]
|
135
|
+
A set of TaskIns IDs. For each ID in the set, the corresponding
|
136
|
+
TaskIns and its associated TaskRes will be deleted.
|
137
|
+
"""
|
138
|
+
|
139
|
+
@abc.abstractmethod
|
140
|
+
def get_task_ids_from_run_id(self, run_id: int) -> set[UUID]:
|
141
|
+
"""Get all TaskIns IDs for the given run_id."""
|
142
|
+
|
143
|
+
@abc.abstractmethod
|
144
|
+
def create_node(self, ping_interval: float) -> int:
|
145
|
+
"""Create, store in the link state, and return `node_id`."""
|
146
|
+
|
147
|
+
@abc.abstractmethod
|
148
|
+
def delete_node(self, node_id: int) -> None:
|
149
|
+
"""Remove `node_id` from the link state."""
|
150
|
+
|
151
|
+
@abc.abstractmethod
|
152
|
+
def get_nodes(self, run_id: int) -> set[int]:
|
153
|
+
"""Retrieve all currently stored node IDs as a set.
|
154
|
+
|
155
|
+
Constraints
|
156
|
+
-----------
|
157
|
+
If the provided `run_id` does not exist or has no matching nodes,
|
158
|
+
an empty `Set` MUST be returned.
|
159
|
+
"""
|
160
|
+
|
161
|
+
@abc.abstractmethod
|
162
|
+
def set_node_public_key(self, node_id: int, public_key: bytes) -> None:
|
163
|
+
"""Set `public_key` for the specified `node_id`."""
|
164
|
+
|
165
|
+
@abc.abstractmethod
|
166
|
+
def get_node_public_key(self, node_id: int) -> Optional[bytes]:
|
167
|
+
"""Get `public_key` for the specified `node_id`."""
|
168
|
+
|
169
|
+
@abc.abstractmethod
|
170
|
+
def get_node_id(self, node_public_key: bytes) -> Optional[int]:
|
171
|
+
"""Retrieve stored `node_id` filtered by `node_public_keys`."""
|
172
|
+
|
173
|
+
@abc.abstractmethod
|
174
|
+
def create_run( # pylint: disable=too-many-arguments,too-many-positional-arguments
|
175
|
+
self,
|
176
|
+
fab_id: Optional[str],
|
177
|
+
fab_version: Optional[str],
|
178
|
+
fab_hash: Optional[str],
|
179
|
+
override_config: UserConfig,
|
180
|
+
federation_options: ConfigsRecord,
|
181
|
+
) -> int:
|
182
|
+
"""Create a new run for the specified `fab_hash`."""
|
183
|
+
|
184
|
+
@abc.abstractmethod
|
185
|
+
def get_run_ids(self) -> set[int]:
|
186
|
+
"""Retrieve all run IDs."""
|
187
|
+
|
188
|
+
@abc.abstractmethod
|
189
|
+
def get_run(self, run_id: int) -> Optional[Run]:
|
190
|
+
"""Retrieve information about the run with the specified `run_id`.
|
191
|
+
|
192
|
+
Parameters
|
193
|
+
----------
|
194
|
+
run_id : int
|
195
|
+
The identifier of the run.
|
196
|
+
|
197
|
+
Returns
|
198
|
+
-------
|
199
|
+
Optional[Run]
|
200
|
+
The `Run` instance if found; otherwise, `None`.
|
201
|
+
"""
|
202
|
+
|
203
|
+
@abc.abstractmethod
|
204
|
+
def get_run_status(self, run_ids: set[int]) -> dict[int, RunStatus]:
|
205
|
+
"""Retrieve the statuses for the specified runs.
|
206
|
+
|
207
|
+
Parameters
|
208
|
+
----------
|
209
|
+
run_ids : set[int]
|
210
|
+
A set of run identifiers for which to retrieve statuses.
|
211
|
+
|
212
|
+
Returns
|
213
|
+
-------
|
214
|
+
dict[int, RunStatus]
|
215
|
+
A dictionary mapping each valid run ID to its corresponding status.
|
216
|
+
|
217
|
+
Notes
|
218
|
+
-----
|
219
|
+
Only valid run IDs that exist in the State will be included in the returned
|
220
|
+
dictionary. If a run ID is not found, it will be omitted from the result.
|
221
|
+
"""
|
222
|
+
|
223
|
+
@abc.abstractmethod
|
224
|
+
def update_run_status(self, run_id: int, new_status: RunStatus) -> bool:
|
225
|
+
"""Update the status of the run with the specified `run_id`.
|
226
|
+
|
227
|
+
Parameters
|
228
|
+
----------
|
229
|
+
run_id : int
|
230
|
+
The identifier of the run.
|
231
|
+
new_status : RunStatus
|
232
|
+
The new status to be assigned to the run.
|
233
|
+
|
234
|
+
Returns
|
235
|
+
-------
|
236
|
+
bool
|
237
|
+
True if the status update is successful; False otherwise.
|
238
|
+
"""
|
239
|
+
|
240
|
+
@abc.abstractmethod
|
241
|
+
def get_pending_run_id(self) -> Optional[int]:
|
242
|
+
"""Get the `run_id` of a run with `Status.PENDING` status.
|
243
|
+
|
244
|
+
Returns
|
245
|
+
-------
|
246
|
+
Optional[int]
|
247
|
+
The `run_id` of a `Run` that is pending to be started; None if
|
248
|
+
there is no Run pending.
|
249
|
+
"""
|
250
|
+
|
251
|
+
@abc.abstractmethod
|
252
|
+
def get_federation_options(self, run_id: int) -> Optional[ConfigsRecord]:
|
253
|
+
"""Retrieve the federation options for the specified `run_id`.
|
254
|
+
|
255
|
+
Parameters
|
256
|
+
----------
|
257
|
+
run_id : int
|
258
|
+
The identifier of the run.
|
259
|
+
|
260
|
+
Returns
|
261
|
+
-------
|
262
|
+
Optional[ConfigsRecord]
|
263
|
+
The federation options for the run if it exists; None otherwise.
|
264
|
+
"""
|
265
|
+
|
266
|
+
@abc.abstractmethod
|
267
|
+
def store_server_private_public_key(
|
268
|
+
self, private_key: bytes, public_key: bytes
|
269
|
+
) -> None:
|
270
|
+
"""Store `server_private_key` and `server_public_key` in the link state."""
|
271
|
+
|
272
|
+
@abc.abstractmethod
|
273
|
+
def get_server_private_key(self) -> Optional[bytes]:
|
274
|
+
"""Retrieve `server_private_key` in urlsafe bytes."""
|
275
|
+
|
276
|
+
@abc.abstractmethod
|
277
|
+
def get_server_public_key(self) -> Optional[bytes]:
|
278
|
+
"""Retrieve `server_public_key` in urlsafe bytes."""
|
279
|
+
|
280
|
+
@abc.abstractmethod
|
281
|
+
def clear_supernode_auth_keys_and_credentials(self) -> None:
|
282
|
+
"""Clear stored `node_public_keys` and credentials in the link state if any."""
|
283
|
+
|
284
|
+
@abc.abstractmethod
|
285
|
+
def store_node_public_keys(self, public_keys: set[bytes]) -> None:
|
286
|
+
"""Store a set of `node_public_keys` in the link state."""
|
287
|
+
|
288
|
+
@abc.abstractmethod
|
289
|
+
def store_node_public_key(self, public_key: bytes) -> None:
|
290
|
+
"""Store a `node_public_key` in the link state."""
|
291
|
+
|
292
|
+
@abc.abstractmethod
|
293
|
+
def get_node_public_keys(self) -> set[bytes]:
|
294
|
+
"""Retrieve all currently stored `node_public_keys` as a set."""
|
295
|
+
|
296
|
+
@abc.abstractmethod
|
297
|
+
def acknowledge_ping(self, node_id: int, ping_interval: float) -> bool:
|
298
|
+
"""Acknowledge a ping received from a node, serving as a heartbeat.
|
299
|
+
|
300
|
+
Parameters
|
301
|
+
----------
|
302
|
+
node_id : int
|
303
|
+
The `node_id` from which the ping was received.
|
304
|
+
ping_interval : float
|
305
|
+
The interval (in seconds) from the current timestamp within which the next
|
306
|
+
ping from this node must be received. This acts as a hard deadline to ensure
|
307
|
+
an accurate assessment of the node's availability.
|
308
|
+
|
309
|
+
Returns
|
310
|
+
-------
|
311
|
+
is_acknowledged : bool
|
312
|
+
True if the ping is successfully acknowledged; otherwise, False.
|
313
|
+
"""
|
314
|
+
|
315
|
+
@abc.abstractmethod
|
316
|
+
def get_serverapp_context(self, run_id: int) -> Optional[Context]:
|
317
|
+
"""Get the context for the specified `run_id`.
|
318
|
+
|
319
|
+
Parameters
|
320
|
+
----------
|
321
|
+
run_id : int
|
322
|
+
The identifier of the run for which to retrieve the context.
|
323
|
+
|
324
|
+
Returns
|
325
|
+
-------
|
326
|
+
Optional[Context]
|
327
|
+
The context associated with the specified `run_id`, or `None` if no context
|
328
|
+
exists for the given `run_id`.
|
329
|
+
"""
|
330
|
+
|
331
|
+
@abc.abstractmethod
|
332
|
+
def set_serverapp_context(self, run_id: int, context: Context) -> None:
|
333
|
+
"""Set the context for the specified `run_id`.
|
334
|
+
|
335
|
+
Parameters
|
336
|
+
----------
|
337
|
+
run_id : int
|
338
|
+
The identifier of the run for which to set the context.
|
339
|
+
context : Context
|
340
|
+
The context to be associated with the specified `run_id`.
|
341
|
+
"""
|
342
|
+
|
343
|
+
@abc.abstractmethod
|
344
|
+
def add_serverapp_log(self, run_id: int, log_message: str) -> None:
|
345
|
+
"""Add a log entry to the ServerApp logs for the specified `run_id`.
|
346
|
+
|
347
|
+
Parameters
|
348
|
+
----------
|
349
|
+
run_id : int
|
350
|
+
The identifier of the run for which to add a log entry.
|
351
|
+
log_message : str
|
352
|
+
The log entry to be added to the ServerApp logs.
|
353
|
+
"""
|
354
|
+
|
355
|
+
@abc.abstractmethod
|
356
|
+
def get_serverapp_log(
|
357
|
+
self, run_id: int, after_timestamp: Optional[float]
|
358
|
+
) -> tuple[str, float]:
|
359
|
+
"""Get the ServerApp logs for the specified `run_id`.
|
360
|
+
|
361
|
+
Parameters
|
362
|
+
----------
|
363
|
+
run_id : int
|
364
|
+
The identifier of the run for which to retrieve the ServerApp logs.
|
365
|
+
|
366
|
+
after_timestamp : Optional[float]
|
367
|
+
Retrieve logs after this timestamp. If set to `None`, retrieve all logs.
|
368
|
+
|
369
|
+
Returns
|
370
|
+
-------
|
371
|
+
tuple[str, float]
|
372
|
+
A tuple containing:
|
373
|
+
- The ServerApp logs associated with the specified `run_id`.
|
374
|
+
- The timestamp of the latest log entry in the returned logs.
|
375
|
+
Returns `0` if no logs are returned.
|
376
|
+
"""
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -20,29 +20,38 @@ from typing import Optional
|
|
20
20
|
|
21
21
|
from flwr.common.logger import log
|
22
22
|
|
23
|
-
from .
|
24
|
-
from .
|
25
|
-
from .
|
23
|
+
from .in_memory_linkstate import InMemoryLinkState
|
24
|
+
from .linkstate import LinkState
|
25
|
+
from .sqlite_linkstate import SqliteLinkState
|
26
26
|
|
27
27
|
|
28
|
-
class
|
29
|
-
"""Factory class that creates
|
28
|
+
class LinkStateFactory:
|
29
|
+
"""Factory class that creates LinkState instances.
|
30
|
+
|
31
|
+
Parameters
|
32
|
+
----------
|
33
|
+
database : str
|
34
|
+
A string representing the path to the database file that will be opened.
|
35
|
+
Note that passing ':memory:' will open a connection to a database that is
|
36
|
+
in RAM, instead of on disk. For more information on special in-memory
|
37
|
+
databases, please refer to https://sqlite.org/inmemorydb.html.
|
38
|
+
"""
|
30
39
|
|
31
40
|
def __init__(self, database: str) -> None:
|
32
41
|
self.database = database
|
33
|
-
self.state_instance: Optional[
|
42
|
+
self.state_instance: Optional[LinkState] = None
|
34
43
|
|
35
|
-
def state(self) ->
|
44
|
+
def state(self) -> LinkState:
|
36
45
|
"""Return a State instance and create it, if necessary."""
|
37
46
|
# InMemoryState
|
38
47
|
if self.database == ":flwr-in-memory-state:":
|
39
48
|
if self.state_instance is None:
|
40
|
-
self.state_instance =
|
49
|
+
self.state_instance = InMemoryLinkState()
|
41
50
|
log(DEBUG, "Using InMemoryState")
|
42
51
|
return self.state_instance
|
43
52
|
|
44
53
|
# SqliteState
|
45
|
-
state =
|
54
|
+
state = SqliteLinkState(self.database)
|
46
55
|
state.initialize()
|
47
56
|
log(DEBUG, "Using SqliteState")
|
48
57
|
return state
|