Skip to content

Commit

Permalink
Add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljanes committed Nov 22, 2023
1 parent 578df87 commit 0c9f6ea
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/py/flwr/client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _parse_args_client() -> argparse.ArgumentParser:
)
parser.add_argument(
"--callable",
help="For example: `client:flower` or `project.package.module:wrapper.flower",
help="For example: `client:flower` or `project.package.module:wrapper.flower`",
)
parser.add_argument(
"--callable-dir",
Expand Down
33 changes: 31 additions & 2 deletions src/py/flwr/client/flower.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,30 @@ class Bwd:


class Flower:
"""Flower callable."""
"""Flower callable.
Examples
--------
Assuming a typical client implementation in `FlowerClient`, you can wrap it in a
Flower callable as follows:
>>> class FlowerClient(NumPyClient):
>>> # ...
>>>
>>> def client_fn(cid):
>>> return FlowerClient().to_client()
>>>
>>> flower = Flower(client_fn)
If the above code is in a Python module called `client`, it can be started as
follows:
>>> flower-client --callable client:flower
In this `client:flower` example, `client` refers to the Python module in which the
previous code lives in. `flower` refers to the global attribute `flower` that points
to an object of type `Flower` (a Flower callable).
"""

def __init__(
self,
Expand All @@ -71,7 +94,13 @@ class LoadCallableError(Exception):


def load_callable(module_attribute_str: str) -> Flower:
"""."""
"""Load the `Flower` object specified in a module attribute string.
The module/attribute string should have the form <module>:<attribute>. Valid
examples include `client:flower` and `project.package.module:wrapper.flower`. It
must refer to a module on the PYTHONPATH, the module needs to have the specified
attribute, and the attribute must be of type `Flower`.
"""
module_str, _, attributes_str = module_attribute_str.partition(":")
if not module_str:
raise LoadCallableError(
Expand Down

0 comments on commit 0c9f6ea

Please sign in to comment.