Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
chongshenng committed Nov 4, 2024
1 parent 8f92a3d commit cf213bc
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 48 deletions.
6 changes: 2 additions & 4 deletions src/proto/flwr/proto/clientappio.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ syntax = "proto3";
package flwr.proto;

import "flwr/proto/fab.proto";
import "flwr/proto/run.proto";
import "flwr/proto/message.proto";

service ClientAppIo {
// Get token
rpc GetToken(GetTokenRequest) returns (GetTokenResponse) {}

// Get Message, Context, and Run
// Get Message, Context and Fab
rpc PullClientAppInputs(PullClientAppInputsRequest)
returns (PullClientAppInputsResponse) {}

Expand All @@ -51,8 +50,7 @@ message PullClientAppInputsRequest { uint64 token = 1; }
message PullClientAppInputsResponse {
Message message = 1;
Context context = 2;
Run run = 3;
Fab fab = 4;
Fab fab = 3;
}

message PushClientAppOutputsRequest {
Expand Down
1 change: 0 additions & 1 deletion src/py/flwr/client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ def _on_backoff(retry_state: RetryState) -> None:
clientapp_input=ClientAppInputs(
message=message,
context=context,
run=run,
fab=fab,
token=token,
),
Expand Down
16 changes: 8 additions & 8 deletions src/py/flwr/client/clientapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import grpc

from flwr.cli.config_utils import get_fab_metadata
from flwr.cli.install import install_from_fab
from flwr.client.client_app import ClientApp, LoadClientAppError
from flwr.common import Context, Message
Expand All @@ -34,9 +35,8 @@
fab_from_proto,
message_from_proto,
message_to_proto,
run_from_proto,
)
from flwr.common.typing import Fab, Run
from flwr.common.typing import Fab

# pylint: disable=E0611
from flwr.proto.clientappio_pb2 import (
Expand Down Expand Up @@ -115,13 +115,14 @@ def run_clientapp( # pylint: disable=R0914
token = get_token(stub)
time.sleep(1)

# Pull Message, Context, Run and (optional) FAB from SuperNode
message, context, run, fab = pull_message(stub=stub, token=token)
# Pull Message, Context, and (optional) FAB from SuperNode
message, context, fab = pull_message(stub=stub, token=token)

# Install FAB, if provided
if fab:
log(DEBUG, "Flower ClientApp starts FAB installation.")
install_from_fab(fab.content, flwr_dir=None, skip_prompt=True)
fab_id, fab_version = get_fab_metadata(fab.content)

load_client_app_fn = get_load_client_app_fn(
default_app_ref="",
Expand All @@ -133,7 +134,7 @@ def run_clientapp( # pylint: disable=R0914
try:
# Load ClientApp
client_app: ClientApp = load_client_app_fn(
run.fab_id, run.fab_version, fab.hash_str if fab else ""
fab_id, fab_version, fab.hash_str if fab else ""
)

# Execute ClientApp
Expand Down Expand Up @@ -197,7 +198,7 @@ def get_token(stub: grpc.Channel) -> Optional[int]:

def pull_message(
stub: grpc.Channel, token: int
) -> tuple[Message, Context, Run, Optional[Fab]]:
) -> tuple[Message, Context, Optional[Fab]]:
"""Pull message from SuperNode to ClientApp."""
log(INFO, "Pulling ClientAppInputs for token %s", token)
try:
Expand All @@ -206,9 +207,8 @@ def pull_message(
)
message = message_from_proto(res.message)
context = context_from_proto(res.context)
run = run_from_proto(res.run)
fab = fab_from_proto(res.fab) if res.fab else None
return message, context, run, fab
return message, context, fab
except grpc.RpcError as e:
log(ERROR, "[PullClientAppInputs] gRPC error occurred: %s", str(e))
raise e
Expand Down
7 changes: 2 additions & 5 deletions src/py/flwr/client/clientapp/clientappio_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
fab_to_proto,
message_from_proto,
message_to_proto,
run_to_proto,
)
from flwr.common.typing import Fab, Run
from flwr.common.typing import Fab

# pylint: disable=E0611
from flwr.proto import clientappio_pb2_grpc
Expand All @@ -52,7 +51,6 @@ class ClientAppInputs:

message: Message
context: Context
run: Run
fab: Optional[Fab]
token: int

Expand Down Expand Up @@ -106,7 +104,7 @@ def GetToken(
def PullClientAppInputs(
self, request: PullClientAppInputsRequest, context: grpc.ServicerContext
) -> PullClientAppInputsResponse:
"""Pull Message, Context, and Run."""
"""Pull Message, Context, and Fab."""
log(DEBUG, "ClientAppIo.PullClientAppInputs")

# Fail if no ClientAppInputs are available
Expand Down Expand Up @@ -137,7 +135,6 @@ def PullClientAppInputs(
return PullClientAppInputsResponse(
message=message_to_proto(clientapp_input.message),
context=context_to_proto(clientapp_input.context),
run=run_to_proto(clientapp_input.run),
fab=fab_to_proto(clientapp_input.fab) if clientapp_input.fab else None,
)

Expand Down
39 changes: 19 additions & 20 deletions src/py/flwr/proto/clientappio_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions src/py/flwr/proto/clientappio_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ isort:skip_file
import builtins
import flwr.proto.fab_pb2
import flwr.proto.message_pb2
import flwr.proto.run_pb2
import google.protobuf.descriptor
import google.protobuf.internal.enum_type_wrapper
import google.protobuf.message
Expand Down Expand Up @@ -77,25 +76,21 @@ class PullClientAppInputsResponse(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor
MESSAGE_FIELD_NUMBER: builtins.int
CONTEXT_FIELD_NUMBER: builtins.int
RUN_FIELD_NUMBER: builtins.int
FAB_FIELD_NUMBER: builtins.int
@property
def message(self) -> flwr.proto.message_pb2.Message: ...
@property
def context(self) -> flwr.proto.message_pb2.Context: ...
@property
def run(self) -> flwr.proto.run_pb2.Run: ...
@property
def fab(self) -> flwr.proto.fab_pb2.Fab: ...
def __init__(self,
*,
message: typing.Optional[flwr.proto.message_pb2.Message] = ...,
context: typing.Optional[flwr.proto.message_pb2.Context] = ...,
run: typing.Optional[flwr.proto.run_pb2.Run] = ...,
fab: typing.Optional[flwr.proto.fab_pb2.Fab] = ...,
) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["context",b"context","fab",b"fab","message",b"message","run",b"run"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["context",b"context","fab",b"fab","message",b"message","run",b"run"]) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["context",b"context","fab",b"fab","message",b"message"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["context",b"context","fab",b"fab","message",b"message"]) -> None: ...
global___PullClientAppInputsResponse = PullClientAppInputsResponse

class PushClientAppOutputsRequest(google.protobuf.message.Message):
Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/proto/clientappio_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def GetToken(self, request, context):
raise NotImplementedError('Method not implemented!')

def PullClientAppInputs(self, request, context):
"""Get Message, Context, and Run
"""Get Message, Context and Fab
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
Expand Down
4 changes: 2 additions & 2 deletions src/py/flwr/proto/clientappio_pb2_grpc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ClientAppIoStub:
PullClientAppInputs: grpc.UnaryUnaryMultiCallable[
flwr.proto.clientappio_pb2.PullClientAppInputsRequest,
flwr.proto.clientappio_pb2.PullClientAppInputsResponse]
"""Get Message, Context, and Run"""
"""Get Message, Context and Fab"""

PushClientAppOutputs: grpc.UnaryUnaryMultiCallable[
flwr.proto.clientappio_pb2.PushClientAppOutputsRequest,
Expand All @@ -38,7 +38,7 @@ class ClientAppIoServicer(metaclass=abc.ABCMeta):
request: flwr.proto.clientappio_pb2.PullClientAppInputsRequest,
context: grpc.ServicerContext,
) -> flwr.proto.clientappio_pb2.PullClientAppInputsResponse:
"""Get Message, Context, and Run"""
"""Get Message, Context and Fab"""
pass

@abc.abstractmethod
Expand Down

0 comments on commit cf213bc

Please sign in to comment.