Skip to main content

cugraph backend for NetworkX

Project description

ย 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.2 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.1

# 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.1

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

Algorithms

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

Generators

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nx_cugraph_cu12-26.2.0.tar.gz (6.1 kB view details)

Uploaded Source

File details

Details for the file nx_cugraph_cu12-26.2.0.tar.gz.

File metadata

  • Download URL: nx_cugraph_cu12-26.2.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.19

File hashes

Hashes for nx_cugraph_cu12-26.2.0.tar.gz
Algorithm Hash digest
SHA256 de4c6143b7fd5dc54f474e6beb32c721012cd62368b9c8d1664bfbe589c17d2d
MD5 e70412708007e8b701babe14eb841735
BLAKE2b-256 824c14b6ae938b60c57786192bce114827d68128cd1e9fb54caa78238657805e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page