Skip to content

eriknw/nx-cugraph

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Β nx-cugraph - GPU Backend for NetworkX

Description

nx-cugraph is a backend to NetworkX to run algorithms with zero code change GPU acceleration.

πŸ” Try it in Google Colab!

Open In Colab


System Requirements

  • 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.

Installation

nx-cugraph can be installed using either conda or pip with the following commands.

conda

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.9

We 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.9

pip

nx-cugraph can be installed via pip from the NVIDIA Python Package Index.

For CUDA 13.x:

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:

For CUDA 12.x:

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:

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 β”œβ”€ 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 

Other

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.

Contributing

If you would like to contribute to nx-cugraph, refer to the Contributing Guide

About

GPU Accelerated Backend for NetworkX

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 89.1%
  • Jupyter Notebook 6.7%
  • Shell 4.1%
  • Makefile 0.1%