Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 94 additions & 75 deletions notebooks/algorithms/layout/Force-Atlas2.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -9,6 +10,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -19,19 +21,14 @@
"| Author Credit | Date | Update | cuGraph Version | Test Hardware |\n",
"| -----------------|------------|------------------|-----------------|----------------|\n",
"| Hugo Linsenmaier | 11/16/2020 | created | 0.17 | GV100, CUDA 11.0\n",
"| Brad Rees | 01/11/2022 | tested / updated | 22.02 nightly | RTX A6000 CUDA 11.5\n",
"| Ralph Liu | 06/22/2022 | updated/tested | 22.08 | TV100, CUDA 11.5\n",
"| Don Acosta | 08/01/2022 | tested / updated | 22.08 nightly | DGX Tesla A100 CUDA 11.5 "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### This notebook will not currently run because there is a conflict between the version of CuPy required by cugraph (11.0) and the version supported in cuxfilter (7.8 to 10.0). Notebook will be updated when cuxfilter supports CuPy 11."
"| Brad Rees | 01/11/2022 | tested / updated | 22.02 nightly | RTX A6000 48GB CUDA 11.5\n",
"| Ralph Liu | 06/22/2022 | updated/tested | 22.08 nightly | V100, CUDA 11.5\n",
"| Don Acosta | 08/01/2022 | tested / updated | 22.08 nightly | DGX Tesla A100 CUDA 11.5 \n",
"| Don Acosta | 07/17/2023 | tested / updated | 23.08 nightly |RTX A6000 48GB CUDA 11.7 "
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -44,45 +41,20 @@
"See https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0098679 for more details.\n",
"\n",
"\n",
"Please refer to the [documentation](https://docs.rapids.ai/api/cugraph/stable/api_docs/api/cugraph.force_atlas2.html) on how to use the different parameters.\n",
"\n",
"This library has some additional dependencies that need to be installed prior to running:\n",
"* Holoviews - provides "
"Please refer to the [documentation](https://docs.rapids.ai/api/cugraph/stable/api_docs/api/cugraph.force_atlas2.html) on how to use the different parameters.\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Import RAPIDS libraries\n",
"import cudf\n",
"import cugraph\n",
"import time"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Viz libraries\n",
"\n",
"from cuxfilter.charts.datashader.custom_extensions.graph_assets import calc_connected_edges\n",
"\n",
"import holoviews as hv\n",
"\n",
"from colorcet import fire\n",
"from datashader.bundling import directly_connect_edges, hammer_bundle\n",
"\n",
"from holoviews.operation.datashader import datashade, dynspread\n",
"from holoviews.operation import decimate\n",
"\n",
"from dask.distributed import Client"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -106,22 +78,7 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Setup Viz\n",
"client = Client()\n",
"hv.notebook_extension('bokeh','matplotlib')\n",
"decimate.max_samples=20000\n",
"dynspread.threshold=0.01\n",
"datashade.cmap=fire[40:]\n",
"sz = dict(width=150,height=150)\n",
"%opts RGB [xaxis=None yaxis=None show_grid=False bgcolor=\"black\"]"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -134,11 +91,12 @@
"metadata": {},
"outputs": [],
"source": [
"G = netscience.get_graph()\n",
"G = netscience.get_graph(fetch=True)\n",
"G.number_of_nodes(), G.number_of_edges()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -167,14 +125,31 @@
" verbose=False,\n",
" callback=None)\n",
"elapsed = time.time() - start\n",
"print(\"Cugraph time : \" + str(elapsed))"
"print(\"Cugraph time : \" + str(elapsed))\n",
"pos_gdf.head(5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Visualize the graph\n",
"\n",
"The following section creates a visualization of the network using the locations generated by the Force Atlas algorithms. However, the following section is dependent on having the **cuxfilter** package installed. \n",
"\n",
"See the cuxfilter GitHub page for installation: https://github.com/rapidsai/cuxfilter. \n",
"\n",
"Alternatively, the package comes installed in the RAPIDS development Docker container. \n",
"See: https://hub.docker.com/r/rapidsai/rapidsai-dev/ \n",
"\n",
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Convert a graph into paths suitable for datashading"
"Set up the visualization"
]
},
{
Expand All @@ -183,20 +158,54 @@
"metadata": {},
"outputs": [],
"source": [
"edges_gdf = netscience.get_edgelist()\n",
"import importlib.util\n",
"cux_spec = importlib.util.find_spec(\"cuxfilter\")\n",
"if cux_spec is None:\n",
" print(\"Visualization package is not available.\")\n",
"else:\n",
" from cuxfilter.charts.datashader.custom_extensions.graph_assets import calc_connected_edges\n",
" # Viz libraries\n",
" import holoviews as hv\n",
"\n",
" from colorcet import fire\n",
" from datashader.bundling import directly_connect_edges, hammer_bundle\n",
"\n",
" from holoviews.operation.datashader import datashade, dynspread\n",
" from holoviews.operation import decimate\n",
"\n",
"connected = calc_connected_edges(pos_gdf,\n",
" edges_gdf,\n",
" node_x=\"x\",\n",
" node_y=\"y\",\n",
" node_x_dtype=\"float32\",\n",
" node_y_dtype=\"float32\",\n",
" node_id=\"vertex\",\n",
" edge_source=\"src\",\n",
" edge_target=\"dst\",\n",
" edge_aggregate_col=None,\n",
" edge_render_type=\"direct\",\n",
" )"
" from dask.distributed import Client\n",
"\n",
" # Define the parameters \n",
" ITERATIONS=500\n",
" THETA=1.0\n",
" OPTIMIZE=True\n",
"\n",
" # Import a built-in dataset\n",
" from cugraph.experimental.datasets import netscience\n",
"\n",
" # Setup Viz\n",
" client = Client()\n",
" hv.notebook_extension('bokeh','matplotlib')\n",
" decimate.max_samples=20000\n",
" dynspread.threshold=0.01\n",
" datashade.cmap=fire[40:]\n",
" sz = dict(width=150,height=150)\n",
" %opts RGB [xaxis=None yaxis=None show_grid=False bgcolor=\"black\"]\n",
"\n",
" edges_gdf = netscience.get_edgelist()\n",
"\n",
" connected = calc_connected_edges(pos_gdf,\n",
" edges_gdf,\n",
" node_x=\"x\",\n",
" node_y=\"y\",\n",
" node_x_dtype=\"float32\",\n",
" node_y_dtype=\"float32\",\n",
" node_id=\"vertex\",\n",
" edge_source=\"src\",\n",
" edge_target=\"dst\",\n",
" edge_aggregate_col=None,\n",
" edge_render_type=\"direct\",\n",
" )\n"
]
},
{
Expand All @@ -206,23 +215,33 @@
"### Output"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%opts RGB [tools=[\"hover\"] width=800 height=800]\n",
"\n",
"r_direct = hv.Curve(connected, label=\"Direct\")\n",
"datashade(r_direct)"
"r_direct = None\n",
"if cux_spec is not None:\n",
" %opts RGB [tools=[\"hover\"] width=800 height=800]\n",
" r_direct = hv.Curve(connected, label=\"Direct\")\n",
" \n",
"r_direct"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Copyright (c) 2020 - 2022, NVIDIA CORPORATION.\n",
"Copyright (c) 2020 - 2023, NVIDIA CORPORATION.\n",
"\n",
"Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\n",
"\n",
Expand All @@ -246,7 +265,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.10.12"
},
"vscode": {
"interpreter": {
Expand Down