Skip to content

Commit

Permalink
adding notebook to demo nx_cugraph (#4366)
Browse files Browse the repository at this point in the history
This notebook will be used to demontstrate how to  use nx-cugraph and show the speed-up.

Authors:
  - Don Acosta (https://github.com/acostadon)

Approvers:
  - Brad Rees (https://github.com/BradReesWork)

URL: #4366
  • Loading branch information
acostadon authored May 29, 2024
1 parent 562b5a5 commit 169d162
Show file tree
Hide file tree
Showing 2 changed files with 275 additions and 128 deletions.
159 changes: 31 additions & 128 deletions docs/cugraph/source/nx_cugraph/nx_cugraph.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,142 +24,45 @@ Each chart has three measurements.
![Single Source Shortest Path](../images/sssp.png)
![Weakly Connected Components](../images/wcc.png)

### Command line example
Open bc_demo.ipy and paste the code below.

The following algorithms are supported and automatically dispatched to nx-cuGraph for acceleration.
```
import pandas as pd
import networkx as nx
url = "https://data.rapids.ai/cugraph/datasets/cit-Patents.csv"
df = pd.read_csv(url, sep=" ", names=["src", "dst"], dtype="int32")
G = nx.from_pandas_edgelist(df, source="src", target="dst")
#### Algorithms
%time result = nx.betweenness_centrality(G, k=10)
```
Run the command:
```
bipartite
├─ basic
│ └─ is_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
└─ unweighted
├─ single_source_shortest_path_length
└─ single_target_shortest_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
user@machine:/# ipython bc_demo.ipy
```

#### Generators
You will observe a run time of approximately 7 minutes...more or less depending on your cpu.

Run the command again, this time specifiying cugraph as the NetworkX backend of choice.
```
user@machine:/# NETWORKX_BACKEND_PRIORITY=cugraph ipython bc_demo.ipy
```
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
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
This run will be much faster, typically around 20 seconds depending on your GPU.
```
user@machine:/# NETWORKX_BACKEND_PRIORITY=cugraph ipython bc_demo.ipy
```
There is also an option to add caching. This will dramatically help performance when running multiple algorithms on the same graph.
```
NETWORKX_BACKEND_PRIORITY=cugraph CACHE_CONVERTED_GRAPH=True ipython bc_demo.ipy
```

#### Other
When running Python interactively, cugraph backend can be specified as an argument in the algorithm call.

For example:
```
convert_matrix
├─ from_pandas_edgelist
└─ from_scipy_sparse_array
nx.betweenness_centrality(cit_patents_graph, k=k, backend="cugraph")
```


The latest list of algorithms that can be dispatched to nx-cuGraph for acceleration is found [here](https://github.com/rapidsai/cugraph/blob/main/python/nx-cugraph/README.md#algorithms).
Loading

0 comments on commit 169d162

Please sign in to comment.