Skip to content

Commit

Permalink
Use config file to run experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminastrand committed Nov 29, 2024
1 parent b50c394 commit 3574d77
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions examples/async-clients/run_experiment.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
import time
import uuid

from config import settings
from fedn import APIClient

DISCOVER_HOST = "127.0.0.1"
DISCOVER_PORT = 8092
client = APIClient(DISCOVER_HOST, DISCOVER_PORT)
client = APIClient(
host=settings["DISCOVER_HOST"],
port=settings["DISCOVER_PORT"],
secure=settings["SECURE"],
verify=settings["VERIFY"],
token=settings["ADMIN_TOKEN"],
)

if __name__ == "__main__":
# Run six sessions, each with 100 rounds.
num_sessions = 6
for s in range(num_sessions):
for s in range(settings["N_SESSIONS"]):
active_model = client.get_active_model()
session_config = {
"helper": "numpyhelper",
"id": str(uuid.uuid4()),
"aggregator": "fedopt",
"id": f"async-test-{s+1}-{str(uuid.uuid4())[:4]}",
"aggregator": "fedavg",
"round_timeout": 20,
"rounds": 100,
"validate": False,
"rounds": settings["N_ROUNDS"],
"validate": True,
"model_id": active_model["model"],
}

session = client.start_session(**session_config)
if session["success"] is False:
if session["message"] != "Session started":
print(session["message"])
exit(0)

print("Started session: {}".format(session))

# Wait for session to finish
while not client.session_is_finished(session_config["id"]):
time.sleep(2)
t_sleep = 2
session_status = client.get_session_status(session_config["id"])
print(f"Session status: {session_status}. Sleeping for {t_sleep}")
time.sleep(t_sleep)

0 comments on commit 3574d77

Please sign in to comment.