File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change @@ -60,5 +60,5 @@ def sum_dev(df1: pd.DataFrame, column: str) -> dict:
6060def 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 }
You can’t perform that action at this time.
0 commit comments