flwr-nightly 1.14.0.dev20241202__py3-none-any.whl → 1.14.0.dev20241214__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.

Potentially problematic release.


This version of flwr-nightly might be problematic. Click here for more details.

Files changed (108) hide show
  1. flwr/cli/app.py +5 -0
  2. flwr/cli/build.py +1 -0
  3. flwr/cli/cli_user_auth_interceptor.py +86 -0
  4. flwr/cli/config_utils.py +19 -2
  5. flwr/cli/example.py +1 -0
  6. flwr/cli/install.py +1 -0
  7. flwr/cli/log.py +11 -31
  8. flwr/cli/login/__init__.py +22 -0
  9. flwr/cli/login/login.py +83 -0
  10. flwr/cli/ls.py +198 -102
  11. flwr/cli/new/__init__.py +1 -0
  12. flwr/cli/new/new.py +2 -1
  13. flwr/cli/new/templates/app/pyproject.flowertune.toml.tpl +2 -2
  14. flwr/cli/new/templates/app/pyproject.mlx.toml.tpl +1 -2
  15. flwr/cli/run/__init__.py +1 -0
  16. flwr/cli/run/run.py +96 -39
  17. flwr/cli/stop.py +91 -0
  18. flwr/cli/utils.py +109 -1
  19. flwr/client/app.py +3 -2
  20. flwr/client/client.py +1 -0
  21. flwr/client/clientapp/app.py +1 -0
  22. flwr/client/clientapp/utils.py +1 -0
  23. flwr/client/grpc_adapter_client/connection.py +1 -1
  24. flwr/client/grpc_client/connection.py +1 -1
  25. flwr/client/grpc_rere_client/connection.py +3 -3
  26. flwr/client/message_handler/message_handler.py +1 -0
  27. flwr/client/mod/comms_mods.py +1 -0
  28. flwr/client/mod/localdp_mod.py +1 -1
  29. flwr/client/nodestate/__init__.py +1 -0
  30. flwr/client/nodestate/nodestate.py +1 -0
  31. flwr/client/nodestate/nodestate_factory.py +1 -0
  32. flwr/client/rest_client/connection.py +3 -3
  33. flwr/client/supernode/app.py +1 -0
  34. flwr/common/address.py +1 -0
  35. flwr/common/args.py +1 -0
  36. flwr/common/auth_plugin/__init__.py +24 -0
  37. flwr/common/auth_plugin/auth_plugin.py +111 -0
  38. flwr/common/config.py +3 -1
  39. flwr/common/constant.py +17 -1
  40. flwr/common/logger.py +25 -0
  41. flwr/common/message.py +1 -0
  42. flwr/common/object_ref.py +57 -54
  43. flwr/common/pyproject.py +1 -0
  44. flwr/common/record/__init__.py +1 -0
  45. flwr/common/record/parametersrecord.py +1 -0
  46. flwr/common/retry_invoker.py +75 -0
  47. flwr/common/secure_aggregation/secaggplus_utils.py +2 -2
  48. flwr/common/telemetry.py +2 -1
  49. flwr/common/typing.py +12 -0
  50. flwr/common/version.py +1 -0
  51. flwr/proto/exec_pb2.py +38 -14
  52. flwr/proto/exec_pb2.pyi +107 -2
  53. flwr/proto/exec_pb2_grpc.py +102 -0
  54. flwr/proto/exec_pb2_grpc.pyi +39 -0
  55. flwr/proto/fab_pb2.py +4 -4
  56. flwr/proto/fab_pb2.pyi +4 -1
  57. flwr/proto/serverappio_pb2.py +18 -18
  58. flwr/proto/serverappio_pb2.pyi +8 -2
  59. flwr/proto/serverappio_pb2_grpc.py +34 -0
  60. flwr/proto/serverappio_pb2_grpc.pyi +13 -0
  61. flwr/proto/simulationio_pb2.py +2 -2
  62. flwr/proto/simulationio_pb2_grpc.py +34 -0
  63. flwr/proto/simulationio_pb2_grpc.pyi +13 -0
  64. flwr/server/app.py +53 -1
  65. flwr/server/compat/app_utils.py +7 -1
  66. flwr/server/driver/grpc_driver.py +11 -63
  67. flwr/server/driver/inmemory_driver.py +5 -1
  68. flwr/server/serverapp/app.py +9 -2
  69. flwr/server/strategy/dpfedavg_fixed.py +1 -0
  70. flwr/server/superlink/driver/serverappio_grpc.py +1 -0
  71. flwr/server/superlink/driver/serverappio_servicer.py +73 -23
  72. flwr/server/superlink/ffs/disk_ffs.py +1 -0
  73. flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py +1 -0
  74. flwr/server/superlink/fleet/grpc_bidi/flower_service_servicer.py +1 -0
  75. flwr/server/superlink/fleet/grpc_rere/fleet_servicer.py +32 -12
  76. flwr/server/superlink/fleet/message_handler/message_handler.py +31 -2
  77. flwr/server/superlink/fleet/rest_rere/rest_api.py +4 -1
  78. flwr/server/superlink/fleet/vce/__init__.py +1 -0
  79. flwr/server/superlink/fleet/vce/backend/__init__.py +1 -0
  80. flwr/server/superlink/fleet/vce/backend/raybackend.py +1 -0
  81. flwr/server/superlink/linkstate/in_memory_linkstate.py +14 -30
  82. flwr/server/superlink/linkstate/linkstate.py +13 -2
  83. flwr/server/superlink/linkstate/sqlite_linkstate.py +24 -44
  84. flwr/server/superlink/simulation/simulationio_servicer.py +20 -0
  85. flwr/server/superlink/utils.py +65 -0
  86. flwr/simulation/app.py +1 -0
  87. flwr/simulation/ray_transport/ray_actor.py +1 -0
  88. flwr/simulation/ray_transport/utils.py +1 -0
  89. flwr/simulation/run_simulation.py +1 -0
  90. flwr/superexec/app.py +1 -0
  91. flwr/superexec/deployment.py +1 -0
  92. flwr/superexec/exec_grpc.py +19 -1
  93. flwr/superexec/exec_servicer.py +76 -2
  94. flwr/superexec/exec_user_auth_interceptor.py +101 -0
  95. flwr/superexec/executor.py +1 -0
  96. {flwr_nightly-1.14.0.dev20241202.dist-info → flwr_nightly-1.14.0.dev20241214.dist-info}/METADATA +8 -7
  97. {flwr_nightly-1.14.0.dev20241202.dist-info → flwr_nightly-1.14.0.dev20241214.dist-info}/RECORD +100 -100
  98. flwr/proto/common_pb2.py +0 -36
  99. flwr/proto/common_pb2.pyi +0 -121
  100. flwr/proto/common_pb2_grpc.py +0 -4
  101. flwr/proto/common_pb2_grpc.pyi +0 -4
  102. flwr/proto/control_pb2.py +0 -27
  103. flwr/proto/control_pb2.pyi +0 -7
  104. flwr/proto/control_pb2_grpc.py +0 -135
  105. flwr/proto/control_pb2_grpc.pyi +0 -53
  106. {flwr_nightly-1.14.0.dev20241202.dist-info → flwr_nightly-1.14.0.dev20241214.dist-info}/LICENSE +0 -0
  107. {flwr_nightly-1.14.0.dev20241202.dist-info → flwr_nightly-1.14.0.dev20241214.dist-info}/WHEEL +0 -0
  108. {flwr_nightly-1.14.0.dev20241202.dist-info → flwr_nightly-1.14.0.dev20241214.dist-info}/entry_points.txt +0 -0
flwr/cli/app.py CHANGED
@@ -14,15 +14,18 @@
14
14
  # ==============================================================================
15
15
  """Flower command line interface."""
16
16
 
17
+
17
18
  import typer
18
19
  from typer.main import get_command
19
20
 
20
21
  from .build import build
21
22
  from .install import install
22
23
  from .log import log
24
+ from .login import login
23
25
  from .ls import ls
24
26
  from .new import new
25
27
  from .run import run
28
+ from .stop import stop
26
29
 
27
30
  app = typer.Typer(
28
31
  help=typer.style(
@@ -39,6 +42,8 @@ app.command()(build)
39
42
  app.command()(install)
40
43
  app.command()(log)
41
44
  app.command()(ls)
45
+ app.command()(stop)
46
+ app.command()(login)
42
47
 
43
48
  typer_click_object = get_command(app)
44
49
 
flwr/cli/build.py CHANGED
@@ -14,6 +14,7 @@
14
14
  # ==============================================================================
15
15
  """Flower command line interface `build` command."""
16
16
 
17
+
17
18
  import hashlib
18
19
  import os
19
20
  import shutil
@@ -0,0 +1,86 @@
1
+ # Copyright 2024 Flower Labs GmbH. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ==============================================================================
15
+ """Flower run interceptor."""
16
+
17
+
18
+ from typing import Any, Callable, Union
19
+
20
+ import grpc
21
+
22
+ from flwr.common.auth_plugin import CliAuthPlugin
23
+ from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
24
+ StartRunRequest,
25
+ StreamLogsRequest,
26
+ )
27
+
28
+ Request = Union[
29
+ StartRunRequest,
30
+ StreamLogsRequest,
31
+ ]
32
+
33
+
34
+ class CliUserAuthInterceptor(
35
+ grpc.UnaryUnaryClientInterceptor, grpc.UnaryStreamClientInterceptor # type: ignore
36
+ ):
37
+ """CLI interceptor for user authentication."""
38
+
39
+ def __init__(self, auth_plugin: CliAuthPlugin):
40
+ self.auth_plugin = auth_plugin
41
+
42
+ def _authenticated_call(
43
+ self,
44
+ continuation: Callable[[Any, Any], Any],
45
+ client_call_details: grpc.ClientCallDetails,
46
+ request: Request,
47
+ ) -> grpc.Call:
48
+ """Send and receive tokens via metadata."""
49
+ new_metadata = self.auth_plugin.write_tokens_to_metadata(
50
+ client_call_details.metadata or []
51
+ )
52
+
53
+ details = client_call_details._replace(metadata=new_metadata)
54
+
55
+ response = continuation(details, request)
56
+ if response.initial_metadata():
57
+ retrieved_metadata = dict(response.initial_metadata())
58
+ self.auth_plugin.store_tokens(retrieved_metadata)
59
+
60
+ return response
61
+
62
+ def intercept_unary_unary(
63
+ self,
64
+ continuation: Callable[[Any, Any], Any],
65
+ client_call_details: grpc.ClientCallDetails,
66
+ request: Request,
67
+ ) -> grpc.Call:
68
+ """Intercept a unary-unary call for user authentication.
69
+
70
+ This method intercepts a unary-unary RPC call initiated from the CLI and adds
71
+ the required authentication tokens to the RPC metadata.
72
+ """
73
+ return self._authenticated_call(continuation, client_call_details, request)
74
+
75
+ def intercept_unary_stream(
76
+ self,
77
+ continuation: Callable[[Any, Any], Any],
78
+ client_call_details: grpc.ClientCallDetails,
79
+ request: Request,
80
+ ) -> grpc.Call:
81
+ """Intercept a unary-stream call for user authentication.
82
+
83
+ This method intercepts a unary-stream RPC call initiated from the CLI and adds
84
+ the required authentication tokens to the RPC metadata.
85
+ """
86
+ return self._authenticated_call(continuation, client_call_details, request)
flwr/cli/config_utils.py CHANGED
@@ -14,6 +14,7 @@
14
14
  # ==============================================================================
15
15
  """Utility to validate the `pyproject.toml` file."""
16
16
 
17
+
17
18
  import zipfile
18
19
  from io import BytesIO
19
20
  from pathlib import Path
@@ -230,10 +231,14 @@ def load_from_string(toml_content: str) -> Optional[dict[str, Any]]:
230
231
  return None
231
232
 
232
233
 
233
- def validate_project_config(
234
+ def process_loaded_project_config(
234
235
  config: Union[dict[str, Any], None], errors: list[str], warnings: list[str]
235
236
  ) -> dict[str, Any]:
236
- """Validate and return the Flower project configuration."""
237
+ """Process and return the loaded project configuration.
238
+
239
+ This function handles errors and warnings from the `load_and_validate` function,
240
+ exits on critical issues, and returns the validated configuration.
241
+ """
237
242
  if config is None:
238
243
  typer.secho(
239
244
  "Project configuration could not be loaded.\n"
@@ -324,3 +329,15 @@ def validate_certificate_in_federation_config(
324
329
  raise typer.Exit(code=1)
325
330
 
326
331
  return insecure, root_certificates_bytes
332
+
333
+
334
+ def exit_if_no_address(federation_config: dict[str, Any], cmd: str) -> None:
335
+ """Exit if the provided federation_config has no "address" key."""
336
+ if "address" not in federation_config:
337
+ typer.secho(
338
+ f"❌ `flwr {cmd}` currently works with a SuperLink. Ensure that the correct"
339
+ "SuperLink (Exec API) address is provided in `pyproject.toml`.",
340
+ fg=typer.colors.RED,
341
+ bold=True,
342
+ )
343
+ raise typer.Exit(code=1)
flwr/cli/example.py CHANGED
@@ -14,6 +14,7 @@
14
14
  # ==============================================================================
15
15
  """Flower command line interface `example` command."""
16
16
 
17
+
17
18
  import json
18
19
  import os
19
20
  import subprocess
flwr/cli/install.py CHANGED
@@ -14,6 +14,7 @@
14
14
  # ==============================================================================
15
15
  """Flower command line interface `install` command."""
16
16
 
17
+
17
18
  import hashlib
18
19
  import shutil
19
20
  import tempfile
flwr/cli/log.py CHANGED
@@ -14,6 +14,7 @@
14
14
  # ==============================================================================
15
15
  """Flower command line interface `log` command."""
16
16
 
17
+
17
18
  import time
18
19
  from logging import DEBUG, ERROR, INFO
19
20
  from pathlib import Path
@@ -23,17 +24,18 @@ import grpc
23
24
  import typer
24
25
 
25
26
  from flwr.cli.config_utils import (
27
+ exit_if_no_address,
26
28
  load_and_validate,
27
- validate_certificate_in_federation_config,
29
+ process_loaded_project_config,
28
30
  validate_federation_in_project_config,
29
- validate_project_config,
30
31
  )
31
32
  from flwr.common.constant import CONN_RECONNECT_INTERVAL, CONN_REFRESH_PERIOD
32
- from flwr.common.grpc import GRPC_MAX_MESSAGE_LENGTH, create_channel
33
33
  from flwr.common.logger import log as logger
34
34
  from flwr.proto.exec_pb2 import StreamLogsRequest # pylint: disable=E0611
35
35
  from flwr.proto.exec_pb2_grpc import ExecStub
36
36
 
37
+ from .utils import init_channel, try_obtain_cli_auth_plugin
38
+
37
39
 
38
40
  def start_stream(
39
41
  run_id: int, channel: grpc.Channel, refresh_period: int = CONN_REFRESH_PERIOD
@@ -126,11 +128,6 @@ def print_logs(run_id: int, channel: grpc.Channel, timeout: int) -> None:
126
128
  logger(DEBUG, "Channel closed")
127
129
 
128
130
 
129
- def on_channel_state_change(channel_connectivity: str) -> None:
130
- """Log channel connectivity."""
131
- logger(DEBUG, channel_connectivity)
132
-
133
-
134
131
  def log(
135
132
  run_id: Annotated[
136
133
  int,
@@ -157,41 +154,24 @@ def log(
157
154
 
158
155
  pyproject_path = app / "pyproject.toml" if app else None
159
156
  config, errors, warnings = load_and_validate(path=pyproject_path)
160
- config = validate_project_config(config, errors, warnings)
157
+ config = process_loaded_project_config(config, errors, warnings)
161
158
  federation, federation_config = validate_federation_in_project_config(
162
159
  federation, config
163
160
  )
161
+ exit_if_no_address(federation_config, "log")
164
162
 
165
- if "address" not in federation_config:
166
- typer.secho(
167
- "❌ `flwr log` currently works with Exec API. Ensure that the correct"
168
- "Exec API address is provided in the `pyproject.toml`.",
169
- fg=typer.colors.RED,
170
- bold=True,
171
- )
172
- raise typer.Exit(code=1)
173
-
174
- _log_with_exec_api(app, federation_config, run_id, stream)
163
+ _log_with_exec_api(app, federation, federation_config, run_id, stream)
175
164
 
176
165
 
177
166
  def _log_with_exec_api(
178
167
  app: Path,
168
+ federation: str,
179
169
  federation_config: dict[str, Any],
180
170
  run_id: int,
181
171
  stream: bool,
182
172
  ) -> None:
183
-
184
- insecure, root_certificates_bytes = validate_certificate_in_federation_config(
185
- app, federation_config
186
- )
187
- channel = create_channel(
188
- server_address=federation_config["address"],
189
- insecure=insecure,
190
- root_certificates=root_certificates_bytes,
191
- max_message_length=GRPC_MAX_MESSAGE_LENGTH,
192
- interceptors=None,
193
- )
194
- channel.subscribe(on_channel_state_change)
173
+ auth_plugin = try_obtain_cli_auth_plugin(app, federation, federation_config)
174
+ channel = init_channel(app, federation_config, auth_plugin)
195
175
 
196
176
  if stream:
197
177
  start_stream(run_id, channel, CONN_REFRESH_PERIOD)
@@ -0,0 +1,22 @@
1
+ # Copyright 2024 Flower Labs GmbH. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ==============================================================================
15
+ """Flower command line interface `login` command."""
16
+
17
+
18
+ from .login import login as login
19
+
20
+ __all__ = [
21
+ "login",
22
+ ]
@@ -0,0 +1,83 @@
1
+ # Copyright 2024 Flower Labs GmbH. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ==============================================================================
15
+ """Flower command line interface `login` command."""
16
+
17
+
18
+ from pathlib import Path
19
+ from typing import Annotated, Optional
20
+
21
+ import typer
22
+
23
+ from flwr.cli.config_utils import (
24
+ exit_if_no_address,
25
+ load_and_validate,
26
+ process_loaded_project_config,
27
+ validate_federation_in_project_config,
28
+ )
29
+ from flwr.common.constant import AUTH_TYPE
30
+ from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
31
+ GetLoginDetailsRequest,
32
+ GetLoginDetailsResponse,
33
+ )
34
+ from flwr.proto.exec_pb2_grpc import ExecStub
35
+
36
+ from ..utils import init_channel, try_obtain_cli_auth_plugin
37
+
38
+
39
+ def login( # pylint: disable=R0914
40
+ app: Annotated[
41
+ Path,
42
+ typer.Argument(help="Path of the Flower App to run."),
43
+ ] = Path("."),
44
+ federation: Annotated[
45
+ Optional[str],
46
+ typer.Argument(help="Name of the federation to login into."),
47
+ ] = None,
48
+ ) -> None:
49
+ """Login to Flower SuperLink."""
50
+ typer.secho("Loading project configuration... ", fg=typer.colors.BLUE)
51
+
52
+ pyproject_path = app / "pyproject.toml" if app else None
53
+ config, errors, warnings = load_and_validate(path=pyproject_path)
54
+
55
+ config = process_loaded_project_config(config, errors, warnings)
56
+ federation, federation_config = validate_federation_in_project_config(
57
+ federation, config
58
+ )
59
+ exit_if_no_address(federation_config, "login")
60
+ channel = init_channel(app, federation_config, None)
61
+ stub = ExecStub(channel)
62
+
63
+ login_request = GetLoginDetailsRequest()
64
+ login_response: GetLoginDetailsResponse = stub.GetLoginDetails(login_request)
65
+
66
+ # Get the auth plugin
67
+ auth_type = login_response.login_details.get(AUTH_TYPE)
68
+ auth_plugin = try_obtain_cli_auth_plugin(
69
+ app, federation, federation_config, auth_type
70
+ )
71
+ if auth_plugin is None:
72
+ typer.secho(
73
+ f'❌ Authentication type "{auth_type}" not found',
74
+ fg=typer.colors.RED,
75
+ bold=True,
76
+ )
77
+ raise typer.Exit(code=1)
78
+
79
+ # Login
80
+ auth_config = auth_plugin.login(dict(login_response.login_details), stub)
81
+
82
+ # Store the tokens
83
+ auth_plugin.store_tokens(auth_config)