From 8bcc4bdaa80f065ce5a95f19326c9a7bc0ef74f7 Mon Sep 17 00:00:00 2001 From: "Daniel J. Beutel" Date: Tue, 21 Nov 2023 12:16:47 +0100 Subject: [PATCH] Introduce experimental feature warning (#2622) --- .../flwr/client/grpc_rere_client/connection.py | 14 ++++---------- src/py/flwr/common/logger.py | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/py/flwr/client/grpc_rere_client/connection.py b/src/py/flwr/client/grpc_rere_client/connection.py index b69228826e13..424e413dc484 100644 --- a/src/py/flwr/client/grpc_rere_client/connection.py +++ b/src/py/flwr/client/grpc_rere_client/connection.py @@ -16,7 +16,7 @@ from contextlib import contextmanager -from logging import DEBUG, ERROR, WARN +from logging import DEBUG, ERROR from pathlib import Path from typing import Callable, Dict, Iterator, Optional, Tuple, Union, cast @@ -28,7 +28,7 @@ ) from flwr.common import GRPC_MAX_MESSAGE_LENGTH from flwr.common.grpc import create_channel -from flwr.common.logger import log +from flwr.common.logger import log, warn_experimental_feature from flwr.proto.fleet_pb2 import ( CreateNodeRequest, DeleteNodeRequest, @@ -88,6 +88,8 @@ def grpc_request_response( create_node : Optional[Callable] delete_node : Optional[Callable] """ + warn_experimental_feature("`grpc-rere`") + if isinstance(root_certificates, str): root_certificates = Path(root_certificates).read_bytes() @@ -99,14 +101,6 @@ def grpc_request_response( channel.subscribe(on_channel_state_change) stub = FleetStub(channel) - log( - WARN, - """ - EXPERIMENTAL: `grpc-rere` is an experimental transport layer, it might change - considerably in future versions of Flower - """, - ) - # Necessary state to link TaskRes to TaskIns state: Dict[str, Optional[TaskIns]] = {KEY_TASK_INS: None} diff --git a/src/py/flwr/common/logger.py b/src/py/flwr/common/logger.py index e543d6565878..29d1562a86d3 100644 --- a/src/py/flwr/common/logger.py +++ b/src/py/flwr/common/logger.py @@ -16,7 +16,7 @@ import logging -from logging import LogRecord +from logging import WARN, LogRecord from logging.handlers import HTTPHandler from typing import Any, Dict, Optional, Tuple @@ -97,3 +97,17 @@ def configure( logger = logging.getLogger(LOGGER_NAME) # pylint: disable=invalid-name log = logger.log # pylint: disable=invalid-name + + +def warn_experimental_feature(name: str) -> None: + """Warn the user when they use an experimental feature.""" + log( + WARN, + """ + EXPERIMENTAL FEATURE: %s + + This is an experimental feature. It could change significantly or be removed + entirely in future versions of Flower. + """, + name, + )