flwr 1.18.0__py3-none-any.whl → 1.19.0__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.
Files changed (143) hide show
  1. flwr/app/__init__.py +15 -0
  2. flwr/app/error.py +68 -0
  3. flwr/app/metadata.py +223 -0
  4. flwr/cli/build.py +82 -57
  5. flwr/cli/log.py +3 -3
  6. flwr/cli/login/login.py +3 -7
  7. flwr/cli/ls.py +15 -36
  8. flwr/cli/new/templates/app/code/client.baseline.py.tpl +1 -1
  9. flwr/cli/new/templates/app/code/model.baseline.py.tpl +1 -1
  10. flwr/cli/new/templates/app/code/server.baseline.py.tpl +2 -3
  11. flwr/cli/new/templates/app/pyproject.baseline.toml.tpl +14 -17
  12. flwr/cli/new/templates/app/pyproject.flowertune.toml.tpl +1 -1
  13. flwr/cli/new/templates/app/pyproject.huggingface.toml.tpl +1 -1
  14. flwr/cli/new/templates/app/pyproject.jax.toml.tpl +1 -1
  15. flwr/cli/new/templates/app/pyproject.mlx.toml.tpl +1 -1
  16. flwr/cli/new/templates/app/pyproject.numpy.toml.tpl +1 -1
  17. flwr/cli/new/templates/app/pyproject.pytorch.toml.tpl +1 -1
  18. flwr/cli/new/templates/app/pyproject.sklearn.toml.tpl +1 -1
  19. flwr/cli/new/templates/app/pyproject.tensorflow.toml.tpl +1 -1
  20. flwr/cli/run/run.py +10 -18
  21. flwr/cli/stop.py +2 -2
  22. flwr/cli/utils.py +31 -5
  23. flwr/client/__init__.py +2 -2
  24. flwr/client/client_app.py +1 -1
  25. flwr/client/clientapp/__init__.py +0 -7
  26. flwr/client/grpc_adapter_client/connection.py +4 -4
  27. flwr/client/grpc_rere_client/connection.py +130 -60
  28. flwr/client/grpc_rere_client/grpc_adapter.py +34 -6
  29. flwr/client/message_handler/message_handler.py +1 -1
  30. flwr/client/mod/comms_mods.py +36 -17
  31. flwr/client/rest_client/connection.py +173 -67
  32. flwr/clientapp/__init__.py +15 -0
  33. flwr/common/__init__.py +2 -2
  34. flwr/common/auth_plugin/__init__.py +2 -0
  35. flwr/common/auth_plugin/auth_plugin.py +29 -3
  36. flwr/common/constant.py +36 -7
  37. flwr/common/event_log_plugin/event_log_plugin.py +3 -3
  38. flwr/common/exit_handlers.py +30 -0
  39. flwr/common/heartbeat.py +165 -0
  40. flwr/common/inflatable.py +290 -0
  41. flwr/common/inflatable_grpc_utils.py +99 -0
  42. flwr/common/inflatable_rest_utils.py +99 -0
  43. flwr/common/inflatable_utils.py +341 -0
  44. flwr/common/message.py +110 -242
  45. flwr/common/record/__init__.py +2 -1
  46. flwr/common/record/array.py +323 -0
  47. flwr/common/record/arrayrecord.py +103 -225
  48. flwr/common/record/configrecord.py +59 -4
  49. flwr/common/record/conversion_utils.py +1 -1
  50. flwr/common/record/metricrecord.py +55 -4
  51. flwr/common/record/recorddict.py +69 -1
  52. flwr/common/recorddict_compat.py +2 -2
  53. flwr/common/retry_invoker.py +5 -1
  54. flwr/common/serde.py +59 -183
  55. flwr/common/serde_utils.py +175 -0
  56. flwr/common/typing.py +5 -3
  57. flwr/compat/__init__.py +15 -0
  58. flwr/compat/client/__init__.py +15 -0
  59. flwr/{client → compat/client}/app.py +19 -159
  60. flwr/compat/common/__init__.py +15 -0
  61. flwr/compat/server/__init__.py +15 -0
  62. flwr/compat/server/app.py +174 -0
  63. flwr/compat/simulation/__init__.py +15 -0
  64. flwr/proto/fleet_pb2.py +32 -27
  65. flwr/proto/fleet_pb2.pyi +49 -35
  66. flwr/proto/fleet_pb2_grpc.py +117 -13
  67. flwr/proto/fleet_pb2_grpc.pyi +47 -6
  68. flwr/proto/heartbeat_pb2.py +33 -0
  69. flwr/proto/heartbeat_pb2.pyi +66 -0
  70. flwr/proto/heartbeat_pb2_grpc.py +4 -0
  71. flwr/proto/heartbeat_pb2_grpc.pyi +4 -0
  72. flwr/proto/message_pb2.py +28 -11
  73. flwr/proto/message_pb2.pyi +125 -0
  74. flwr/proto/recorddict_pb2.py +16 -28
  75. flwr/proto/recorddict_pb2.pyi +46 -64
  76. flwr/proto/run_pb2.py +24 -32
  77. flwr/proto/run_pb2.pyi +4 -52
  78. flwr/proto/serverappio_pb2.py +32 -23
  79. flwr/proto/serverappio_pb2.pyi +45 -3
  80. flwr/proto/serverappio_pb2_grpc.py +138 -34
  81. flwr/proto/serverappio_pb2_grpc.pyi +54 -13
  82. flwr/proto/simulationio_pb2.py +12 -11
  83. flwr/proto/simulationio_pb2_grpc.py +35 -0
  84. flwr/proto/simulationio_pb2_grpc.pyi +14 -0
  85. flwr/server/__init__.py +1 -1
  86. flwr/server/app.py +68 -186
  87. flwr/server/compat/app_utils.py +50 -28
  88. flwr/server/fleet_event_log_interceptor.py +2 -2
  89. flwr/server/grid/grpc_grid.py +104 -34
  90. flwr/server/grid/inmemory_grid.py +5 -4
  91. flwr/server/serverapp/app.py +18 -0
  92. flwr/server/superlink/ffs/__init__.py +2 -0
  93. flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py +13 -3
  94. flwr/server/superlink/fleet/grpc_rere/fleet_servicer.py +101 -7
  95. flwr/server/superlink/fleet/message_handler/message_handler.py +135 -18
  96. flwr/server/superlink/fleet/rest_rere/rest_api.py +72 -11
  97. flwr/server/superlink/fleet/vce/vce_api.py +6 -3
  98. flwr/server/superlink/linkstate/in_memory_linkstate.py +138 -43
  99. flwr/server/superlink/linkstate/linkstate.py +53 -20
  100. flwr/server/superlink/linkstate/sqlite_linkstate.py +149 -55
  101. flwr/server/superlink/linkstate/utils.py +33 -29
  102. flwr/server/superlink/serverappio/serverappio_grpc.py +3 -0
  103. flwr/server/superlink/serverappio/serverappio_servicer.py +211 -57
  104. flwr/server/superlink/simulation/simulationio_servicer.py +25 -1
  105. flwr/server/superlink/utils.py +44 -2
  106. flwr/server/utils/validator.py +2 -2
  107. flwr/serverapp/__init__.py +15 -0
  108. flwr/simulation/app.py +17 -0
  109. flwr/supercore/__init__.py +15 -0
  110. flwr/supercore/object_store/__init__.py +24 -0
  111. flwr/supercore/object_store/in_memory_object_store.py +229 -0
  112. flwr/supercore/object_store/object_store.py +192 -0
  113. flwr/supercore/object_store/object_store_factory.py +44 -0
  114. flwr/superexec/deployment.py +6 -2
  115. flwr/superexec/exec_event_log_interceptor.py +4 -4
  116. flwr/superexec/exec_grpc.py +7 -3
  117. flwr/superexec/exec_servicer.py +125 -23
  118. flwr/superexec/exec_user_auth_interceptor.py +37 -8
  119. flwr/superexec/executor.py +4 -0
  120. flwr/superexec/simulation.py +7 -1
  121. flwr/superlink/__init__.py +15 -0
  122. flwr/{client/supernode → supernode}/__init__.py +0 -7
  123. flwr/{client/nodestate/nodestate.py → supernode/cli/__init__.py} +7 -14
  124. flwr/{client/supernode/app.py → supernode/cli/flower_supernode.py} +3 -12
  125. flwr/supernode/cli/flwr_clientapp.py +81 -0
  126. flwr/supernode/nodestate/in_memory_nodestate.py +190 -0
  127. flwr/supernode/nodestate/nodestate.py +212 -0
  128. flwr/supernode/runtime/__init__.py +15 -0
  129. flwr/{client/clientapp/app.py → supernode/runtime/run_clientapp.py} +25 -56
  130. flwr/supernode/servicer/__init__.py +15 -0
  131. flwr/supernode/servicer/clientappio/__init__.py +24 -0
  132. flwr/supernode/start_client_internal.py +491 -0
  133. {flwr-1.18.0.dist-info → flwr-1.19.0.dist-info}/METADATA +5 -4
  134. {flwr-1.18.0.dist-info → flwr-1.19.0.dist-info}/RECORD +141 -108
  135. {flwr-1.18.0.dist-info → flwr-1.19.0.dist-info}/WHEEL +1 -1
  136. {flwr-1.18.0.dist-info → flwr-1.19.0.dist-info}/entry_points.txt +2 -2
  137. flwr/client/heartbeat.py +0 -74
  138. flwr/client/nodestate/in_memory_nodestate.py +0 -38
  139. /flwr/{client → compat/client}/grpc_client/__init__.py +0 -0
  140. /flwr/{client → compat/client}/grpc_client/connection.py +0 -0
  141. /flwr/{client → supernode}/nodestate/__init__.py +0 -0
  142. /flwr/{client → supernode}/nodestate/nodestate_factory.py +0 -0
  143. /flwr/{client/clientapp → supernode/servicer/clientappio}/clientappio_servicer.py +0 -0
@@ -15,38 +15,30 @@
15
15
  """Flower client app."""
16
16
 
17
17
 
18
- import multiprocessing
19
- import os
20
- import sys
21
- import threading
22
18
  import time
23
19
  from contextlib import AbstractContextManager
24
20
  from logging import ERROR, INFO, WARN
25
- from os import urandom
26
21
  from pathlib import Path
27
- from typing import Callable, Optional, Union, cast
22
+ from typing import Callable, Optional, Union
28
23
 
29
- import grpc
30
24
  from cryptography.hazmat.primitives.asymmetric import ec
31
25
  from grpc import RpcError
32
26
 
27
+ from flwr.app.error import Error
33
28
  from flwr.cli.config_utils import get_fab_metadata
34
29
  from flwr.cli.install import install_from_fab
35
30
  from flwr.client.client import Client
36
31
  from flwr.client.client_app import ClientApp, LoadClientAppError
37
- from flwr.client.clientapp.app import flwr_clientapp
38
- from flwr.client.nodestate.nodestate_factory import NodeStateFactory
32
+ from flwr.client.grpc_adapter_client.connection import grpc_adapter
33
+ from flwr.client.grpc_rere_client.connection import grpc_request_response
34
+ from flwr.client.message_handler.message_handler import handle_control_message
35
+ from flwr.client.numpy_client import NumPyClient
36
+ from flwr.client.run_info_store import DeprecatedRunInfoStore
39
37
  from flwr.client.typing import ClientFnExt
40
38
  from flwr.common import GRPC_MAX_MESSAGE_LENGTH, Context, EventType, Message, event
41
39
  from flwr.common.address import parse_address
42
40
  from flwr.common.constant import (
43
- CLIENT_OCTET,
44
- CLIENTAPPIO_API_DEFAULT_SERVER_ADDRESS,
45
- ISOLATION_MODE_PROCESS,
46
- ISOLATION_MODE_SUBPROCESS,
47
41
  MAX_RETRY_DELAY,
48
- RUN_ID_NUM_BYTES,
49
- SERVER_OCTET,
50
42
  TRANSPORT_TYPE_GRPC_ADAPTER,
51
43
  TRANSPORT_TYPE_GRPC_BIDI,
52
44
  TRANSPORT_TYPE_GRPC_RERE,
@@ -55,20 +47,11 @@ from flwr.common.constant import (
55
47
  ErrorCode,
56
48
  )
57
49
  from flwr.common.exit import ExitCode, flwr_exit
58
- from flwr.common.grpc import generic_create_grpc_server
59
50
  from flwr.common.logger import log, warn_deprecated_feature
60
- from flwr.common.message import Error
61
51
  from flwr.common.retry_invoker import RetryInvoker, RetryState, exponential
62
52
  from flwr.common.typing import Fab, Run, RunNotRunningException, UserConfig
63
- from flwr.proto.clientappio_pb2_grpc import add_ClientAppIoServicer_to_server
64
-
65
- from .clientapp.clientappio_servicer import ClientAppInputs, ClientAppIoServicer
66
- from .grpc_adapter_client.connection import grpc_adapter
67
- from .grpc_client.connection import grpc_connection
68
- from .grpc_rere_client.connection import grpc_request_response
69
- from .message_handler.message_handler import handle_control_message
70
- from .numpy_client import NumPyClient
71
- from .run_info_store import DeprecatedRunInfoStore
53
+ from flwr.compat.client.grpc_client.connection import grpc_connection
54
+ from flwr.supernode.nodestate import NodeStateFactory
72
55
 
73
56
 
74
57
  def _check_actionable_client(
@@ -236,8 +219,6 @@ def start_client_internal(
236
219
  max_retries: Optional[int] = None,
237
220
  max_wait_time: Optional[float] = None,
238
221
  flwr_path: Optional[Path] = None,
239
- isolation: Optional[str] = None,
240
- clientappio_api_address: Optional[str] = CLIENTAPPIO_API_DEFAULT_SERVER_ADDRESS,
241
222
  ) -> None:
242
223
  """Start a Flower client node which connects to a Flower server.
243
224
 
@@ -290,17 +271,6 @@ def start_client_internal(
290
271
  If set to None, there is no limit to the total time.
291
272
  flwr_path: Optional[Path] (default: None)
292
273
  The fully resolved path containing installed Flower Apps.
293
- isolation : Optional[str] (default: None)
294
- Isolation mode for `ClientApp`. Possible values are `subprocess` and
295
- `process`. Defaults to `None`, which runs the `ClientApp` in the same process
296
- as the SuperNode. If `subprocess`, the `ClientApp` runs in a subprocess started
297
- by the SueprNode and communicates using gRPC at the address
298
- `clientappio_api_address`. If `process`, the `ClientApp` runs in a separate
299
- isolated process and communicates using gRPC at the address
300
- `clientappio_api_address`.
301
- clientappio_api_address : Optional[str]
302
- (default: `CLIENTAPPIO_API_DEFAULT_SERVER_ADDRESS`)
303
- The SuperNode gRPC server address.
304
274
  """
305
275
  if insecure is None:
306
276
  insecure = root_certificates is None
@@ -326,18 +296,6 @@ def start_client_internal(
326
296
 
327
297
  load_client_app_fn = _load_client_app
328
298
 
329
- if isolation:
330
- if clientappio_api_address is None:
331
- raise ValueError(
332
- f"`clientappio_api_address` required when `isolation` is "
333
- f"{ISOLATION_MODE_SUBPROCESS} or {ISOLATION_MODE_PROCESS}",
334
- )
335
- _clientappio_grpc_server, clientappio_servicer = run_clientappio_api_grpc(
336
- address=clientappio_api_address,
337
- certificates=None,
338
- )
339
- clientappio_api_address = cast(str, clientappio_api_address)
340
-
341
299
  # At this point, only `load_client_app_fn` should be used
342
300
  # Both `client` and `client_fn` must not be used directly
343
301
 
@@ -388,7 +346,6 @@ def start_client_internal(
388
346
  run_info_store: Optional[DeprecatedRunInfoStore] = None
389
347
  state_factory = NodeStateFactory()
390
348
  state = state_factory.state()
391
- mp_spawn_context = multiprocessing.get_context("spawn")
392
349
 
393
350
  runs: dict[int, Run] = {}
394
351
 
@@ -473,9 +430,8 @@ def start_client_internal(
473
430
  run: Run = runs[run_id]
474
431
  if get_fab is not None and run.fab_hash:
475
432
  fab = get_fab(run.fab_hash, run_id)
476
- if not isolation:
477
- # If `ClientApp` runs in the same process, install the FAB
478
- install_from_fab(fab.content, flwr_path, True)
433
+ # If `ClientApp` runs in the same process, install the FAB
434
+ install_from_fab(fab.content, flwr_path, True)
479
435
  fab_id, fab_version = get_fab_metadata(fab.content)
480
436
  else:
481
437
  fab = None
@@ -502,73 +458,13 @@ def start_client_internal(
502
458
 
503
459
  # Handle app loading and task message
504
460
  try:
505
- if isolation:
506
- # Two isolation modes:
507
- # 1. `subprocess`: SuperNode is starting the ClientApp
508
- # process as a subprocess.
509
- # 2. `process`: ClientApp process gets started separately
510
- # (via `flwr-clientapp`), for example, in a separate
511
- # Docker container.
512
-
513
- # Generate SuperNode token
514
- token = int.from_bytes(urandom(RUN_ID_NUM_BYTES), "little")
515
-
516
- # Mode 1: SuperNode starts ClientApp as subprocess
517
- start_subprocess = isolation == ISOLATION_MODE_SUBPROCESS
518
-
519
- # Share Message and Context with servicer
520
- clientappio_servicer.set_inputs(
521
- clientapp_input=ClientAppInputs(
522
- message=message,
523
- context=context,
524
- run=run,
525
- fab=fab,
526
- token=token,
527
- ),
528
- token_returned=start_subprocess,
529
- )
530
-
531
- if start_subprocess:
532
- _octet, _colon, _port = (
533
- clientappio_api_address.rpartition(":")
534
- )
535
- io_address = (
536
- f"{CLIENT_OCTET}:{_port}"
537
- if _octet == SERVER_OCTET
538
- else clientappio_api_address
539
- )
540
- # Start ClientApp subprocess
541
- command = [
542
- "flwr-clientapp",
543
- "--clientappio-api-address",
544
- io_address,
545
- "--token",
546
- str(token),
547
- ]
548
- command.append("--insecure")
549
-
550
- proc = mp_spawn_context.Process(
551
- target=_run_flwr_clientapp,
552
- args=(command, os.getpid()),
553
- daemon=True,
554
- )
555
- proc.start()
556
- proc.join()
557
- else:
558
- # Wait for output to become available
559
- while not clientappio_servicer.has_outputs():
560
- time.sleep(0.1)
561
-
562
- outputs = clientappio_servicer.get_outputs()
563
- reply_message, context = outputs.message, outputs.context
564
- else:
565
- # Load ClientApp instance
566
- client_app: ClientApp = load_client_app_fn(
567
- fab_id, fab_version, run.fab_hash
568
- )
461
+ # Load ClientApp instance
462
+ client_app: ClientApp = load_client_app_fn(
463
+ fab_id, fab_version, run.fab_hash
464
+ )
569
465
 
570
- # Execute ClientApp
571
- reply_message = client_app(message=message, context=context)
466
+ # Execute ClientApp
467
+ reply_message = client_app(message=message, context=context)
572
468
  except Exception as ex: # pylint: disable=broad-exception-caught
573
469
 
574
470
  # Legacy grpc-bidi
@@ -781,7 +677,7 @@ def _init_connection(transport: Optional[str], server_address: str) -> tuple[
781
677
  try:
782
678
  from requests.exceptions import ConnectionError as RequestsConnectionError
783
679
 
784
- from .rest_client.connection import http_request_response
680
+ from flwr.client.rest_client.connection import http_request_response
785
681
  except ModuleNotFoundError:
786
682
  flwr_exit(ExitCode.COMMON_MISSING_EXTRA_REST)
787
683
  if server_address[:4] != "http":
@@ -792,46 +688,10 @@ def _init_connection(transport: Optional[str], server_address: str) -> tuple[
792
688
  elif transport == TRANSPORT_TYPE_GRPC_ADAPTER:
793
689
  connection, error_type = grpc_adapter, RpcError
794
690
  elif transport == TRANSPORT_TYPE_GRPC_BIDI:
795
- connection, error_type = grpc_connection, RpcError
691
+ connection, error_type = grpc_connection, RpcError # type: ignore[assignment]
796
692
  else:
797
693
  raise ValueError(
798
694
  f"Unknown transport type: {transport} (possible: {TRANSPORT_TYPES})"
799
695
  )
800
696
 
801
697
  return connection, address, error_type
802
-
803
-
804
- def _run_flwr_clientapp(args: list[str], main_pid: int) -> None:
805
- # Monitor the main process in case of SIGKILL
806
- def main_process_monitor() -> None:
807
- while True:
808
- time.sleep(1)
809
- if os.getppid() != main_pid:
810
- os.kill(os.getpid(), 9)
811
-
812
- threading.Thread(target=main_process_monitor, daemon=True).start()
813
-
814
- # Run the command
815
- sys.argv = args
816
- flwr_clientapp()
817
-
818
-
819
- def run_clientappio_api_grpc(
820
- address: str,
821
- certificates: Optional[tuple[bytes, bytes, bytes]],
822
- ) -> tuple[grpc.Server, ClientAppIoServicer]:
823
- """Run ClientAppIo API gRPC server."""
824
- clientappio_servicer: grpc.Server = ClientAppIoServicer()
825
- clientappio_add_servicer_to_server_fn = add_ClientAppIoServicer_to_server
826
- clientappio_grpc_server = generic_create_grpc_server(
827
- servicer_and_add_fn=(
828
- clientappio_servicer,
829
- clientappio_add_servicer_to_server_fn,
830
- ),
831
- server_address=address,
832
- max_message_length=GRPC_MAX_MESSAGE_LENGTH,
833
- certificates=certificates,
834
- )
835
- log(INFO, "Starting Flower ClientAppIo gRPC server on %s", address)
836
- clientappio_grpc_server.start()
837
- return clientappio_grpc_server, clientappio_servicer
@@ -0,0 +1,15 @@
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
+ """Legacy components previously located in ``flwr.common``."""
@@ -0,0 +1,15 @@
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
+ """Legacy components previously located in ``flwr.server``."""
@@ -0,0 +1,174 @@
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
+ """Flower server app."""
16
+
17
+
18
+ import sys
19
+ from logging import INFO
20
+ from typing import Optional
21
+
22
+ from flwr.common import GRPC_MAX_MESSAGE_LENGTH, EventType, event
23
+ from flwr.common.address import parse_address
24
+ from flwr.common.constant import FLEET_API_GRPC_BIDI_DEFAULT_ADDRESS
25
+ from flwr.common.exit_handlers import register_exit_handlers
26
+ from flwr.common.logger import log, warn_deprecated_feature
27
+ from flwr.server.client_manager import ClientManager
28
+ from flwr.server.history import History
29
+ from flwr.server.server import Server, init_defaults, run_fl
30
+ from flwr.server.server_config import ServerConfig
31
+ from flwr.server.strategy import Strategy
32
+ from flwr.server.superlink.fleet.grpc_bidi.grpc_server import start_grpc_server
33
+
34
+
35
+ def start_server( # pylint: disable=too-many-arguments,too-many-locals
36
+ *,
37
+ server_address: str = FLEET_API_GRPC_BIDI_DEFAULT_ADDRESS,
38
+ server: Optional[Server] = None,
39
+ config: Optional[ServerConfig] = None,
40
+ strategy: Optional[Strategy] = None,
41
+ client_manager: Optional[ClientManager] = None,
42
+ grpc_max_message_length: int = GRPC_MAX_MESSAGE_LENGTH,
43
+ certificates: Optional[tuple[bytes, bytes, bytes]] = None,
44
+ ) -> History:
45
+ """Start a Flower server using the gRPC transport layer.
46
+
47
+ Warning
48
+ -------
49
+ This function is deprecated since 1.13.0. Use the :code:`flower-superlink` command
50
+ instead to start a SuperLink.
51
+
52
+ Parameters
53
+ ----------
54
+ server_address : Optional[str]
55
+ The IPv4 or IPv6 address of the server. Defaults to `"[::]:8080"`.
56
+ server : Optional[flwr.server.Server] (default: None)
57
+ A server implementation, either `flwr.server.Server` or a subclass
58
+ thereof. If no instance is provided, then `start_server` will create
59
+ one.
60
+ config : Optional[ServerConfig] (default: None)
61
+ Currently supported values are `num_rounds` (int, default: 1) and
62
+ `round_timeout` in seconds (float, default: None).
63
+ strategy : Optional[flwr.server.Strategy] (default: None).
64
+ An implementation of the abstract base class
65
+ `flwr.server.strategy.Strategy`. If no strategy is provided, then
66
+ `start_server` will use `flwr.server.strategy.FedAvg`.
67
+ client_manager : Optional[flwr.server.ClientManager] (default: None)
68
+ An implementation of the abstract base class
69
+ `flwr.server.ClientManager`. If no implementation is provided, then
70
+ `start_server` will use
71
+ `flwr.server.client_manager.SimpleClientManager`.
72
+ grpc_max_message_length : int (default: 536_870_912, this equals 512MB)
73
+ The maximum length of gRPC messages that can be exchanged with the
74
+ Flower clients. The default should be sufficient for most models.
75
+ Users who train very large models might need to increase this
76
+ value. Note that the Flower clients need to be started with the
77
+ same value (see `flwr.client.start_client`), otherwise clients will
78
+ not know about the increased limit and block larger messages.
79
+ certificates : Tuple[bytes, bytes, bytes] (default: None)
80
+ Tuple containing root certificate, server certificate, and private key
81
+ to start a secure SSL-enabled server. The tuple is expected to have
82
+ three bytes elements in the following order:
83
+
84
+ * CA certificate.
85
+ * server certificate.
86
+ * server private key.
87
+
88
+ Returns
89
+ -------
90
+ hist : flwr.server.history.History
91
+ Object containing training and evaluation metrics.
92
+
93
+ Examples
94
+ --------
95
+ Starting an insecure server::
96
+
97
+ start_server()
98
+
99
+ Starting a TLS-enabled server::
100
+
101
+ start_server(
102
+ certificates=(
103
+ Path("/crts/root.pem").read_bytes(),
104
+ Path("/crts/localhost.crt").read_bytes(),
105
+ Path("/crts/localhost.key").read_bytes()
106
+ )
107
+ )
108
+ """
109
+ msg = (
110
+ "flwr.server.start_server() is deprecated."
111
+ "\n\tInstead, use the `flower-superlink` CLI command to start a SuperLink "
112
+ "as shown below:"
113
+ "\n\n\t\t$ flower-superlink --insecure"
114
+ "\n\n\tTo view usage and all available options, run:"
115
+ "\n\n\t\t$ flower-superlink --help"
116
+ "\n\n\tUsing `start_server()` is deprecated."
117
+ )
118
+ warn_deprecated_feature(name=msg)
119
+
120
+ event(EventType.START_SERVER_ENTER)
121
+
122
+ # Parse IP address
123
+ parsed_address = parse_address(server_address)
124
+ if not parsed_address:
125
+ sys.exit(f"Server IP address ({server_address}) cannot be parsed.")
126
+ host, port, is_v6 = parsed_address
127
+ address = f"[{host}]:{port}" if is_v6 else f"{host}:{port}"
128
+
129
+ # Initialize server and server config
130
+ initialized_server, initialized_config = init_defaults(
131
+ server=server,
132
+ config=config,
133
+ strategy=strategy,
134
+ client_manager=client_manager,
135
+ )
136
+ log(
137
+ INFO,
138
+ "Starting Flower server, config: %s",
139
+ initialized_config,
140
+ )
141
+
142
+ # Start gRPC server
143
+ grpc_server = start_grpc_server(
144
+ client_manager=initialized_server.client_manager(),
145
+ server_address=address,
146
+ max_message_length=grpc_max_message_length,
147
+ certificates=certificates,
148
+ )
149
+ log(
150
+ INFO,
151
+ "Flower ECE: gRPC server running (%s rounds), SSL is %s",
152
+ initialized_config.num_rounds,
153
+ "enabled" if certificates is not None else "disabled",
154
+ )
155
+
156
+ # Graceful shutdown
157
+ register_exit_handlers(
158
+ event_type=EventType.START_SERVER_LEAVE,
159
+ exit_message="Flower server terminated gracefully.",
160
+ grpc_servers=[grpc_server],
161
+ )
162
+
163
+ # Start training
164
+ hist = run_fl(
165
+ server=initialized_server,
166
+ config=initialized_config,
167
+ )
168
+
169
+ # Stop the gRPC server
170
+ grpc_server.stop(grace=1)
171
+
172
+ event(EventType.START_SERVER_LEAVE)
173
+
174
+ return hist
@@ -0,0 +1,15 @@
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
+ """Legacy components previously located in ``flwr.simulation``."""
flwr/proto/fleet_pb2.py CHANGED
@@ -12,45 +12,50 @@ from google.protobuf.internal import builder as _builder
12
12
  _sym_db = _symbol_database.Default()
13
13
 
14
14
 
15
+ from flwr.proto import heartbeat_pb2 as flwr_dot_proto_dot_heartbeat__pb2
15
16
  from flwr.proto import node_pb2 as flwr_dot_proto_dot_node__pb2
16
17
  from flwr.proto import run_pb2 as flwr_dot_proto_dot_run__pb2
17
18
  from flwr.proto import fab_pb2 as flwr_dot_proto_dot_fab__pb2
18
19
  from flwr.proto import message_pb2 as flwr_dot_proto_dot_message__pb2
19
20
 
20
21
 
21
- DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x16\x66lwr/proto/fleet.proto\x12\nflwr.proto\x1a\x15\x66lwr/proto/node.proto\x1a\x14\x66lwr/proto/run.proto\x1a\x14\x66lwr/proto/fab.proto\x1a\x18\x66lwr/proto/message.proto\"*\n\x11\x43reateNodeRequest\x12\x15\n\rping_interval\x18\x01 \x01(\x01\"4\n\x12\x43reateNodeResponse\x12\x1e\n\x04node\x18\x01 \x01(\x0b\x32\x10.flwr.proto.Node\"3\n\x11\x44\x65leteNodeRequest\x12\x1e\n\x04node\x18\x01 \x01(\x0b\x32\x10.flwr.proto.Node\"\x14\n\x12\x44\x65leteNodeResponse\"D\n\x0bPingRequest\x12\x1e\n\x04node\x18\x01 \x01(\x0b\x32\x10.flwr.proto.Node\x12\x15\n\rping_interval\x18\x02 \x01(\x01\"\x1f\n\x0cPingResponse\x12\x0f\n\x07success\x18\x01 \x01(\x08\"J\n\x13PullMessagesRequest\x12\x1e\n\x04node\x18\x01 \x01(\x0b\x32\x10.flwr.proto.Node\x12\x13\n\x0bmessage_ids\x18\x02 \x03(\t\"l\n\x14PullMessagesResponse\x12(\n\treconnect\x18\x01 \x01(\x0b\x32\x15.flwr.proto.Reconnect\x12*\n\rmessages_list\x18\x02 \x03(\x0b\x32\x13.flwr.proto.Message\"a\n\x13PushMessagesRequest\x12\x1e\n\x04node\x18\x01 \x01(\x0b\x32\x10.flwr.proto.Node\x12*\n\rmessages_list\x18\x02 \x03(\x0b\x32\x13.flwr.proto.Message\"\xb0\x01\n\x14PushMessagesResponse\x12(\n\treconnect\x18\x01 \x01(\x0b\x32\x15.flwr.proto.Reconnect\x12>\n\x07results\x18\x02 \x03(\x0b\x32-.flwr.proto.PushMessagesResponse.ResultsEntry\x1a.\n\x0cResultsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\r:\x02\x38\x01\"\x1e\n\tReconnect\x12\x11\n\treconnect\x18\x01 \x01(\x04\x32\x92\x04\n\x05\x46leet\x12M\n\nCreateNode\x12\x1d.flwr.proto.CreateNodeRequest\x1a\x1e.flwr.proto.CreateNodeResponse\"\x00\x12M\n\nDeleteNode\x12\x1d.flwr.proto.DeleteNodeRequest\x1a\x1e.flwr.proto.DeleteNodeResponse\"\x00\x12;\n\x04Ping\x12\x17.flwr.proto.PingRequest\x1a\x18.flwr.proto.PingResponse\"\x00\x12S\n\x0cPullMessages\x12\x1f.flwr.proto.PullMessagesRequest\x1a .flwr.proto.PullMessagesResponse\"\x00\x12S\n\x0cPushMessages\x12\x1f.flwr.proto.PushMessagesRequest\x1a .flwr.proto.PushMessagesResponse\"\x00\x12\x41\n\x06GetRun\x12\x19.flwr.proto.GetRunRequest\x1a\x1a.flwr.proto.GetRunResponse\"\x00\x12\x41\n\x06GetFab\x12\x19.flwr.proto.GetFabRequest\x1a\x1a.flwr.proto.GetFabResponse\"\x00\x62\x06proto3')
22
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x16\x66lwr/proto/fleet.proto\x12\nflwr.proto\x1a\x1a\x66lwr/proto/heartbeat.proto\x1a\x15\x66lwr/proto/node.proto\x1a\x14\x66lwr/proto/run.proto\x1a\x14\x66lwr/proto/fab.proto\x1a\x18\x66lwr/proto/message.proto\"/\n\x11\x43reateNodeRequest\x12\x1a\n\x12heartbeat_interval\x18\x01 \x01(\x01\"4\n\x12\x43reateNodeResponse\x12\x1e\n\x04node\x18\x01 \x01(\x0b\x32\x10.flwr.proto.Node\"3\n\x11\x44\x65leteNodeRequest\x12\x1e\n\x04node\x18\x01 \x01(\x0b\x32\x10.flwr.proto.Node\"\x14\n\x12\x44\x65leteNodeResponse\"J\n\x13PullMessagesRequest\x12\x1e\n\x04node\x18\x01 \x01(\x0b\x32\x10.flwr.proto.Node\x12\x13\n\x0bmessage_ids\x18\x02 \x03(\t\"\x87\x02\n\x14PullMessagesResponse\x12(\n\treconnect\x18\x01 \x01(\x0b\x32\x15.flwr.proto.Reconnect\x12*\n\rmessages_list\x18\x02 \x03(\x0b\x32\x13.flwr.proto.Message\x12L\n\x0fobjects_to_pull\x18\x03 \x03(\x0b\x32\x33.flwr.proto.PullMessagesResponse.ObjectsToPullEntry\x1aK\n\x12ObjectsToPullEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12$\n\x05value\x18\x02 \x01(\x0b\x32\x15.flwr.proto.ObjectIDs:\x02\x38\x01\"\x97\x01\n\x13PushMessagesRequest\x12\x1e\n\x04node\x18\x01 \x01(\x0b\x32\x10.flwr.proto.Node\x12*\n\rmessages_list\x18\x02 \x03(\x0b\x32\x13.flwr.proto.Message\x12\x34\n\x14message_object_trees\x18\x03 \x03(\x0b\x32\x16.flwr.proto.ObjectTree\"\xcb\x02\n\x14PushMessagesResponse\x12(\n\treconnect\x18\x01 \x01(\x0b\x32\x15.flwr.proto.Reconnect\x12>\n\x07results\x18\x02 \x03(\x0b\x32-.flwr.proto.PushMessagesResponse.ResultsEntry\x12L\n\x0fobjects_to_push\x18\x03 \x03(\x0b\x32\x33.flwr.proto.PushMessagesResponse.ObjectsToPushEntry\x1a.\n\x0cResultsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\r:\x02\x38\x01\x1aK\n\x12ObjectsToPushEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12$\n\x05value\x18\x02 \x01(\x0b\x32\x15.flwr.proto.ObjectIDs:\x02\x38\x01\"\x1e\n\tReconnect\x12\x11\n\treconnect\x18\x01 \x01(\x04\x32\xca\x06\n\x05\x46leet\x12M\n\nCreateNode\x12\x1d.flwr.proto.CreateNodeRequest\x1a\x1e.flwr.proto.CreateNodeResponse\"\x00\x12M\n\nDeleteNode\x12\x1d.flwr.proto.DeleteNodeRequest\x1a\x1e.flwr.proto.DeleteNodeResponse\"\x00\x12\x62\n\x11SendNodeHeartbeat\x12$.flwr.proto.SendNodeHeartbeatRequest\x1a%.flwr.proto.SendNodeHeartbeatResponse\"\x00\x12S\n\x0cPullMessages\x12\x1f.flwr.proto.PullMessagesRequest\x1a .flwr.proto.PullMessagesResponse\"\x00\x12S\n\x0cPushMessages\x12\x1f.flwr.proto.PushMessagesRequest\x1a .flwr.proto.PushMessagesResponse\"\x00\x12\x41\n\x06GetRun\x12\x19.flwr.proto.GetRunRequest\x1a\x1a.flwr.proto.GetRunResponse\"\x00\x12\x41\n\x06GetFab\x12\x19.flwr.proto.GetFabRequest\x1a\x1a.flwr.proto.GetFabResponse\"\x00\x12M\n\nPushObject\x12\x1d.flwr.proto.PushObjectRequest\x1a\x1e.flwr.proto.PushObjectResponse\"\x00\x12M\n\nPullObject\x12\x1d.flwr.proto.PullObjectRequest\x1a\x1e.flwr.proto.PullObjectResponse\"\x00\x12q\n\x16\x43onfirmMessageReceived\x12).flwr.proto.ConfirmMessageReceivedRequest\x1a*.flwr.proto.ConfirmMessageReceivedResponse\"\x00\x62\x06proto3')
22
23
 
23
24
  _globals = globals()
24
25
  _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
25
26
  _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'flwr.proto.fleet_pb2', _globals)
26
27
  if _descriptor._USE_C_DESCRIPTORS == False:
27
28
  DESCRIPTOR._options = None
29
+ _globals['_PULLMESSAGESRESPONSE_OBJECTSTOPULLENTRY']._options = None
30
+ _globals['_PULLMESSAGESRESPONSE_OBJECTSTOPULLENTRY']._serialized_options = b'8\001'
28
31
  _globals['_PUSHMESSAGESRESPONSE_RESULTSENTRY']._options = None
29
32
  _globals['_PUSHMESSAGESRESPONSE_RESULTSENTRY']._serialized_options = b'8\001'
30
- _globals['_CREATENODEREQUEST']._serialized_start=131
31
- _globals['_CREATENODEREQUEST']._serialized_end=173
32
- _globals['_CREATENODERESPONSE']._serialized_start=175
33
- _globals['_CREATENODERESPONSE']._serialized_end=227
34
- _globals['_DELETENODEREQUEST']._serialized_start=229
35
- _globals['_DELETENODEREQUEST']._serialized_end=280
36
- _globals['_DELETENODERESPONSE']._serialized_start=282
37
- _globals['_DELETENODERESPONSE']._serialized_end=302
38
- _globals['_PINGREQUEST']._serialized_start=304
39
- _globals['_PINGREQUEST']._serialized_end=372
40
- _globals['_PINGRESPONSE']._serialized_start=374
41
- _globals['_PINGRESPONSE']._serialized_end=405
42
- _globals['_PULLMESSAGESREQUEST']._serialized_start=407
43
- _globals['_PULLMESSAGESREQUEST']._serialized_end=481
44
- _globals['_PULLMESSAGESRESPONSE']._serialized_start=483
45
- _globals['_PULLMESSAGESRESPONSE']._serialized_end=591
46
- _globals['_PUSHMESSAGESREQUEST']._serialized_start=593
47
- _globals['_PUSHMESSAGESREQUEST']._serialized_end=690
48
- _globals['_PUSHMESSAGESRESPONSE']._serialized_start=693
49
- _globals['_PUSHMESSAGESRESPONSE']._serialized_end=869
50
- _globals['_PUSHMESSAGESRESPONSE_RESULTSENTRY']._serialized_start=823
51
- _globals['_PUSHMESSAGESRESPONSE_RESULTSENTRY']._serialized_end=869
52
- _globals['_RECONNECT']._serialized_start=871
53
- _globals['_RECONNECT']._serialized_end=901
54
- _globals['_FLEET']._serialized_start=904
55
- _globals['_FLEET']._serialized_end=1434
33
+ _globals['_PUSHMESSAGESRESPONSE_OBJECTSTOPUSHENTRY']._options = None
34
+ _globals['_PUSHMESSAGESRESPONSE_OBJECTSTOPUSHENTRY']._serialized_options = b'8\001'
35
+ _globals['_CREATENODEREQUEST']._serialized_start=159
36
+ _globals['_CREATENODEREQUEST']._serialized_end=206
37
+ _globals['_CREATENODERESPONSE']._serialized_start=208
38
+ _globals['_CREATENODERESPONSE']._serialized_end=260
39
+ _globals['_DELETENODEREQUEST']._serialized_start=262
40
+ _globals['_DELETENODEREQUEST']._serialized_end=313
41
+ _globals['_DELETENODERESPONSE']._serialized_start=315
42
+ _globals['_DELETENODERESPONSE']._serialized_end=335
43
+ _globals['_PULLMESSAGESREQUEST']._serialized_start=337
44
+ _globals['_PULLMESSAGESREQUEST']._serialized_end=411
45
+ _globals['_PULLMESSAGESRESPONSE']._serialized_start=414
46
+ _globals['_PULLMESSAGESRESPONSE']._serialized_end=677
47
+ _globals['_PULLMESSAGESRESPONSE_OBJECTSTOPULLENTRY']._serialized_start=602
48
+ _globals['_PULLMESSAGESRESPONSE_OBJECTSTOPULLENTRY']._serialized_end=677
49
+ _globals['_PUSHMESSAGESREQUEST']._serialized_start=680
50
+ _globals['_PUSHMESSAGESREQUEST']._serialized_end=831
51
+ _globals['_PUSHMESSAGESRESPONSE']._serialized_start=834
52
+ _globals['_PUSHMESSAGESRESPONSE']._serialized_end=1165
53
+ _globals['_PUSHMESSAGESRESPONSE_RESULTSENTRY']._serialized_start=1042
54
+ _globals['_PUSHMESSAGESRESPONSE_RESULTSENTRY']._serialized_end=1088
55
+ _globals['_PUSHMESSAGESRESPONSE_OBJECTSTOPUSHENTRY']._serialized_start=1090
56
+ _globals['_PUSHMESSAGESRESPONSE_OBJECTSTOPUSHENTRY']._serialized_end=1165
57
+ _globals['_RECONNECT']._serialized_start=1167
58
+ _globals['_RECONNECT']._serialized_end=1197
59
+ _globals['_FLEET']._serialized_start=1200
60
+ _globals['_FLEET']._serialized_end=2042
56
61
  # @@protoc_insertion_point(module_scope)