Skip to content

Commit

Permalink
Use keyword-only arguments in public API (adap#1338)
Browse files Browse the repository at this point in the history
* Use keyword-only arguments in public API
* Update changelog and upgrade guide
  • Loading branch information
danieljanes committed Jul 27, 2022
1 parent 4517fdc commit 998e0c2
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 21 deletions.
4 changes: 4 additions & 0 deletions doc/source/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ We thank all contributors who made Flower 1.0 possible (in reverse [GitHub Contr

### Incompatible changes

- **All arguments must be passed as keyword arguments** ([#1338](https://github.com/adap/flower/pull/1338))

Pass all arguments as keyword arguments, positional arguments are not longer supported. Code that uses positional arguments (e.g., ``start_client("127.0.0.1:8080", FlowerClient())``) must add the keyword for each positional argument (e.g., ``start_client(server_address="127.0.0.1:8080", client=FlowerClient())``).

- **Introduce configuration object** `ServerConfig` **in** `start_server` **and** `start_simulation` ([#1317](https://github.com/adap/flower/pull/1317))

Instead of a config dictionary `{"num_rounds": 3, "round_timeout": 600.0}`, `start_server` and `start_simulation` now expect a configuration object of type `flwr.server.ServerConfig`. `ServerConfig` takes the same arguments that as the previous config dict, but it makes writing type-safe code easier and the default parameters values more transparent.
Expand Down
8 changes: 8 additions & 0 deletions doc/source/upgrade-to-flower-1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ Required changes

A few breaking changes require small manual updates:

General
~~~~~~~

Pass all arguments as keyword arguments (not as positional arguments). Here's an example:

- Flower 0.19 (positional arguments): ``start_client("127.0.0.1:8080", FlowerClient())``
- Flower 1.0 (keyword arguments): ``start_client(server_address="127.0.0.1:8080", client=FlowerClient())``

Client
~~~~~~

Expand Down
38 changes: 18 additions & 20 deletions src/py/flwr/client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@


def start_client(
*,
server_address: str,
client: Client,
grpc_max_message_length: int = GRPC_MAX_MESSAGE_LENGTH,
Expand Down Expand Up @@ -157,6 +158,7 @@ class `flwr.client.Client`.


def start_numpy_client(
*,
server_address: str,
client: NumPyClient,
grpc_max_message_length: int = GRPC_MAX_MESSAGE_LENGTH,
Expand All @@ -166,26 +168,22 @@ def start_numpy_client(
Parameters
----------
server_address: str. The IPv6 address of the server. If the Flower
server runs on the same machine on port 8080, then `server_address`
would be `"[::]:8080"`.
client: flwr.client.NumPyClient. An implementation of the abstract base
class `flwr.client.NumPyClient`.
grpc_max_message_length: int (default: 536_870_912, this equals 512MB).
The maximum length of gRPC messages that can be exchanged with the
Flower server. The default should be sufficient for most models.
Users who train very large models might need to increase this
value. Note that the Flower server needs to be started with the
same value (see `flwr.server.start_server`), otherwise it will not
know about the increased limit and block larger messages.
root_certificates: bytes (default: None)
The PEM-encoded root certificates a byte string. If provided, a secure
connection using the certificates will be established to a
SSL-enabled Flower server.
Returns
-------
None
server_address : str
The IPv6 address of the server. If the Flower server runs on the same
machine on port 8080, then `server_address` would be `"[::]:8080"`.
client : flwr.client.NumPyClient
An implementation of the abstract base class `flwr.client.NumPyClient`.
grpc_max_message_length : int (default: 536_870_912, this equals 512MB)
The maximum length of gRPC messages that can be exchanged with the
Flower server. The default should be sufficient for most models.
Users who train very large models might need to increase this
value. Note that the Flower server needs to be started with the
same value (see `flwr.server.start_server`), otherwise it will not
know about the increased limit and block larger messages.
root_certificates : bytes (default: None)
The PEM-encoded root certificates a byte string. If provided, a secure
connection using the certificates will be established to a
SSL-enabled Flower server.
Examples
--------
Expand Down
1 change: 1 addition & 0 deletions src/py/flwr/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ServerConfig:


def start_server( # pylint: disable=too-many-arguments
*,
server_address: str = DEFAULT_SERVER_ADDRESS,
server: Optional[Server] = None,
config: Optional[ServerConfig] = None,
Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Server:
"""Flower server."""

def __init__(
self, client_manager: ClientManager, strategy: Optional[Strategy] = None
self, *, client_manager: ClientManager, strategy: Optional[Strategy] = None
) -> None:
self._client_manager: ClientManager = client_manager
self.parameters: Parameters = Parameters(
Expand Down
1 change: 1 addition & 0 deletions src/py/flwr/server/strategy/fault_tolerant_fedavg.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class FaultTolerantFedAvg(FedAvg):
# pylint: disable=too-many-arguments,too-many-instance-attributes
def __init__(
self,
*,
fraction_fit: float = 1.0,
fraction_evaluate: float = 1.0,
min_fit_clients: int = 1,
Expand Down
1 change: 1 addition & 0 deletions src/py/flwr/server/strategy/fedavg.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class FedAvg(Strategy):
# pylint: disable=too-many-arguments,too-many-instance-attributes
def __init__(
self,
*,
fraction_fit: float = 1.0,
fraction_evaluate: float = 1.0,
min_fit_clients: int = 2,
Expand Down
1 change: 1 addition & 0 deletions src/py/flwr/server/strategy/fedavg_android.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class FedAvgAndroid(Strategy):
# pylint: disable=too-many-arguments,too-many-instance-attributes
def __init__(
self,
*,
fraction_fit: float = 1.0,
fraction_evaluate: float = 1.0,
min_fit_clients: int = 2,
Expand Down
1 change: 1 addition & 0 deletions src/py/flwr/server/strategy/qfedavg.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class QFedAvg(FedAvg):
# pylint: disable=too-many-arguments,too-many-instance-attributes
def __init__(
self,
*,
q_param: float = 0.2,
qffl_learning_rate: float = 0.1,
fraction_fit: float = 1.0,
Expand Down

0 comments on commit 998e0c2

Please sign in to comment.