Skip to content

Commit

Permalink
Add NumPy template to new command (#3059)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanertopal authored Mar 5, 2024
1 parent a5cf735 commit 4fd9f85
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/py/flwr/cli/new/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class MlFramework(str, Enum):
"""Available frameworks."""

NUMPY = "NumPy"
PYTORCH = "PyTorch"
TENSORFLOW = "TensorFlow"

Expand Down
24 changes: 24 additions & 0 deletions src/py/flwr/cli/new/templates/app/code/client.numpy.py.tpl
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions src/py/flwr/cli/new/templates/app/code/server.numpy.py.tpl
Original file line number Diff line number Diff line change
@@ -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,
)
4 changes: 2 additions & 2 deletions src/py/flwr/cli/new/templates/app/flower.toml.tpl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[flower]
[project]
name = "$project_name"
version = "1.0.0"
description = ""
license = "Apache-2.0"
authors = ["The Flower Authors <hello@flower.ai>"]

[components]
[flower.components]
serverapp = "$project_name.server:app"
clientapp = "$project_name.client:app"
2 changes: 2 additions & 0 deletions src/py/flwr/cli/new/templates/app/requirements.numpy.txt.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flwr>=1.8, <2.0
numpy >= 1.21.0

0 comments on commit 4fd9f85

Please sign in to comment.