diff --git a/src/py/flwr/cli/new/new.py b/src/py/flwr/cli/new/new.py index d5db6091344d..04e28efdf76a 100644 --- a/src/py/flwr/cli/new/new.py +++ b/src/py/flwr/cli/new/new.py @@ -28,6 +28,7 @@ class MlFramework(str, Enum): """Available frameworks.""" + NUMPY = "NumPy" PYTORCH = "PyTorch" TENSORFLOW = "TensorFlow" diff --git a/src/py/flwr/cli/new/templates/app/code/client.numpy.py.tpl b/src/py/flwr/cli/new/templates/app/code/client.numpy.py.tpl new file mode 100644 index 000000000000..cf24457c8d2c --- /dev/null +++ b/src/py/flwr/cli/new/templates/app/code/client.numpy.py.tpl @@ -0,0 +1,24 @@ +"""$project_name: A Flower / NumPy app.""" + +import flwr as fl +import numpy as np + + +# Flower client, adapted from Pytorch quickstart example +class FlowerClient(fl.client.NumPyClient): + def get_parameters(self, config): + return [np.ones((1, 1))] + + def fit(self, parameters, config): + return ([np.ones((1, 1))], 1, {}) + + def evaluate(self, parameters, config): + return float(0.0), 1, {"accuracy": float(1.0)} + + +def client_fn(cid: str): + return FlowerClient().to_client() + + +# ClientApp for Flower-Next +app = fl.client.ClientApp(client_fn=client_fn) diff --git a/src/py/flwr/cli/new/templates/app/code/server.numpy.py.tpl b/src/py/flwr/cli/new/templates/app/code/server.numpy.py.tpl new file mode 100644 index 000000000000..03f95ae35cfd --- /dev/null +++ b/src/py/flwr/cli/new/templates/app/code/server.numpy.py.tpl @@ -0,0 +1,12 @@ +"""$project_name: A Flower / NumPy app.""" + +import flwr as fl + +# Configure the strategy +strategy = fl.server.strategy.FedAvg() + +# Flower ServerApp +app = fl.server.ServerApp( + config=fl.server.ServerConfig(num_rounds=1), + strategy=strategy, +) diff --git a/src/py/flwr/cli/new/templates/app/flower.toml.tpl b/src/py/flwr/cli/new/templates/app/flower.toml.tpl index 4dd7117bc3a3..e171783527af 100644 --- a/src/py/flwr/cli/new/templates/app/flower.toml.tpl +++ b/src/py/flwr/cli/new/templates/app/flower.toml.tpl @@ -1,10 +1,10 @@ -[flower] +[project] name = "$project_name" version = "1.0.0" description = "" license = "Apache-2.0" authors = ["The Flower Authors "] -[components] +[flower.components] serverapp = "$project_name.server:app" clientapp = "$project_name.client:app" diff --git a/src/py/flwr/cli/new/templates/app/requirements.numpy.txt.tpl b/src/py/flwr/cli/new/templates/app/requirements.numpy.txt.tpl new file mode 100644 index 000000000000..dfb385079b23 --- /dev/null +++ b/src/py/flwr/cli/new/templates/app/requirements.numpy.txt.tpl @@ -0,0 +1,2 @@ +flwr>=1.8, <2.0 +numpy >= 1.21.0