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

Rename status code value, improve consistency #1258

Merged
merged 2 commits into from
Jun 21, 2022
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
28 changes: 14 additions & 14 deletions src/proto/flwr/proto/transport.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ service FlowerService {

enum Code {
OK = 0;
GET_PARAMETERS_NOT_IMPLEMENTED = 1;
GET_PROPERTIES_NOT_IMPLEMENTED = 1;
}
message Status {
Code code = 1;
Expand All @@ -43,6 +43,7 @@ enum Reason {

message ServerMessage {
message Reconnect { int64 seconds = 1; }
message GetPropertiesIns { map<string, Scalar> config = 1; }
message GetParametersIns { map<string, Scalar> config = 1; }
message FitIns {
Parameters parameters = 1;
Expand All @@ -52,18 +53,21 @@ message ServerMessage {
Parameters parameters = 1;
map<string, Scalar> config = 2;
}
message GetPropertiesIns { map<string, Scalar> config = 1; }
oneof msg {
Reconnect reconnect = 1;
GetParametersIns get_parameters_ins = 2;
FitIns fit_ins = 3;
EvaluateIns evaluate_ins = 4;
GetPropertiesIns get_properties_ins = 5;
GetPropertiesIns get_properties_ins = 2;
GetParametersIns get_parameters_ins = 3;
FitIns fit_ins = 4;
EvaluateIns evaluate_ins = 5;
}
}

message ClientMessage {
message Disconnect { Reason reason = 1; }
message GetPropertiesRes {
Status status = 1;
map<string, Scalar> properties = 2;
}
message GetParametersRes { Parameters parameters = 1; }
message FitRes {
Parameters parameters = 1;
Expand All @@ -75,16 +79,12 @@ message ClientMessage {
float loss = 2;
map<string, Scalar> metrics = 4;
}
message GetPropertiesRes {
Status status = 1;
map<string, Scalar> properties = 2;
}
oneof msg {
Disconnect disconnect = 1;
GetParametersRes get_parameters_res = 2;
FitRes fit_res = 3;
EvaluateRes evaluate_res = 4;
GetPropertiesRes get_properties_res = 5;
GetPropertiesRes get_properties_res = 2;
GetParametersRes get_parameters_res = 3;
FitRes fit_res = 4;
EvaluateRes evaluate_res = 5;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/client/grpc_client/message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _get_properties(
# If client does not override get_properties, don't call it
get_properties_res = typing.GetPropertiesRes(
status=typing.Status(
code=typing.Code.GET_PARAMETERS_NOT_IMPLEMENTED,
code=typing.Code.GET_PROPERTIES_NOT_IMPLEMENTED,
message="Client does not implement get_properties",
),
properties={},
Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/client/grpc_client/message_handler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_client_without_get_properties() -> None:
# Assert
expected_get_properties_res = ClientMessage.GetPropertiesRes(
status=Status(
code=Code.GET_PARAMETERS_NOT_IMPLEMENTED,
code=Code.GET_PROPERTIES_NOT_IMPLEMENTED,
message="Client does not implement get_properties",
)
)
Expand Down
8 changes: 4 additions & 4 deletions src/py/flwr/common/serde.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,16 @@ def get_properties_res_from_proto(
def status_to_proto(status: typing.Status) -> Status:
"""Serialize Code to ProtoBuf message."""
code = Code.OK
if status.code == typing.Code.GET_PARAMETERS_NOT_IMPLEMENTED:
code = Code.GET_PARAMETERS_NOT_IMPLEMENTED
if status.code == typing.Code.GET_PROPERTIES_NOT_IMPLEMENTED:
code = Code.GET_PROPERTIES_NOT_IMPLEMENTED
return Status(code=code, message=status.message)


def status_from_proto(msg: Status) -> typing.Status:
"""Deserialize Code from ProtoBuf message."""
code = typing.Code.OK
if msg.code == Code.GET_PARAMETERS_NOT_IMPLEMENTED:
code = typing.Code.GET_PARAMETERS_NOT_IMPLEMENTED
if msg.code == Code.GET_PROPERTIES_NOT_IMPLEMENTED:
code = typing.Code.GET_PROPERTIES_NOT_IMPLEMENTED
return typing.Status(code=code, message=msg.message)


Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/common/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Code(Enum):
"""Client status codes."""

OK = 0
GET_PARAMETERS_NOT_IMPLEMENTED = 1
GET_PROPERTIES_NOT_IMPLEMENTED = 1


@dataclass
Expand Down
Loading