# Copyright 2023 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 constants."""from__future__importannotationsMISSING_EXTRA_REST="""Extra dependencies required for using the REST-based Fleet API are missing.To use the REST API, install `flwr` with the `rest` extra: `pip install flwr[rest]`."""TRANSPORT_TYPE_GRPC_BIDI="grpc-bidi"TRANSPORT_TYPE_GRPC_RERE="grpc-rere"TRANSPORT_TYPE_GRPC_ADAPTER="grpc-adapter"TRANSPORT_TYPE_REST="rest"TRANSPORT_TYPE_VCE="vce"TRANSPORT_TYPES=[TRANSPORT_TYPE_GRPC_BIDI,TRANSPORT_TYPE_GRPC_RERE,TRANSPORT_TYPE_REST,TRANSPORT_TYPE_VCE,]# Addresses# PortsCLIENTAPPIO_PORT="9094"SERVERAPPIO_PORT="9091"FLEETAPI_GRPC_RERE_PORT="9092"FLEETAPI_PORT="9095"EXEC_API_PORT="9093"SIMULATIONIO_PORT="9096"# OctetsSERVER_OCTET="0.0.0.0"CLIENT_OCTET="127.0.0.1"# SuperNodeCLIENTAPPIO_API_DEFAULT_SERVER_ADDRESS=f"{SERVER_OCTET}:{CLIENTAPPIO_PORT}"CLIENTAPPIO_API_DEFAULT_CLIENT_ADDRESS=f"{CLIENT_OCTET}:{CLIENTAPPIO_PORT}"# SuperLinkSERVERAPPIO_API_DEFAULT_SERVER_ADDRESS=f"{SERVER_OCTET}:{SERVERAPPIO_PORT}"SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS=f"{CLIENT_OCTET}:{SERVERAPPIO_PORT}"FLEET_API_GRPC_RERE_DEFAULT_ADDRESS=f"{SERVER_OCTET}:{FLEETAPI_GRPC_RERE_PORT}"FLEET_API_GRPC_BIDI_DEFAULT_ADDRESS=("[::]:8080"# IPv6 to keep start_server compatible)FLEET_API_REST_DEFAULT_ADDRESS=f"{SERVER_OCTET}:{FLEETAPI_PORT}"EXEC_API_DEFAULT_SERVER_ADDRESS=f"{SERVER_OCTET}:{EXEC_API_PORT}"SIMULATIONIO_API_DEFAULT_SERVER_ADDRESS=f"{SERVER_OCTET}:{SIMULATIONIO_PORT}"SIMULATIONIO_API_DEFAULT_CLIENT_ADDRESS=f"{CLIENT_OCTET}:{SIMULATIONIO_PORT}"# Constants for pingPING_DEFAULT_INTERVAL=30PING_CALL_TIMEOUT=5PING_BASE_MULTIPLIER=0.8PING_RANDOM_RANGE=(-0.1,0.1)PING_MAX_INTERVAL=1e300# IDsRUN_ID_NUM_BYTES=8NODE_ID_NUM_BYTES=8# Constants for FABAPP_DIR="apps"FAB_ALLOWED_EXTENSIONS={".py",".toml",".md"}FAB_CONFIG_FILE="pyproject.toml"FAB_DATE=(2024,10,1,0,0,0)FAB_HASH_TRUNCATION=8FLWR_HOME="FLWR_HOME"# Constants entries in Node config for SimulationPARTITION_ID_KEY="partition-id"NUM_PARTITIONS_KEY="num-partitions"# Constants for keys in `metadata` of `MessageContainer` in `grpc-adapter`GRPC_ADAPTER_METADATA_FLOWER_PACKAGE_NAME_KEY="flower-package-name"GRPC_ADAPTER_METADATA_FLOWER_PACKAGE_VERSION_KEY="flower-package-version"GRPC_ADAPTER_METADATA_FLOWER_VERSION_KEY="flower-version"# DeprecatedGRPC_ADAPTER_METADATA_SHOULD_EXIT_KEY="should-exit"GRPC_ADAPTER_METADATA_MESSAGE_MODULE_KEY="grpc-message-module"GRPC_ADAPTER_METADATA_MESSAGE_QUALNAME_KEY="grpc-message-qualname"# Message TTLMESSAGE_TTL_TOLERANCE=1e-1# Isolation modesISOLATION_MODE_SUBPROCESS="subprocess"ISOLATION_MODE_PROCESS="process"# Log streaming configurationsCONN_REFRESH_PERIOD=60# Stream connection refresh periodCONN_RECONNECT_INTERVAL=0.5# Reconnect interval between two stream connectionsLOG_STREAM_INTERVAL=0.5# Log stream interval for `ExecServicer.StreamLogs`LOG_UPLOAD_INTERVAL=0.2# Minimum interval between two log uploads# Retry configurationsMAX_RETRY_DELAY=20# Maximum delay duration between two consecutive retries.
[docs]classMessageType:"""Message type."""TRAIN="train"EVALUATE="evaluate"QUERY="query"def__new__(cls)->MessageType:"""Prevent instantiation."""raiseTypeError(f"{cls.__name__} cannot be instantiated.")
[docs]classMessageTypeLegacy:"""Legacy message type."""GET_PROPERTIES="get_properties"GET_PARAMETERS="get_parameters"def__new__(cls)->MessageTypeLegacy:"""Prevent instantiation."""raiseTypeError(f"{cls.__name__} cannot be instantiated.")
classSType:"""Serialisation type."""NUMPY="numpy.ndarray"def__new__(cls)->SType:"""Prevent instantiation."""raiseTypeError(f"{cls.__name__} cannot be instantiated.")classErrorCode:"""Error codes for Message's Error."""UNKNOWN=0LOAD_CLIENT_APP_EXCEPTION=1CLIENT_APP_RAISED_EXCEPTION=2MESSAGE_UNAVAILABLE=3REPLY_MESSAGE_UNAVAILABLE=4def__new__(cls)->ErrorCode:"""Prevent instantiation."""raiseTypeError(f"{cls.__name__} cannot be instantiated.")classStatus:"""Run status."""PENDING="pending"STARTING="starting"RUNNING="running"FINISHED="finished"def__new__(cls)->Status:"""Prevent instantiation."""raiseTypeError(f"{cls.__name__} cannot be instantiated.")classSubStatus:"""Run sub-status."""COMPLETED="completed"FAILED="failed"STOPPED="stopped"def__new__(cls)->SubStatus:"""Prevent instantiation."""raiseTypeError(f"{cls.__name__} cannot be instantiated.")