Skip to main content

grapher.select_shortest_path_subgraph()

Return the induced subgraph over all hop-shortest paths between two nodes.

Usage

Source

grapher.select_shortest_path_subgraph(
    graph, *, source_key, target_key, directed=True, max_path_length=None
)

Edge direction on the returned graph follows DependencyGraph semantics: A -> B means A depends on B. directed affects search only.

Parameters

graph: DependencyGraph

Dependency graph to search.

source_key: NodeKey

Path start node.

target_key: NodeKey

Path end node.

directed: bool = True

If True, walk outgoing dependency edges only. If False, treat each edge as bidirectional for reachability.

max_path_length: int | None = None
Optional hop-count ceiling. 0 allows only the trivial same-key path.

Returns

DependencyGraph

Induced subgraph of every hop-shortest path. Endpoints are always

included. Returned edges keep original direction, guards, and

provenance.

Raises

ValueError
If a key is missing, max_path_length is negative, no path exists under the requested directionality, or the shortest path is longer than max_path_length. A directed miss that still has an undirected path mentions directed=False.