flwr-nightly 1.8.0.dev20240315__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.dev20240315.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.dev20240315.dist-info/RECORD +0 -211
  309. flwr_nightly-1.8.0.dev20240315.dist-info/entry_points.txt +0 -9
  310. {flwr_nightly-1.8.0.dev20240315.dist-info → flwr_nightly-1.15.0.dev20250114.dist-info}/LICENSE +0 -0
  311. {flwr_nightly-1.8.0.dev20240315.dist-info → flwr_nightly-1.15.0.dev20250114.dist-info}/WHEEL +0 -0
@@ -0,0 +1,389 @@
1
+ # Copyright 2024 Flower Labs GmbH. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ==============================================================================
15
+ """Abstract base class LinkState."""
16
+
17
+
18
+ import abc
19
+ from typing import Optional
20
+ from uuid import UUID
21
+
22
+ from flwr.common import Context
23
+ from flwr.common.record import ConfigsRecord
24
+ from flwr.common.typing import Run, RunStatus, UserConfig
25
+ from flwr.proto.task_pb2 import TaskIns, TaskRes # pylint: disable=E0611
26
+
27
+
28
+ class LinkState(abc.ABC): # pylint: disable=R0904
29
+ """Abstract LinkState."""
30
+
31
+ @abc.abstractmethod
32
+ def store_task_ins(self, task_ins: TaskIns) -> Optional[UUID]:
33
+ """Store one TaskIns.
34
+
35
+ Usually, the ServerAppIo API calls this to schedule instructions.
36
+
37
+ Stores the value of the `task_ins` in the link state and, if successful,
38
+ returns the `task_id` (UUID) of the `task_ins`. If, for any reason,
39
+ storing the `task_ins` fails, `None` is returned.
40
+
41
+ Constraints
42
+ -----------
43
+ If `task_ins.task.consumer.anonymous` is `True`, then
44
+ `task_ins.task.consumer.node_id` MUST NOT be set (equal 0).
45
+
46
+ If `task_ins.task.consumer.anonymous` is `False`, then
47
+ `task_ins.task.consumer.node_id` MUST be set (not 0)
48
+
49
+ If `task_ins.run_id` is invalid, then
50
+ storing the `task_ins` MUST fail.
51
+ """
52
+
53
+ @abc.abstractmethod
54
+ def get_task_ins(
55
+ self, node_id: Optional[int], limit: Optional[int]
56
+ ) -> list[TaskIns]:
57
+ """Get TaskIns optionally filtered by node_id.
58
+
59
+ Usually, the Fleet API calls this for Nodes planning to work on one or more
60
+ TaskIns.
61
+
62
+ Constraints
63
+ -----------
64
+ If `node_id` is not `None`, retrieve all TaskIns where
65
+
66
+ 1. the `task_ins.task.consumer.node_id` equals `node_id` AND
67
+ 2. the `task_ins.task.consumer.anonymous` equals `False` AND
68
+ 3. the `task_ins.task.delivered_at` equals `""`.
69
+
70
+ If `node_id` is `None`, retrieve all TaskIns where the
71
+ `task_ins.task.consumer.node_id` equals `0` and
72
+ `task_ins.task.consumer.anonymous` is set to `True`.
73
+
74
+ If `delivered_at` MUST BE set (not `""`) otherwise the TaskIns MUST not be in
75
+ the result.
76
+
77
+ If `limit` is not `None`, return, at most, `limit` number of `task_ins`. If
78
+ `limit` is set, it has to be greater zero.
79
+ """
80
+
81
+ @abc.abstractmethod
82
+ def store_task_res(self, task_res: TaskRes) -> Optional[UUID]:
83
+ """Store one TaskRes.
84
+
85
+ Usually, the Fleet API calls this for Nodes returning results.
86
+
87
+ Stores the TaskRes and, if successful, returns the `task_id` (UUID) of
88
+ the `task_res`. If storing the `task_res` fails, `None` is returned.
89
+
90
+ Constraints
91
+ -----------
92
+ If `task_res.task.consumer.anonymous` is `True`, then
93
+ `task_res.task.consumer.node_id` MUST NOT be set (equal 0).
94
+
95
+ If `task_res.task.consumer.anonymous` is `False`, then
96
+ `task_res.task.consumer.node_id` MUST be set (not 0)
97
+
98
+ If `task_res.run_id` is invalid, then
99
+ storing the `task_res` MUST fail.
100
+ """
101
+
102
+ @abc.abstractmethod
103
+ def get_task_res(self, task_ids: set[UUID]) -> list[TaskRes]:
104
+ """Get TaskRes for the given TaskIns IDs.
105
+
106
+ This method is typically called by the ServerAppIo API to obtain
107
+ results (TaskRes) for previously scheduled instructions (TaskIns).
108
+ For each task_id provided, this method returns one of the following responses:
109
+
110
+ - An error TaskRes if the corresponding TaskIns does not exist or has expired.
111
+ - An error TaskRes if the corresponding TaskRes exists but has expired.
112
+ - The valid TaskRes if the TaskIns has a corresponding valid TaskRes.
113
+ - Nothing if the TaskIns is still valid and waiting for a TaskRes.
114
+
115
+ Parameters
116
+ ----------
117
+ task_ids : set[UUID]
118
+ A set of TaskIns IDs for which to retrieve results (TaskRes).
119
+
120
+ Returns
121
+ -------
122
+ list[TaskRes]
123
+ A list of TaskRes corresponding to the given task IDs. If no
124
+ TaskRes could be found for any of the task IDs, an empty list is returned.
125
+ """
126
+
127
+ @abc.abstractmethod
128
+ def num_task_ins(self) -> int:
129
+ """Calculate the number of task_ins in store.
130
+
131
+ This includes delivered but not yet deleted task_ins.
132
+ """
133
+
134
+ @abc.abstractmethod
135
+ def num_task_res(self) -> int:
136
+ """Calculate the number of task_res in store.
137
+
138
+ This includes delivered but not yet deleted task_res.
139
+ """
140
+
141
+ @abc.abstractmethod
142
+ def delete_tasks(self, task_ins_ids: set[UUID]) -> None:
143
+ """Delete TaskIns/TaskRes pairs based on provided TaskIns IDs.
144
+
145
+ Parameters
146
+ ----------
147
+ task_ins_ids : set[UUID]
148
+ A set of TaskIns IDs. For each ID in the set, the corresponding
149
+ TaskIns and its associated TaskRes will be deleted.
150
+ """
151
+
152
+ @abc.abstractmethod
153
+ def get_task_ids_from_run_id(self, run_id: int) -> set[UUID]:
154
+ """Get all TaskIns IDs for the given run_id."""
155
+
156
+ @abc.abstractmethod
157
+ def create_node(self, ping_interval: float) -> int:
158
+ """Create, store in the link state, and return `node_id`."""
159
+
160
+ @abc.abstractmethod
161
+ def delete_node(self, node_id: int) -> None:
162
+ """Remove `node_id` from the link state."""
163
+
164
+ @abc.abstractmethod
165
+ def get_nodes(self, run_id: int) -> set[int]:
166
+ """Retrieve all currently stored node IDs as a set.
167
+
168
+ Constraints
169
+ -----------
170
+ If the provided `run_id` does not exist or has no matching nodes,
171
+ an empty `Set` MUST be returned.
172
+ """
173
+
174
+ @abc.abstractmethod
175
+ def set_node_public_key(self, node_id: int, public_key: bytes) -> None:
176
+ """Set `public_key` for the specified `node_id`."""
177
+
178
+ @abc.abstractmethod
179
+ def get_node_public_key(self, node_id: int) -> Optional[bytes]:
180
+ """Get `public_key` for the specified `node_id`."""
181
+
182
+ @abc.abstractmethod
183
+ def get_node_id(self, node_public_key: bytes) -> Optional[int]:
184
+ """Retrieve stored `node_id` filtered by `node_public_keys`."""
185
+
186
+ @abc.abstractmethod
187
+ def create_run( # pylint: disable=too-many-arguments,too-many-positional-arguments
188
+ self,
189
+ fab_id: Optional[str],
190
+ fab_version: Optional[str],
191
+ fab_hash: Optional[str],
192
+ override_config: UserConfig,
193
+ federation_options: ConfigsRecord,
194
+ ) -> int:
195
+ """Create a new run for the specified `fab_hash`."""
196
+
197
+ @abc.abstractmethod
198
+ def get_run_ids(self) -> set[int]:
199
+ """Retrieve all run IDs."""
200
+
201
+ @abc.abstractmethod
202
+ def get_run(self, run_id: int) -> Optional[Run]:
203
+ """Retrieve information about the run with the specified `run_id`.
204
+
205
+ Parameters
206
+ ----------
207
+ run_id : int
208
+ The identifier of the run.
209
+
210
+ Returns
211
+ -------
212
+ Optional[Run]
213
+ The `Run` instance if found; otherwise, `None`.
214
+ """
215
+
216
+ @abc.abstractmethod
217
+ def get_run_status(self, run_ids: set[int]) -> dict[int, RunStatus]:
218
+ """Retrieve the statuses for the specified runs.
219
+
220
+ Parameters
221
+ ----------
222
+ run_ids : set[int]
223
+ A set of run identifiers for which to retrieve statuses.
224
+
225
+ Returns
226
+ -------
227
+ dict[int, RunStatus]
228
+ A dictionary mapping each valid run ID to its corresponding status.
229
+
230
+ Notes
231
+ -----
232
+ Only valid run IDs that exist in the State will be included in the returned
233
+ dictionary. If a run ID is not found, it will be omitted from the result.
234
+ """
235
+
236
+ @abc.abstractmethod
237
+ def update_run_status(self, run_id: int, new_status: RunStatus) -> bool:
238
+ """Update the status of the run with the specified `run_id`.
239
+
240
+ Parameters
241
+ ----------
242
+ run_id : int
243
+ The identifier of the run.
244
+ new_status : RunStatus
245
+ The new status to be assigned to the run.
246
+
247
+ Returns
248
+ -------
249
+ bool
250
+ True if the status update is successful; False otherwise.
251
+ """
252
+
253
+ @abc.abstractmethod
254
+ def get_pending_run_id(self) -> Optional[int]:
255
+ """Get the `run_id` of a run with `Status.PENDING` status.
256
+
257
+ Returns
258
+ -------
259
+ Optional[int]
260
+ The `run_id` of a `Run` that is pending to be started; None if
261
+ there is no Run pending.
262
+ """
263
+
264
+ @abc.abstractmethod
265
+ def get_federation_options(self, run_id: int) -> Optional[ConfigsRecord]:
266
+ """Retrieve the federation options for the specified `run_id`.
267
+
268
+ Parameters
269
+ ----------
270
+ run_id : int
271
+ The identifier of the run.
272
+
273
+ Returns
274
+ -------
275
+ Optional[ConfigsRecord]
276
+ The federation options for the run if it exists; None otherwise.
277
+ """
278
+
279
+ @abc.abstractmethod
280
+ def store_server_private_public_key(
281
+ self, private_key: bytes, public_key: bytes
282
+ ) -> None:
283
+ """Store `server_private_key` and `server_public_key` in the link state."""
284
+
285
+ @abc.abstractmethod
286
+ def get_server_private_key(self) -> Optional[bytes]:
287
+ """Retrieve `server_private_key` in urlsafe bytes."""
288
+
289
+ @abc.abstractmethod
290
+ def get_server_public_key(self) -> Optional[bytes]:
291
+ """Retrieve `server_public_key` in urlsafe bytes."""
292
+
293
+ @abc.abstractmethod
294
+ def clear_supernode_auth_keys_and_credentials(self) -> None:
295
+ """Clear stored `node_public_keys` and credentials in the link state if any."""
296
+
297
+ @abc.abstractmethod
298
+ def store_node_public_keys(self, public_keys: set[bytes]) -> None:
299
+ """Store a set of `node_public_keys` in the link state."""
300
+
301
+ @abc.abstractmethod
302
+ def store_node_public_key(self, public_key: bytes) -> None:
303
+ """Store a `node_public_key` in the link state."""
304
+
305
+ @abc.abstractmethod
306
+ def get_node_public_keys(self) -> set[bytes]:
307
+ """Retrieve all currently stored `node_public_keys` as a set."""
308
+
309
+ @abc.abstractmethod
310
+ def acknowledge_ping(self, node_id: int, ping_interval: float) -> bool:
311
+ """Acknowledge a ping received from a node, serving as a heartbeat.
312
+
313
+ Parameters
314
+ ----------
315
+ node_id : int
316
+ The `node_id` from which the ping was received.
317
+ ping_interval : float
318
+ The interval (in seconds) from the current timestamp within which the next
319
+ ping from this node must be received. This acts as a hard deadline to ensure
320
+ an accurate assessment of the node's availability.
321
+
322
+ Returns
323
+ -------
324
+ is_acknowledged : bool
325
+ True if the ping is successfully acknowledged; otherwise, False.
326
+ """
327
+
328
+ @abc.abstractmethod
329
+ def get_serverapp_context(self, run_id: int) -> Optional[Context]:
330
+ """Get the context for the specified `run_id`.
331
+
332
+ Parameters
333
+ ----------
334
+ run_id : int
335
+ The identifier of the run for which to retrieve the context.
336
+
337
+ Returns
338
+ -------
339
+ Optional[Context]
340
+ The context associated with the specified `run_id`, or `None` if no context
341
+ exists for the given `run_id`.
342
+ """
343
+
344
+ @abc.abstractmethod
345
+ def set_serverapp_context(self, run_id: int, context: Context) -> None:
346
+ """Set the context for the specified `run_id`.
347
+
348
+ Parameters
349
+ ----------
350
+ run_id : int
351
+ The identifier of the run for which to set the context.
352
+ context : Context
353
+ The context to be associated with the specified `run_id`.
354
+ """
355
+
356
+ @abc.abstractmethod
357
+ def add_serverapp_log(self, run_id: int, log_message: str) -> None:
358
+ """Add a log entry to the ServerApp logs for the specified `run_id`.
359
+
360
+ Parameters
361
+ ----------
362
+ run_id : int
363
+ The identifier of the run for which to add a log entry.
364
+ log_message : str
365
+ The log entry to be added to the ServerApp logs.
366
+ """
367
+
368
+ @abc.abstractmethod
369
+ def get_serverapp_log(
370
+ self, run_id: int, after_timestamp: Optional[float]
371
+ ) -> tuple[str, float]:
372
+ """Get the ServerApp logs for the specified `run_id`.
373
+
374
+ Parameters
375
+ ----------
376
+ run_id : int
377
+ The identifier of the run for which to retrieve the ServerApp logs.
378
+
379
+ after_timestamp : Optional[float]
380
+ Retrieve logs after this timestamp. If set to `None`, retrieve all logs.
381
+
382
+ Returns
383
+ -------
384
+ tuple[str, float]
385
+ A tuple containing:
386
+ - The ServerApp logs associated with the specified `run_id`.
387
+ - The timestamp of the latest log entry in the returned logs.
388
+ Returns `0` if no logs are returned.
389
+ """
@@ -1,4 +1,4 @@
1
- # Copyright 2022 Flower Labs GmbH. All Rights Reserved.
1
+ # Copyright 2024 Flower Labs GmbH. All Rights Reserved.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -20,29 +20,38 @@ from typing import Optional
20
20
 
21
21
  from flwr.common.logger import log
22
22
 
23
- from .in_memory_state import InMemoryState
24
- from .sqlite_state import SqliteState
25
- from .state import State
23
+ from .in_memory_linkstate import InMemoryLinkState
24
+ from .linkstate import LinkState
25
+ from .sqlite_linkstate import SqliteLinkState
26
26
 
27
27
 
28
- class StateFactory:
29
- """Factory class that creates State instances."""
28
+ class LinkStateFactory:
29
+ """Factory class that creates LinkState instances.
30
+
31
+ Parameters
32
+ ----------
33
+ database : str
34
+ A string representing the path to the database file that will be opened.
35
+ Note that passing ':memory:' will open a connection to a database that is
36
+ in RAM, instead of on disk. For more information on special in-memory
37
+ databases, please refer to https://sqlite.org/inmemorydb.html.
38
+ """
30
39
 
31
40
  def __init__(self, database: str) -> None:
32
41
  self.database = database
33
- self.state_instance: Optional[State] = None
42
+ self.state_instance: Optional[LinkState] = None
34
43
 
35
- def state(self) -> State:
44
+ def state(self) -> LinkState:
36
45
  """Return a State instance and create it, if necessary."""
37
46
  # InMemoryState
38
47
  if self.database == ":flwr-in-memory-state:":
39
48
  if self.state_instance is None:
40
- self.state_instance = InMemoryState()
49
+ self.state_instance = InMemoryLinkState()
41
50
  log(DEBUG, "Using InMemoryState")
42
51
  return self.state_instance
43
52
 
44
53
  # SqliteState
45
- state = SqliteState(self.database)
54
+ state = SqliteLinkState(self.database)
46
55
  state.initialize()
47
56
  log(DEBUG, "Using SqliteState")
48
57
  return state