nx-cugraph is a backend to NetworkX to run algorithms with zero code change GPU acceleration.
- GPU: NVIDIA Volta architecture or later, with compute capability 7.0+
- CUDA Version: 12.0 or higher
- Python Version: 3.10 - 3.13
- NetworkX Version: minimum 3.2 (version 3.5 or higher recommended)
Note: nx-cugraph is supported only on Linux
See RAPIDS System Requirements for detailed information on OS and Versions.
nx-cugraph can be installed using either conda or pip with the following commands.
nx-cugraph can be installed with conda (via Miniforge) from the rapidsai channel.
# CUDA 13 conda install -c rapidsai -c conda-forge nx-cugraph cuda-version=13.0 # CUDA 12 conda install -c rapidsai -c conda-forge nx-cugraph cuda-verison=12.9We also provide nightly Conda packages built from the HEAD of our latest development branch.
# CUDA 13 conda install -c rapidsai-nightly -c conda-forge nx-cugraph cuda-version=13.0 # CUDA 12 conda install -c rapidsai-nightly -c conda-forge nx-cugraph cuda-verison=12.9nx-cugraph can be installed via pip from the NVIDIA Python Package Index.
Latest nightly version
python -m pip install nx-cugraph-cu13 --extra-index-url https://pypi.anaconda.org/rapidsai-wheels-nightly/simple Latest stable version
python -m pip install nx-cugraph-cu13 --extra-index-url https://pypi.nvidia.com Notes:
- Try out the RAPIDS Install Selector Tool to install other RAPIDS packages.
Latest nightly version
python -m pip install nx-cugraph-cu12 --extra-index-url https://pypi.anaconda.org/rapidsai-wheels-nightly/simple Latest stable version
python -m pip install nx-cugraph-cu12 --extra-index-url https://pypi.nvidia.com Notes:
- Try out the RAPIDS Install Selector Tool to install other RAPIDS packages.
NetworkX will use nx-cugraph as the graph analytics backend if any of the following are used:
By setting NX_CUGRAPH_AUTOCONFIG=True, NetworkX will automatically dispatch algorithm calls to nx-cugraph (if the backend is supported). This allows users to GPU accelerate their code with zero code change.
Read more on Networkx Backends and How They Work.
Example:
bash> NX_CUGRAPH_AUTOCONFIG=True python my_networkx_script.py To explicitly specify a particular backend for an API, use the backend= keyword argument. This argument takes precedence over the NX_CUGRAPH_AUTOCONFIG environment variable. This requires anyone running code that uses the backend= keyword argument to have the specified backend installed.
Example:
nx.betweenness_centrality(cit_patents_graph, k=k, backend="cugraph") NetworkX also supports automatically dispatching to backends associated with specific graph types. Like the backend= keyword argument example above, this requires the user to write code for a specific backend, and therefore requires the backend to be installed, but has the advantage of ensuring a particular behavior without the potential for runtime conversions.
To use type-based dispatching with nx-cugraph, the user must import the backend directly in their code to access the utilities provided to create a Graph instance specifically for the nx-cugraph backend.
Example:
import networkx as nx import nx_cugraph as nxcg G = nx.Graph() ... nxcg_G = nxcg.from_networkx(G) # conversion happens once here nx.betweenness_centrality(nxcg_G, k=1000) # nxcg Graph type causes cugraph backend # to be used, no conversion necessary The nx-cugraph backend to NetworkX connects pylibcugraph (cuGraph's low-level python interface to its CUDA-based graph analytics library) and CuPy (a GPU-accelerated array library) to NetworkX's familiar and easy-to-use API.
Below is the list of algorithms that are currently supported in nx-cugraph.
bipartite ββ centrality β ββ betweenness_centrality ββ generators β ββ complete_bipartite_graph ββ matrix ββ biadjacency_matrix ββ from_biadjacency_matrix centrality ββ betweenness β ββ betweenness_centrality β ββ edge_betweenness_centrality ββ degree_alg β ββ degree_centrality β ββ in_degree_centrality β ββ out_degree_centrality ββ eigenvector β ββ eigenvector_centrality ββ katz ββ katz_centrality cluster ββ average_clustering ββ clustering ββ transitivity ββ triangles community ββ leiden β ββ leiden_communities ββ louvain ββ louvain_communities components ββ connected β ββ connected_components β ββ is_connected β ββ node_connected_component β ββ number_connected_components ββ weakly_connected ββ is_weakly_connected ββ number_weakly_connected_components ββ weakly_connected_components core ββ core_number ββ k_truss dag ββ ancestors ββ descendants isolate ββ is_isolate ββ isolates ββ number_of_isolates link_analysis ββ hits_alg β ββ hits ββ pagerank_alg ββ pagerank link_prediction ββ jaccard_coefficient lowest_common_ancestors ββ lowest_common_ancestor operators ββ unary ββ complement ββ reverse reciprocity ββ overall_reciprocity ββ reciprocity shortest_paths ββ generic β ββ has_path β ββ shortest_path β ββ shortest_path_length ββ unweighted β ββ all_pairs_shortest_path β ββ all_pairs_shortest_path_length β ββ bidirectional_shortest_path β ββ single_source_shortest_path β ββ single_source_shortest_path_length β ββ single_target_shortest_path β ββ single_target_shortest_path_length ββ weighted ββ all_pairs_bellman_ford_path ββ all_pairs_bellman_ford_path_length ββ all_pairs_dijkstra ββ all_pairs_dijkstra_path ββ all_pairs_dijkstra_path_length ββ bellman_ford_path ββ bellman_ford_path_length ββ dijkstra_path ββ dijkstra_path_length ββ single_source_bellman_ford ββ single_source_bellman_ford_path ββ single_source_bellman_ford_path_length ββ single_source_dijkstra ββ single_source_dijkstra_path ββ single_source_dijkstra_path_length tournament ββ tournament_matrix traversal ββ breadth_first_search ββ bfs_edges ββ bfs_layers ββ bfs_predecessors ββ bfs_successors ββ bfs_tree ββ descendants_at_distance ββ generic_bfs_edges tree ββ recognition ββ is_arborescence ββ is_branching ββ is_forest ββ is_tree
classic ββ barbell_graph ββ circular_ladder_graph ββ complete_graph ββ complete_multipartite_graph ββ cycle_graph ββ empty_graph ββ ladder_graph ββ lollipop_graph ββ null_graph ββ path_graph ββ star_graph ββ tadpole_graph ββ trivial_graph ββ turan_graph ββ wheel_graph community ββ caveman_graph ego ββ ego_graph small ββ bull_graph ββ chvatal_graph ββ cubical_graph ββ desargues_graph ββ diamond_graph ββ dodecahedral_graph ββ frucht_graph ββ heawood_graph ββ house_graph ββ house_x_graph ββ icosahedral_graph ββ krackhardt_kite_graph ββ moebius_kantor_graph ββ octahedral_graph ββ pappus_graph ββ petersen_graph ββ sedgewick_maze_graph ββ tetrahedral_graph ββ truncated_cube_graph ββ truncated_tetrahedron_graph ββ tutte_graph social ββ davis_southern_women_graph ββ florentine_families_graph ββ karate_club_graph ββ les_miserables_graph
classes ββ function ββ is_negatively_weighted ββ number_of_selfloops convert ββ from_dict_of_lists ββ to_dict_of_lists convert_matrix ββ from_pandas_edgelist ββ from_scipy_sparse_array ββ to_numpy_array ββ to_scipy_sparse_array drawing ββ layout ββ forceatlas2_layout linalg ββ graphmatrix ββ adjacency_matrix relabel ββ convert_node_labels_to_integers ββ relabel_nodes
To request nx-cugraph backend support for a NetworkX API that is not listed above, file an issue.
If you would like to contribute to nx-cugraph, refer to the Contributing Guide
