# Copyright 2020 Flower Labs GmbH. All Rights Reserved.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.# =============================================================================="""Flower type definitions."""fromdataclassesimportdataclassfromenumimportEnumfromtypingimportAny,Callable,Optional,Unionimportnumpyasnpimportnumpy.typingasnptNDArray=npt.NDArray[Any]NDArrayInt=npt.NDArray[np.int_]NDArrayFloat=npt.NDArray[np.float_]NDArrays=list[NDArray]# The following union type contains Python types corresponding to ProtoBuf types that# ProtoBuf considers to be "Scalar Value Types", even though some of them arguably do# not conform to other definitions of what a scalar is. Source:# https://developers.google.com/protocol-buffers/docs/overview#scalarScalar=Union[bool,bytes,float,int,str]Value=Union[bool,bytes,float,int,str,list[bool],list[bytes],list[float],list[int],list[str],]# Value types for common.MetricsRecordMetricsScalar=Union[int,float]MetricsScalarList=Union[list[int],list[float]]MetricsRecordValues=Union[MetricsScalar,MetricsScalarList]# Value types for common.ConfigsRecordConfigsScalar=Union[MetricsScalar,str,bytes,bool]ConfigsScalarList=Union[MetricsScalarList,list[str],list[bytes],list[bool]]ConfigsRecordValues=Union[ConfigsScalar,ConfigsScalarList]Metrics=dict[str,Scalar]MetricsAggregationFn=Callable[[list[tuple[int,Metrics]]],Metrics]Config=dict[str,Scalar]Properties=dict[str,Scalar]# Value type for user configsUserConfigValue=Union[bool,float,int,str]UserConfig=dict[str,UserConfigValue]
[docs]classCode(Enum):"""Client status codes."""OK=0GET_PROPERTIES_NOT_IMPLEMENTED=1GET_PARAMETERS_NOT_IMPLEMENTED=2FIT_NOT_IMPLEMENTED=3EVALUATE_NOT_IMPLEMENTED=4
classClientAppOutputCode(Enum):"""ClientAppIO status codes."""SUCCESS=0DEADLINE_EXCEEDED=1UNKNOWN_ERROR=2@dataclassclassClientAppOutputStatus:"""ClientAppIO status."""code:ClientAppOutputCodemessage:str
[docs]@dataclassclassGetParametersIns:"""Parameters request for a client."""config:Config
[docs]@dataclassclassGetParametersRes:"""Response when asked to return parameters."""status:Statusparameters:Parameters
[docs]@dataclassclassFitIns:"""Fit instructions for a client."""parameters:Parametersconfig:dict[str,Scalar]
[docs]@dataclassclassFitRes:"""Fit response from a client."""status:Statusparameters:Parametersnum_examples:intmetrics:dict[str,Scalar]
[docs]@dataclassclassEvaluateIns:"""Evaluate instructions for a client."""parameters:Parametersconfig:dict[str,Scalar]
[docs]@dataclassclassEvaluateRes:"""Evaluate response from a client."""status:Statusloss:floatnum_examples:intmetrics:dict[str,Scalar]
[docs]@dataclassclassGetPropertiesIns:"""Properties request for a client."""config:Config
[docs]@dataclassclassGetPropertiesRes:"""Properties response from a client."""status:Statusproperties:Properties
[docs]@dataclassclassReconnectIns:"""ReconnectIns message from server to client."""seconds:Optional[int]
[docs]@dataclassclassDisconnectRes:"""DisconnectRes message from client to server."""reason:str
[docs]@dataclassclassServerMessage:"""ServerMessage is a container used to hold one instruction message."""get_properties_ins:Optional[GetPropertiesIns]=Noneget_parameters_ins:Optional[GetParametersIns]=Nonefit_ins:Optional[FitIns]=Noneevaluate_ins:Optional[EvaluateIns]=None
[docs]@dataclassclassClientMessage:"""ClientMessage is a container used to hold one result message."""get_properties_res:Optional[GetPropertiesRes]=Noneget_parameters_res:Optional[GetParametersRes]=Nonefit_res:Optional[FitRes]=Noneevaluate_res:Optional[EvaluateRes]=None
@dataclassclassRun:"""Run details."""run_id:intfab_id:strfab_version:strfab_hash:stroverride_config:UserConfig@dataclassclassRunStatus:"""Run status information."""status:strsub_status:strdetails:str@dataclassclassFab:"""Fab file representation."""hash_str:strcontent:bytes