Skip to content

Commit

Permalink
Apply formatting changes
Browse files Browse the repository at this point in the history
Signed-off-by: Shah, Karan <[email protected]>
  • Loading branch information
MasterSkepticista committed Jul 10, 2024
1 parent d2914d3 commit b4cf970
Show file tree
Hide file tree
Showing 111 changed files with 842 additions and 2,504 deletions.
8 changes: 2 additions & 6 deletions openfl/component/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@

from openfl.component.aggregator.aggregator import Aggregator
from openfl.component.assigner.assigner import Assigner
from openfl.component.assigner.random_grouped_assigner import (
RandomGroupedAssigner,
)
from openfl.component.assigner.static_grouped_assigner import (
StaticGroupedAssigner,
)
from openfl.component.assigner.random_grouped_assigner import RandomGroupedAssigner
from openfl.component.assigner.static_grouped_assigner import StaticGroupedAssigner
from openfl.component.collaborator.collaborator import Collaborator
from openfl.component.straggler_handling_functions.cutoff_time_based_straggler_handling import (
CutoffTimeBasedStragglerHandling,
Expand Down
179 changes: 47 additions & 132 deletions openfl/component/aggregator/aggregator.py

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions openfl/component/assigner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@
# limitations under the License.

from openfl.component.assigner.assigner import Assigner
from openfl.component.assigner.random_grouped_assigner import (
RandomGroupedAssigner,
)
from openfl.component.assigner.static_grouped_assigner import (
StaticGroupedAssigner,
)
from openfl.component.assigner.random_grouped_assigner import RandomGroupedAssigner
from openfl.component.assigner.static_grouped_assigner import StaticGroupedAssigner
30 changes: 7 additions & 23 deletions openfl/component/assigner/custom_assigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ class Assigner:
"""Custom assigner class."""

def __init__(
self,
*,
assigner_function,
aggregation_functions_by_task,
authorized_cols,
rounds_to_train
self, *, assigner_function, aggregation_functions_by_task, authorized_cols, rounds_to_train
):
"""Initialize."""
self.agg_functions_by_task = aggregation_functions_by_task
Expand All @@ -55,19 +50,13 @@ def define_task_assignments(self):
number_of_callaborators=len(self.authorized_cols),
)
for collaborator_name, tasks in tasks_by_collaborator.items():
self.collaborator_tasks[round_number][collaborator_name].extend(
tasks
)
self.collaborator_tasks[round_number][collaborator_name].extend(tasks)
for task in tasks:
self.all_tasks_for_round[round_number][task.name] = task
self.collaborators_for_task[round_number][task.name].append(
collaborator_name
)
self.collaborators_for_task[round_number][task.name].append(collaborator_name)
if self.agg_functions_by_task:
self.agg_functions_by_task_name[task.name] = (
self.agg_functions_by_task.get(
task.function_name, WeightedAverage()
)
self.agg_functions_by_task_name[task.name] = self.agg_functions_by_task.get(
task.function_name, WeightedAverage()
)

def get_tasks_for_collaborator(self, collaborator_name, round_number):
Expand All @@ -85,14 +74,9 @@ def get_all_tasks_for_round(self, round_number):
Currently all tasks are performed on each round,
But there may be a reason to change this.
"""
return [
task.name
for task in self.all_tasks_for_round[round_number].values()
]
return [task.name for task in self.all_tasks_for_round[round_number].values()]

def get_aggregation_type_for_task(self, task_name):
"""Extract aggregation type from self.tasks."""
agg_fn = self.agg_functions_by_task_name.get(
task_name, WeightedAverage()
)
agg_fn = self.agg_functions_by_task_name.get(task_name, WeightedAverage())
return agg_fn
26 changes: 6 additions & 20 deletions openfl/component/assigner/random_grouped_assigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ def __init__(self, task_groups, **kwargs):
def define_task_assignments(self):
"""All of the logic to set up the map of tasks to collaborators is done here."""
assert (
np.abs(
1.0
- np.sum([group["percentage"] for group in self.task_groups])
)
< 0.01
np.abs(1.0 - np.sum([group["percentage"] for group in self.task_groups])) < 0.01
), "Task group percentages must sum to 100%"

# Start by finding all of the tasks in all specified groups
Expand All @@ -68,9 +64,7 @@ def define_task_assignments(self):

# Initialize the map of collaborators for a given task on a given round
for task in self.all_tasks_in_groups:
self.collaborators_for_task[task] = {
i: [] for i in range(self.rounds)
}
self.collaborators_for_task[task] = {i: [] for i in range(self.rounds)}

for col in self.authorized_cols:
self.collaborator_tasks[col] = {i: [] for i in range(self.rounds)}
Expand All @@ -87,26 +81,18 @@ def define_task_assignments(self):
num_col_in_group = int(group["percentage"] * col_list_size)
rand_col_group_list = [
self.authorized_cols[i]
for i in randomized_col_idx[
col_idx : col_idx + num_col_in_group
]
for i in randomized_col_idx[col_idx : col_idx + num_col_in_group]
]
self.task_group_collaborators[group["name"]] = (
rand_col_group_list
)
self.task_group_collaborators[group["name"]] = rand_col_group_list
for col in rand_col_group_list:
self.collaborator_tasks[col][round_num] = group["tasks"]
# Now populate reverse lookup of tasks->group
for task in group["tasks"]:
# This should append the list of collaborators performing
# that task
self.collaborators_for_task[task][
round_num
] += rand_col_group_list
self.collaborators_for_task[task][round_num] += rand_col_group_list
col_idx += num_col_in_group
assert (
col_idx == col_list_size
), "Task groups were not divided properly"
assert col_idx == col_list_size, "Task groups were not divided properly"

def get_tasks_for_collaborator(self, collaborator_name, round_number):
"""Get tasks for the collaborator specified."""
Expand Down
21 changes: 5 additions & 16 deletions openfl/component/assigner/static_grouped_assigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,13 @@ def __init__(self, task_groups, **kwargs):

def define_task_assignments(self):
"""All of the logic to set up the map of tasks to collaborators is done here."""
cols_amount = sum(
[len(group["collaborators"]) for group in self.task_groups]
)
cols_amount = sum([len(group["collaborators"]) for group in self.task_groups])
authorized_cols_amount = len(self.authorized_cols)

unique_cols = {
col for group in self.task_groups for col in group["collaborators"]
}
unique_cols = {col for group in self.task_groups for col in group["collaborators"]}
unique_authorized_cols = set(self.authorized_cols)

assert (
cols_amount == authorized_cols_amount
and unique_cols == unique_authorized_cols
), (
assert cols_amount == authorized_cols_amount and unique_cols == unique_authorized_cols, (
f"Collaborators in each group must be distinct: "
f"{unique_cols}, {unique_authorized_cols}"
)
Expand All @@ -75,19 +68,15 @@ def define_task_assignments(self):

# Initialize the map of collaborators for a given task on a given round
for task in self.all_tasks_in_groups:
self.collaborators_for_task[task] = {
i: [] for i in range(self.rounds)
}
self.collaborators_for_task[task] = {i: [] for i in range(self.rounds)}

for group in self.task_groups:
group_col_list = group["collaborators"]
self.task_group_collaborators[group["name"]] = group_col_list
for col in group_col_list:
# For now, we assume that collaborators have the same tasks for
# every round
self.collaborator_tasks[col] = {
i: group["tasks"] for i in range(self.rounds)
}
self.collaborator_tasks[col] = {i: group["tasks"] for i in range(self.rounds)}
# Now populate reverse lookup of tasks->group
for task in group["tasks"]:
for round_ in range(self.rounds):
Expand Down
4 changes: 1 addition & 3 deletions openfl/component/assigner/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ class Task:
function_name: str
task_type: str
apply_local: bool = False
parameters: dict = field(
default_factory=dict
) # We can expend it in the future
parameters: dict = field(default_factory=dict) # We can expend it in the future


@dataclass
Expand Down
Loading

0 comments on commit b4cf970

Please sign in to comment.