Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce flower-{driver,fleet}-api #1664

Merged
merged 10 commits into from
Feb 15, 2023
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ exclude = [
]

[tool.poetry.scripts]
flower-driver-api = "flwr.server:run_driver_api"
flower-fleet-api = "flwr.server:run_fleet_api"
flower-server = "flwr.server:run_server"
flower-client = "flwr.client:run_client"

Expand Down
10 changes: 9 additions & 1 deletion src/py/flwr/common/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ def _generate_next_value_(name: str, start: int, count: int, last_values: List[A
START_SERVER_ENTER = auto()
START_SERVER_LEAVE = auto()

# New Server
# Driver API
RUN_DRIVER_API_ENTER = auto()
RUN_DRIVER_API_LEAVE = auto()

# Fleet API
RUN_FLEET_API_ENTER = auto()
RUN_FLEET_API_LEAVE = auto()

# Driver API and Fleet API
RUN_SERVER_ENTER = auto()
RUN_SERVER_LEAVE = auto()

Expand Down
6 changes: 5 additions & 1 deletion src/py/flwr/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@


from .app import ServerConfig as ServerConfig
from .app import run_driver_api as run_driver_api
from .app import run_fleet_api as run_fleet_api
from .app import run_server as run_server
from .app import start_server as start_server
from .client_manager import ClientManager as ClientManager
Expand All @@ -25,10 +27,12 @@

__all__ = [
"ClientManager",
"ServerConfig",
"History",
"run_driver_api",
"run_fleet_api",
"run_server",
"Server",
"ServerConfig",
"SimpleClientManager",
"start_server",
]
73 changes: 73 additions & 0 deletions src/py/flwr/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,57 @@ def _fl(
return hist


def run_driver_api() -> None:
"""Run Flower server (Driver API)."""

log(INFO, "Starting Flower server (Driver API)")
event(EventType.RUN_DRIVER_API_ENTER)
args = _parse_args_driver()

# Init state
state = InMemoryState()

# Start server
grpc_server: grpc.Server = _run_driver_api_grpc(
address=args.driver_api_address,
state=state,
)

# Graceful shutdown
_register_exit_handlers(
grpc_servers=[grpc_server],
event_type=EventType.RUN_DRIVER_API_LEAVE,
)

# Block
grpc_server.wait_for_termination()


def run_fleet_api() -> None:
"""Run Flower server (Fleet API)."""

log(INFO, "Starting Flower server (Fleet API)")
event(EventType.RUN_FLEET_API_ENTER)
args = _parse_args_fleet()

# Init state
state = InMemoryState()

# Start server
grpc_server: grpc.Server = _run_fleet_api_grpc_bidi(
address=args.fleet_api_address,
state=state,
)

_register_exit_handlers(
grpc_servers=[grpc_server],
event_type=EventType.RUN_FLEET_API_LEAVE,
)

# Block
grpc_server.wait_for_termination()


def run_server() -> None:
"""Run Flower server (Driver API and Fleet API)."""

Expand Down Expand Up @@ -338,6 +389,28 @@ def _run_fleet_api_grpc_bidi(
return fleet_grpc_server


def _parse_args_driver() -> argparse.Namespace:
"""Parse command line arguments for Driver API."""
parser = argparse.ArgumentParser(
description="Start Flower server (Driver API)",
)

_add_arg_driver_api_address(parser=parser)

return parser.parse_args()


def _parse_args_fleet() -> argparse.Namespace:
"""Parse command line arguments for Fleet API."""
parser = argparse.ArgumentParser(
description="Start Flower server (Fleet API)",
)

_add_arg_fleet_api_address(parser=parser)

return parser.parse_args()


def _parse_args() -> argparse.Namespace:
"""Parse command line arguments for both Driver API and Fleet API."""
parser = argparse.ArgumentParser(
Expand Down