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

feat(framework) Allow flower-server-app to start with run_id #3658

Merged
merged 45 commits into from
Jun 21, 2024
Merged
Changes from 37 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
82a399a
add run proto
panh99 Jun 11, 2024
019d490
implement getrun in driver_servicer and grpc_driver
panh99 Jun 11, 2024
322440e
Merge remote-tracking branch 'origin/impl-get-run-driver' into add-ru…
panh99 Jun 12, 2024
54b185a
Merge branch 'main' into impl-get-run-driver
panh99 Jun 12, 2024
df79edb
Merge branch 'impl-get-run-driver' into add-run-id-to-server-app-cli
panh99 Jun 12, 2024
e6cbede
Merge branch 'main' into impl-get-run-driver
panh99 Jun 13, 2024
bf3cd3b
Merge branch 'main' into impl-get-run-driver
panh99 Jun 14, 2024
5bc1c9c
Merge branch 'main' into impl-get-run-driver
danieljanes Jun 18, 2024
7c82082
amend driver class and in mem driver
panh99 Jun 18, 2024
20d66ea
Merge branch 'main' into add-run-id-to-server-app-cli
panh99 Jun 18, 2024
06d68dc
add run_id arg
panh99 Jun 18, 2024
f9f8a10
Merge branch 'main' into impl-get-run-driver
danieljanes Jun 18, 2024
1150474
Merge branch 'main' into impl-get-run-driver
danieljanes Jun 18, 2024
6ef8ceb
update with main
panh99 Jun 19, 2024
bf10f81
fix the test for in mem driver
panh99 Jun 19, 2024
b57eeb7
Merge branch 'main' into impl-get-run-driver
panh99 Jun 19, 2024
0a09223
Merge branch 'main' into impl-get-run-driver
panh99 Jun 19, 2024
5461e5d
make run_id mandatory
panh99 Jun 19, 2024
77f8927
Merge branch 'main' into impl-get-run-driver
panh99 Jun 19, 2024
dcc6cfd
fix a bug in _init_run_id in simulation
panh99 Jun 19, 2024
dc03386
format
panh99 Jun 19, 2024
c786e65
Merge remote-tracking branch 'origin/impl-get-run-driver' into add-ru…
panh99 Jun 19, 2024
130435f
amend run_server_app
panh99 Jun 19, 2024
b983714
Merge remote-tracking branch 'origin/main' into add-run-id-to-server-…
panh99 Jun 20, 2024
454722d
restore
panh99 Jun 20, 2024
0fea381
restore
panh99 Jun 20, 2024
9000964
format
panh99 Jun 20, 2024
df6502d
connect
panh99 Jun 20, 2024
b197b2c
update run_serverapp
panh99 Jun 20, 2024
f45eac6
add sancheck
panh99 Jun 20, 2024
ccbc986
use sys.exit
panh99 Jun 20, 2024
958f826
Merge branch 'main' into add-run-id-to-server-app-cli
panh99 Jun 20, 2024
ad1ff9d
rm empty spaces
panh99 Jun 20, 2024
c6846a6
Merge remote-tracking branch 'refs/remotes/origin/add-run-id-to-serve…
panh99 Jun 20, 2024
60dcb2d
Merge branch 'main' into add-run-id-to-server-app-cli
panh99 Jun 20, 2024
30fb153
Merge branch 'main' into add-run-id-to-server-app-cli
panh99 Jun 20, 2024
62e85a0
Update src/py/flwr/server/run_serverapp.py
danieljanes Jun 20, 2024
13abfad
Merge remote-tracking branch 'origin/main' into add-run-id-to-server-…
panh99 Jun 21, 2024
3d6a321
update based on comments
panh99 Jun 21, 2024
fb485c6
update exit message
panh99 Jun 21, 2024
25b9b1f
update msg
panh99 Jun 21, 2024
e06c4dc
Apply suggestions from code review
danieljanes Jun 21, 2024
e661d63
Update src/py/flwr/server/run_serverapp.py
danieljanes Jun 21, 2024
9d97dbd
Update src/py/flwr/server/run_serverapp.py
danieljanes Jun 21, 2024
5601c05
Format
danieljanes Jun 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 58 additions & 20 deletions src/py/flwr/server/run_serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from typing import Optional

from flwr.common import Context, EventType, RecordSet, event
from flwr.common.config import get_flwr_dir, get_project_config, get_project_dir
from flwr.common.logger import log, update_console_handler, warn_deprecated_feature
from flwr.common.object_ref import load_app
from flwr.proto.driver_pb2 import CreateRunRequest # pylint: disable=E0611
Expand All @@ -43,7 +44,7 @@ def run(
if not (server_app_attr is None) ^ (loaded_server_app is None):
raise ValueError(
"Either `server_app_attr` or `loaded_server_app` should be set "
"but not both. "
"but not both."
)

if server_app_dir is not None:
Expand Down Expand Up @@ -76,7 +77,7 @@ def _load() -> ServerApp:
log(DEBUG, "ServerApp finished running.")


def run_server_app() -> None:
def run_server_app() -> None: # pylint: disable=too-many-branches
"""Run Flower server app."""
event(EventType.RUN_SERVER_APP_ENTER)

Expand Down Expand Up @@ -136,32 +137,50 @@ def run_server_app() -> None:
cert_path,
)

log(
DEBUG,
"Flower will load ServerApp `%s`",
getattr(args, "server-app"),
if not (getattr(args, "server-app") is None) ^ (args.run_id is None):
panh99 marked this conversation as resolved.
Show resolved Hide resolved
raise sys.exit(
"Invalid options: Either `server-app` or `--run-id` "
"should be set but not both."
danieljanes marked this conversation as resolved.
Show resolved Hide resolved
)

stub = GrpcDriverStub(
driver_service_address=args.superlink, root_certificates=root_certificates
)
# Create run if run_id is not provided
if args.run_id is None:
stub.connect()
danieljanes marked this conversation as resolved.
Show resolved Hide resolved
req = CreateRunRequest(fab_id=args.fab_id, fab_version=args.fab_version)
res = stub.create_run(req)
run_id = res.run_id
else:
run_id = args.run_id
danieljanes marked this conversation as resolved.
Show resolved Hide resolved

# Initialize GrpcDriver
driver = GrpcDriver(run_id=run_id, stub=stub)

# Dynamically obtain ServerApp path based on run_id
if args.run_id is not None:
if args.flwr_dir is None:
flwr_dir = get_flwr_dir()
else:
flwr_dir = Path(args.flwr_dir).absolute()
panh99 marked this conversation as resolved.
Show resolved Hide resolved
server_app_dir = str(
get_project_dir(driver.run.fab_id, driver.run.fab_version, flwr_dir)
)
panh99 marked this conversation as resolved.
Show resolved Hide resolved
config = get_project_config(server_app_dir)
danieljanes marked this conversation as resolved.
Show resolved Hide resolved
server_app_attr = config["flower"]["components"]["serverapp"]
else:
server_app_dir = str(Path(args.dir).absolute())
danieljanes marked this conversation as resolved.
Show resolved Hide resolved
server_app_attr = getattr(args, "server-app")
panh99 marked this conversation as resolved.
Show resolved Hide resolved

log(DEBUG, "Flower will load ServerApp `%s` in %s", server_app_attr, server_app_dir)

log(
DEBUG,
"root_certificates: `%s`",
root_certificates,
)

server_app_dir = args.dir
server_app_attr = getattr(args, "server-app")

# Create run
stub = GrpcDriverStub(
driver_service_address=args.superlink, root_certificates=root_certificates
)
stub.connect()
req = CreateRunRequest(fab_id=args.fab_id, fab_version=args.fab_version)
res = stub.create_run(req)

# Initialize GrpcDriver
driver = GrpcDriver(run_id=res.run_id, stub=stub)

# Run the ServerApp with the Driver
run(driver=driver, server_app_dir=server_app_dir, server_app_attr=server_app_attr)

Expand All @@ -179,6 +198,8 @@ def _parse_args_run_server_app() -> argparse.ArgumentParser:

parser.add_argument(
"server-app",
nargs="?",
default=None,
help="For example: `server:app` or `project.package.module:wrapper.app`",
)
parser.add_argument(
Expand Down Expand Up @@ -228,5 +249,22 @@ def _parse_args_run_server_app() -> argparse.ArgumentParser:
type=str,
help="The version of the FAB used in the run.",
)
parser.add_argument(
"--run-id",
default=None,
type=int,
help="The identifier of the run.",
)
parser.add_argument(
"--flwr-dir",
default=None,
help="""The path containing installed Flower Apps.
By default, this value is equal to:

- `$FLWR_HOME/` if `$FLWR_HOME` is defined
- `$XDG_DATA_HOME/.flwr/` if `$XDG_DATA_HOME` is defined
- `$HOME/.flwr/` in all other cases
""",
)

return parser