Skip to content

rapidsai/nx-cugraph

nx-cugraph

Description

RAPIDS nx-cugraph is a backend to NetworkX to run supported algorithms with GPU acceleration.

System Requirements

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.

Installation

nx-cugraph can be installed using either conda or pip.

conda

latest nightly version

conda install -c rapidsai-nightly -c conda-forge -c nvidia nx-cugraph

latest stable version

conda install -c rapidsai -c conda-forge -c nvidia nx-cugraph

pip

latest nightly version

python -m pip install nx-cugraph-cu11 --extra-index-url https://pypi.anaconda.org/rapidsai-wheels-nightly/simple

latest stable version

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.

Enabling nx-cugraph

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 argument

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")

Type-based dispatching

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

Supported Algorithms

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

Other

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.