Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 5dfa0e6

Browse files
committed
fix(cugraph): filter isolated nodes in CreateCugraphFromMemgraph
Fixes "Index out of range!" error when running cuGraph algorithms on graphs containing isolated nodes (nodes with no edges). The bug: CreateCugraphFromMemgraph passed ALL nodes to cuGraph via cu_vertices, but the GraphView's inner_to_memgraph_id_ mapping only reliably maps nodes that appear in edges. When cuGraph returned results for isolated nodes, GetMemgraphNodeId() failed because those node IDs weren't properly mapped. The fix: Only include nodes that have at least one edge (in-degree > 0 or out-degree > 0) in the vertex list passed to cuGraph. This is also semantically correct - isolated nodes have betweenness/PageRank/etc of zero by definition since no paths traverse them.
1 parent 04a0455 commit 5dfa0e6

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

cpp/cugraph_module/mg_cugraph_utility.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#pragma once
77

8+
#include <unordered_set>
89
#include <cugraph/algorithms.hpp>
910
#include <cugraph/arithmetic_variant_types.hpp>
1011
#include <cugraph/graph.hpp>
@@ -102,8 +103,19 @@ auto CreateCugraphFromMemgraph(const mg_graph::GraphView<> &mg_graph, const mg_g
102103
std::transform(
103104
mg_edges.begin(), mg_edges.end(), std::back_inserter(mg_weight),
104105
[&mg_graph](const auto &edge) -> TWeightT { return mg_graph.IsWeighted() ? mg_graph.GetWeight(edge.id) : 1.0; });
105-
std::transform(mg_nodes.begin(), mg_nodes.end(), std::back_inserter(mg_vertices),
106-
[](const auto &node) -> TVertexT { return node.id; });
106+
// Only include nodes that have edges - isolated nodes cause ID mapping issues
107+
// and have betweenness = 0 by definition (no paths through them)
108+
// Build set of vertices that appear in edges
109+
std::unordered_set<TVertexT> vertices_with_edges;
110+
for (const auto& edge : mg_edges) {
111+
vertices_with_edges.insert(static_cast<TVertexT>(edge.from));
112+
vertices_with_edges.insert(static_cast<TVertexT>(edge.to));
113+
}
114+
for (const auto& node : mg_nodes) {
115+
if (vertices_with_edges.count(static_cast<TVertexT>(node.id)) > 0) {
116+
mg_vertices.push_back(static_cast<TVertexT>(node.id));
117+
}
118+
}
107119

108120
// Synchronize the data structures to the GPU
109121
auto stream = handle.get_stream();

0 commit comments

Comments
 (0)