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) Add federation argument to flwr run #3807

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Changes from all 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
30 changes: 23 additions & 7 deletions src/py/flwr/cli/run/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def run(
Path,
typer.Argument(help="Path of the Flower project to run"),
] = Path("."),
federation_name: Annotated[
Optional[str],
typer.Argument(help="Name of the federation to run the app on"),
] = None,
config_overrides: Annotated[
Optional[str],
typer.Option(
Expand Down Expand Up @@ -73,18 +77,30 @@ def run(

typer.secho("Success", fg=typer.colors.GREEN)

try:
federation_name = config["flower"]["federations"]["default"]
federation = config["flower"]["federations"][federation_name]
except KeyError as err:
federation_name = federation_name or config["flower"]["federations"].get("default")

if federation_name is None:
typer.secho(
"❌ The project's `pyproject.toml` needs to declare "
"a default federation (with a SuperExec address or an "
"❌ No federation name was provided and the project's `pyproject.toml` "
"doesn't declare a default federation (with a SuperExec address or an "
"`options.num-supernodes` value).",
fg=typer.colors.RED,
bold=True,
)
raise typer.Exit(code=1) from err
raise typer.Exit(code=1)

# Validate the federation exists in the configuration
federation = config["flower"]["federations"].get(federation_name)
if federation is None:
available_feds = list(config["flower"]["federations"])
typer.secho(
f"❌ There is no `{federation_name}` federation declared in the "
"`pyproject.toml`.\n The following federations were found:\n\n"
"\n".join(available_feds) + "\n\n",
fg=typer.colors.RED,
bold=True,
)
raise typer.Exit(code=1)

if "address" in federation:
_run_with_superexec(federation, directory, config_overrides)
Expand Down