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,89 @@
|
|
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
|
+
"""Flower SimulationIo connection."""
|
16
|
+
|
17
|
+
|
18
|
+
from logging import DEBUG, WARNING
|
19
|
+
from typing import Optional, cast
|
20
|
+
|
21
|
+
import grpc
|
22
|
+
|
23
|
+
from flwr.common.constant import SIMULATIONIO_API_DEFAULT_CLIENT_ADDRESS
|
24
|
+
from flwr.common.grpc import create_channel
|
25
|
+
from flwr.common.logger import log
|
26
|
+
from flwr.common.retry_invoker import _make_simple_grpc_retry_invoker, _wrap_stub
|
27
|
+
from flwr.proto.simulationio_pb2_grpc import SimulationIoStub # pylint: disable=E0611
|
28
|
+
|
29
|
+
|
30
|
+
class SimulationIoConnection:
|
31
|
+
"""`SimulationIoConnection` provides an interface to the SimulationIo API.
|
32
|
+
|
33
|
+
Parameters
|
34
|
+
----------
|
35
|
+
simulationio_service_address : str (default: "[::]:9094")
|
36
|
+
The address (URL, IPv6, IPv4) of the SuperLink SimulationIo API service.
|
37
|
+
root_certificates : Optional[bytes] (default: None)
|
38
|
+
The PEM-encoded root certificates as a byte string.
|
39
|
+
If provided, a secure connection using the certificates will be
|
40
|
+
established to an SSL-enabled Flower server.
|
41
|
+
"""
|
42
|
+
|
43
|
+
def __init__( # pylint: disable=too-many-arguments
|
44
|
+
self,
|
45
|
+
simulationio_service_address: str = SIMULATIONIO_API_DEFAULT_CLIENT_ADDRESS,
|
46
|
+
root_certificates: Optional[bytes] = None,
|
47
|
+
) -> None:
|
48
|
+
self._addr = simulationio_service_address
|
49
|
+
self._cert = root_certificates
|
50
|
+
self._grpc_stub: Optional[SimulationIoStub] = None
|
51
|
+
self._channel: Optional[grpc.Channel] = None
|
52
|
+
self._retry_invoker = _make_simple_grpc_retry_invoker()
|
53
|
+
|
54
|
+
@property
|
55
|
+
def _is_connected(self) -> bool:
|
56
|
+
"""Check if connected to the SimulationIo API server."""
|
57
|
+
return self._channel is not None
|
58
|
+
|
59
|
+
@property
|
60
|
+
def _stub(self) -> SimulationIoStub:
|
61
|
+
"""SimulationIo stub."""
|
62
|
+
if not self._is_connected:
|
63
|
+
self._connect()
|
64
|
+
return cast(SimulationIoStub, self._grpc_stub)
|
65
|
+
|
66
|
+
def _connect(self) -> None:
|
67
|
+
"""Connect to the SimulationIo API."""
|
68
|
+
if self._is_connected:
|
69
|
+
log(WARNING, "Already connected")
|
70
|
+
return
|
71
|
+
self._channel = create_channel(
|
72
|
+
server_address=self._addr,
|
73
|
+
insecure=(self._cert is None),
|
74
|
+
root_certificates=self._cert,
|
75
|
+
)
|
76
|
+
self._grpc_stub = SimulationIoStub(self._channel)
|
77
|
+
_wrap_stub(self._grpc_stub, self._retry_invoker)
|
78
|
+
log(DEBUG, "[SimulationIO] Connected to %s", self._addr)
|
79
|
+
|
80
|
+
def _disconnect(self) -> None:
|
81
|
+
"""Disconnect from the SimulationIo API."""
|
82
|
+
if not self._is_connected:
|
83
|
+
log(DEBUG, "Already disconnected")
|
84
|
+
return
|
85
|
+
channel: grpc.Channel = self._channel
|
86
|
+
self._channel = None
|
87
|
+
self._grpc_stub = None
|
88
|
+
channel.close()
|
89
|
+
log(DEBUG, "[SimulationIO] Disconnected")
|
@@ -0,0 +1,15 @@
|
|
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
|
+
"""Flower SuperExec service."""
|
flwr/superexec/app.py
ADDED
@@ -0,0 +1,59 @@
|
|
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
|
+
"""Flower SuperExec app."""
|
16
|
+
|
17
|
+
|
18
|
+
import argparse
|
19
|
+
import sys
|
20
|
+
from logging import INFO
|
21
|
+
|
22
|
+
from flwr.common import log
|
23
|
+
from flwr.common.object_ref import load_app, validate
|
24
|
+
|
25
|
+
from .executor import Executor
|
26
|
+
|
27
|
+
|
28
|
+
def run_superexec() -> None:
|
29
|
+
"""Run Flower SuperExec."""
|
30
|
+
log(INFO, "Starting Flower SuperExec")
|
31
|
+
|
32
|
+
sys.exit(
|
33
|
+
"Manually launching the SuperExec is deprecated. Since `flwr 1.13.0` "
|
34
|
+
"the executor service runs in the SuperLink. Launching it manually is not "
|
35
|
+
"recommended."
|
36
|
+
)
|
37
|
+
|
38
|
+
|
39
|
+
def load_executor(
|
40
|
+
args: argparse.Namespace,
|
41
|
+
) -> Executor:
|
42
|
+
"""Get the executor plugin."""
|
43
|
+
executor_ref: str = args.executor
|
44
|
+
valid, error_msg = validate(executor_ref, project_dir=args.executor_dir)
|
45
|
+
if not valid and error_msg:
|
46
|
+
raise LoadExecutorError(error_msg) from None
|
47
|
+
|
48
|
+
executor = load_app(executor_ref, LoadExecutorError, args.executor_dir)
|
49
|
+
|
50
|
+
if not isinstance(executor, Executor):
|
51
|
+
raise LoadExecutorError(
|
52
|
+
f"Attribute {executor_ref} is not of type {Executor}",
|
53
|
+
) from None
|
54
|
+
|
55
|
+
return executor
|
56
|
+
|
57
|
+
|
58
|
+
class LoadExecutorError(Exception):
|
59
|
+
"""Error when trying to load `Executor`."""
|
@@ -0,0 +1,188 @@
|
|
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
|
+
"""Deployment engine executor."""
|
16
|
+
|
17
|
+
|
18
|
+
import hashlib
|
19
|
+
from logging import ERROR, INFO
|
20
|
+
from pathlib import Path
|
21
|
+
from typing import Optional
|
22
|
+
|
23
|
+
from typing_extensions import override
|
24
|
+
|
25
|
+
from flwr.cli.config_utils import get_fab_metadata
|
26
|
+
from flwr.common import ConfigsRecord, Context, RecordSet
|
27
|
+
from flwr.common.constant import (
|
28
|
+
SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS,
|
29
|
+
Status,
|
30
|
+
SubStatus,
|
31
|
+
)
|
32
|
+
from flwr.common.logger import log
|
33
|
+
from flwr.common.typing import Fab, RunStatus, UserConfig
|
34
|
+
from flwr.server.superlink.ffs import Ffs
|
35
|
+
from flwr.server.superlink.ffs.ffs_factory import FfsFactory
|
36
|
+
from flwr.server.superlink.linkstate import LinkState, LinkStateFactory
|
37
|
+
|
38
|
+
from .executor import Executor
|
39
|
+
|
40
|
+
|
41
|
+
class DeploymentEngine(Executor):
|
42
|
+
"""Deployment engine executor.
|
43
|
+
|
44
|
+
Parameters
|
45
|
+
----------
|
46
|
+
serverappio_api_address: str (default: "127.0.0.1:9091")
|
47
|
+
Address of the SuperLink to connect to.
|
48
|
+
root_certificates: Optional[str] (default: None)
|
49
|
+
Specifies the path to the PEM-encoded root certificate file for
|
50
|
+
establishing secure HTTPS connections.
|
51
|
+
flwr_dir: Optional[str] (default: None)
|
52
|
+
The path containing installed Flower Apps.
|
53
|
+
"""
|
54
|
+
|
55
|
+
def __init__(
|
56
|
+
self,
|
57
|
+
serverappio_api_address: str = SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS,
|
58
|
+
root_certificates: Optional[str] = None,
|
59
|
+
flwr_dir: Optional[str] = None,
|
60
|
+
) -> None:
|
61
|
+
self.serverappio_api_address = serverappio_api_address
|
62
|
+
if root_certificates is None:
|
63
|
+
self.root_certificates = None
|
64
|
+
self.root_certificates_bytes = None
|
65
|
+
else:
|
66
|
+
self.root_certificates = root_certificates
|
67
|
+
self.root_certificates_bytes = Path(root_certificates).read_bytes()
|
68
|
+
self.flwr_dir = flwr_dir
|
69
|
+
self.linkstate_factory: Optional[LinkStateFactory] = None
|
70
|
+
self.ffs_factory: Optional[FfsFactory] = None
|
71
|
+
|
72
|
+
@override
|
73
|
+
def initialize(
|
74
|
+
self, linkstate_factory: LinkStateFactory, ffs_factory: FfsFactory
|
75
|
+
) -> None:
|
76
|
+
"""Initialize the executor with the necessary factories."""
|
77
|
+
self.linkstate_factory = linkstate_factory
|
78
|
+
self.ffs_factory = ffs_factory
|
79
|
+
|
80
|
+
@property
|
81
|
+
def linkstate(self) -> LinkState:
|
82
|
+
"""Return the LinkState."""
|
83
|
+
if self.linkstate_factory is None:
|
84
|
+
raise RuntimeError("Executor is not initialized.")
|
85
|
+
return self.linkstate_factory.state()
|
86
|
+
|
87
|
+
@property
|
88
|
+
def ffs(self) -> Ffs:
|
89
|
+
"""Return the Flower File Storage (FFS)."""
|
90
|
+
if self.ffs_factory is None:
|
91
|
+
raise RuntimeError("Executor is not initialized.")
|
92
|
+
return self.ffs_factory.ffs()
|
93
|
+
|
94
|
+
@override
|
95
|
+
def set_config(
|
96
|
+
self,
|
97
|
+
config: UserConfig,
|
98
|
+
) -> None:
|
99
|
+
"""Set executor config arguments.
|
100
|
+
|
101
|
+
Parameters
|
102
|
+
----------
|
103
|
+
config : UserConfig
|
104
|
+
A dictionary for configuration values.
|
105
|
+
Supported configuration key/value pairs:
|
106
|
+
- "superlink": str
|
107
|
+
The address of the SuperLink ServerAppIo API.
|
108
|
+
- "root-certificates": str
|
109
|
+
The path to the root certificates.
|
110
|
+
- "flwr-dir": str
|
111
|
+
The path to the Flower directory.
|
112
|
+
"""
|
113
|
+
if not config:
|
114
|
+
return
|
115
|
+
if superlink_address := config.get("superlink"):
|
116
|
+
if not isinstance(superlink_address, str):
|
117
|
+
raise ValueError("The `superlink` value should be of type `str`.")
|
118
|
+
self.serverappio_api_address = superlink_address
|
119
|
+
if root_certificates := config.get("root-certificates"):
|
120
|
+
if not isinstance(root_certificates, str):
|
121
|
+
raise ValueError(
|
122
|
+
"The `root-certificates` value should be of type `str`."
|
123
|
+
)
|
124
|
+
self.root_certificates = root_certificates
|
125
|
+
self.root_certificates_bytes = Path(str(root_certificates)).read_bytes()
|
126
|
+
if flwr_dir := config.get("flwr-dir"):
|
127
|
+
if not isinstance(flwr_dir, str):
|
128
|
+
raise ValueError("The `flwr-dir` value should be of type `str`.")
|
129
|
+
self.flwr_dir = str(flwr_dir)
|
130
|
+
|
131
|
+
def _create_run(
|
132
|
+
self,
|
133
|
+
fab: Fab,
|
134
|
+
override_config: UserConfig,
|
135
|
+
) -> int:
|
136
|
+
fab_hash = self.ffs.put(fab.content, {})
|
137
|
+
if fab_hash != fab.hash_str:
|
138
|
+
raise RuntimeError(
|
139
|
+
f"FAB ({fab.hash_str}) hash from request doesn't match contents"
|
140
|
+
)
|
141
|
+
fab_id, fab_version = get_fab_metadata(fab.content)
|
142
|
+
|
143
|
+
run_id = self.linkstate.create_run(
|
144
|
+
fab_id, fab_version, fab_hash, override_config, ConfigsRecord()
|
145
|
+
)
|
146
|
+
return run_id
|
147
|
+
|
148
|
+
def _create_context(self, run_id: int) -> None:
|
149
|
+
"""Register a Context for a Run."""
|
150
|
+
# Create an empty context for the Run
|
151
|
+
context = Context(
|
152
|
+
run_id=run_id, node_id=0, node_config={}, state=RecordSet(), run_config={}
|
153
|
+
)
|
154
|
+
|
155
|
+
# Register the context at the LinkState
|
156
|
+
self.linkstate.set_serverapp_context(run_id=run_id, context=context)
|
157
|
+
|
158
|
+
@override
|
159
|
+
def start_run(
|
160
|
+
self,
|
161
|
+
fab_file: bytes,
|
162
|
+
override_config: UserConfig,
|
163
|
+
federation_options: ConfigsRecord,
|
164
|
+
) -> Optional[int]:
|
165
|
+
"""Start run using the Flower Deployment Engine."""
|
166
|
+
run_id = None
|
167
|
+
try:
|
168
|
+
|
169
|
+
# Call SuperLink to create run
|
170
|
+
run_id = self._create_run(
|
171
|
+
Fab(hashlib.sha256(fab_file).hexdigest(), fab_file), override_config
|
172
|
+
)
|
173
|
+
|
174
|
+
# Register context for the Run
|
175
|
+
self._create_context(run_id=run_id)
|
176
|
+
log(INFO, "Created run %s", str(run_id))
|
177
|
+
|
178
|
+
return run_id
|
179
|
+
# pylint: disable-next=broad-except
|
180
|
+
except Exception as e:
|
181
|
+
log(ERROR, "Could not start run: %s", str(e))
|
182
|
+
if run_id:
|
183
|
+
run_status = RunStatus(Status.FINISHED, SubStatus.FAILED, str(e))
|
184
|
+
self.linkstate.update_run_status(run_id, new_status=run_status)
|
185
|
+
return None
|
186
|
+
|
187
|
+
|
188
|
+
executor = DeploymentEngine()
|
@@ -0,0 +1,80 @@
|
|
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
|
+
"""SuperExec gRPC API."""
|
16
|
+
|
17
|
+
|
18
|
+
from collections.abc import Sequence
|
19
|
+
from logging import INFO
|
20
|
+
from typing import Optional
|
21
|
+
|
22
|
+
import grpc
|
23
|
+
|
24
|
+
from flwr.common import GRPC_MAX_MESSAGE_LENGTH
|
25
|
+
from flwr.common.auth_plugin import ExecAuthPlugin
|
26
|
+
from flwr.common.grpc import generic_create_grpc_server
|
27
|
+
from flwr.common.logger import log
|
28
|
+
from flwr.common.typing import UserConfig
|
29
|
+
from flwr.proto.exec_pb2_grpc import add_ExecServicer_to_server
|
30
|
+
from flwr.server.superlink.ffs.ffs_factory import FfsFactory
|
31
|
+
from flwr.server.superlink.linkstate import LinkStateFactory
|
32
|
+
from flwr.superexec.exec_user_auth_interceptor import ExecUserAuthInterceptor
|
33
|
+
|
34
|
+
from .exec_servicer import ExecServicer
|
35
|
+
from .executor import Executor
|
36
|
+
|
37
|
+
|
38
|
+
# pylint: disable-next=too-many-arguments, too-many-positional-arguments
|
39
|
+
def run_exec_api_grpc(
|
40
|
+
address: str,
|
41
|
+
executor: Executor,
|
42
|
+
state_factory: LinkStateFactory,
|
43
|
+
ffs_factory: FfsFactory,
|
44
|
+
certificates: Optional[tuple[bytes, bytes, bytes]],
|
45
|
+
config: UserConfig,
|
46
|
+
auth_plugin: Optional[ExecAuthPlugin] = None,
|
47
|
+
) -> grpc.Server:
|
48
|
+
"""Run Exec API (gRPC, request-response)."""
|
49
|
+
executor.set_config(config)
|
50
|
+
|
51
|
+
exec_servicer: grpc.Server = ExecServicer(
|
52
|
+
linkstate_factory=state_factory,
|
53
|
+
ffs_factory=ffs_factory,
|
54
|
+
executor=executor,
|
55
|
+
auth_plugin=auth_plugin,
|
56
|
+
)
|
57
|
+
interceptors: Optional[Sequence[grpc.ServerInterceptor]] = None
|
58
|
+
if auth_plugin is not None:
|
59
|
+
interceptors = [ExecUserAuthInterceptor(auth_plugin)]
|
60
|
+
exec_add_servicer_to_server_fn = add_ExecServicer_to_server
|
61
|
+
exec_grpc_server = generic_create_grpc_server(
|
62
|
+
servicer_and_add_fn=(exec_servicer, exec_add_servicer_to_server_fn),
|
63
|
+
server_address=address,
|
64
|
+
max_message_length=GRPC_MAX_MESSAGE_LENGTH,
|
65
|
+
certificates=certificates,
|
66
|
+
interceptors=interceptors,
|
67
|
+
)
|
68
|
+
|
69
|
+
if auth_plugin is None:
|
70
|
+
log(INFO, "Flower Deployment Engine: Starting Exec API on %s", address)
|
71
|
+
else:
|
72
|
+
log(
|
73
|
+
INFO,
|
74
|
+
"Flower Deployment Engine: Starting Exec API with user "
|
75
|
+
"authentication on %s",
|
76
|
+
address,
|
77
|
+
)
|
78
|
+
exec_grpc_server.start()
|
79
|
+
|
80
|
+
return exec_grpc_server
|
@@ -0,0 +1,231 @@
|
|
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
|
+
"""SuperExec API servicer."""
|
16
|
+
|
17
|
+
|
18
|
+
import time
|
19
|
+
from collections.abc import Generator
|
20
|
+
from logging import ERROR, INFO
|
21
|
+
from typing import Any, Optional
|
22
|
+
from uuid import UUID
|
23
|
+
|
24
|
+
import grpc
|
25
|
+
|
26
|
+
from flwr.common import now
|
27
|
+
from flwr.common.auth_plugin import ExecAuthPlugin
|
28
|
+
from flwr.common.constant import LOG_STREAM_INTERVAL, Status, SubStatus
|
29
|
+
from flwr.common.logger import log
|
30
|
+
from flwr.common.serde import (
|
31
|
+
configs_record_from_proto,
|
32
|
+
run_to_proto,
|
33
|
+
user_config_from_proto,
|
34
|
+
)
|
35
|
+
from flwr.common.typing import RunStatus
|
36
|
+
from flwr.proto import exec_pb2_grpc # pylint: disable=E0611
|
37
|
+
from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
|
38
|
+
GetAuthTokensRequest,
|
39
|
+
GetAuthTokensResponse,
|
40
|
+
GetLoginDetailsRequest,
|
41
|
+
GetLoginDetailsResponse,
|
42
|
+
ListRunsRequest,
|
43
|
+
ListRunsResponse,
|
44
|
+
StartRunRequest,
|
45
|
+
StartRunResponse,
|
46
|
+
StopRunRequest,
|
47
|
+
StopRunResponse,
|
48
|
+
StreamLogsRequest,
|
49
|
+
StreamLogsResponse,
|
50
|
+
)
|
51
|
+
from flwr.server.superlink.ffs.ffs_factory import FfsFactory
|
52
|
+
from flwr.server.superlink.linkstate import LinkState, LinkStateFactory
|
53
|
+
|
54
|
+
from .executor import Executor
|
55
|
+
|
56
|
+
|
57
|
+
class ExecServicer(exec_pb2_grpc.ExecServicer):
|
58
|
+
"""SuperExec API servicer."""
|
59
|
+
|
60
|
+
def __init__(
|
61
|
+
self,
|
62
|
+
linkstate_factory: LinkStateFactory,
|
63
|
+
ffs_factory: FfsFactory,
|
64
|
+
executor: Executor,
|
65
|
+
auth_plugin: Optional[ExecAuthPlugin] = None,
|
66
|
+
) -> None:
|
67
|
+
self.linkstate_factory = linkstate_factory
|
68
|
+
self.ffs_factory = ffs_factory
|
69
|
+
self.executor = executor
|
70
|
+
self.executor.initialize(linkstate_factory, ffs_factory)
|
71
|
+
self.auth_plugin = auth_plugin
|
72
|
+
|
73
|
+
def StartRun(
|
74
|
+
self, request: StartRunRequest, context: grpc.ServicerContext
|
75
|
+
) -> StartRunResponse:
|
76
|
+
"""Create run ID."""
|
77
|
+
log(INFO, "ExecServicer.StartRun")
|
78
|
+
|
79
|
+
run_id = self.executor.start_run(
|
80
|
+
request.fab.content,
|
81
|
+
user_config_from_proto(request.override_config),
|
82
|
+
configs_record_from_proto(request.federation_options),
|
83
|
+
)
|
84
|
+
|
85
|
+
if run_id is None:
|
86
|
+
log(ERROR, "Executor failed to start run")
|
87
|
+
return StartRunResponse()
|
88
|
+
|
89
|
+
return StartRunResponse(run_id=run_id)
|
90
|
+
|
91
|
+
def StreamLogs( # pylint: disable=C0103
|
92
|
+
self, request: StreamLogsRequest, context: grpc.ServicerContext
|
93
|
+
) -> Generator[StreamLogsResponse, Any, None]:
|
94
|
+
"""Get logs."""
|
95
|
+
log(INFO, "ExecServicer.StreamLogs")
|
96
|
+
state = self.linkstate_factory.state()
|
97
|
+
|
98
|
+
# Retrieve run ID
|
99
|
+
run_id = request.run_id
|
100
|
+
|
101
|
+
# Exit if `run_id` not found
|
102
|
+
if not state.get_run(run_id):
|
103
|
+
context.abort(grpc.StatusCode.NOT_FOUND, "Run ID not found")
|
104
|
+
|
105
|
+
after_timestamp = request.after_timestamp + 1e-6
|
106
|
+
while context.is_active():
|
107
|
+
log_msg, latest_timestamp = state.get_serverapp_log(run_id, after_timestamp)
|
108
|
+
if log_msg:
|
109
|
+
yield StreamLogsResponse(
|
110
|
+
log_output=log_msg,
|
111
|
+
latest_timestamp=latest_timestamp,
|
112
|
+
)
|
113
|
+
# Add a small epsilon to the latest timestamp to avoid getting
|
114
|
+
# the same log
|
115
|
+
after_timestamp = max(latest_timestamp + 1e-6, after_timestamp)
|
116
|
+
|
117
|
+
# Wait for and continue to yield more log responses only if the
|
118
|
+
# run isn't completed yet. If the run is finished, the entire log
|
119
|
+
# is returned at this point and the server ends the stream.
|
120
|
+
run_status = state.get_run_status({run_id})[run_id]
|
121
|
+
if run_status.status == Status.FINISHED:
|
122
|
+
log(INFO, "All logs for run ID `%s` returned", request.run_id)
|
123
|
+
context.cancel()
|
124
|
+
|
125
|
+
time.sleep(LOG_STREAM_INTERVAL) # Sleep briefly to avoid busy waiting
|
126
|
+
|
127
|
+
def ListRuns(
|
128
|
+
self, request: ListRunsRequest, context: grpc.ServicerContext
|
129
|
+
) -> ListRunsResponse:
|
130
|
+
"""Handle `flwr ls` command."""
|
131
|
+
log(INFO, "ExecServicer.List")
|
132
|
+
state = self.linkstate_factory.state()
|
133
|
+
|
134
|
+
# Handle `flwr ls --runs`
|
135
|
+
if not request.HasField("run_id"):
|
136
|
+
return _create_list_runs_response(state.get_run_ids(), state)
|
137
|
+
# Handle `flwr ls --run-id <run_id>`
|
138
|
+
return _create_list_runs_response({request.run_id}, state)
|
139
|
+
|
140
|
+
def StopRun(
|
141
|
+
self, request: StopRunRequest, context: grpc.ServicerContext
|
142
|
+
) -> StopRunResponse:
|
143
|
+
"""Stop a given run ID."""
|
144
|
+
log(INFO, "ExecServicer.StopRun")
|
145
|
+
state = self.linkstate_factory.state()
|
146
|
+
|
147
|
+
# Exit if `run_id` not found
|
148
|
+
if not state.get_run(request.run_id):
|
149
|
+
context.abort(
|
150
|
+
grpc.StatusCode.NOT_FOUND, f"Run ID {request.run_id} not found"
|
151
|
+
)
|
152
|
+
|
153
|
+
run_status = state.get_run_status({request.run_id})[request.run_id]
|
154
|
+
if run_status.status == Status.FINISHED:
|
155
|
+
context.abort(
|
156
|
+
grpc.StatusCode.FAILED_PRECONDITION,
|
157
|
+
f"Run ID {request.run_id} is already finished",
|
158
|
+
)
|
159
|
+
|
160
|
+
update_success = state.update_run_status(
|
161
|
+
run_id=request.run_id,
|
162
|
+
new_status=RunStatus(Status.FINISHED, SubStatus.STOPPED, ""),
|
163
|
+
)
|
164
|
+
|
165
|
+
if update_success:
|
166
|
+
task_ids: set[UUID] = state.get_task_ids_from_run_id(request.run_id)
|
167
|
+
|
168
|
+
# Delete TaskIns and TaskRes for the `run_id`
|
169
|
+
state.delete_tasks(task_ids)
|
170
|
+
|
171
|
+
return StopRunResponse(success=update_success)
|
172
|
+
|
173
|
+
def GetLoginDetails(
|
174
|
+
self, request: GetLoginDetailsRequest, context: grpc.ServicerContext
|
175
|
+
) -> GetLoginDetailsResponse:
|
176
|
+
"""Start login."""
|
177
|
+
log(INFO, "ExecServicer.GetLoginDetails")
|
178
|
+
if self.auth_plugin is None:
|
179
|
+
context.abort(
|
180
|
+
grpc.StatusCode.UNIMPLEMENTED,
|
181
|
+
"ExecServicer initialized without user authentication",
|
182
|
+
)
|
183
|
+
raise grpc.RpcError() # This line is unreachable
|
184
|
+
|
185
|
+
# Get login details
|
186
|
+
details = self.auth_plugin.get_login_details()
|
187
|
+
|
188
|
+
# Return empty response if details is None
|
189
|
+
if details is None:
|
190
|
+
return GetLoginDetailsResponse()
|
191
|
+
|
192
|
+
return GetLoginDetailsResponse(
|
193
|
+
auth_type=details.auth_type,
|
194
|
+
device_code=details.device_code,
|
195
|
+
verification_uri_complete=details.verification_uri_complete,
|
196
|
+
expires_in=details.expires_in,
|
197
|
+
interval=details.interval,
|
198
|
+
)
|
199
|
+
|
200
|
+
def GetAuthTokens(
|
201
|
+
self, request: GetAuthTokensRequest, context: grpc.ServicerContext
|
202
|
+
) -> GetAuthTokensResponse:
|
203
|
+
"""Get auth token."""
|
204
|
+
log(INFO, "ExecServicer.GetAuthTokens")
|
205
|
+
if self.auth_plugin is None:
|
206
|
+
context.abort(
|
207
|
+
grpc.StatusCode.UNIMPLEMENTED,
|
208
|
+
"ExecServicer initialized without user authentication",
|
209
|
+
)
|
210
|
+
raise grpc.RpcError() # This line is unreachable
|
211
|
+
|
212
|
+
# Get auth tokens
|
213
|
+
credentials = self.auth_plugin.get_auth_tokens(request.device_code)
|
214
|
+
|
215
|
+
# Return empty response if credentials is None
|
216
|
+
if credentials is None:
|
217
|
+
return GetAuthTokensResponse()
|
218
|
+
|
219
|
+
return GetAuthTokensResponse(
|
220
|
+
access_token=credentials.access_token,
|
221
|
+
refresh_token=credentials.refresh_token,
|
222
|
+
)
|
223
|
+
|
224
|
+
|
225
|
+
def _create_list_runs_response(run_ids: set[int], state: LinkState) -> ListRunsResponse:
|
226
|
+
"""Create response for `flwr ls --runs` and `flwr ls --run-id <run_id>`."""
|
227
|
+
run_dict = {run_id: state.get_run(run_id) for run_id in run_ids}
|
228
|
+
return ListRunsResponse(
|
229
|
+
run_dict={run_id: run_to_proto(run) for run_id, run in run_dict.items() if run},
|
230
|
+
now=now().isoformat(),
|
231
|
+
)
|