Skip to content

Commit

Permalink
rename make_app to make_fc
Browse files Browse the repository at this point in the history
  • Loading branch information
panh99 committed Dec 1, 2023
1 parent d4a9f7d commit 2df4116
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
23 changes: 9 additions & 14 deletions src/py/flwr/client/flower.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from typing import List, Optional, cast

from flwr.client.message_handler.message_handler import handle
from flwr.client.middleware.utils import make_app
from flwr.client.middleware.utils import make_fc
from flwr.client.typing import Bwd, ClientFn, Fwd, Layer


Expand Down Expand Up @@ -54,26 +54,21 @@ def __init__(
client_fn: ClientFn, # Only for backward compatibility
middleware: Optional[List[Layer]] = None,
) -> None:
self.client_fn = client_fn
self.mw_list = middleware if middleware is not None else []

def __call__(self, fwd: Fwd) -> Bwd:
"""."""

# Create wrapper function for `handle`
def handle_app(_fwd: Fwd) -> Bwd:
def fn(fwd: Fwd) -> Bwd:
task_res, state_updated = handle(
client_fn=self.client_fn,
state=_fwd.state,
task_ins=_fwd.task_ins,
client_fn=client_fn,
state=fwd.state,
task_ins=fwd.task_ins,
)
return Bwd(task_res=task_res, state=state_updated)

# Wrap middleware layers around handle_app
app = make_app(handle_app, self.mw_list)
self._call = make_fc(fn, middleware if middleware is not None else [])

# Execute the task
return app(fwd)
def __call__(self, fwd: Fwd) -> Bwd:
"""."""
return self._call(fwd)


class LoadCallableError(Exception):
Expand Down
4 changes: 2 additions & 2 deletions src/py/flwr/client/middleware/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"""Middleware layers."""


from .utils import make_app
from .utils import make_fc

__all__ = [
"make_app",
"make_fc",
]
2 changes: 1 addition & 1 deletion src/py/flwr/client/middleware/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from flwr.client.typing import Bwd, FlowerCallable, Fwd, Layer


def make_app(app: FlowerCallable, middleware_layers: List[Layer]) -> FlowerCallable:
def make_fc(app: FlowerCallable, middleware_layers: List[Layer]) -> FlowerCallable:
"""."""

def wrap_app(_app: FlowerCallable, _layer: Layer) -> FlowerCallable:
Expand Down
6 changes: 3 additions & 3 deletions src/py/flwr/client/middleware/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from flwr.client.workload_state import WorkloadState
from flwr.proto.task_pb2 import TaskIns, TaskRes

from .utils import make_app
from .utils import make_fc


def make_mock_middleware(name: str, footprint: List[str]) -> Layer:
Expand Down Expand Up @@ -65,7 +65,7 @@ def test_multiple_middlewares(self) -> None:
task_ins = TaskIns()

# Execute
wrapped_app = make_app(mock_app, mock_middleware_layers)
wrapped_app = make_fc(mock_app, mock_middleware_layers)
task_res = wrapped_app(Fwd(task_ins=task_ins, state=WorkloadState({}))).task_res

# Assert
Expand All @@ -89,7 +89,7 @@ def filter_layer(fwd: Fwd, _: FlowerCallable) -> Bwd:
return Bwd(task_res=TaskRes(task_id="filter"), state=WorkloadState({}))

# Execute
wrapped_app = make_app(mock_app, [filter_layer])
wrapped_app = make_fc(mock_app, [filter_layer])
task_res = wrapped_app(Fwd(task_ins=task_ins, state=WorkloadState({}))).task_res

# Assert
Expand Down

0 comments on commit 2df4116

Please sign in to comment.