RAPIDS nx-cugraph is a backend to NetworkX to run supported algorithms with GPU acceleration.
nx-cugraph requires the following:
- NVIDIA GPU, Volta architecture or later, with compute capability 7.0+
- CUDA 11.4-11.8 or 12.0-12.5
- Python version 3.10, 3.11, or 3.12
- NetworkX >= version 3.2 (version 3.4 or higher recommended)
More details about system requirements can be found in the RAPIDS System Requirements documentation.
nx-cugraph can be installed using either conda or pip.
conda install -c rapidsai-nightly -c conda-forge -c nvidia nx-cugraph
conda install -c rapidsai -c conda-forge -c nvidia nx-cugraph
python -m pip install nx-cugraph-cu11 --extra-index-url https://pypi.anaconda.org/rapidsai-wheels-nightly/simple
python -m pip install nx-cugraph-cu11 --extra-index-url https://pypi.nvidia.com
Notes:
- The pip example above installs for CUDA 11. To install for CUDA 12, replace
-cu11
with-cu12
- Additional information relevant to installing any RAPIDS package can be found here.
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 ββ generators ββ complete_bipartite_graph 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 ββ 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 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 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 convert ββ from_dict_of_lists ββ to_dict_of_lists convert_matrix ββ from_pandas_edgelist ββ from_scipy_sparse_array relabel ββ convert_node_labels_to_integers ββ relabel_nodes
To request nx-cugraph backend support for a NetworkX API that is not listed above, visit the cuGraph GitHub repo.