SSSP
UDTF: cugraph_sssp
Official cuGraph reference: C API
Compute minimum path distances and predecessors from one source vertex, using edges.weight or unit cost 1 when that field is omitted.
Quickstart
The call below supplies edges from registered relation target_edges with canonical src and dst columns and may include weight, and starts from source vertex 123.
SELECT *
FROM cugraph_sssp(
edges => (SELECT src, dst, weight FROM target_edges),
source_vertex => 123
);
Inputs
Every relation is a named parenthesized SELECT subquery. The required edges role uses canonical src and dst columns. Every role, its canonical columns, and their accepted Arrow types are listed under Relation arguments. Metadata validation resolves registered tables named in its JSON request.
The vertex-ID types this UDTF accepts, the numeric types a per-call codebook maps to native ids, and its string-key limits are listed in Vertex ID support; the concrete call-specific schema comes from gpu_validate_call.
Arguments and options
Relation arguments
Every edge_id column must have the integer type of src and dst; string-keyed graphs accept no edge IDs.
Named value arguments
Graph construction options
Graph construction follows the shared defaults (directed=true, renumbering, python_cugraph policy) documented in Graph Construction Options.
Output
These are generic descriptor schemas. Run gpu_validate_call to get the concrete, table-specific output schema.
Examples
This example runs on the citation network demo dataset.
Which widely cited early language-modeling papers are closest to the Transformer?
For a historical reading route, assign each citation a cost of
1 + (citing_year - cited_year)^2. The fixed cost penalizes extra hops, while
the squared year gap penalizes large jumps between publication dates. SSSP
minimizes the sum along each route. This is an explicit reading-cost policy,
not a measure of a paper's influence or difficulty.
The query follows references from the 2017 Transformer paper and ranks reachable language-related papers published by 2005 with at least 500 reported citations. Each row includes the previous paper on its cheapest route. The source ID is the Transformer record in the seed table.
SELECT p.year, p.title, p.n_citation, CAST(s.distance AS BIGINT) AS reading_cost,
previous.title AS previous_paper
FROM cugraph_sssp(
edges => (
SELECT e.src, e.dst,
CAST(1 + (ps.year - pd.year) * (ps.year - pd.year) AS DOUBLE) AS weight
FROM citation_edges e
JOIN papers ps ON ps.paper_id = e.src
JOIN papers pd ON pd.paper_id = e.dst
WHERE ps.year BETWEEN 1900 AND 2017 AND pd.year BETWEEN 1900 AND 2017),
source_vertex => 2963403868) s
JOIN papers p ON p.paper_id = s.vertex
JOIN papers previous ON previous.paper_id = s.predecessor
WHERE s.distance < 1e300
AND p.year <= 2005
AND p.n_citation >= 500
AND p.primary_fos IN ('Language model', 'Machine translation', 'Natural language processing')
ORDER BY s.distance, p.paper_id
LIMIT 6;
The table abbreviates the GENIA title to GENIA corpus….
Unreachable vertices are excluded. If several routes have the same minimum cost, the query names the predecessor of one of them. Repeated runs on the same data name the same paper, but which of the tied routes that is stays unspecified.
Limits
- omitting edges.weight assigns unit cost 1 to every edge