Skip to content

Commit

Permalink
fix: also ensure it's connected
Browse files Browse the repository at this point in the history
  • Loading branch information
andylizf committed Oct 26, 2024
1 parent cf06c10 commit 8899963
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions sky/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,15 @@ def is_chain(self) -> bool:
(all(degree <= 1 for degree in out_degrees) and
sum(degree == 0 for degree in out_degrees) == 1))

def is_dag(self) -> bool:
"""Check if the DAG is a DAG."""
return nx.is_directed_acyclic_graph(self.graph)
def is_connected_dag(self) -> bool:
"""Check if the graph is a connected directed acyclic graph (DAG).
Returns:
True if the graph is a connected DAG (weakly connected,
directed and acyclic), False otherwise.
"""
return (nx.is_directed_acyclic_graph(self.graph) and
nx.is_weakly_connected(self.graph))


class _DagContext(threading.local):
Expand Down
2 changes: 1 addition & 1 deletion sky/jobs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def launch(
dag = dag_utils.convert_entrypoint_to_dag(entrypoint)
dag, mutated_user_config = admin_policy_utils.apply(
dag, use_mutated_config_in_current_request=False)
if not dag.is_dag():
if not dag.is_connected_dag():
with ux_utils.print_exception_no_traceback():
raise ValueError(f'Only DAG is allowed for job_launch. Dag: {dag}')

Expand Down

0 comments on commit 8899963

Please sign in to comment.