Skip to content

Commit 1b5c52c

Browse files
authored
Refactor DAG Optimizer (skypilot-org#628)
* Refactor optimizer * Remove unnecessary import * yapf * Minor fix * Add NotImplementedError * Minor * Rename vars & Annotate types * Minor fix * Minor * Minor fix * Fix type annotation * yapf * [Minor] Address comment * Add type alias & enhance comments * yapf * Fix minor error in dag_lib.Dag * Add is_chain to Dag * Address comments * yapf * yapf * Address comments * Add total in optimizer msg * Add a comment in is_chain * Address reviews & Fix egress msg * yapf * Minor fix * Fix egress msg * yapf * obj -> objective * pass yapf * cost -> cost/time
1 parent b5e277e commit 1b5c52c

File tree

3 files changed

+310
-118
lines changed

3 files changed

+310
-118
lines changed

examples/example_app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ def make_application():
7676

7777
dag = make_application()
7878
sky.optimize(dag, minimize=sky.OptimizeTarget.COST)
79-
# sky.optimize(dag, minimize=OptimizeTarget.TIME)
79+
# sky.optimize(dag, minimize=sky.OptimizeTarget.TIME)

sky/dag.py

+17
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,20 @@ def __repr__(self):
7171

7272
def get_graph(self):
7373
return self.graph
74+
75+
def is_chain(self) -> bool:
76+
# NOTE: this method assumes that the graph has no cycle.
77+
is_chain = True
78+
visited_zero_out_degree = False
79+
for node in self.graph.nodes:
80+
out_degree = self.graph.out_degree(node)
81+
if out_degree > 1:
82+
is_chain = False
83+
break
84+
elif out_degree == 0:
85+
if visited_zero_out_degree:
86+
is_chain = False
87+
break
88+
else:
89+
visited_zero_out_degree = True
90+
return is_chain

0 commit comments

Comments
 (0)