nx-cugraph is a backend to NetworkX to run algorithms with zero code change GPU acceleration.
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.
conda install -c rapidsai -c conda-forge -c nvidia nx-cugraph
We also provide nightly Conda packages built from the HEAD of our latest development branch.
conda install -c rapidsai-nightly -c conda-forge -c nvidia nx-cugraph
nx-cugraph can be installed via pip
from the NVIDIA Python Package Index.
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:
NX_CUGRAPH_AUTOCONFIG
environment variable.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
backend=
keyword argumentTo 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