Skip to content

Commit

Permalink
Add: Stage parallelization using topological sorter
Browse files Browse the repository at this point in the history
  • Loading branch information
wysockipiotr committed May 8, 2024
1 parent 3c8a4c7 commit 1ead640
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion smartschedule/parallelization/parallel_stages_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def __str__(self) -> str:

def add(self, new_parallel_stages: ParallelStages) -> Self:
result = [*self.all, new_parallel_stages]
return ParallelStagesList(result)
return ParallelStagesList(all=result)
21 changes: 20 additions & 1 deletion smartschedule/parallelization/stage_parallelization.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
from graphlib import TopologicalSorter, CycleError

from smartschedule.parallelization.parallel_stages import ParallelStages
from smartschedule.parallelization.parallel_stages_list import ParallelStagesList
from smartschedule.parallelization.stage import Stage


class StageParallelization:
@staticmethod
def of(stages: set[Stage]) -> ParallelStagesList:
return ParallelStagesList()
parallel_stages_list = ParallelStagesList()
sorter = TopologicalSorter(
graph={stage: stage.dependencies for stage in stages}
)

try:
sorter.prepare()
except CycleError:
return parallel_stages_list

while sorter.is_active():
group = sorter.get_ready()
parallel_stages = ParallelStages(set(group))
parallel_stages_list = parallel_stages_list.add(parallel_stages)
sorter.done(*group)

return parallel_stages_list

0 comments on commit 1ead640

Please sign in to comment.