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

refactor(framework) Switch to tool.flwr instead of flower in pyproject.toml #3809

Merged
merged 5 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/py/flwr/cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def build(

# Set the name of the zip file
fab_filename = (
f"{conf['flower']['publisher']}"
f"{conf['tool']['flwr']['publisher']}"
f".{directory.name}"
f".{conf['project']['version'].replace('.', '-')}.fab"
)
Expand Down
30 changes: 15 additions & 15 deletions src/py/flwr/cli/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_fab_metadata(fab_file: Union[Path, bytes]) -> Tuple[str, str]:

return (
conf["project"]["version"],
f"{conf['flower']['publisher']}/{conf['project']['name']}",
f"{conf['tool']['flwr']['publisher']}/{conf['project']['name']}",
)


Expand Down Expand Up @@ -136,20 +136,20 @@ def validate_fields(config: Dict[str, Any]) -> Tuple[bool, List[str], List[str]]
if "authors" not in config["project"]:
warnings.append('Recommended property "authors" missing in [project]')

if "flower" not in config:
errors.append("Missing [flower] section")
if "tool" not in config or "flwr" not in config["tool"]:
errors.append("Missing [tool.flwr] section")
else:
if "publisher" not in config["flower"]:
errors.append('Property "publisher" missing in [flower]')
if "config" in config["flower"]:
_validate_run_config(config["flower"]["config"], errors)
if "components" not in config["flower"]:
errors.append("Missing [flower.components] section")
if "publisher" not in config["tool"]["flwr"]:
errors.append('Property "publisher" missing in [tool.flwr]')
if "config" in config["tool"]["flwr"]:
_validate_run_config(config["tool"]["flwr"]["config"], errors)
if "components" not in config["tool"]["flwr"]:
errors.append("Missing [tool.flwr.components] section")
else:
if "serverapp" not in config["flower"]["components"]:
errors.append('Property "serverapp" missing in [flower.components]')
if "clientapp" not in config["flower"]["components"]:
errors.append('Property "clientapp" missing in [flower.components]')
if "serverapp" not in config["tool"]["flwr"]["components"]:
errors.append('Property "serverapp" missing in [tool.flwr.components]')
if "clientapp" not in config["tool"]["flwr"]["components"]:
errors.append('Property "clientapp" missing in [tool.flwr.components]')

return len(errors) == 0, errors, warnings

Expand All @@ -165,14 +165,14 @@ def validate(

# Validate serverapp
is_valid, reason = object_ref.validate(
config["flower"]["components"]["serverapp"], check_module
config["tool"]["flwr"]["components"]["serverapp"], check_module
)
if not is_valid and isinstance(reason, str):
return False, [reason], []

# Validate clientapp
is_valid, reason = object_ref.validate(
config["flower"]["components"]["clientapp"], check_module
config["tool"]["flwr"]["components"]["clientapp"], check_module
)

if not is_valid and isinstance(reason, str):
Expand Down
96 changes: 39 additions & 57 deletions src/py/flwr/cli/config_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,47 +34,35 @@ def test_load_pyproject_toml_load_from_cwd(tmp_path: Path) -> None:
name = "fedgpt"
version = "1.0.0"
description = ""
authors = [
{ name = "The Flower Authors", email = "hello@flower.ai" },
]
license = {text = "Apache License (2.0)"}
dependencies = [
"flwr[simulation]>=1.9.0,<2.0",
"numpy>=1.21.0",
]

[flower]
[tool.flwr]
publisher = "flwrlabs"

[flower.components]
[tool.flwr.components]
serverapp = "fedgpt.server:app"
clientapp = "fedgpt.client:app"

[flower.engine]
name = "simulation" # optional

[flower.engine.simulation.supernode]
count = 10 # optional
"""
expected_config = {
"build-system": {"build-backend": "hatchling.build", "requires": ["hatchling"]},
"project": {
"name": "fedgpt",
"version": "1.0.0",
"description": "",
"authors": [{"email": "hello@flower.ai", "name": "The Flower Authors"}],
"license": {"text": "Apache License (2.0)"},
"dependencies": ["flwr[simulation]>=1.9.0,<2.0", "numpy>=1.21.0"],
},
"flower": {
"publisher": "flwrlabs",
"components": {
"serverapp": "fedgpt.server:app",
"clientapp": "fedgpt.client:app",
},
"engine": {
"name": "simulation",
"simulation": {"supernode": {"count": 10}},
"tool": {
"flwr": {
"publisher": "flwrlabs",
"components": {
"serverapp": "fedgpt.server:app",
"clientapp": "fedgpt.client:app",
},
},
},
}
Expand Down Expand Up @@ -109,47 +97,35 @@ def test_load_pyproject_toml_from_path(tmp_path: Path) -> None:
name = "fedgpt"
version = "1.0.0"
description = ""
authors = [
{ name = "The Flower Authors", email = "hello@flower.ai" },
]
license = {text = "Apache License (2.0)"}
dependencies = [
"flwr[simulation]>=1.9.0,<2.0",
"numpy>=1.21.0",
]

[flower]
[tool.flwr]
publisher = "flwrlabs"

[flower.components]
[tool.flwr.components]
serverapp = "fedgpt.server:app"
clientapp = "fedgpt.client:app"

[flower.engine]
name = "simulation" # optional

[flower.engine.simulation.supernode]
count = 10 # optional
"""
expected_config = {
"build-system": {"build-backend": "hatchling.build", "requires": ["hatchling"]},
"project": {
"name": "fedgpt",
"version": "1.0.0",
"description": "",
"authors": [{"email": "hello@flower.ai", "name": "The Flower Authors"}],
"license": {"text": "Apache License (2.0)"},
"dependencies": ["flwr[simulation]>=1.9.0,<2.0", "numpy>=1.21.0"],
},
"flower": {
"publisher": "flwrlabs",
"components": {
"serverapp": "fedgpt.server:app",
"clientapp": "fedgpt.client:app",
},
"engine": {
"name": "simulation",
"simulation": {"supernode": {"count": 10}},
"tool": {
"flwr": {
"publisher": "flwrlabs",
"components": {
"serverapp": "fedgpt.server:app",
"clientapp": "fedgpt.client:app",
},
},
},
}
Expand Down Expand Up @@ -219,7 +195,7 @@ def test_validate_pyproject_toml_fields_no_flower_components() -> None:
"license": "",
"authors": [],
},
"flower": {},
"tool": {"flwr": {}},
}

# Execute
Expand All @@ -242,7 +218,7 @@ def test_validate_pyproject_toml_fields_no_server_and_client_app() -> None:
"license": "",
"authors": [],
},
"flower": {"components": {}},
"tool": {"flwr": {"components": {}}},
}

# Execute
Expand All @@ -265,9 +241,11 @@ def test_validate_pyproject_toml_fields() -> None:
"license": "",
"authors": [],
},
"flower": {
"publisher": "flwrlabs",
"components": {"serverapp": "", "clientapp": ""},
"tool": {
"flwr": {
"publisher": "flwrlabs",
"components": {"serverapp": "", "clientapp": ""},
},
},
}

Expand All @@ -291,11 +269,13 @@ def test_validate_pyproject_toml() -> None:
"license": "",
"authors": [],
},
"flower": {
"publisher": "flwrlabs",
"components": {
"serverapp": "flwr.cli.run:run",
"clientapp": "flwr.cli.run:run",
"tool": {
"flwr": {
"publisher": "flwrlabs",
"components": {
"serverapp": "flwr.cli.run:run",
"clientapp": "flwr.cli.run:run",
},
},
},
}
Expand All @@ -320,11 +300,13 @@ def test_validate_pyproject_toml_fail() -> None:
"license": "",
"authors": [],
},
"flower": {
"publisher": "flwrlabs",
"components": {
"serverapp": "flwr.cli.run:run",
"clientapp": "flwr.cli.run:runa",
"tool": {
"flwr": {
"publisher": "flwrlabs",
"components": {
"serverapp": "flwr.cli.run:run",
"clientapp": "flwr.cli.run:runa",
},
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def validate_and_install(
)
raise typer.Exit(code=1)

publisher = config["flower"]["publisher"]
publisher = config["tool"]["flwr"]["publisher"]
project_name = config["project"]["name"]
version = config["project"]["version"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ dependencies = [
[tool.hatch.build.targets.wheel]
packages = ["."]

[flower]
[tool.flwr]
publisher = "$username"

[flower.components]
[tool.flwr.components]
serverapp = "$import_name.app:server"
clientapp = "$import_name.app:client"

[flower.federations]
[tool.flwr.federations]
default = "localhost"

[flower.federations.localhost]
[tool.flwr.federations.localhost]
options.num-supernodes = 10
8 changes: 4 additions & 4 deletions src/py/flwr/cli/new/templates/app/pyproject.hf.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ dependencies = [
[tool.hatch.build.targets.wheel]
packages = ["."]

[flower]
[tool.flwr]
publisher = "$username"

[flower.components]
[tool.flwr.components]
serverapp = "$import_name.server:app"
clientapp = "$import_name.client:app"

[flower.federations]
[tool.flwr.federations]
default = "localhost"

[flower.federations.localhost]
[tool.flwr.federations.localhost]
options.num-supernodes = 10
8 changes: 4 additions & 4 deletions src/py/flwr/cli/new/templates/app/pyproject.jax.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ dependencies = [
[tool.hatch.build.targets.wheel]
packages = ["."]

[flower]
[tool.flwr]
publisher = "$username"

[flower.components]
[tool.flwr.components]
serverapp = "$import_name.server:app"
clientapp = "$import_name.client:app"

[flower.federations]
[tool.flwr.federations]
default = "localhost"

[flower.federations.localhost]
[tool.flwr.federations.localhost]
options.num-supernodes = 10
8 changes: 4 additions & 4 deletions src/py/flwr/cli/new/templates/app/pyproject.mlx.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ dependencies = [
[tool.hatch.build.targets.wheel]
packages = ["."]

[flower]
[tool.flwr]
publisher = "$username"

[flower.components]
[tool.flwr.components]
serverapp = "$import_name.server:app"
clientapp = "$import_name.client:app"

[flower.federations]
[tool.flwr.federations]
default = "localhost"

[flower.federations.localhost]
[tool.flwr.federations.localhost]
options.num-supernodes = 10
8 changes: 4 additions & 4 deletions src/py/flwr/cli/new/templates/app/pyproject.numpy.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ dependencies = [
[tool.hatch.build.targets.wheel]
packages = ["."]

[flower]
[tool.flwr]
publisher = "$username"

[flower.components]
[tool.flwr.components]
serverapp = "$import_name.server:app"
clientapp = "$import_name.client:app"

[flower.federations]
[tool.flwr.federations]
default = "localhost"

[flower.federations.localhost]
[tool.flwr.federations.localhost]
options.num-supernodes = 10
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ dependencies = [
[tool.hatch.build.targets.wheel]
packages = ["."]

[flower]
[tool.flwr]
publisher = "$username"

[flower.components]
[tool.flwr.components]
serverapp = "$import_name.server:app"
clientapp = "$import_name.client:app"

[flower.federations]
[tool.flwr.federations]
default = "localhost"

[flower.federations.localhost]
[tool.flwr.federations.localhost]
options.num-supernodes = 10
Loading