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) Update context registration when running an app directory #3815

Merged
merged 7 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
6 changes: 3 additions & 3 deletions src/py/flwr/client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _start_client_internal(
] = None,
max_retries: Optional[int] = None,
max_wait_time: Optional[float] = None,
flwr_dir: Optional[Path] = None,
flwr_path: Optional[Path] = None,
) -> None:
"""Start a Flower client node which connects to a Flower server.

Expand Down Expand Up @@ -241,7 +241,7 @@ class `flwr.client.Client` (default: None)
The maximum duration before the client stops trying to
connect to the server in case of connection error.
If set to None, there is no limit to the total time.
flwr_dir: Optional[Path] (default: None)
flwr_path: Optional[Path] (default: None)
The fully resolved path containing installed Flower Apps.
"""
if insecure is None:
Expand Down Expand Up @@ -402,7 +402,7 @@ def _on_backoff(retry_state: RetryState) -> None:

# Register context for this run
node_state.register_context(
run_id=run_id, run=runs[run_id], flwr_dir=flwr_dir
run_id=run_id, run=runs[run_id], flwr_path=flwr_path
)

# Retrieve context for this run
Expand Down
18 changes: 15 additions & 3 deletions src/py/flwr/client/node_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from typing import Dict, Optional

from flwr.common import Context, RecordSet
from flwr.common.config import get_fused_config
from flwr.common.config import get_fused_config, get_fused_config_from_dir
from flwr.common.typing import Run


Expand Down Expand Up @@ -48,11 +48,23 @@ def register_context(
self,
run_id: int,
run: Optional[Run] = None,
flwr_dir: Optional[Path] = None,
flwr_path: Optional[Path] = None,
app_dir: Optional[str] = None,
) -> None:
"""Register new run context for this node."""
if run_id not in self.run_infos:
initial_run_config = get_fused_config(run, flwr_dir) if run else {}
initial_run_config = {}
if app_dir:
# Load from FAB-like directory
jafermarq marked this conversation as resolved.
Show resolved Hide resolved
app_path = Path(app_dir)
if app_path.is_dir():
jafermarq marked this conversation as resolved.
Show resolved Hide resolved
override_config = run.override_config if run else {}
initial_run_config = get_fused_config_from_dir(
app_path, override_config
)
else:
# Load from .fab
initial_run_config = get_fused_config(run, flwr_path) if run else {}
self.run_infos[run_id] = RunInfo(
initial_run_config=initial_run_config,
context=Context(
Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/client/supernode/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def run_supernode() -> None:
max_retries=args.max_retries,
max_wait_time=args.max_wait_time,
node_config=parse_config_args(args.node_config),
flwr_dir=get_flwr_dir(args.flwr_dir),
flwr_path=get_flwr_dir(args.flwr_dir),
)

# Graceful shutdown
Expand Down
Loading