skypilot-org / skypilot

SkyPilot: Run AI and batch jobs on any infra (Kubernetes or 12+ clouds). Get unified execution, cost savings, and high GPU availability via a simple interface.
https://skypilot.readthedocs.io
Apache License 2.0
6.71k stars 496 forks source link

Bug: `is_chain` function inaccurately detects chain structure #4187

Open andylizf opened 2 hours ago

andylizf commented 2 hours ago

The is_chain function fails to accurately detect chain structures. The current logic only checks that there's one node with an out-degree of 0 and all other nodes have an out-degree of 1. However, this overlooks cases where multiple nodes converge (i.e., nodes with an in-degree > 1), which are not valid for a chain structure.

Example: Consider a graph with paths:

A → B → D
C → B

Here, D has an out-degree of 0, and all other nodes have an out-degree of 1, yet this is clearly not a single chain.

Suggested Fix: To correctly identify a chain, the function should:

  1. Verify there is exactly one start node (in-degree 0) and one end node (out-degree 0).
  2. Ensure all other nodes have in-degree and out-degree of 1.

This correction will prevent false positives and ensure accurate chain detection.

andylizf commented 2 hours ago

@cblmemo PTAL, thanks!