Skip to main content

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. Substitute your own registered relations.

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.

Endpoint columns accept numeric Int32, Int64 vertex IDs or logical string Utf8, LargeUtf8, Utf8View vertex IDs; string vertex-identity outputs are canonicalized to Utf8 (native mapping Int64) while scores, distances, counts, coordinates, and opaque labels stay numeric. The shared vertex-ID contract is summarized in Vertex ID support; the concrete call-specific schema comes from gpu_validate_call.

Logical string side-input limitations:

  • edge ID columns and edge-ID predicate side inputs are not supported for logical string graphs

Arguments and options​

Relation arguments​

ArgumentRequiredColumnsDescription
edgesyes
  • src, dst: Int32, Int64, Utf8, LargeUtf8, Utf8View
  • weight (optional): Float32, Float64
  • edge_id (optional): Int32, Int64
edge relation with canonical src and dst columns, plus optional weight and edge_id columns

Every edge_id column must have the integer type of src and dst; string-keyed graphs accept no edge IDs.

Named value arguments​

OptionTypeDefaultConstraintsDescription
cutoffnumber|nullnullmin 0optional non-negative SSSP distance cutoff
source_vertexinteger|stringNo defaultrequiredrequired scalar SSSP source vertex

Graph construction options​

Graph construction follows the shared defaults (directed=true, renumbering, python_cugraph policy) documented in Graph Construction Options.

Output​

ColumnTypeNullableDescription
vertexInt64|Utf8noVertex reached by the shortest-path traversal.
distanceFloat64noShortest weighted-path distance from the source vertex.
predecessorInt64|Utf8yesPrevious vertex on the shortest-path tree, null for the source or unreachable vertices.

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; source_vertex accepts a literal, so the lookup does not need a separate example query.

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;
yeartitlen_citationreading_costprevious_paper
2004Statistical Significance Tests for Machine Translation Evaluation.79326Hybrid data-driven models of machine translation
2003A neural probabilistic language model323628Random Forests in Language Modelin.
2003GENIA corpus…68828Comparison of character-level and part of speech features for name recognition in biomedical texts
2002A Phrase-Based,Joint Probability Model for Statistical Machine Translation58030Statistical phrase-based translation
2001A Study of Smoothing Methods for Language Models Applied to Ad Hoc Information Retrieval182932Passage retrieval based on language models
2000Improved statistical alignment models92434A Syntax-based Statistical Translation Model

The first listed route reaches Statistical Significance Tests for Machine Translation Evaluation. at cost 26 through Hybrid data-driven models of machine translation. The table abbreviates the GENIA title to GENIA corpus….

The edge filter excludes invalid years and publications after the source's year. Forward-dated citations within that interval retain a positive cost. Unreachable vertices are excluded. If several routes have the same minimum cost, their predecessor papers can differ between runs.

Limits​

  • omitting edges.weight assigns unit cost 1 to every edge

To dry-run validate relation metadata, column types, and options without execution, see gpu_validate_call.