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.


System Requirements

  • GPU: NVIDIA Volta architecture or later, with compute capability 7.0+
    • Pascal GPU support was removed in 24.02. Compute capability 7.0+ is required for RAPIDS 24.02 and later.
  • CUDA Version: 11.4 - 11.8 or 12.0 - 12.5
  • Python Version: 3.10, 3.11, or 3.12
  • NetworkX Version: minimum 3.2 (version 3.4 or higher recommended)

Note: nx-cugraph is supported only on Linux, and with Python versions 3.10 and later.

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.

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

pip

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

For CUDA 11.x:

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
  • Try out the RAPIDS Install Selector Tool to install other RAPIDS packages.

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
 └─ 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
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
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_cu11-25.6.0.tar.gz (6.0 kB view details)

Uploaded Source

File details

Details for the file nx_cugraph_cu11-25.6.0.tar.gz.

File metadata

  • Download URL: nx_cugraph_cu11-25.6.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.18

File hashes

Hashes for nx_cugraph_cu11-25.6.0.tar.gz
Algorithm Hash digest
SHA256 2057f9a42448445551a1b0c6753ff451b68b5842e04b5bc2107f03dd0c91623f
MD5 969f83defbd8f7478412eecb7ce80e30
BLAKE2b-256 1ad7ce5dabf6b4a8851f1d7d5a9abfe33b001f2d8707d82ba78fd7f4d510e7a5

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