flwr-nightly 1.8.0.dev20240314__py3-none-any.whl → 1.15.0.dev20250114__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (311) hide show
  1. flwr/cli/app.py +16 -2
  2. flwr/cli/build.py +181 -0
  3. flwr/cli/cli_user_auth_interceptor.py +90 -0
  4. flwr/cli/config_utils.py +343 -0
  5. flwr/cli/example.py +4 -1
  6. flwr/cli/install.py +253 -0
  7. flwr/cli/log.py +182 -0
  8. flwr/{server/superlink/state → cli/login}/__init__.py +4 -10
  9. flwr/cli/login/login.py +88 -0
  10. flwr/cli/ls.py +327 -0
  11. flwr/cli/new/__init__.py +1 -0
  12. flwr/cli/new/new.py +210 -66
  13. flwr/cli/new/templates/app/.gitignore.tpl +163 -0
  14. flwr/cli/new/templates/app/LICENSE.tpl +202 -0
  15. flwr/cli/new/templates/app/README.baseline.md.tpl +127 -0
  16. flwr/cli/new/templates/app/README.flowertune.md.tpl +66 -0
  17. flwr/cli/new/templates/app/README.md.tpl +16 -32
  18. flwr/cli/new/templates/app/code/__init__.baseline.py.tpl +1 -0
  19. flwr/cli/new/templates/app/code/__init__.py.tpl +1 -1
  20. flwr/cli/new/templates/app/code/client.baseline.py.tpl +58 -0
  21. flwr/cli/new/templates/app/code/client.huggingface.py.tpl +55 -0
  22. flwr/cli/new/templates/app/code/client.jax.py.tpl +50 -0
  23. flwr/cli/new/templates/app/code/client.mlx.py.tpl +73 -0
  24. flwr/cli/new/templates/app/code/client.numpy.py.tpl +7 -7
  25. flwr/cli/new/templates/app/code/client.pytorch.py.tpl +30 -21
  26. flwr/cli/new/templates/app/code/client.sklearn.py.tpl +63 -0
  27. flwr/cli/new/templates/app/code/client.tensorflow.py.tpl +57 -1
  28. flwr/cli/new/templates/app/code/dataset.baseline.py.tpl +36 -0
  29. flwr/cli/new/templates/app/code/flwr_tune/__init__.py +15 -0
  30. flwr/cli/new/templates/app/code/flwr_tune/client_app.py.tpl +126 -0
  31. flwr/cli/new/templates/app/code/flwr_tune/dataset.py.tpl +87 -0
  32. flwr/cli/new/templates/app/code/flwr_tune/models.py.tpl +78 -0
  33. flwr/cli/new/templates/app/code/flwr_tune/server_app.py.tpl +94 -0
  34. flwr/cli/new/templates/app/code/flwr_tune/strategy.py.tpl +83 -0
  35. flwr/cli/new/templates/app/code/model.baseline.py.tpl +80 -0
  36. flwr/cli/new/templates/app/code/server.baseline.py.tpl +46 -0
  37. flwr/cli/new/templates/app/code/server.huggingface.py.tpl +38 -0
  38. flwr/cli/new/templates/app/code/server.jax.py.tpl +26 -0
  39. flwr/cli/new/templates/app/code/server.mlx.py.tpl +31 -0
  40. flwr/cli/new/templates/app/code/server.numpy.py.tpl +22 -9
  41. flwr/cli/new/templates/app/code/server.pytorch.py.tpl +21 -18
  42. flwr/cli/new/templates/app/code/server.sklearn.py.tpl +36 -0
  43. flwr/cli/new/templates/app/code/server.tensorflow.py.tpl +29 -1
  44. flwr/cli/new/templates/app/code/strategy.baseline.py.tpl +1 -0
  45. flwr/cli/new/templates/app/code/task.huggingface.py.tpl +102 -0
  46. flwr/cli/new/templates/app/code/task.jax.py.tpl +57 -0
  47. flwr/cli/new/templates/app/code/task.mlx.py.tpl +102 -0
  48. flwr/cli/new/templates/app/code/task.numpy.py.tpl +7 -0
  49. flwr/cli/new/templates/app/code/task.pytorch.py.tpl +29 -24
  50. flwr/cli/new/templates/app/code/task.sklearn.py.tpl +67 -0
  51. flwr/cli/new/templates/app/code/task.tensorflow.py.tpl +53 -0
  52. flwr/cli/new/templates/app/code/utils.baseline.py.tpl +1 -0
  53. flwr/cli/new/templates/app/pyproject.baseline.toml.tpl +138 -0
  54. flwr/cli/new/templates/app/pyproject.flowertune.toml.tpl +68 -0
  55. flwr/cli/new/templates/app/pyproject.huggingface.toml.tpl +46 -0
  56. flwr/cli/new/templates/app/pyproject.jax.toml.tpl +35 -0
  57. flwr/cli/new/templates/app/pyproject.mlx.toml.tpl +39 -0
  58. flwr/cli/new/templates/app/pyproject.numpy.toml.tpl +25 -12
  59. flwr/cli/new/templates/app/pyproject.pytorch.toml.tpl +29 -14
  60. flwr/cli/new/templates/app/pyproject.sklearn.toml.tpl +35 -0
  61. flwr/cli/new/templates/app/pyproject.tensorflow.toml.tpl +29 -14
  62. flwr/cli/run/__init__.py +1 -0
  63. flwr/cli/run/run.py +212 -34
  64. flwr/cli/stop.py +130 -0
  65. flwr/cli/utils.py +240 -5
  66. flwr/client/__init__.py +3 -2
  67. flwr/client/app.py +432 -255
  68. flwr/client/client.py +1 -11
  69. flwr/client/client_app.py +74 -13
  70. flwr/client/clientapp/__init__.py +22 -0
  71. flwr/client/clientapp/app.py +259 -0
  72. flwr/client/clientapp/clientappio_servicer.py +244 -0
  73. flwr/client/clientapp/utils.py +115 -0
  74. flwr/client/dpfedavg_numpy_client.py +7 -8
  75. flwr/client/grpc_adapter_client/__init__.py +15 -0
  76. flwr/client/grpc_adapter_client/connection.py +98 -0
  77. flwr/client/grpc_client/connection.py +21 -7
  78. flwr/client/grpc_rere_client/__init__.py +1 -1
  79. flwr/client/grpc_rere_client/client_interceptor.py +176 -0
  80. flwr/client/grpc_rere_client/connection.py +163 -56
  81. flwr/client/grpc_rere_client/grpc_adapter.py +167 -0
  82. flwr/client/heartbeat.py +74 -0
  83. flwr/client/message_handler/__init__.py +1 -1
  84. flwr/client/message_handler/message_handler.py +10 -11
  85. flwr/client/mod/__init__.py +5 -5
  86. flwr/client/mod/centraldp_mods.py +4 -2
  87. flwr/client/mod/comms_mods.py +5 -4
  88. flwr/client/mod/localdp_mod.py +10 -5
  89. flwr/client/mod/secure_aggregation/__init__.py +1 -1
  90. flwr/client/mod/secure_aggregation/secaggplus_mod.py +26 -26
  91. flwr/client/mod/utils.py +2 -4
  92. flwr/client/nodestate/__init__.py +26 -0
  93. flwr/client/nodestate/in_memory_nodestate.py +38 -0
  94. flwr/client/nodestate/nodestate.py +31 -0
  95. flwr/client/nodestate/nodestate_factory.py +38 -0
  96. flwr/client/numpy_client.py +8 -31
  97. flwr/client/rest_client/__init__.py +1 -1
  98. flwr/client/rest_client/connection.py +199 -176
  99. flwr/client/run_info_store.py +112 -0
  100. flwr/client/supernode/__init__.py +24 -0
  101. flwr/client/supernode/app.py +321 -0
  102. flwr/client/typing.py +1 -0
  103. flwr/common/__init__.py +17 -11
  104. flwr/common/address.py +47 -3
  105. flwr/common/args.py +153 -0
  106. flwr/common/auth_plugin/__init__.py +24 -0
  107. flwr/common/auth_plugin/auth_plugin.py +121 -0
  108. flwr/common/config.py +243 -0
  109. flwr/common/constant.py +132 -1
  110. flwr/common/context.py +32 -2
  111. flwr/common/date.py +22 -4
  112. flwr/common/differential_privacy.py +2 -2
  113. flwr/common/dp.py +2 -4
  114. flwr/common/exit_handlers.py +3 -3
  115. flwr/common/grpc.py +164 -5
  116. flwr/common/logger.py +230 -12
  117. flwr/common/message.py +191 -106
  118. flwr/common/object_ref.py +179 -44
  119. flwr/common/pyproject.py +1 -0
  120. flwr/common/record/__init__.py +2 -1
  121. flwr/common/record/configsrecord.py +58 -18
  122. flwr/common/record/metricsrecord.py +57 -17
  123. flwr/common/record/parametersrecord.py +88 -20
  124. flwr/common/record/recordset.py +153 -30
  125. flwr/common/record/typeddict.py +30 -55
  126. flwr/common/recordset_compat.py +31 -12
  127. flwr/common/retry_invoker.py +123 -30
  128. flwr/common/secure_aggregation/__init__.py +1 -1
  129. flwr/common/secure_aggregation/crypto/__init__.py +1 -1
  130. flwr/common/secure_aggregation/crypto/shamir.py +11 -11
  131. flwr/common/secure_aggregation/crypto/symmetric_encryption.py +68 -4
  132. flwr/common/secure_aggregation/ndarrays_arithmetic.py +17 -17
  133. flwr/common/secure_aggregation/quantization.py +8 -8
  134. flwr/common/secure_aggregation/secaggplus_constants.py +1 -1
  135. flwr/common/secure_aggregation/secaggplus_utils.py +10 -12
  136. flwr/common/serde.py +298 -19
  137. flwr/common/telemetry.py +65 -29
  138. flwr/common/typing.py +120 -19
  139. flwr/common/version.py +17 -3
  140. flwr/proto/clientappio_pb2.py +45 -0
  141. flwr/proto/clientappio_pb2.pyi +132 -0
  142. flwr/proto/clientappio_pb2_grpc.py +135 -0
  143. flwr/proto/clientappio_pb2_grpc.pyi +53 -0
  144. flwr/proto/exec_pb2.py +62 -0
  145. flwr/proto/exec_pb2.pyi +212 -0
  146. flwr/proto/exec_pb2_grpc.py +237 -0
  147. flwr/proto/exec_pb2_grpc.pyi +93 -0
  148. flwr/proto/fab_pb2.py +31 -0
  149. flwr/proto/fab_pb2.pyi +65 -0
  150. flwr/proto/fab_pb2_grpc.py +4 -0
  151. flwr/proto/fab_pb2_grpc.pyi +4 -0
  152. flwr/proto/fleet_pb2.py +42 -23
  153. flwr/proto/fleet_pb2.pyi +123 -1
  154. flwr/proto/fleet_pb2_grpc.py +170 -0
  155. flwr/proto/fleet_pb2_grpc.pyi +61 -0
  156. flwr/proto/grpcadapter_pb2.py +32 -0
  157. flwr/proto/grpcadapter_pb2.pyi +43 -0
  158. flwr/proto/grpcadapter_pb2_grpc.py +66 -0
  159. flwr/proto/grpcadapter_pb2_grpc.pyi +24 -0
  160. flwr/proto/log_pb2.py +29 -0
  161. flwr/proto/log_pb2.pyi +39 -0
  162. flwr/proto/log_pb2_grpc.py +4 -0
  163. flwr/proto/log_pb2_grpc.pyi +4 -0
  164. flwr/proto/message_pb2.py +41 -0
  165. flwr/proto/message_pb2.pyi +128 -0
  166. flwr/proto/message_pb2_grpc.py +4 -0
  167. flwr/proto/message_pb2_grpc.pyi +4 -0
  168. flwr/proto/node_pb2.py +1 -1
  169. flwr/proto/recordset_pb2.py +35 -33
  170. flwr/proto/recordset_pb2.pyi +40 -14
  171. flwr/proto/run_pb2.py +64 -0
  172. flwr/proto/run_pb2.pyi +268 -0
  173. flwr/proto/run_pb2_grpc.py +4 -0
  174. flwr/proto/run_pb2_grpc.pyi +4 -0
  175. flwr/proto/serverappio_pb2.py +52 -0
  176. flwr/proto/{driver_pb2.pyi → serverappio_pb2.pyi} +62 -20
  177. flwr/proto/serverappio_pb2_grpc.py +410 -0
  178. flwr/proto/serverappio_pb2_grpc.pyi +160 -0
  179. flwr/proto/simulationio_pb2.py +38 -0
  180. flwr/proto/simulationio_pb2.pyi +65 -0
  181. flwr/proto/simulationio_pb2_grpc.py +239 -0
  182. flwr/proto/simulationio_pb2_grpc.pyi +94 -0
  183. flwr/proto/task_pb2.py +7 -8
  184. flwr/proto/task_pb2.pyi +8 -5
  185. flwr/proto/transport_pb2.py +8 -8
  186. flwr/proto/transport_pb2.pyi +9 -6
  187. flwr/server/__init__.py +2 -10
  188. flwr/server/app.py +579 -402
  189. flwr/server/client_manager.py +8 -6
  190. flwr/server/compat/app.py +6 -62
  191. flwr/server/compat/app_utils.py +14 -8
  192. flwr/server/compat/driver_client_proxy.py +25 -58
  193. flwr/server/compat/legacy_context.py +5 -4
  194. flwr/server/driver/__init__.py +2 -0
  195. flwr/server/driver/driver.py +36 -131
  196. flwr/server/driver/grpc_driver.py +217 -81
  197. flwr/server/driver/inmemory_driver.py +182 -0
  198. flwr/server/history.py +28 -29
  199. flwr/server/run_serverapp.py +15 -126
  200. flwr/server/server.py +50 -44
  201. flwr/server/server_app.py +59 -10
  202. flwr/server/serverapp/__init__.py +22 -0
  203. flwr/server/serverapp/app.py +256 -0
  204. flwr/server/serverapp_components.py +52 -0
  205. flwr/server/strategy/__init__.py +2 -2
  206. flwr/server/strategy/aggregate.py +37 -23
  207. flwr/server/strategy/bulyan.py +9 -9
  208. flwr/server/strategy/dp_adaptive_clipping.py +25 -25
  209. flwr/server/strategy/dp_fixed_clipping.py +23 -22
  210. flwr/server/strategy/dpfedavg_adaptive.py +8 -8
  211. flwr/server/strategy/dpfedavg_fixed.py +13 -12
  212. flwr/server/strategy/fault_tolerant_fedavg.py +11 -11
  213. flwr/server/strategy/fedadagrad.py +9 -9
  214. flwr/server/strategy/fedadam.py +20 -10
  215. flwr/server/strategy/fedavg.py +16 -16
  216. flwr/server/strategy/fedavg_android.py +17 -17
  217. flwr/server/strategy/fedavgm.py +9 -9
  218. flwr/server/strategy/fedmedian.py +5 -5
  219. flwr/server/strategy/fedopt.py +6 -6
  220. flwr/server/strategy/fedprox.py +7 -7
  221. flwr/server/strategy/fedtrimmedavg.py +8 -8
  222. flwr/server/strategy/fedxgb_bagging.py +12 -12
  223. flwr/server/strategy/fedxgb_cyclic.py +10 -10
  224. flwr/server/strategy/fedxgb_nn_avg.py +6 -6
  225. flwr/server/strategy/fedyogi.py +9 -9
  226. flwr/server/strategy/krum.py +9 -9
  227. flwr/server/strategy/qfedavg.py +16 -16
  228. flwr/server/strategy/strategy.py +10 -10
  229. flwr/server/superlink/driver/__init__.py +2 -2
  230. flwr/server/superlink/driver/serverappio_grpc.py +61 -0
  231. flwr/server/superlink/driver/serverappio_servicer.py +363 -0
  232. flwr/server/superlink/ffs/__init__.py +24 -0
  233. flwr/server/superlink/ffs/disk_ffs.py +108 -0
  234. flwr/server/superlink/ffs/ffs.py +79 -0
  235. flwr/server/superlink/ffs/ffs_factory.py +47 -0
  236. flwr/server/superlink/fleet/__init__.py +1 -1
  237. flwr/server/superlink/fleet/grpc_adapter/__init__.py +15 -0
  238. flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py +162 -0
  239. flwr/server/superlink/fleet/grpc_bidi/__init__.py +1 -1
  240. flwr/server/superlink/fleet/grpc_bidi/flower_service_servicer.py +4 -2
  241. flwr/server/superlink/fleet/grpc_bidi/grpc_bridge.py +3 -2
  242. flwr/server/superlink/fleet/grpc_bidi/grpc_client_proxy.py +1 -1
  243. flwr/server/superlink/fleet/grpc_bidi/grpc_server.py +5 -154
  244. flwr/server/superlink/fleet/grpc_rere/__init__.py +1 -1
  245. flwr/server/superlink/fleet/grpc_rere/fleet_servicer.py +120 -13
  246. flwr/server/superlink/fleet/grpc_rere/server_interceptor.py +228 -0
  247. flwr/server/superlink/fleet/message_handler/__init__.py +1 -1
  248. flwr/server/superlink/fleet/message_handler/message_handler.py +153 -9
  249. flwr/server/superlink/fleet/rest_rere/__init__.py +1 -1
  250. flwr/server/superlink/fleet/rest_rere/rest_api.py +119 -81
  251. flwr/server/superlink/fleet/vce/__init__.py +1 -0
  252. flwr/server/superlink/fleet/vce/backend/__init__.py +4 -4
  253. flwr/server/superlink/fleet/vce/backend/backend.py +8 -9
  254. flwr/server/superlink/fleet/vce/backend/raybackend.py +87 -68
  255. flwr/server/superlink/fleet/vce/vce_api.py +208 -146
  256. flwr/server/superlink/linkstate/__init__.py +28 -0
  257. flwr/server/superlink/linkstate/in_memory_linkstate.py +581 -0
  258. flwr/server/superlink/linkstate/linkstate.py +389 -0
  259. flwr/server/superlink/{state/state_factory.py → linkstate/linkstate_factory.py} +19 -10
  260. flwr/server/superlink/linkstate/sqlite_linkstate.py +1236 -0
  261. flwr/server/superlink/linkstate/utils.py +389 -0
  262. flwr/server/superlink/simulation/__init__.py +15 -0
  263. flwr/server/superlink/simulation/simulationio_grpc.py +65 -0
  264. flwr/server/superlink/simulation/simulationio_servicer.py +186 -0
  265. flwr/server/superlink/utils.py +65 -0
  266. flwr/server/typing.py +2 -0
  267. flwr/server/utils/__init__.py +1 -1
  268. flwr/server/utils/tensorboard.py +5 -5
  269. flwr/server/utils/validator.py +31 -11
  270. flwr/server/workflow/default_workflows.py +70 -26
  271. flwr/server/workflow/secure_aggregation/secagg_workflow.py +1 -0
  272. flwr/server/workflow/secure_aggregation/secaggplus_workflow.py +40 -27
  273. flwr/simulation/__init__.py +12 -5
  274. flwr/simulation/app.py +247 -315
  275. flwr/simulation/legacy_app.py +402 -0
  276. flwr/simulation/ray_transport/__init__.py +1 -1
  277. flwr/simulation/ray_transport/ray_actor.py +42 -67
  278. flwr/simulation/ray_transport/ray_client_proxy.py +37 -17
  279. flwr/simulation/ray_transport/utils.py +1 -0
  280. flwr/simulation/run_simulation.py +306 -163
  281. flwr/simulation/simulationio_connection.py +89 -0
  282. flwr/superexec/__init__.py +15 -0
  283. flwr/superexec/app.py +59 -0
  284. flwr/superexec/deployment.py +188 -0
  285. flwr/superexec/exec_grpc.py +80 -0
  286. flwr/superexec/exec_servicer.py +231 -0
  287. flwr/superexec/exec_user_auth_interceptor.py +101 -0
  288. flwr/superexec/executor.py +96 -0
  289. flwr/superexec/simulation.py +124 -0
  290. {flwr_nightly-1.8.0.dev20240314.dist-info → flwr_nightly-1.15.0.dev20250114.dist-info}/METADATA +33 -26
  291. flwr_nightly-1.15.0.dev20250114.dist-info/RECORD +328 -0
  292. flwr_nightly-1.15.0.dev20250114.dist-info/entry_points.txt +12 -0
  293. flwr/cli/flower_toml.py +0 -140
  294. flwr/cli/new/templates/app/flower.toml.tpl +0 -13
  295. flwr/cli/new/templates/app/requirements.numpy.txt.tpl +0 -2
  296. flwr/cli/new/templates/app/requirements.pytorch.txt.tpl +0 -4
  297. flwr/cli/new/templates/app/requirements.tensorflow.txt.tpl +0 -4
  298. flwr/client/node_state.py +0 -48
  299. flwr/client/node_state_tests.py +0 -65
  300. flwr/proto/driver_pb2.py +0 -44
  301. flwr/proto/driver_pb2_grpc.py +0 -169
  302. flwr/proto/driver_pb2_grpc.pyi +0 -66
  303. flwr/server/superlink/driver/driver_grpc.py +0 -54
  304. flwr/server/superlink/driver/driver_servicer.py +0 -129
  305. flwr/server/superlink/state/in_memory_state.py +0 -230
  306. flwr/server/superlink/state/sqlite_state.py +0 -630
  307. flwr/server/superlink/state/state.py +0 -154
  308. flwr_nightly-1.8.0.dev20240314.dist-info/RECORD +0 -211
  309. flwr_nightly-1.8.0.dev20240314.dist-info/entry_points.txt +0 -9
  310. {flwr_nightly-1.8.0.dev20240314.dist-info → flwr_nightly-1.15.0.dev20250114.dist-info}/LICENSE +0 -0
  311. {flwr_nightly-1.8.0.dev20240314.dist-info → flwr_nightly-1.15.0.dev20250114.dist-info}/WHEEL +0 -0
flwr/common/args.py ADDED
@@ -0,0 +1,153 @@
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
+ """Common Flower arguments."""
16
+
17
+
18
+ import argparse
19
+ import sys
20
+ from logging import DEBUG, ERROR, WARN
21
+ from os.path import isfile
22
+ from pathlib import Path
23
+ from typing import Optional
24
+
25
+ from flwr.common.constant import (
26
+ TRANSPORT_TYPE_GRPC_ADAPTER,
27
+ TRANSPORT_TYPE_GRPC_RERE,
28
+ TRANSPORT_TYPE_REST,
29
+ )
30
+ from flwr.common.logger import log
31
+
32
+
33
+ def add_args_flwr_app_common(parser: argparse.ArgumentParser) -> None:
34
+ """Add common Flower arguments for flwr-*app to the provided parser."""
35
+ parser.add_argument(
36
+ "--flwr-dir",
37
+ default=None,
38
+ help="""The path containing installed Flower Apps.
39
+ By default, this value is equal to:
40
+
41
+ - `$FLWR_HOME/` if `$FLWR_HOME` is defined
42
+ - `$XDG_DATA_HOME/.flwr/` if `$XDG_DATA_HOME` is defined
43
+ - `$HOME/.flwr/` in all other cases
44
+ """,
45
+ )
46
+ parser.add_argument(
47
+ "--insecure",
48
+ action="store_true",
49
+ help="Run the server without HTTPS, regardless of whether certificate "
50
+ "paths are provided. By default, the server runs with HTTPS enabled. "
51
+ "Use this flag only if you understand the risks.",
52
+ )
53
+
54
+
55
+ def try_obtain_root_certificates(
56
+ args: argparse.Namespace,
57
+ grpc_server_address: str,
58
+ ) -> Optional[bytes]:
59
+ """Validate and return the root certificates."""
60
+ root_cert_path = args.root_certificates
61
+ if args.insecure:
62
+ if root_cert_path is not None:
63
+ sys.exit(
64
+ "Conflicting options: The '--insecure' flag disables HTTPS, "
65
+ "but '--root-certificates' was also specified. Please remove "
66
+ "the '--root-certificates' option when running in insecure mode, "
67
+ "or omit '--insecure' to use HTTPS."
68
+ )
69
+ log(
70
+ WARN,
71
+ "Option `--insecure` was set. Starting insecure HTTP channel to %s.",
72
+ grpc_server_address,
73
+ )
74
+ root_certificates = None
75
+ else:
76
+ # Load the certificates if provided, or load the system certificates
77
+ if root_cert_path is None:
78
+ log(
79
+ WARN,
80
+ "Both `--insecure` and `--root-certificates` were not set. "
81
+ "Using system certificates.",
82
+ )
83
+ root_certificates = None
84
+ elif not isfile(root_cert_path):
85
+ log(ERROR, "Path argument `--root-certificates` does not point to a file.")
86
+ sys.exit(1)
87
+ else:
88
+ root_certificates = Path(root_cert_path).read_bytes()
89
+ log(
90
+ DEBUG,
91
+ "Starting secure HTTPS channel to %s "
92
+ "with the following certificates: %s.",
93
+ grpc_server_address,
94
+ root_cert_path,
95
+ )
96
+ return root_certificates
97
+
98
+
99
+ def try_obtain_server_certificates(
100
+ args: argparse.Namespace,
101
+ transport_type: str,
102
+ ) -> Optional[tuple[bytes, bytes, bytes]]:
103
+ """Validate and return the CA cert, server cert, and server private key."""
104
+ if args.insecure:
105
+ log(WARN, "Option `--insecure` was set. Starting insecure HTTP server.")
106
+ return None
107
+ # Check if certificates are provided
108
+ if transport_type in [TRANSPORT_TYPE_GRPC_RERE, TRANSPORT_TYPE_GRPC_ADAPTER]:
109
+ if args.ssl_certfile and args.ssl_keyfile and args.ssl_ca_certfile:
110
+ if not isfile(args.ssl_ca_certfile):
111
+ sys.exit("Path argument `--ssl-ca-certfile` does not point to a file.")
112
+ if not isfile(args.ssl_certfile):
113
+ sys.exit("Path argument `--ssl-certfile` does not point to a file.")
114
+ if not isfile(args.ssl_keyfile):
115
+ sys.exit("Path argument `--ssl-keyfile` does not point to a file.")
116
+ certificates = (
117
+ Path(args.ssl_ca_certfile).read_bytes(), # CA certificate
118
+ Path(args.ssl_certfile).read_bytes(), # server certificate
119
+ Path(args.ssl_keyfile).read_bytes(), # server private key
120
+ )
121
+ return certificates
122
+ if args.ssl_certfile or args.ssl_keyfile or args.ssl_ca_certfile:
123
+ sys.exit(
124
+ "You need to provide valid file paths to `--ssl-certfile`, "
125
+ "`--ssl-keyfile`, and `—-ssl-ca-certfile` to create a secure "
126
+ "connection in Fleet API server (gRPC-rere)."
127
+ )
128
+ if transport_type == TRANSPORT_TYPE_REST:
129
+ if args.ssl_certfile and args.ssl_keyfile:
130
+ if not isfile(args.ssl_certfile):
131
+ sys.exit("Path argument `--ssl-certfile` does not point to a file.")
132
+ if not isfile(args.ssl_keyfile):
133
+ sys.exit("Path argument `--ssl-keyfile` does not point to a file.")
134
+ certificates = (
135
+ b"",
136
+ Path(args.ssl_certfile).read_bytes(), # server certificate
137
+ Path(args.ssl_keyfile).read_bytes(), # server private key
138
+ )
139
+ return certificates
140
+ if args.ssl_certfile or args.ssl_keyfile:
141
+ sys.exit(
142
+ "You need to provide valid file paths to `--ssl-certfile` "
143
+ "and `--ssl-keyfile` to create a secure connection "
144
+ "in Fleet API server (REST, experimental)."
145
+ )
146
+ log(
147
+ ERROR,
148
+ "Certificates are required unless running in insecure mode. "
149
+ "Please provide certificate paths to `--ssl-certfile`, "
150
+ "`--ssl-keyfile`, and `—-ssl-ca-certfile` or run the server "
151
+ "in insecure mode using '--insecure' if you understand the risks.",
152
+ )
153
+ sys.exit(1)
@@ -0,0 +1,24 @@
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
+ """Auth plugin components."""
16
+
17
+
18
+ from .auth_plugin import CliAuthPlugin as CliAuthPlugin
19
+ from .auth_plugin import ExecAuthPlugin as ExecAuthPlugin
20
+
21
+ __all__ = [
22
+ "CliAuthPlugin",
23
+ "ExecAuthPlugin",
24
+ ]
@@ -0,0 +1,121 @@
1
+ # Copyright 2024 Flower Labs GmbH. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ==============================================================================
15
+ """Abstract classes for Flower User Auth Plugin."""
16
+
17
+
18
+ from abc import ABC, abstractmethod
19
+ from collections.abc import Sequence
20
+ from pathlib import Path
21
+ from typing import Optional, Union
22
+
23
+ from flwr.proto.exec_pb2_grpc import ExecStub
24
+
25
+ from ..typing import UserAuthCredentials, UserAuthLoginDetails
26
+
27
+
28
+ class ExecAuthPlugin(ABC):
29
+ """Abstract Flower Auth Plugin class for ExecServicer.
30
+
31
+ Parameters
32
+ ----------
33
+ user_auth_config_path : Path
34
+ Path to the YAML file containing the authentication configuration.
35
+ """
36
+
37
+ @abstractmethod
38
+ def __init__(
39
+ self,
40
+ user_auth_config_path: Path,
41
+ ):
42
+ """Abstract constructor."""
43
+
44
+ @abstractmethod
45
+ def get_login_details(self) -> Optional[UserAuthLoginDetails]:
46
+ """Get the login details."""
47
+
48
+ @abstractmethod
49
+ def validate_tokens_in_metadata(
50
+ self, metadata: Sequence[tuple[str, Union[str, bytes]]]
51
+ ) -> bool:
52
+ """Validate authentication tokens in the provided metadata."""
53
+
54
+ @abstractmethod
55
+ def get_auth_tokens(self, device_code: str) -> Optional[UserAuthCredentials]:
56
+ """Get authentication tokens."""
57
+
58
+ @abstractmethod
59
+ def refresh_tokens(
60
+ self, metadata: Sequence[tuple[str, Union[str, bytes]]]
61
+ ) -> Optional[Sequence[tuple[str, Union[str, bytes]]]]:
62
+ """Refresh authentication tokens in the provided metadata."""
63
+
64
+
65
+ class CliAuthPlugin(ABC):
66
+ """Abstract Flower Auth Plugin class for CLI.
67
+
68
+ Parameters
69
+ ----------
70
+ credentials_path : Path
71
+ Path to the user's authentication credentials file.
72
+ """
73
+
74
+ @staticmethod
75
+ @abstractmethod
76
+ def login(
77
+ login_details: UserAuthLoginDetails,
78
+ exec_stub: ExecStub,
79
+ ) -> UserAuthCredentials:
80
+ """Authenticate the user and retrieve authentication credentials.
81
+
82
+ Parameters
83
+ ----------
84
+ login_details : UserAuthLoginDetails
85
+ An object containing the user's login details.
86
+ exec_stub : ExecStub
87
+ A stub for executing RPC calls to the server.
88
+
89
+ Returns
90
+ -------
91
+ UserAuthCredentials
92
+ The authentication credentials obtained after login.
93
+ """
94
+
95
+ @abstractmethod
96
+ def __init__(self, credentials_path: Path):
97
+ """Abstract constructor."""
98
+
99
+ @abstractmethod
100
+ def store_tokens(self, credentials: UserAuthCredentials) -> None:
101
+ """Store authentication tokens to the `credentials_path`.
102
+
103
+ The credentials, including tokens, will be saved as a JSON file
104
+ at `credentials_path`.
105
+ """
106
+
107
+ @abstractmethod
108
+ def load_tokens(self) -> None:
109
+ """Load authentication tokens from the `credentials_path`."""
110
+
111
+ @abstractmethod
112
+ def write_tokens_to_metadata(
113
+ self, metadata: Sequence[tuple[str, Union[str, bytes]]]
114
+ ) -> Sequence[tuple[str, Union[str, bytes]]]:
115
+ """Write authentication tokens to the provided metadata."""
116
+
117
+ @abstractmethod
118
+ def read_tokens_from_metadata(
119
+ self, metadata: Sequence[tuple[str, Union[str, bytes]]]
120
+ ) -> Optional[UserAuthCredentials]:
121
+ """Read authentication tokens from the provided metadata."""
flwr/common/config.py ADDED
@@ -0,0 +1,243 @@
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
+ """Provide functions for managing global Flower config."""
16
+
17
+
18
+ import os
19
+ import re
20
+ from pathlib import Path
21
+ from typing import Any, Optional, Union, cast, get_args
22
+
23
+ import tomli
24
+
25
+ from flwr.cli.config_utils import get_fab_config, validate_fields
26
+ from flwr.common import ConfigsRecord
27
+ from flwr.common.constant import (
28
+ APP_DIR,
29
+ FAB_CONFIG_FILE,
30
+ FAB_HASH_TRUNCATION,
31
+ FLWR_DIR,
32
+ FLWR_HOME,
33
+ )
34
+ from flwr.common.typing import Run, UserConfig, UserConfigValue
35
+
36
+
37
+ def get_flwr_dir(provided_path: Optional[str] = None) -> Path:
38
+ """Return the Flower home directory based on env variables."""
39
+ if provided_path is None or not Path(provided_path).is_dir():
40
+ return Path(
41
+ os.getenv(
42
+ FLWR_HOME,
43
+ Path(f"{os.getenv('XDG_DATA_HOME', os.getenv('HOME'))}") / FLWR_DIR,
44
+ )
45
+ )
46
+ return Path(provided_path).absolute()
47
+
48
+
49
+ def get_project_dir(
50
+ fab_id: str,
51
+ fab_version: str,
52
+ fab_hash: str,
53
+ flwr_dir: Optional[Union[str, Path]] = None,
54
+ ) -> Path:
55
+ """Return the project directory based on the given fab_id and fab_version."""
56
+ # Check the fab_id
57
+ if fab_id.count("/") != 1:
58
+ raise ValueError(
59
+ f"Invalid FAB ID: {fab_id}",
60
+ )
61
+ publisher, project_name = fab_id.split("/")
62
+ if flwr_dir is None:
63
+ flwr_dir = get_flwr_dir()
64
+ return (
65
+ Path(flwr_dir)
66
+ / APP_DIR
67
+ / f"{publisher}.{project_name}.{fab_version}.{fab_hash[:FAB_HASH_TRUNCATION]}"
68
+ )
69
+
70
+
71
+ def get_project_config(project_dir: Union[str, Path]) -> dict[str, Any]:
72
+ """Return pyproject.toml in the given project directory."""
73
+ # Load pyproject.toml file
74
+ toml_path = Path(project_dir) / FAB_CONFIG_FILE
75
+ if not toml_path.is_file():
76
+ raise FileNotFoundError(
77
+ f"Cannot find {FAB_CONFIG_FILE} in {project_dir}",
78
+ )
79
+ with toml_path.open(encoding="utf-8") as toml_file:
80
+ config = tomli.loads(toml_file.read())
81
+
82
+ # Validate pyproject.toml fields
83
+ is_valid, errors, _ = validate_fields(config)
84
+ if not is_valid:
85
+ error_msg = "\n".join([f" - {error}" for error in errors])
86
+ raise ValueError(
87
+ f"Invalid {FAB_CONFIG_FILE}:\n{error_msg}",
88
+ )
89
+
90
+ return config
91
+
92
+
93
+ def fuse_dicts(
94
+ main_dict: UserConfig,
95
+ override_dict: UserConfig,
96
+ ) -> UserConfig:
97
+ """Merge a config with the overrides.
98
+
99
+ Remove the nesting by adding the nested keys as prefixes separated by dots, and fuse
100
+ it with the override dict.
101
+ """
102
+ fused_dict = main_dict.copy()
103
+
104
+ for key, value in override_dict.items():
105
+ if key in main_dict:
106
+ fused_dict[key] = value
107
+
108
+ return fused_dict
109
+
110
+
111
+ def get_fused_config_from_dir(
112
+ project_dir: Path, override_config: UserConfig
113
+ ) -> UserConfig:
114
+ """Merge the overrides from a given dict with the config from a Flower App."""
115
+ default_config = get_project_config(project_dir)["tool"]["flwr"]["app"].get(
116
+ "config", {}
117
+ )
118
+ flat_default_config = flatten_dict(default_config)
119
+
120
+ return fuse_dicts(flat_default_config, override_config)
121
+
122
+
123
+ def get_fused_config_from_fab(fab_file: Union[Path, bytes], run: Run) -> UserConfig:
124
+ """Fuse default config in a `FAB` with overrides in a `Run`.
125
+
126
+ This enables obtaining a run-config without having to install the FAB. This
127
+ function mirrors `get_fused_config_from_dir`. This is useful when the execution
128
+ of the FAB is delegated to a different process.
129
+ """
130
+ default_config = get_fab_config(fab_file)["tool"]["flwr"]["app"].get("config", {})
131
+ flat_config_flat = flatten_dict(default_config)
132
+ return fuse_dicts(flat_config_flat, run.override_config)
133
+
134
+
135
+ def get_fused_config(run: Run, flwr_dir: Optional[Path]) -> UserConfig:
136
+ """Merge the overrides from a `Run` with the config from a FAB.
137
+
138
+ Get the config using the fab_id and the fab_version, remove the nesting by adding
139
+ the nested keys as prefixes separated by dots, and fuse it with the override dict.
140
+ """
141
+ # Return empty dict if fab_id or fab_version is empty
142
+ if not run.fab_id or not run.fab_version:
143
+ return {}
144
+
145
+ project_dir = get_project_dir(run.fab_id, run.fab_version, run.fab_hash, flwr_dir)
146
+
147
+ # Return empty dict if project directory does not exist
148
+ if not project_dir.is_dir():
149
+ return {}
150
+
151
+ return get_fused_config_from_dir(project_dir, run.override_config)
152
+
153
+
154
+ def flatten_dict(
155
+ raw_dict: Optional[dict[str, Any]], parent_key: str = ""
156
+ ) -> UserConfig:
157
+ """Flatten dict by joining nested keys with a given separator."""
158
+ if raw_dict is None:
159
+ return {}
160
+
161
+ items: list[tuple[str, UserConfigValue]] = []
162
+ separator: str = "."
163
+ for k, v in raw_dict.items():
164
+ new_key = f"{parent_key}{separator}{k}" if parent_key else k
165
+ if isinstance(v, dict):
166
+ items.extend(flatten_dict(v, parent_key=new_key).items())
167
+ elif isinstance(v, get_args(UserConfigValue)):
168
+ items.append((new_key, cast(UserConfigValue, v)))
169
+ else:
170
+ raise ValueError(
171
+ f"The value for key {k} needs to be of type `int`, `float`, "
172
+ "`bool, `str`, or a `dict` of those.",
173
+ )
174
+ return dict(items)
175
+
176
+
177
+ def unflatten_dict(flat_dict: dict[str, Any]) -> dict[str, Any]:
178
+ """Unflatten a dict with keys containing separators into a nested dict."""
179
+ unflattened_dict: dict[str, Any] = {}
180
+ separator: str = "."
181
+
182
+ for key, value in flat_dict.items():
183
+ parts = key.split(separator)
184
+ d = unflattened_dict
185
+ for part in parts[:-1]:
186
+ if part not in d:
187
+ d[part] = {}
188
+ d = d[part]
189
+ d[parts[-1]] = value
190
+
191
+ return unflattened_dict
192
+
193
+
194
+ def parse_config_args(
195
+ config: Optional[list[str]],
196
+ ) -> UserConfig:
197
+ """Parse separator separated list of key-value pairs separated by '='."""
198
+ overrides: UserConfig = {}
199
+
200
+ if config is None:
201
+ return overrides
202
+
203
+ # Handle if .toml file is passed
204
+ if len(config) == 1 and config[0].endswith(".toml"):
205
+ with Path(config[0]).open("rb") as config_file:
206
+ overrides = flatten_dict(tomli.load(config_file))
207
+ return overrides
208
+
209
+ # Regular expression to capture key-value pairs with possible quoted values
210
+ pattern = re.compile(r"(\S+?)=(\'[^\']*\'|\"[^\"]*\"|\S+)")
211
+
212
+ flat_overrides = {}
213
+ for config_line in config:
214
+ if config_line:
215
+ # .toml files aren't allowed alongside other configs
216
+ if config_line.endswith(".toml"):
217
+ raise ValueError(
218
+ "TOML files cannot be passed alongside key-value pairs."
219
+ )
220
+
221
+ matches = pattern.findall(config_line)
222
+ toml_str = "\n".join(f"{k} = {v}" for k, v in matches)
223
+ overrides.update(tomli.loads(toml_str))
224
+ flat_overrides = flatten_dict(overrides)
225
+
226
+ return flat_overrides
227
+
228
+
229
+ def get_metadata_from_config(config: dict[str, Any]) -> tuple[str, str]:
230
+ """Extract `fab_version` and `fab_id` from a project config."""
231
+ return (
232
+ config["project"]["version"],
233
+ f"{config['tool']['flwr']['app']['publisher']}/{config['project']['name']}",
234
+ )
235
+
236
+
237
+ def user_config_to_configsrecord(config: UserConfig) -> ConfigsRecord:
238
+ """Construct a `ConfigsRecord` out of a `UserConfig`."""
239
+ c_record = ConfigsRecord()
240
+ for k, v in config.items():
241
+ c_record[k] = v
242
+
243
+ return c_record
flwr/common/constant.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright 2020 Flower Labs GmbH. All Rights Reserved.
1
+ # Copyright 2023 Flower Labs GmbH. All Rights Reserved.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ To use the REST API, install `flwr` with the `rest` extra:
27
27
 
28
28
  TRANSPORT_TYPE_GRPC_BIDI = "grpc-bidi"
29
29
  TRANSPORT_TYPE_GRPC_RERE = "grpc-rere"
30
+ TRANSPORT_TYPE_GRPC_ADAPTER = "grpc-adapter"
30
31
  TRANSPORT_TYPE_REST = "rest"
31
32
  TRANSPORT_TYPE_VCE = "vce"
32
33
  TRANSPORT_TYPES = [
@@ -36,6 +37,86 @@ TRANSPORT_TYPES = [
36
37
  TRANSPORT_TYPE_VCE,
37
38
  ]
38
39
 
40
+ # Addresses
41
+ # Ports
42
+ CLIENTAPPIO_PORT = "9094"
43
+ SERVERAPPIO_PORT = "9091"
44
+ FLEETAPI_GRPC_RERE_PORT = "9092"
45
+ FLEETAPI_PORT = "9095"
46
+ EXEC_API_PORT = "9093"
47
+ SIMULATIONIO_PORT = "9096"
48
+ # Octets
49
+ SERVER_OCTET = "0.0.0.0"
50
+ CLIENT_OCTET = "127.0.0.1"
51
+ # SuperNode
52
+ CLIENTAPPIO_API_DEFAULT_SERVER_ADDRESS = f"{SERVER_OCTET}:{CLIENTAPPIO_PORT}"
53
+ CLIENTAPPIO_API_DEFAULT_CLIENT_ADDRESS = f"{CLIENT_OCTET}:{CLIENTAPPIO_PORT}"
54
+ # SuperLink
55
+ SERVERAPPIO_API_DEFAULT_SERVER_ADDRESS = f"{SERVER_OCTET}:{SERVERAPPIO_PORT}"
56
+ SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS = f"{CLIENT_OCTET}:{SERVERAPPIO_PORT}"
57
+ FLEET_API_GRPC_RERE_DEFAULT_ADDRESS = f"{SERVER_OCTET}:{FLEETAPI_GRPC_RERE_PORT}"
58
+ FLEET_API_GRPC_BIDI_DEFAULT_ADDRESS = (
59
+ "[::]:8080" # IPv6 to keep start_server compatible
60
+ )
61
+ FLEET_API_REST_DEFAULT_ADDRESS = f"{SERVER_OCTET}:{FLEETAPI_PORT}"
62
+ EXEC_API_DEFAULT_SERVER_ADDRESS = f"{SERVER_OCTET}:{EXEC_API_PORT}"
63
+ SIMULATIONIO_API_DEFAULT_SERVER_ADDRESS = f"{SERVER_OCTET}:{SIMULATIONIO_PORT}"
64
+ SIMULATIONIO_API_DEFAULT_CLIENT_ADDRESS = f"{CLIENT_OCTET}:{SIMULATIONIO_PORT}"
65
+
66
+ # Constants for ping
67
+ PING_DEFAULT_INTERVAL = 30
68
+ PING_CALL_TIMEOUT = 5
69
+ PING_BASE_MULTIPLIER = 0.8
70
+ PING_RANDOM_RANGE = (-0.1, 0.1)
71
+ PING_MAX_INTERVAL = 1e300
72
+
73
+ # IDs
74
+ RUN_ID_NUM_BYTES = 8
75
+ NODE_ID_NUM_BYTES = 8
76
+
77
+ # Constants for FAB
78
+ APP_DIR = "apps"
79
+ FAB_ALLOWED_EXTENSIONS = {".py", ".toml", ".md"}
80
+ FAB_CONFIG_FILE = "pyproject.toml"
81
+ FAB_DATE = (2024, 10, 1, 0, 0, 0)
82
+ FAB_HASH_TRUNCATION = 8
83
+ FLWR_DIR = ".flwr" # The default Flower directory: ~/.flwr/
84
+ FLWR_HOME = "FLWR_HOME" # If set, override the default Flower directory
85
+
86
+ # Constants entries in Node config for Simulation
87
+ PARTITION_ID_KEY = "partition-id"
88
+ NUM_PARTITIONS_KEY = "num-partitions"
89
+
90
+ # Constants for keys in `metadata` of `MessageContainer` in `grpc-adapter`
91
+ GRPC_ADAPTER_METADATA_FLOWER_PACKAGE_NAME_KEY = "flower-package-name"
92
+ GRPC_ADAPTER_METADATA_FLOWER_PACKAGE_VERSION_KEY = "flower-package-version"
93
+ GRPC_ADAPTER_METADATA_FLOWER_VERSION_KEY = "flower-version" # Deprecated
94
+ GRPC_ADAPTER_METADATA_SHOULD_EXIT_KEY = "should-exit"
95
+ GRPC_ADAPTER_METADATA_MESSAGE_MODULE_KEY = "grpc-message-module"
96
+ GRPC_ADAPTER_METADATA_MESSAGE_QUALNAME_KEY = "grpc-message-qualname"
97
+
98
+ # Message TTL
99
+ MESSAGE_TTL_TOLERANCE = 1e-1
100
+
101
+ # Isolation modes
102
+ ISOLATION_MODE_SUBPROCESS = "subprocess"
103
+ ISOLATION_MODE_PROCESS = "process"
104
+
105
+ # Log streaming configurations
106
+ CONN_REFRESH_PERIOD = 60 # Stream connection refresh period
107
+ CONN_RECONNECT_INTERVAL = 0.5 # Reconnect interval between two stream connections
108
+ LOG_STREAM_INTERVAL = 0.5 # Log stream interval for `ExecServicer.StreamLogs`
109
+ LOG_UPLOAD_INTERVAL = 0.2 # Minimum interval between two log uploads
110
+
111
+ # Retry configurations
112
+ MAX_RETRY_DELAY = 20 # Maximum delay duration between two consecutive retries.
113
+
114
+ # Constants for user authentication
115
+ CREDENTIALS_DIR = ".credentials"
116
+ AUTH_TYPE = "auth_type"
117
+ ACCESS_TOKEN_KEY = "access_token"
118
+ REFRESH_TOKEN_KEY = "refresh_token"
119
+
39
120
 
40
121
  class MessageType:
41
122
  """Message type."""
@@ -68,3 +149,53 @@ class SType:
68
149
  def __new__(cls) -> SType:
69
150
  """Prevent instantiation."""
70
151
  raise TypeError(f"{cls.__name__} cannot be instantiated.")
152
+
153
+
154
+ class ErrorCode:
155
+ """Error codes for Message's Error."""
156
+
157
+ UNKNOWN = 0
158
+ LOAD_CLIENT_APP_EXCEPTION = 1
159
+ CLIENT_APP_RAISED_EXCEPTION = 2
160
+ MESSAGE_UNAVAILABLE = 3
161
+ REPLY_MESSAGE_UNAVAILABLE = 4
162
+
163
+ def __new__(cls) -> ErrorCode:
164
+ """Prevent instantiation."""
165
+ raise TypeError(f"{cls.__name__} cannot be instantiated.")
166
+
167
+
168
+ class Status:
169
+ """Run status."""
170
+
171
+ PENDING = "pending"
172
+ STARTING = "starting"
173
+ RUNNING = "running"
174
+ FINISHED = "finished"
175
+
176
+ def __new__(cls) -> Status:
177
+ """Prevent instantiation."""
178
+ raise TypeError(f"{cls.__name__} cannot be instantiated.")
179
+
180
+
181
+ class SubStatus:
182
+ """Run sub-status."""
183
+
184
+ COMPLETED = "completed"
185
+ FAILED = "failed"
186
+ STOPPED = "stopped"
187
+
188
+ def __new__(cls) -> SubStatus:
189
+ """Prevent instantiation."""
190
+ raise TypeError(f"{cls.__name__} cannot be instantiated.")
191
+
192
+
193
+ class CliOutputFormat:
194
+ """Define output format for `flwr` CLI commands."""
195
+
196
+ DEFAULT = "default"
197
+ JSON = "json"
198
+
199
+ def __new__(cls) -> CliOutputFormat:
200
+ """Prevent instantiation."""
201
+ raise TypeError(f"{cls.__name__} cannot be instantiated.")