Skip to content

Commit 4bee7b3

Browse files
Fixed a bug in the many example
1 parent a242f41 commit 4bee7b3

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

v6-session-basics/central.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,35 @@ def global_sum_dev(client: AlgorithmClient, column: str) -> dict:
6666
global_sum += output["sum"]
6767

6868
return {"global_sum": global_sum}
69+
70+
71+
@central
72+
@algorithm_client
73+
def global_sum_dev_many(client: AlgorithmClient, column: str) -> dict:
74+
info("Central function that sums the results of the federated sum function")
75+
76+
# Collect all organization that participate in this collaboration.
77+
# These organizations will receive the task to compute the partial.
78+
info("Collecting participating organizations")
79+
organizations = client.organization.list()
80+
ids = [organization.get("id") for organization in organizations]
81+
82+
info(f"Sending task to {len(ids)} organizations")
83+
task = client.task.create(
84+
name="central-sum",
85+
description="subtask",
86+
method="sum_many",
87+
organizations=ids,
88+
input_={"args": [column], "kwargs": {}},
89+
)
90+
91+
info("Waiting for results...")
92+
results = client.wait_for_results(task_id=task.get("id"))
93+
info("Partial results are in!")
94+
95+
info("Computing global sum")
96+
global_sums = {}
97+
for output in results:
98+
global_sums.update(output["sums"])
99+
100+
return {"global_sum": global_sum}

v6-session-basics/partial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ def sum_dev(df1: pd.DataFrame, column: str) -> dict:
6060
def sum_many(dfs: dict[str, pd.DataFrame], column: str) -> dict:
6161
sums = {}
6262
for df_name, df in dfs.items():
63-
sums[df_name] = df[column].sum()
63+
sums[df_name] = int(df[column].sum())
6464
return {"sums": sums}

0 commit comments

Comments
 (0)