flwr 1.20.0__py3-none-any.whl → 1.22.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 (182) hide show
  1. flwr/__init__.py +4 -1
  2. flwr/app/__init__.py +28 -0
  3. flwr/app/exception.py +31 -0
  4. flwr/cli/app.py +2 -0
  5. flwr/cli/auth_plugin/oidc_cli_plugin.py +4 -4
  6. flwr/cli/cli_user_auth_interceptor.py +1 -1
  7. flwr/cli/config_utils.py +3 -3
  8. flwr/cli/constant.py +25 -8
  9. flwr/cli/log.py +9 -9
  10. flwr/cli/login/login.py +3 -3
  11. flwr/cli/ls.py +5 -5
  12. flwr/cli/new/new.py +15 -2
  13. flwr/cli/new/templates/app/README.flowertune.md.tpl +1 -1
  14. flwr/cli/new/templates/app/code/__init__.pytorch_legacy_api.py.tpl +1 -0
  15. flwr/cli/new/templates/app/code/client.baseline.py.tpl +64 -47
  16. flwr/cli/new/templates/app/code/client.huggingface.py.tpl +68 -30
  17. flwr/cli/new/templates/app/code/client.jax.py.tpl +63 -42
  18. flwr/cli/new/templates/app/code/client.mlx.py.tpl +80 -51
  19. flwr/cli/new/templates/app/code/client.numpy.py.tpl +36 -13
  20. flwr/cli/new/templates/app/code/client.pytorch.py.tpl +71 -46
  21. flwr/cli/new/templates/app/code/client.pytorch_legacy_api.py.tpl +55 -0
  22. flwr/cli/new/templates/app/code/client.sklearn.py.tpl +75 -30
  23. flwr/cli/new/templates/app/code/client.tensorflow.py.tpl +69 -44
  24. flwr/cli/new/templates/app/code/client.xgboost.py.tpl +110 -0
  25. flwr/cli/new/templates/app/code/flwr_tune/client_app.py.tpl +56 -90
  26. flwr/cli/new/templates/app/code/flwr_tune/models.py.tpl +1 -23
  27. flwr/cli/new/templates/app/code/flwr_tune/server_app.py.tpl +37 -58
  28. flwr/cli/new/templates/app/code/flwr_tune/strategy.py.tpl +39 -44
  29. flwr/cli/new/templates/app/code/model.baseline.py.tpl +0 -14
  30. flwr/cli/new/templates/app/code/server.baseline.py.tpl +27 -29
  31. flwr/cli/new/templates/app/code/server.huggingface.py.tpl +23 -19
  32. flwr/cli/new/templates/app/code/server.jax.py.tpl +27 -14
  33. flwr/cli/new/templates/app/code/server.mlx.py.tpl +29 -19
  34. flwr/cli/new/templates/app/code/server.numpy.py.tpl +30 -17
  35. flwr/cli/new/templates/app/code/server.pytorch.py.tpl +36 -26
  36. flwr/cli/new/templates/app/code/server.pytorch_legacy_api.py.tpl +31 -0
  37. flwr/cli/new/templates/app/code/server.sklearn.py.tpl +29 -21
  38. flwr/cli/new/templates/app/code/server.tensorflow.py.tpl +28 -19
  39. flwr/cli/new/templates/app/code/server.xgboost.py.tpl +56 -0
  40. flwr/cli/new/templates/app/code/task.huggingface.py.tpl +16 -20
  41. flwr/cli/new/templates/app/code/task.jax.py.tpl +1 -1
  42. flwr/cli/new/templates/app/code/task.numpy.py.tpl +1 -1
  43. flwr/cli/new/templates/app/code/task.pytorch.py.tpl +14 -27
  44. flwr/cli/new/templates/app/code/task.pytorch_legacy_api.py.tpl +111 -0
  45. flwr/cli/new/templates/app/code/task.tensorflow.py.tpl +1 -2
  46. flwr/cli/new/templates/app/code/task.xgboost.py.tpl +67 -0
  47. flwr/cli/new/templates/app/pyproject.baseline.toml.tpl +4 -4
  48. flwr/cli/new/templates/app/pyproject.flowertune.toml.tpl +2 -2
  49. flwr/cli/new/templates/app/pyproject.huggingface.toml.tpl +4 -4
  50. flwr/cli/new/templates/app/pyproject.jax.toml.tpl +1 -1
  51. flwr/cli/new/templates/app/pyproject.mlx.toml.tpl +2 -2
  52. flwr/cli/new/templates/app/pyproject.numpy.toml.tpl +1 -1
  53. flwr/cli/new/templates/app/pyproject.pytorch.toml.tpl +3 -3
  54. flwr/cli/new/templates/app/pyproject.pytorch_legacy_api.toml.tpl +53 -0
  55. flwr/cli/new/templates/app/pyproject.sklearn.toml.tpl +1 -1
  56. flwr/cli/new/templates/app/pyproject.tensorflow.toml.tpl +1 -1
  57. flwr/cli/new/templates/app/pyproject.xgboost.toml.tpl +61 -0
  58. flwr/cli/pull.py +100 -0
  59. flwr/cli/run/run.py +9 -13
  60. flwr/cli/stop.py +7 -4
  61. flwr/cli/utils.py +36 -8
  62. flwr/client/grpc_rere_client/connection.py +1 -12
  63. flwr/client/rest_client/connection.py +3 -0
  64. flwr/clientapp/__init__.py +10 -0
  65. flwr/clientapp/mod/__init__.py +29 -0
  66. flwr/clientapp/mod/centraldp_mods.py +248 -0
  67. flwr/clientapp/mod/localdp_mod.py +169 -0
  68. flwr/clientapp/typing.py +22 -0
  69. flwr/common/args.py +20 -6
  70. flwr/common/auth_plugin/__init__.py +4 -4
  71. flwr/common/auth_plugin/auth_plugin.py +7 -7
  72. flwr/common/constant.py +26 -4
  73. flwr/common/event_log_plugin/event_log_plugin.py +1 -1
  74. flwr/common/exit/__init__.py +4 -0
  75. flwr/common/exit/exit.py +8 -1
  76. flwr/common/exit/exit_code.py +30 -7
  77. flwr/common/exit/exit_handler.py +62 -0
  78. flwr/common/{exit_handlers.py → exit/signal_handler.py} +20 -37
  79. flwr/common/grpc.py +0 -11
  80. flwr/common/inflatable_utils.py +1 -1
  81. flwr/common/logger.py +1 -1
  82. flwr/common/record/typeddict.py +12 -0
  83. flwr/common/retry_invoker.py +30 -11
  84. flwr/common/telemetry.py +4 -0
  85. flwr/compat/server/app.py +2 -2
  86. flwr/proto/appio_pb2.py +25 -17
  87. flwr/proto/appio_pb2.pyi +46 -2
  88. flwr/proto/clientappio_pb2.py +3 -11
  89. flwr/proto/clientappio_pb2.pyi +0 -47
  90. flwr/proto/clientappio_pb2_grpc.py +19 -20
  91. flwr/proto/clientappio_pb2_grpc.pyi +10 -11
  92. flwr/proto/control_pb2.py +66 -0
  93. flwr/proto/{exec_pb2.pyi → control_pb2.pyi} +24 -0
  94. flwr/proto/{exec_pb2_grpc.py → control_pb2_grpc.py} +88 -54
  95. flwr/proto/control_pb2_grpc.pyi +106 -0
  96. flwr/proto/serverappio_pb2.py +2 -2
  97. flwr/proto/serverappio_pb2_grpc.py +68 -0
  98. flwr/proto/serverappio_pb2_grpc.pyi +26 -0
  99. flwr/proto/simulationio_pb2.py +4 -11
  100. flwr/proto/simulationio_pb2.pyi +0 -58
  101. flwr/proto/simulationio_pb2_grpc.py +129 -27
  102. flwr/proto/simulationio_pb2_grpc.pyi +52 -13
  103. flwr/server/app.py +142 -152
  104. flwr/server/grid/grpc_grid.py +3 -0
  105. flwr/server/grid/inmemory_grid.py +1 -0
  106. flwr/server/serverapp/app.py +157 -146
  107. flwr/server/superlink/fleet/vce/backend/raybackend.py +3 -1
  108. flwr/server/superlink/fleet/vce/vce_api.py +6 -6
  109. flwr/server/superlink/linkstate/in_memory_linkstate.py +34 -0
  110. flwr/server/superlink/linkstate/linkstate.py +2 -1
  111. flwr/server/superlink/linkstate/sqlite_linkstate.py +45 -0
  112. flwr/server/superlink/serverappio/serverappio_grpc.py +1 -1
  113. flwr/server/superlink/serverappio/serverappio_servicer.py +61 -6
  114. flwr/server/superlink/simulation/simulationio_servicer.py +97 -21
  115. flwr/serverapp/__init__.py +12 -0
  116. flwr/serverapp/exception.py +38 -0
  117. flwr/serverapp/strategy/__init__.py +64 -0
  118. flwr/serverapp/strategy/bulyan.py +238 -0
  119. flwr/serverapp/strategy/dp_adaptive_clipping.py +335 -0
  120. flwr/serverapp/strategy/dp_fixed_clipping.py +374 -0
  121. flwr/serverapp/strategy/fedadagrad.py +159 -0
  122. flwr/serverapp/strategy/fedadam.py +178 -0
  123. flwr/serverapp/strategy/fedavg.py +320 -0
  124. flwr/serverapp/strategy/fedavgm.py +198 -0
  125. flwr/serverapp/strategy/fedmedian.py +105 -0
  126. flwr/serverapp/strategy/fedopt.py +218 -0
  127. flwr/serverapp/strategy/fedprox.py +174 -0
  128. flwr/serverapp/strategy/fedtrimmedavg.py +176 -0
  129. flwr/serverapp/strategy/fedxgb_bagging.py +117 -0
  130. flwr/serverapp/strategy/fedxgb_cyclic.py +220 -0
  131. flwr/serverapp/strategy/fedyogi.py +170 -0
  132. flwr/serverapp/strategy/krum.py +112 -0
  133. flwr/serverapp/strategy/multikrum.py +247 -0
  134. flwr/serverapp/strategy/qfedavg.py +252 -0
  135. flwr/serverapp/strategy/result.py +105 -0
  136. flwr/serverapp/strategy/strategy.py +285 -0
  137. flwr/serverapp/strategy/strategy_utils.py +299 -0
  138. flwr/simulation/app.py +161 -164
  139. flwr/simulation/run_simulation.py +25 -30
  140. flwr/supercore/app_utils.py +58 -0
  141. flwr/{supernode/scheduler → supercore/cli}/__init__.py +3 -3
  142. flwr/supercore/cli/flower_superexec.py +166 -0
  143. flwr/supercore/constant.py +19 -0
  144. flwr/supercore/{scheduler → corestate}/__init__.py +3 -3
  145. flwr/supercore/corestate/corestate.py +81 -0
  146. flwr/supercore/grpc_health/__init__.py +3 -0
  147. flwr/supercore/grpc_health/health_server.py +53 -0
  148. flwr/supercore/grpc_health/simple_health_servicer.py +2 -2
  149. flwr/{superexec → supercore/superexec}/__init__.py +1 -1
  150. flwr/supercore/superexec/plugin/__init__.py +28 -0
  151. flwr/{supernode/scheduler/simple_clientapp_scheduler_plugin.py → supercore/superexec/plugin/base_exec_plugin.py} +10 -6
  152. flwr/supercore/superexec/plugin/clientapp_exec_plugin.py +28 -0
  153. flwr/supercore/{scheduler/plugin.py → superexec/plugin/exec_plugin.py} +15 -5
  154. flwr/supercore/superexec/plugin/serverapp_exec_plugin.py +28 -0
  155. flwr/supercore/superexec/plugin/simulation_exec_plugin.py +28 -0
  156. flwr/supercore/superexec/run_superexec.py +199 -0
  157. flwr/superlink/artifact_provider/__init__.py +22 -0
  158. flwr/superlink/artifact_provider/artifact_provider.py +37 -0
  159. flwr/superlink/servicer/__init__.py +15 -0
  160. flwr/superlink/servicer/control/__init__.py +22 -0
  161. flwr/{superexec/exec_event_log_interceptor.py → superlink/servicer/control/control_event_log_interceptor.py} +7 -7
  162. flwr/{superexec/exec_grpc.py → superlink/servicer/control/control_grpc.py} +27 -29
  163. flwr/{superexec/exec_license_interceptor.py → superlink/servicer/control/control_license_interceptor.py} +6 -6
  164. flwr/{superexec/exec_servicer.py → superlink/servicer/control/control_servicer.py} +127 -31
  165. flwr/{superexec/exec_user_auth_interceptor.py → superlink/servicer/control/control_user_auth_interceptor.py} +10 -10
  166. flwr/supernode/cli/flower_supernode.py +3 -0
  167. flwr/supernode/cli/flwr_clientapp.py +18 -21
  168. flwr/supernode/nodestate/in_memory_nodestate.py +2 -2
  169. flwr/supernode/nodestate/nodestate.py +3 -59
  170. flwr/supernode/runtime/run_clientapp.py +39 -102
  171. flwr/supernode/servicer/clientappio/clientappio_servicer.py +10 -17
  172. flwr/supernode/start_client_internal.py +35 -76
  173. {flwr-1.20.0.dist-info → flwr-1.22.0.dist-info}/METADATA +9 -18
  174. {flwr-1.20.0.dist-info → flwr-1.22.0.dist-info}/RECORD +176 -128
  175. {flwr-1.20.0.dist-info → flwr-1.22.0.dist-info}/entry_points.txt +1 -0
  176. flwr/proto/exec_pb2.py +0 -62
  177. flwr/proto/exec_pb2_grpc.pyi +0 -93
  178. flwr/superexec/app.py +0 -45
  179. flwr/superexec/deployment.py +0 -191
  180. flwr/superexec/executor.py +0 -100
  181. flwr/superexec/simulation.py +0 -129
  182. {flwr-1.20.0.dist-info → flwr-1.22.0.dist-info}/WHEEL +0 -0
@@ -1,93 +0,0 @@
1
- """
2
- @generated by mypy-protobuf. Do not edit manually!
3
- isort:skip_file
4
- """
5
- import abc
6
- import flwr.proto.exec_pb2
7
- import grpc
8
- import typing
9
-
10
- class ExecStub:
11
- def __init__(self, channel: grpc.Channel) -> None: ...
12
- StartRun: grpc.UnaryUnaryMultiCallable[
13
- flwr.proto.exec_pb2.StartRunRequest,
14
- flwr.proto.exec_pb2.StartRunResponse]
15
- """Start run upon request"""
16
-
17
- StopRun: grpc.UnaryUnaryMultiCallable[
18
- flwr.proto.exec_pb2.StopRunRequest,
19
- flwr.proto.exec_pb2.StopRunResponse]
20
- """Stop run upon request"""
21
-
22
- StreamLogs: grpc.UnaryStreamMultiCallable[
23
- flwr.proto.exec_pb2.StreamLogsRequest,
24
- flwr.proto.exec_pb2.StreamLogsResponse]
25
- """Start log stream upon request"""
26
-
27
- ListRuns: grpc.UnaryUnaryMultiCallable[
28
- flwr.proto.exec_pb2.ListRunsRequest,
29
- flwr.proto.exec_pb2.ListRunsResponse]
30
- """flwr ls command"""
31
-
32
- GetLoginDetails: grpc.UnaryUnaryMultiCallable[
33
- flwr.proto.exec_pb2.GetLoginDetailsRequest,
34
- flwr.proto.exec_pb2.GetLoginDetailsResponse]
35
- """Get login details upon request"""
36
-
37
- GetAuthTokens: grpc.UnaryUnaryMultiCallable[
38
- flwr.proto.exec_pb2.GetAuthTokensRequest,
39
- flwr.proto.exec_pb2.GetAuthTokensResponse]
40
- """Get auth tokens upon request"""
41
-
42
-
43
- class ExecServicer(metaclass=abc.ABCMeta):
44
- @abc.abstractmethod
45
- def StartRun(self,
46
- request: flwr.proto.exec_pb2.StartRunRequest,
47
- context: grpc.ServicerContext,
48
- ) -> flwr.proto.exec_pb2.StartRunResponse:
49
- """Start run upon request"""
50
- pass
51
-
52
- @abc.abstractmethod
53
- def StopRun(self,
54
- request: flwr.proto.exec_pb2.StopRunRequest,
55
- context: grpc.ServicerContext,
56
- ) -> flwr.proto.exec_pb2.StopRunResponse:
57
- """Stop run upon request"""
58
- pass
59
-
60
- @abc.abstractmethod
61
- def StreamLogs(self,
62
- request: flwr.proto.exec_pb2.StreamLogsRequest,
63
- context: grpc.ServicerContext,
64
- ) -> typing.Iterator[flwr.proto.exec_pb2.StreamLogsResponse]:
65
- """Start log stream upon request"""
66
- pass
67
-
68
- @abc.abstractmethod
69
- def ListRuns(self,
70
- request: flwr.proto.exec_pb2.ListRunsRequest,
71
- context: grpc.ServicerContext,
72
- ) -> flwr.proto.exec_pb2.ListRunsResponse:
73
- """flwr ls command"""
74
- pass
75
-
76
- @abc.abstractmethod
77
- def GetLoginDetails(self,
78
- request: flwr.proto.exec_pb2.GetLoginDetailsRequest,
79
- context: grpc.ServicerContext,
80
- ) -> flwr.proto.exec_pb2.GetLoginDetailsResponse:
81
- """Get login details upon request"""
82
- pass
83
-
84
- @abc.abstractmethod
85
- def GetAuthTokens(self,
86
- request: flwr.proto.exec_pb2.GetAuthTokensRequest,
87
- context: grpc.ServicerContext,
88
- ) -> flwr.proto.exec_pb2.GetAuthTokensResponse:
89
- """Get auth tokens upon request"""
90
- pass
91
-
92
-
93
- def add_ExecServicer_to_server(servicer: ExecServicer, server: grpc.Server) -> None: ...
flwr/superexec/app.py DELETED
@@ -1,45 +0,0 @@
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 SuperExec app."""
16
-
17
-
18
- import argparse
19
-
20
- from flwr.common.object_ref import load_app, validate
21
-
22
- from .executor import Executor
23
-
24
-
25
- def load_executor(
26
- args: argparse.Namespace,
27
- ) -> Executor:
28
- """Get the executor plugin."""
29
- executor_ref: str = args.executor
30
- valid, error_msg = validate(executor_ref, project_dir=args.executor_dir)
31
- if not valid and error_msg:
32
- raise LoadExecutorError(error_msg) from None
33
-
34
- executor = load_app(executor_ref, LoadExecutorError, args.executor_dir)
35
-
36
- if not isinstance(executor, Executor):
37
- raise LoadExecutorError(
38
- f"Attribute {executor_ref} is not of type {Executor}",
39
- ) from None
40
-
41
- return executor
42
-
43
-
44
- class LoadExecutorError(Exception):
45
- """Error when trying to load `Executor`."""
@@ -1,191 +0,0 @@
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
- """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 ConfigRecord, Context, RecordDict
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.linkstate import LinkState, LinkStateFactory
35
- from flwr.supercore.ffs import Ffs, FfsFactory
36
-
37
- from .executor import Executor
38
-
39
-
40
- class DeploymentEngine(Executor):
41
- """Deployment engine executor.
42
-
43
- Parameters
44
- ----------
45
- serverappio_api_address: str (default: "127.0.0.1:9091")
46
- Address of the SuperLink to connect to.
47
- root_certificates: Optional[str] (default: None)
48
- Specifies the path to the PEM-encoded root certificate file for
49
- establishing secure HTTPS connections.
50
- flwr_dir: Optional[str] (default: None)
51
- The path containing installed Flower Apps.
52
- """
53
-
54
- def __init__(
55
- self,
56
- serverappio_api_address: str = SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS,
57
- root_certificates: Optional[str] = None,
58
- flwr_dir: Optional[str] = None,
59
- ) -> None:
60
- self.serverappio_api_address = serverappio_api_address
61
- if root_certificates is None:
62
- self.root_certificates = None
63
- self.root_certificates_bytes = None
64
- else:
65
- self.root_certificates = root_certificates
66
- self.root_certificates_bytes = Path(root_certificates).read_bytes()
67
- self.flwr_dir = flwr_dir
68
- self.linkstate_factory: Optional[LinkStateFactory] = None
69
- self.ffs_factory: Optional[FfsFactory] = None
70
-
71
- @override
72
- def initialize(
73
- self, linkstate_factory: LinkStateFactory, ffs_factory: FfsFactory
74
- ) -> None:
75
- """Initialize the executor with the necessary factories."""
76
- self.linkstate_factory = linkstate_factory
77
- self.ffs_factory = ffs_factory
78
-
79
- @property
80
- def linkstate(self) -> LinkState:
81
- """Return the LinkState."""
82
- if self.linkstate_factory is None:
83
- raise RuntimeError("Executor is not initialized.")
84
- return self.linkstate_factory.state()
85
-
86
- @property
87
- def ffs(self) -> Ffs:
88
- """Return the Flower File Storage (FFS)."""
89
- if self.ffs_factory is None:
90
- raise RuntimeError("Executor is not initialized.")
91
- return self.ffs_factory.ffs()
92
-
93
- @override
94
- def set_config(
95
- self,
96
- config: UserConfig,
97
- ) -> None:
98
- """Set executor config arguments.
99
-
100
- Parameters
101
- ----------
102
- config : UserConfig
103
- A dictionary for configuration values.
104
- Supported configuration key/value pairs:
105
- - "superlink": str
106
- The address of the SuperLink ServerAppIo API.
107
- - "root-certificates": str
108
- The path to the root certificates.
109
- - "flwr-dir": str
110
- The path to the Flower directory.
111
- """
112
- if not config:
113
- return
114
- if superlink_address := config.get("superlink"):
115
- if not isinstance(superlink_address, str):
116
- raise ValueError("The `superlink` value should be of type `str`.")
117
- self.serverappio_api_address = superlink_address
118
- if root_certificates := config.get("root-certificates"):
119
- if not isinstance(root_certificates, str):
120
- raise ValueError(
121
- "The `root-certificates` value should be of type `str`."
122
- )
123
- self.root_certificates = root_certificates
124
- self.root_certificates_bytes = Path(str(root_certificates)).read_bytes()
125
- if flwr_dir := config.get("flwr-dir"):
126
- if not isinstance(flwr_dir, str):
127
- raise ValueError("The `flwr-dir` value should be of type `str`.")
128
- self.flwr_dir = str(flwr_dir)
129
-
130
- def _create_run(
131
- self,
132
- fab: Fab,
133
- override_config: UserConfig,
134
- flwr_aid: Optional[str],
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, ConfigRecord(), flwr_aid
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=RecordDict(), 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: ConfigRecord,
164
- flwr_aid: Optional[str],
165
- ) -> Optional[int]:
166
- """Start run using the Flower Deployment Engine."""
167
- run_id = None
168
- try:
169
-
170
- # Call SuperLink to create run
171
- run_id = self._create_run(
172
- Fab(hashlib.sha256(fab_file).hexdigest(), fab_file),
173
- override_config,
174
- flwr_aid,
175
- )
176
-
177
- # Register context for the Run
178
- self._create_context(run_id=run_id)
179
- log(INFO, "Created run %s", str(run_id))
180
-
181
- return run_id
182
- # pylint: disable-next=broad-except
183
- except Exception as e:
184
- log(ERROR, "Could not start run: %s", str(e))
185
- if run_id:
186
- run_status = RunStatus(Status.FINISHED, SubStatus.FAILED, str(e))
187
- self.linkstate.update_run_status(run_id, new_status=run_status)
188
- return None
189
-
190
-
191
- executor = DeploymentEngine()
@@ -1,100 +0,0 @@
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
- """Execute and monitor a Flower run."""
16
-
17
-
18
- from abc import ABC, abstractmethod
19
- from dataclasses import dataclass, field
20
- from subprocess import Popen
21
- from typing import Optional
22
-
23
- from flwr.common import ConfigRecord
24
- from flwr.common.typing import UserConfig
25
- from flwr.server.superlink.linkstate import LinkStateFactory
26
- from flwr.supercore.ffs import FfsFactory
27
-
28
-
29
- @dataclass
30
- class RunTracker:
31
- """Track a Flower run (composed of a run_id and the associated process)."""
32
-
33
- run_id: int
34
- proc: Popen # type: ignore
35
- logs: list[str] = field(default_factory=list)
36
-
37
-
38
- class Executor(ABC):
39
- """Execute and monitor a Flower run."""
40
-
41
- @abstractmethod
42
- def initialize(
43
- self, linkstate_factory: LinkStateFactory, ffs_factory: FfsFactory
44
- ) -> None:
45
- """Initialize the executor with the necessary factories.
46
-
47
- This method sets up the executor by providing it with the factories required
48
- to access the LinkState and the Flower File Storage (FFS) in the SuperLink.
49
-
50
- Parameters
51
- ----------
52
- linkstate_factory : LinkStateFactory
53
- The factory to create access to the LinkState.
54
- ffs_factory : FfsFactory
55
- The factory to create access to the Flower File Storage (FFS).
56
- """
57
-
58
- @abstractmethod
59
- def set_config(
60
- self,
61
- config: UserConfig,
62
- ) -> None:
63
- """Register provided config as class attributes.
64
-
65
- Parameters
66
- ----------
67
- config : UserConfig
68
- A dictionary for configuration values.
69
- """
70
-
71
- @abstractmethod
72
- def start_run(
73
- self,
74
- fab_file: bytes,
75
- override_config: UserConfig,
76
- federation_options: ConfigRecord,
77
- flwr_aid: Optional[str],
78
- ) -> Optional[int]:
79
- """Start a run using the given Flower FAB ID and version.
80
-
81
- This method creates a new run on the SuperLink, returns its run_id
82
- and also starts the run execution.
83
-
84
- Parameters
85
- ----------
86
- fab_file : bytes
87
- The Flower App Bundle file bytes.
88
- override_config: UserConfig
89
- The config overrides dict sent by the user (using `flwr run`).
90
- federation_options: ConfigRecord
91
- The federation options sent by the user (using `flwr run`).
92
- flwr_aid : Optional[str]
93
- The Flower Account ID of the user starting the run, if authentication is
94
- enabled.
95
-
96
- Returns
97
- -------
98
- run_id : Optional[int]
99
- The run_id of the run created by the SuperLink, or `None` if it fails.
100
- """
@@ -1,129 +0,0 @@
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
- """Simulation engine executor."""
16
-
17
-
18
- import hashlib
19
- from logging import ERROR, INFO
20
- from typing import Optional
21
-
22
- from typing_extensions import override
23
-
24
- from flwr.cli.config_utils import get_fab_metadata
25
- from flwr.common import ConfigRecord, Context, RecordDict
26
- from flwr.common.logger import log
27
- from flwr.common.typing import Fab, UserConfig
28
- from flwr.server.superlink.linkstate import LinkState, LinkStateFactory
29
- from flwr.supercore.ffs import Ffs, FfsFactory
30
-
31
- from .executor import Executor
32
-
33
-
34
- class SimulationEngine(Executor):
35
- """Simulation engine executor."""
36
-
37
- def __init__(
38
- self,
39
- ) -> None:
40
- self.linkstate_factory: Optional[LinkStateFactory] = None
41
- self.ffs_factory: Optional[FfsFactory] = None
42
-
43
- @override
44
- def initialize(
45
- self, linkstate_factory: LinkStateFactory, ffs_factory: FfsFactory
46
- ) -> None:
47
- """Initialize the executor with the necessary factories."""
48
- self.linkstate_factory = linkstate_factory
49
- self.ffs_factory = ffs_factory
50
-
51
- @property
52
- def linkstate(self) -> LinkState:
53
- """Return the LinkState."""
54
- if self.linkstate_factory is None:
55
- raise RuntimeError("Executor is not initialized.")
56
- return self.linkstate_factory.state()
57
-
58
- @property
59
- def ffs(self) -> Ffs:
60
- """Return the Flower File Storage (FFS)."""
61
- if self.ffs_factory is None:
62
- raise RuntimeError("Executor is not initialized.")
63
- return self.ffs_factory.ffs()
64
-
65
- @override
66
- def set_config(
67
- self,
68
- config: UserConfig,
69
- ) -> None:
70
- """Set executor config arguments."""
71
-
72
- # pylint: disable=too-many-locals
73
- @override
74
- def start_run(
75
- self,
76
- fab_file: bytes,
77
- override_config: UserConfig,
78
- federation_options: ConfigRecord,
79
- flwr_aid: Optional[str],
80
- ) -> Optional[int]:
81
- """Start run using the Flower Simulation Engine."""
82
- try:
83
- # Check that num-supernodes is set
84
- if "num-supernodes" not in federation_options:
85
- raise ValueError(
86
- "Federation options doesn't contain key `num-supernodes`."
87
- )
88
-
89
- # Create run
90
- fab = Fab(hashlib.sha256(fab_file).hexdigest(), fab_file)
91
- fab_hash = self.ffs.put(fab.content, {})
92
- if fab_hash != fab.hash_str:
93
- raise RuntimeError(
94
- f"FAB ({fab.hash_str}) hash from request doesn't match contents"
95
- )
96
- fab_id, fab_version = get_fab_metadata(fab.content)
97
-
98
- run_id = self.linkstate.create_run(
99
- fab_id,
100
- fab_version,
101
- fab_hash,
102
- override_config,
103
- federation_options,
104
- flwr_aid,
105
- )
106
-
107
- # Create an empty context for the Run
108
- context = Context(
109
- run_id=run_id,
110
- node_id=0,
111
- node_config={},
112
- state=RecordDict(),
113
- run_config={},
114
- )
115
-
116
- # Register the context at the LinkState
117
- self.linkstate.set_serverapp_context(run_id=run_id, context=context)
118
-
119
- log(INFO, "Created run %s", str(run_id))
120
-
121
- return run_id
122
-
123
- # pylint: disable-next=broad-except
124
- except Exception as e:
125
- log(ERROR, "Could not start run: %s", str(e))
126
- return None
127
-
128
-
129
- executor = SimulationEngine()
File without changes