Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the optional arg "--callable" in flower-client a required positional arg. #2673

Merged
merged 14 commits into from
Dec 22, 2023
Merged
4 changes: 2 additions & 2 deletions e2e/test_driver.sh
Original file line number Diff line number Diff line change
@@ -16,10 +16,10 @@ esac
timeout 2m flower-server $server_arg &
sleep 3

timeout 2m flower-client $client_arg --callable client:flower --server 127.0.0.1:9092 &
timeout 2m flower-client client:flower $client_arg --server 127.0.0.1:9092 &
sleep 3

timeout 2m flower-client $client_arg --callable client:flower --server 127.0.0.1:9092 &
timeout 2m flower-client client:flower $client_arg --server 127.0.0.1:9092 &
sleep 3

timeout 2m python driver.py &
4 changes: 2 additions & 2 deletions examples/mt-pytorch-callable/README.md
Original file line number Diff line number Diff line change
@@ -33,13 +33,13 @@ flower-server --insecure
In a new terminal window, start the first long-running Flower client:

```bash
flower-client --callable client:flower
flower-client client:flower
```

In yet another new terminal window, start the second long-running Flower client:

```bash
flower-client --callable client:flower
flower-client client:flower
```

## Start the Driver script
2 changes: 1 addition & 1 deletion examples/mt-pytorch-callable/client.py
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ def client_fn(cid: str):
return FlowerClient().to_client()


# To run this: `flower-client --callable client:flower`
# To run this: `flower-client client:flower`
flower = fl.flower.Flower(
client_fn=client_fn,
)
27 changes: 15 additions & 12 deletions src/py/flwr/client/app.py
Original file line number Diff line number Diff line change
@@ -72,15 +72,15 @@ def run_client() -> None:

print(args.root_certificates)
print(args.server)
print(args.callable_dir)
print(args.callable)
print(args.dir)
print(args.target)

callable_dir = args.callable_dir
if callable_dir is not None:
sys.path.insert(0, callable_dir)
target_dir = args.dir
if target_dir is not None:
sys.path.insert(0, target_dir)

def _load() -> Flower:
flower: Flower = load_callable(args.callable)
flower: Flower = load_callable(args.target)
return flower

return start_client(
@@ -98,6 +98,12 @@ def _parse_args_client() -> argparse.ArgumentParser:
description="Start a long-running Flower client",
)

parser.add_argument(
"target",
help="The target Flower object to run as a client. For example: "
"'client:flower' or 'project.package.module:wrapper.flower'. "
"This is a required positional argument.",
)
parser.add_argument(
"--insecure",
action="store_true",
@@ -117,13 +123,10 @@ def _parse_args_client() -> argparse.ArgumentParser:
help="Server address",
)
parser.add_argument(
"--callable",
help="For example: `client:flower` or `project.package.module:wrapper.flower`",
)
parser.add_argument(
"--callable-dir",
"--dir",
default="",
help="Add specified directory to the PYTHONPATH and load callable from there."
help="Add specified directory to the PYTHONPATH and load Flower "
"object from there."
" Default: current working directory.",
)