Skip to content

Commit

Permalink
Re-use client_id for same client across cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminastrand committed Nov 29, 2024
1 parent e8d0eac commit f3a4b38
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions examples/async-clients/run_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def on_validate(in_model):
return metrics


def run_client(online_for=120, name="client"):
def run_client(online_for=120, name="client", client_id=None):
"""Simulates a client that starts and stops
at random intervals.
Expand All @@ -113,14 +113,17 @@ def run_client(online_for=120, name="client"):
This is repeated for N_CYCLES.
"""
if client_id is None:
client_id = str(uuid.uuid4())

for i in range(settings["N_CYCLES"]):
# Sample a delay until the client starts
t_start = np.random.randint(0, settings["CLIENTS_MAX_DELAY"])
time.sleep(t_start)

fl_client = FednClient(train_callback=on_train, validate_callback=on_validate)
fl_client.set_name(name)
fl_client.set_client_id(str(uuid.uuid4()))
fl_client.set_client_id(client_id)

controller_config = {
"name": fl_client.name,
Expand Down Expand Up @@ -149,6 +152,7 @@ def run_client(online_for=120, name="client"):
args=(
settings["CLIENTS_ONLINE_FOR_SECONDS"],
"client{}".format(i + 1),
str(uuid.uuid4()),
),
)
processes.append(p)
Expand Down

0 comments on commit f3a4b38

Please sign in to comment.