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

flwr/cli/app.py CHANGED
@@ -23,6 +23,7 @@ from .log import log
23
23
  from .ls import ls
24
24
  from .new import new
25
25
  from .run import run
26
+ from .stop import stop
26
27
 
27
28
  app = typer.Typer(
28
29
  help=typer.style(
@@ -39,6 +40,7 @@ app.command()(build)
39
40
  app.command()(install)
40
41
  app.command()(log)
41
42
  app.command()(ls)
43
+ app.command()(stop)
42
44
 
43
45
  typer_click_object = get_command(app)
44
46
 
flwr/cli/stop.py ADDED
@@ -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
+ """Flower command line interface `stop` command."""
16
+
17
+
18
+ from logging import DEBUG
19
+ from pathlib import Path
20
+ from typing import Annotated, Any, Optional
21
+
22
+ import grpc
23
+ import typer
24
+
25
+ from flwr.cli.config_utils import (
26
+ load_and_validate,
27
+ validate_certificate_in_federation_config,
28
+ validate_federation_in_project_config,
29
+ validate_project_config,
30
+ )
31
+ from flwr.common.constant import FAB_CONFIG_FILE
32
+ from flwr.common.grpc import GRPC_MAX_MESSAGE_LENGTH, create_channel
33
+ from flwr.common.logger import log
34
+ from flwr.proto.exec_pb2 import StopRunRequest, StopRunResponse # pylint: disable=E0611
35
+ from flwr.proto.exec_pb2_grpc import ExecStub
36
+
37
+
38
+ def stop(
39
+ run_id: Annotated[ # pylint: disable=unused-argument
40
+ int,
41
+ typer.Argument(help="The Flower run ID to stop"),
42
+ ],
43
+ app: Annotated[
44
+ Path,
45
+ typer.Argument(help="Path of the Flower project"),
46
+ ] = Path("."),
47
+ federation: Annotated[
48
+ Optional[str],
49
+ typer.Argument(help="Name of the federation"),
50
+ ] = None,
51
+ ) -> None:
52
+ """Stop a run."""
53
+ # Load and validate federation config
54
+ typer.secho("Loading project configuration... ", fg=typer.colors.BLUE)
55
+
56
+ pyproject_path = app / FAB_CONFIG_FILE if app else None
57
+ config, errors, warnings = load_and_validate(path=pyproject_path)
58
+ config = validate_project_config(config, errors, warnings)
59
+ federation, federation_config = validate_federation_in_project_config(
60
+ federation, config
61
+ )
62
+
63
+ if "address" not in federation_config:
64
+ typer.secho(
65
+ "❌ `flwr stop` currently works with Exec API. Ensure that the correct"
66
+ "Exec API address is provided in the `pyproject.toml`.",
67
+ fg=typer.colors.RED,
68
+ bold=True,
69
+ )
70
+ raise typer.Exit(code=1)
71
+
72
+ try:
73
+ channel = _init_channel(app, federation_config)
74
+ stub = ExecStub(channel) # pylint: disable=unused-variable # noqa: F841
75
+
76
+ typer.secho(f"✋ Stopping run ID {run_id}...", fg=typer.colors.GREEN)
77
+ _stop_run(stub, run_id=run_id)
78
+
79
+ except ValueError as err:
80
+ typer.secho(
81
+ f"❌ {err}",
82
+ fg=typer.colors.RED,
83
+ bold=True,
84
+ )
85
+ raise typer.Exit(code=1) from err
86
+ finally:
87
+ channel.close()
88
+
89
+
90
+ def on_channel_state_change(channel_connectivity: str) -> None:
91
+ """Log channel connectivity."""
92
+ log(DEBUG, channel_connectivity)
93
+
94
+
95
+ def _init_channel(app: Path, federation_config: dict[str, Any]) -> grpc.Channel:
96
+ """Initialize gRPC channel to the Exec API."""
97
+ insecure, root_certificates_bytes = validate_certificate_in_federation_config(
98
+ app, federation_config
99
+ )
100
+ channel = create_channel(
101
+ server_address=federation_config["address"],
102
+ insecure=insecure,
103
+ root_certificates=root_certificates_bytes,
104
+ max_message_length=GRPC_MAX_MESSAGE_LENGTH,
105
+ interceptors=None,
106
+ )
107
+ channel.subscribe(on_channel_state_change)
108
+ return channel
109
+
110
+
111
+ def _stop_run(
112
+ stub: ExecStub, # pylint: disable=unused-argument
113
+ run_id: int, # pylint: disable=unused-argument
114
+ ) -> None:
115
+ """Stop a run."""
116
+ response: StopRunResponse = stub.StopRun(request=StopRunRequest(run_id=run_id))
117
+
118
+ if response.success:
119
+ typer.secho(f"✅ Run {run_id} successfully stopped.", fg=typer.colors.GREEN)
120
+ else:
121
+ typer.secho(f"❌ Run {run_id} couldn't be stopped.", fg=typer.colors.RED)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: flwr-nightly
3
- Version: 1.14.0.dev20241207
3
+ Version: 1.14.0.dev20241208
4
4
  Summary: Flower: A Friendly Federated AI Framework
5
5
  Home-page: https://flower.ai
6
6
  License: Apache-2.0
@@ -1,6 +1,6 @@
1
1
  flwr/__init__.py,sha256=VmBWedrCxqmt4QvUHBLqyVEH6p7zaFMD_oCHerXHSVw,937
2
2
  flwr/cli/__init__.py,sha256=cZJVgozlkC6Ni2Hd_FAIrqefrkCGOV18fikToq-6iLw,720
3
- flwr/cli/app.py,sha256=h1RCGBUtiL1JTC6yoihlOlB-k4imJ0ToS8uG4haFiyU,1292
3
+ flwr/cli/app.py,sha256=4naV5q1Fepne8XAgdGISxotWSIT__sm0TIHdodSvou4,1335
4
4
  flwr/cli/build.py,sha256=k2M0aIY2q5WB_yXQ22Woxt1zb6m-Z1wNwmhWMxEm5Dw,6344
5
5
  flwr/cli/config_utils.py,sha256=n-xNkQG_0POz5UUHyE00lthNaOjuS6IYU9Thzb_BThs,11431
6
6
  flwr/cli/example.py,sha256=1bGDYll3BXQY2kRqSN-oICqS5n1b9m0g0RvXTopXHl4,2215
@@ -63,6 +63,7 @@ flwr/cli/new/templates/app/pyproject.sklearn.toml.tpl,sha256=01HArBqRrbZT3O7pXOM
63
63
  flwr/cli/new/templates/app/pyproject.tensorflow.toml.tpl,sha256=KVCIOEYNWnq6j7XOboXqZshc9aQ2PyRDUu7bZtmfJ24,710
64
64
  flwr/cli/run/__init__.py,sha256=oCd6HmQDx-sqver1gecgx-uMA38BLTSiiKpl7RGNceg,789
65
65
  flwr/cli/run/run.py,sha256=5To92BOrfM5VEwNp2zzRUoz4tHE2NtazxIQICProA8k,8503
66
+ flwr/cli/stop.py,sha256=OrV_znXyu3t_gABHisAA6uHwFdFPP2Z9bKvhcE1O5Yk,4116
66
67
  flwr/cli/utils.py,sha256=emMUdthvoHBTB0iGQp-oFBmA5wV46lw3y3FmfXQPCsc,4500
67
68
  flwr/client/__init__.py,sha256=DGDoO0AEAfz-0CUFmLdyUUweAS64-07AOnmDfWUefK4,1192
68
69
  flwr/client/app.py,sha256=3AKrJduvki_1ATvKCQV4T9_1qZuarVVTtpnsq6_cWw0,34384
@@ -313,8 +314,8 @@ flwr/superexec/exec_grpc.py,sha256=OuhBAk7hiky9rjGceinLGIXqchtzGPQThZnwyYv6Ei0,2
313
314
  flwr/superexec/exec_servicer.py,sha256=qHWbGRuP702-JxlxFuztGlRdRoNET8G-0m1xwnoZgig,6016
314
315
  flwr/superexec/executor.py,sha256=zH3_53il6Jh0ZscIVEB9f4GNnXMeBbCGyCoBCxLgiG0,3114
315
316
  flwr/superexec/simulation.py,sha256=WQDon15oqpMopAZnwRZoTICYCfHqtkvFSqiTQ2hLD_g,4088
316
- flwr_nightly-1.14.0.dev20241207.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
317
- flwr_nightly-1.14.0.dev20241207.dist-info/METADATA,sha256=5QsxHSr8typyN39O_YyHaD3g5t7viGIA7rxbethV6iU,15679
318
- flwr_nightly-1.14.0.dev20241207.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
319
- flwr_nightly-1.14.0.dev20241207.dist-info/entry_points.txt,sha256=JlNxX3qhaV18_2yj5a3kJW1ESxm31cal9iS_N_pf1Rk,538
320
- flwr_nightly-1.14.0.dev20241207.dist-info/RECORD,,
317
+ flwr_nightly-1.14.0.dev20241208.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
318
+ flwr_nightly-1.14.0.dev20241208.dist-info/METADATA,sha256=gRPLRI4oVh__pq8EKcawfWKgN8zkz7nB-4QnrtFiWfs,15679
319
+ flwr_nightly-1.14.0.dev20241208.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
320
+ flwr_nightly-1.14.0.dev20241208.dist-info/entry_points.txt,sha256=JlNxX3qhaV18_2yj5a3kJW1ESxm31cal9iS_N_pf1Rk,538
321
+ flwr_nightly-1.14.0.dev20241208.dist-info/RECORD,,