### Build and install using build.sh Source: https://docs.nvidia.com/cugraph/latest/installation/source_build/index.html Example command to build specific targets while skipping C++ tests. ```bash $ cd $CUGRAPH_HOME $ ./build.sh libcugraph pylibcugraph cugraph --skip_cpp_tests ``` -------------------------------- ### Perform sampling with starting vertex label offsets Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/plc/pylibcugraph.homogeneous_biased_temporal_neighbor_sample/index.html This example shows how to perform temporal neighbor sampling while providing starting vertex label offsets to manage batching and labeling. ```python >>> start_vertices = cupy.asarray([2, 5, 1]).astype(numpy.int32) >>> starting_vertex_label_offsets = cupy.asarray([0, 2, 3]) >>> sampling_results = pylibcugraph.homogeneous_biased_temporal_neighbor_sample( ... resource_handle, G, None, start_vertices, None, starting_vertex_label_offsets, ... h_fan_out, False, True) >>> sampling_results {'majors': array([2, 2, 5, 5, 1, 1], dtype=int32), 'minors': array([0, 3, 3, 4, 2, 3], dtype=int32), 'weight': array([5.1, 4.1, 7.2, 3.2, 3.1, 2.1], dtype=float32), 'edge_start_time': array([11, 10, 6, 7, 8, 3], dtype=int32), 'edge_end_time': array([12, 11, 7, 8, 9, 4], dtype=int32), 'batch_id': array([0, 0, 0, 0, 1, 1], dtype=int32), 'label_hop_offsets': array([0, 4, 6])} ``` -------------------------------- ### Compute SSSP on a Karate graph Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph/cugraph.sssp/index.html This example demonstrates how to load the karate dataset, create a graph, and compute the single-source shortest path starting from vertex 0. ```python >>> from cugraph.datasets import karate >>> G = karate.get_graph(download=True) >>> distances = cugraph.sssp(G, 0) >>> distances distance vertex predecessor ... ... ... ... ... ... ... ... ... ... ... ... ``` -------------------------------- ### Compute node2vec random walks Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph/cugraph.node2vec_random_walks/index.html This example demonstrates how to initialize a graph from the karate dataset and compute random walks starting from specific vertices with defined parameters. ```python >>> from cugraph.datasets import karate >>> G = karate.get_graph(download=True) >>> start_vertices = cudf.Series([0, 2], dtype=np.int32) >>> paths, weights, max_length = cugraph.node2vec_random_walks(G, ... start_vertices, 3, ... 0.8, 0.5) ``` -------------------------------- ### Homogeneous uniform neighbor sampling with starting vertex label offsets Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/plc/pylibcugraph.homogeneous_uniform_neighbor_sample/index.html Extends the previous example by providing starting_vertex_label_offsets to group start vertices. The output dictionary uses keys 'majors', 'minors', and 'weight'. ```Python >>> start_vertices = cupy.asarray([2, 5, 1]).astype(numpy.int32) >>> starting_vertex_label_offsets = cupy.asarray([0, 2, 3]) >>> sampling_results = pylibcugraph.homogeneous_uniform_neighbor_sample( ... resource_handle, G, start_vertices, starting_vertex_label_offsets, ... h_fan_out, False, True) >>> sampling_results {'majors': array([2, 2, 5, 5, 1, 1], dtype=int32), 'minors': array([1, 3, 3, 4, 3, 4], dtype=int32), 'weight': array([3.1, 4.1, 7.2, 3.2, 2.1, 1.1], dtype=float32)} ``` -------------------------------- ### Compute Minimum Spanning Tree with pylibcugraph Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/plc/pylibcugraph.minimum_spanning_tree/index.html This example demonstrates how to initialize a graph and compute its minimum spanning tree using pylibcugraph. It shows the setup of graph properties, the creation of an SGGraph, and the execution of the minimum_spanning_tree function. ```python >>> import pylibcugraph, cupy, numpy >>> srcs = cupy.asarray([0, 1, 1, 2, 2, 2, 3, 4, 1, 3, 4, ... 0, 1, 3, 5, 5], dtype=numpy.int32) >>> dsts = cupy.asarray([1, 3, 4, 0, 1, 3, 5, 5, 0, 1, 1, ... 2, 2, 2, 3, 4], dtype=numpy.int32) >>> weights = cupy.asarray( ... [0.1, 2.1, 1.1, 5.1, 3.1, 4.1, 7.2, 3.2, 0.1, 2.1, ... 1.1, 5.1, 3.1, 4.1, 7.2, 3.2] ... ,dtype=numpy.float32) >>> resource_handle = pylibcugraph.ResourceHandle() >>> graph_props = pylibcugraph.GraphProperties( ... is_symmetric=True, is_multigraph=False) >>> G = pylibcugraph.SGGraph( ... resource_handle, graph_props, srcs, dsts, weight_array=weights, ... store_transposed=False, renumber=False, do_expensive_check=False) >>> (sources, destinations, edge_weights, subgraph_offsets) = ... pylibcugraph.minimum_spanning_tree(resource_handle, G, False) >>> sources array([0, 1, 2, 3, 4, 5, 1, 1, 1, 4], dtype=int32) >>> destinations array([1, 0, 1, 1, 1, 4, 2, 3, 4, 5], dtype=int32) >>> edge_weights array([0.1, 0.1, 3.1, 2.1, 1.1, 3.2, 3.1, 2.1, 1.1, 3.2], dtype=float32) >>> subgraph_offsets array([0, 10]) ``` -------------------------------- ### Analyze clustering ratio cut example Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/plc/pylibcugraph.analyze_clustering_ratio_cut/index.html This example demonstrates how to set up a graph using SGGraph, perform spectral modularity maximization to obtain clusters, and then calculate the ratio cut score using analyze_clustering_ratio_cut. ```python >>> import pylibcugraph, cupy, numpy >>> srcs = cupy.asarray([0, 1, 2], dtype=numpy.int32) >>> dsts = cupy.asarray([1, 2, 0], dtype=numpy.int32) >>> weights = cupy.asarray([1.0, 1.0, 1.0], dtype=numpy.float32) >>> resource_handle = pylibcugraph.ResourceHandle() >>> graph_props = pylibcugraph.GraphProperties( ... is_symmetric=True, is_multigraph=False) >>> G = pylibcugraph.SGGraph( ... resource_handle, graph_props, srcs, dsts, weight_array=weights, ... store_transposed=True, renumber=False, do_expensive_check=False) >>> (vertex, cluster) = pylibcugraph.spectral_modularity_maximization( ... resource_handle, G, num_clusters=5, num_eigen_vects=2, evs_tolerance=0.00001 ... evs_max_iter=100, kmean_tolerance=0.00001, kmean_max_iter=100) # FIXME: Fix docstring result. >>> vertices ############ >>> clusters ############ >>> score = pylibcugraph.analyze_clustering_ratio_cut( ... resource_handle, G, num_clusters=5, vertex=vertex, cluster=cluster) >>> score ############ ``` -------------------------------- ### Python example using pylibcugraph.heterogeneous_biased_neighbor_sample Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/plc/pylibcugraph.heterogeneous_biased_neighbor_sample/index.html Shows how to create a ResourceHandle, GraphProperties, and SGGraph from CuPy arrays, then call heterogeneous_biased_neighbor_sample with start vertices, label offsets, fan-out, and edge type count. The output is a dictionary of sampled majors, minors, and weights. ```Python >>> import pylibcugraph, cupy, numpy >>> srcs = cupy.asarray([0, 1, 1, 2, 2, 2, 3, 4, 1, 3, 4, 0, 1, 3, 5, 5], ... dtype=numpy.int32) >>> dsts = cupy.asarray([1, 3, 4, 0, 1, 3, 5, 5, 0, 1, 1, 2, 2, 2, 3, 4], ... dtype=numpy.int32) >>> weights = cupy.asarray([0.1, 2.1, 1.1, 5.1, 3.1, 4.1, 7.2, 3.2, 0.1, 2.1, ... 1.1, 5.1, 3.1, 4.1, 7.2, 3.2], dtype=numpy.float32) >>> edge_types = cupy.asarray([0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1], ... dtype=numpy.int32) >>> start_vertices = cupy.asarray([2, 5, 1]).astype(numpy.int32) >>> num_edge_types = 2 >>> starting_vertex_label_offsets = cupy.asarray([0, 2, 3]) >>> h_fan_out = numpy.array([2]).astype(numpy.int32) >>> resource_handle = pylibcugraph.ResourceHandle() >>> graph_props = pylibcugraph.GraphProperties( ... is_symmetric=False, is_multigraph=False) >>> G = pylibcugraph.SGGraph( ... resource_handle, graph_props, srcs, dsts, weight_array=weights, ... store_transposed=False, renumber=False, do_expensive_check=False) >>> sampling_results = pylibcugraph.heterogeneous_biased_neighbor_sample( ... resource_handle, G, start_vertices, starting_vertex_label_offsets, ... h_fan_out, num_edge_types, False, True) >>> sampling_results {'majors': array([2, 2, 2, 5, 5, 1, 1, 1, 1], dtype=int32), 'minors': array([0, 1, 3, 3, 4, 0, 2, 3, 4], dtype=int32), 'weight': array([5.1, 3.1, 4.1, 7.2, 3.2, 0.1, 3.1, 2.1, 1.1], dtype=float32)} ``` -------------------------------- ### Balanced Cut Clustering Example Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/plc/pylibcugraph.balanced_cut_clustering/index.html This example demonstrates how to set up a graph using SGGraph and perform balanced cut clustering using the pylibcugraph API. ```python >>> import pylibcugraph, cupy, numpy >>> srcs = cupy.asarray([0, 1, 2], dtype=numpy.int32) >>> dsts = cupy.asarray([1, 2, 0], dtype=numpy.int32) >>> weights = cupy.asarray([1.0, 1.0, 1.0], dtype=numpy.float32) >>> resource_handle = pylibcugraph.ResourceHandle() >>> graph_props = pylibcugraph.GraphProperties( ... is_symmetric=True, is_multigraph=False) >>> G = pylibcugraph.SGGraph( ... resource_handle, graph_props, srcs, dsts, weight_array=weights, ... store_transposed=True, renumber=False, do_expensive_check=False) >>> (vertices, clusters) = pylibcugraph.balanced_cut_clustering( ... resource_handle, G, num_clusters=5, num_eigen_vects=2, evs_tolerance=0.00001 ... evs_max_iter=100, kmean_tolerance=0.00001, kmean_max_iter=100) # FIXME: Fix docstring results. >>> vertices ############ >>> clusters ############ ``` -------------------------------- ### Analyze clustering edge cut example Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/plc/pylibcugraph.analyze_clustering_edge_cut/index.html This example demonstrates how to initialize a graph, perform spectral modularity maximization to obtain clusters, and then calculate the edge cut score using analyze_clustering_edge_cut. ```python >>> import pylibcugraph, cupy, numpy >>> srcs = cupy.asarray([0, 1, 2], dtype=numpy.int32) >>> dsts = cupy.asarray([1, 2, 0], dtype=numpy.int32) >>> weights = cupy.asarray([1.0, 1.0, 1.0], dtype=numpy.float32) >>> resource_handle = pylibcugraph.ResourceHandle() >>> graph_props = pylibcugraph.GraphProperties( ... is_symmetric=True, is_multigraph=False) >>> G = pylibcugraph.SGGraph( ... resource_handle, graph_props, srcs, dsts, weight_array=weights, ... store_transposed=True, renumber=False, do_expensive_check=False) >>> (vertex, cluster) = pylibcugraph.spectral_modularity_maximization( ... resource_handle, G, num_clusters=5, num_eigen_vects=2, evs_tolerance=0.00001 ... evs_max_iter=100, kmean_tolerance=0.00001, kmean_max_iter=100) # FIXME: Fix docstring result. >>> vertices ############ >>> clusters ############ >>> score = pylibcugraph.analyze_clustering_edge_cut( ... resource_handle, G, num_clusters=5, vertex=vertex, cluster=cluster) >>> score ############ ``` -------------------------------- ### wholememory_tensor_get_local_entry_start Source: https://docs.nvidia.com/cugraph/latest/api_docs/wholegraph/libwholegraph/tensor_descriptions_handles/index.html Gets the entry start of the current rank from a WholeMemory Tensor. Returns a wholememory_error_code_t. ```APIDOC ## wholememory_tensor_get_local_entry_start ### Description Get entry start of current rank from WholeMemory Tensor. ### Function Signature wholememory_error_code_t wholememory_tensor_get_local_entry_start(_size_t *local_entry_start_, _wholememory_tensor_t wholememory_tensor_) ### Parameters - **local_entry_start** (size_t*) - returned entry start id of current rank - **wholememory_tensor** (wholememory_tensor_t) - WholeMemory Tensor ### Returns - **wholememory_error_code_t** - error code ``` -------------------------------- ### View build script help Source: https://docs.nvidia.com/cugraph/latest/wholegraph/installation/source_build/index.html Display the complete list of available options for the build script. ```bash ./build.sh --help ``` -------------------------------- ### Create and use a DistributedNeighborSampler Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph-pyg/cugraph_pyg.sampler.BaseDistributedSampler This example demonstrates initializing a distributed neighbor sampler and iterating through node-based samples. ```python >>> # Create a distributed neighbor sampler >>> sampler = DistributedNeighborSampler( ... graph=mg_graph, ... fanout=[25, 10], ... local_seeds_per_call=1024 ... ) >>> >>> # Sample from nodes >>> for batch in sampler.sample_from_nodes(nodes=seed_nodes): ... # Process batch ... pass ``` -------------------------------- ### Compute SSSP with pylibcugraph Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/plc/pylibcugraph.sssp/index.html This example demonstrates how to initialize a graph and compute the single-source shortest path using the sssp function. ```python >>> import pylibcugraph, cupy, numpy >>> srcs = cupy.asarray([0, 1, 2], dtype=numpy.int32) >>> dsts = cupy.asarray([1, 2, 3], dtype=numpy.int32) >>> weights = cupy.asarray([1.0, 1.0, 1.0], dtype=numpy.float32) >>> resource_handle = pylibcugraph.ResourceHandle() >>> graph_props = pylibcugraph.GraphProperties( ... is_symmetric=False, is_multigraph=False) >>> G = pylibcugraph.SGGraph( ... resource_handle, graph_props, srcs, dsts, weight_array=weights, ... store_transposed=False, renumber=False, do_expensive_check=False) >>> (vertices, distances, predecessors) = pylibcugraph.sssp( ... resource_handle, G, source=1, cutoff=999, ... compute_predecessors=True, do_expensive_check=False) >>> vertices array([0, 1, 2, 3], dtype=int32) >>> distances array([3.4028235e+38, 0.0000000e+00, 1.0000000e+00, 2.0000000e+00], dtype=float32) >>> predecessors array([-1, -1, 1, 2], dtype=int32) ``` -------------------------------- ### FeatureStore.__init__ Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph-pyg/cugraph_pyg.data.FeatureStore/index.html Constructs an empty FeatureStore with optional location and backend parameters. ```APIDOC ## FeatureStore.__init__ ### Description Constructs an empty FeatureStore. The location parameter specifies where data is stored ('cpu' or 'cuda'), and the backend parameter specifies the WholeGraph backend ('nccl' or 'vmm'). If backend is omitted, 'vmm' is selected for single-node configurations and 'nccl' for multinode configurations. ### Method Constructor ### Signature __init__(location='cpu', backend=None) ### Parameters - **location** (str, optional, default='cpu') - The location ('cpu' or 'cuda') where data is stored. - **backend** (str, optional, default=None) - The WholeGraph backend ('nccl' or 'vmm') used to store data. When omitted, 'vmm' is selected for single-node configurations and 'nccl' for multinode configurations. ``` -------------------------------- ### BaseDistributedSampler.get_start_batch_offset Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph-pyg/cugraph_pyg.sampler.BaseDistributedSampler/index.html Gets the starting batch offset to ensure each rank's set of batch ids is disjoint. ```APIDOC ## BaseDistributedSampler.get_start_batch_offset ### Description Gets the starting batch offset to ensure each rank's set of batch ids is disjoint. ### Method get_start_batch_offset(local_num_batches, ...) ### Parameters - **local_num_batches** - Required - The number of local batches. - Additional parameters may be supported. ``` -------------------------------- ### DistributedNeighborSampler.get_start_batch_offset Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph-pyg/cugraph_pyg.sampler.DistributedNeighborSampler Gets the starting batch offset to ensure each rank's set of batch ids is disjoint. ```APIDOC ## DistributedNeighborSampler.get_start_batch_offset ### Description Gets the starting batch offset to ensure each rank's set of batch ids is disjoint. ### Method Method ### Signature get_start_batch_offset(local_num_batches, ...) ### Parameters - **local_num_batches** (int) - Required - The number of local batches. - Additional parameters may be present (not fully documented in source). ### Returns Starting batch offset (type not specified in source). ``` -------------------------------- ### Compute Strongly Connected Components with SGGraph Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/plc/pylibcugraph.strongly_connected_components/index.html This example demonstrates how to initialize an SGGraph and compute strongly connected components using the pylibcugraph API. ```python >>> import pylibcugraph, cupy, numpy >>> from pylibcugraph import strongly_connected_components >>> srcs = cupy.asarray([0, 0, 1, 1, 2, 2], dtype=numpy.int32) >>> dsts = cupy.asarray([1, 2, 1, 2, 0, 1], dtype=numpy.int32) >>> weights = cupy.asarray( ... [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], dtype=numpy.float32) >>> resource_handle = pylibcugraph.ResourceHandle() >>> graph_props = pylibcugraph.GraphProperties( ... is_symmetric=False, is_multigraph=False) >>> G = pylibcugraph.SGGraph( ... resource_handle, graph_props, srcs, dsts, weight_array=weights, ... store_transposed=False, renumber=True, do_expensive_check=False) >>> (vertices, labels) = strongly_connected_components( ... resource_handle, G, None, None, None, None, False) ``` -------------------------------- ### DistributedNeighborSampler.get_start_batch_offset Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph-pyg/cugraph_pyg.sampler.DistributedNeighborSampler/index.html Gets the starting batch offset to ensure each rank's set of batch ids is disjoint. ```APIDOC ## DistributedNeighborSampler.get_start_batch_offset ### Description Gets the starting batch offset to ensure each rank's set of batch ids is disjoint. ### Parameters - **local_num_batches** (int) - Required - The number of local batches. - **additional parameters** (optional) - Optional - Additional parameters as needed. ### Returns Starting batch offset. ``` -------------------------------- ### Compute ECG partition Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/plc/pylibcugraph.ecg/index.html This example demonstrates how to initialize a graph and compute the ECG partition using pylibcugraph. ```python >>> import pylibcugraph, cupy, numpy >>> srcs = cupy.asarray([0, 1, 2], dtype=numpy.int32) >>> dsts = cupy.asarray([1, 2, 0], dtype=numpy.int32) >>> weights = cupy.asarray([1.0, 1.0, 1.0], dtype=numpy.float32) >>> resource_handle = pylibcugraph.ResourceHandle() >>> graph_props = pylibcugraph.GraphProperties( ... is_symmetric=True, is_multigraph=False) >>> G = pylibcugraph.SGGraph( ... resource_handle, graph_props, srcs, dsts, weight_array=weights, ... store_transposed=True, renumber=False, do_expensive_check=False) >>> (vertices, clusters) = pylibcugraph.ecg(resource_handle, G) # FIXME: Check this docstring example >>> vertices [0, 1, 2] >>> clusters [0, 0, 0] ``` -------------------------------- ### Check pylibwholegraph version Source: https://docs.nvidia.com/cugraph/latest/wholegraph/installation/getting_wholegraph/index.html Imports the package without starting a distributed environment and prints the version as a basic installation check. ```bash python -c "import pylibwholegraph; print(pylibwholegraph.__version__)" ``` -------------------------------- ### Compute SSSP with cugraph.dask.sssp Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph/cugraph.dask.traversal.sssp.sssp This example demonstrates how to initialize a Dask-cudf graph from a CSV file and compute the single-source shortest path starting from vertex 0. ```python >>> import cugraph.dask as dcg >>> import dask_cudf >>> # ... Init a DASK Cluster >>> # see https://docs.nvidia.com/cugraph/latest/dask-cugraph.html >>> # Download dataset from https://github.com/rapidsai/cugraph/datasets/.. >>> chunksize = dcg.get_chunksize(datasets_path / "karate.csv") >>> ddf = dask_cudf.read_csv(datasets_path / "karate.csv", ... blocksize=chunksize, delimiter=" ", ... names=["src", "dst", "value"], ... dtype=["int32", "int32", "float32"]) >>> dg = cugraph.Graph(directed=True) >>> dg.from_dask_cudf_edgelist(ddf, source='src', destination='dst', ... edge_attr='value') >>> df = dcg.sssp(dg, 0) ``` -------------------------------- ### Compute k-core of a graph Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph/cugraph.k_core/index.html This example demonstrates how to load the karate dataset as a graph and compute its k-core using the default parameters. ```python >>> from cugraph.datasets import karate >>> G = karate.get_graph(download=True) >>> KCoreGraph = cugraph.k_core(G) ``` -------------------------------- ### Spectral Modularity Maximization Example Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/plc/pylibcugraph.spectral_modularity_maximization/index.html Demonstrates how to initialize a graph and perform spectral modularity maximization using pylibcugraph. ```python >>> import pylibcugraph, cupy, numpy >>> srcs = cupy.asarray([0, 1, 2], dtype=numpy.int32) >>> dsts = cupy.asarray([1, 2, 0], dtype=numpy.int32) >>> weights = cupy.asarray([1.0, 1.0, 1.0], dtype=numpy.float32) >>> resource_handle = pylibcugraph.ResourceHandle() >>> graph_props = pylibcugraph.GraphProperties( ... is_symmetric=True, is_multigraph=False) >>> G = pylibcugraph.SGGraph( ... resource_handle, graph_props, srcs, dsts, weight_array=weights, ... store_transposed=True, renumber=False, do_expensive_check=False) >>> (vertices, clusters) = pylibcugraph.spectral_modularity_maximization( ... resource_handle, G, num_clusters=5, num_eigen_vects=2, evs_tolerance=0.00001 ... evs_max_iter=100, kmean_tolerance=0.00001, kmean_max_iter=100) # FIXME: Fix docstring result. >>> vertices ############ >>> clusters ############ ``` -------------------------------- ### Perform BFS on a Karate Club graph Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph/cugraph.bfs/index.html This example demonstrates how to load the karate dataset as a graph and execute a breadth-first search starting from vertex 0. ```python >>> from cugraph.datasets import karate >>> G = karate.get_graph(download=True) >>> df = cugraph.bfs(G, 0) ``` -------------------------------- ### Run bc_demo.ipy with default CPU backend Source: https://docs.nvidia.com/cugraph/latest/nx_cugraph/how-it-works/index.html Run the script with IPython. The output shows the CPU time for the default NetworkX backend, approximately 7 minutes 41 seconds on the specified hardware. ```bash user@machine:/# ipython bc_demo.ipy CPU times: user 7min 36s, sys: 5.22 s, total: 7min 41s Wall time: 7min 41s ``` -------------------------------- ### Compute ECG partition Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph/cugraph.ecg/index.html This example demonstrates how to load the karate dataset, create a graph, and compute the ECG partition. ```python >>> from cugraph.datasets import karate >>> G = karate.get_graph(download=True) >>> parts, mod = cugraph.ecg(G) ``` -------------------------------- ### Compute Louvain community partition Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph/cugraph.louvain/index.html This example demonstrates how to load the karate dataset as a graph and compute its community partition using the Louvain method. ```python >>> from cugraph.datasets import karate >>> G = karate.get_graph(download=True) >>> parts = cugraph.louvain(G) ``` -------------------------------- ### Performing a Breadth-First Search with cugraph.dask.bfs Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph/cugraph.dask.traversal.bfs.bfs/index.html This example demonstrates how to load a graph from a CSV file using dask-cudf and perform a BFS traversal starting from vertex 0. ```python >>> import cugraph.dask as dcg >>> import dask_cudf >>> # ... Init a DASK Cluster >>> # see https://docs.nvidia.com/cugraph/latest/dask-cugraph.html >>> # Download dataset from https://github.com/rapidsai/cugraph/datasets/.. >>> chunksize = dcg.get_chunksize(datasets_path / "karate.csv") >>> ddf = dask_cudf.read_csv(datasets_path / "karate.csv", ... blocksize=chunksize, delimiter=" ", ... names=["src", "dst", "value"], ... dtype=["int32", "int32", "float32"]) >>> dg = cugraph.Graph(directed=True) >>> dg.from_dask_cudf_edgelist(ddf, source='src', destination='dst', ... edge_attr='value') >>> df = dcg.bfs(dg, 0) ``` -------------------------------- ### BaseDistributedSampler.get_start_batch_offset Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph-pyg/cugraph_pyg.sampler.BaseDistributedSampler Gets the starting batch offset to ensure each rank's set of batch ids is disjoint. This method is part of the sampler's public interface. ```APIDOC ## BaseDistributedSampler.get_start_batch_offset ### Description Gets the starting batch offset to ensure each rank's set of batch ids is disjoint. ### Signature get_start_batch_offset(local_num_batches, ...) ### Parameters - **local_num_batches** - Required - The number of local batches. - Additional parameters may be supported. ### Returns The starting batch offset. ``` -------------------------------- ### Compute uniform random walks Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph/cugraph.uniform_random_walks/index.html This example demonstrates how to initialize a graph from the karate dataset and compute uniform random walks starting from vertices 0 and 1 with a maximum depth of 3. ```python >>> from cugraph.datasets import karate >>> M = karate.get_edgelist(download=True) >>> G = karate.get_graph() >>> start_vertices = [0, 1] >>> paths, weights, max_length = cugraph.uniform_random_walks( ... G, start_vertices, 3, random_state=2) ``` -------------------------------- ### Compute biased random walks Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph/cugraph.biased_random_walks/index.html This example demonstrates how to initialize a graph from the karate dataset and compute biased random walks starting from nodes 0 and 1 with a maximum depth of 3. ```python >>> from cugraph.datasets import karate >>> M = karate.get_edgelist(download=True) >>> G = karate.get_graph() >>> start_vertices = [0, 1] >>> paths, weights, max_length = cugraph.biased_random_walks( ... G, start_vertices, 3, random_state=2) ``` -------------------------------- ### Run bc_demo.ipy with NX_CUGRAPH_AUTOCONFIG=True Source: https://docs.nvidia.com/cugraph/latest/nx_cugraph/how-it-works/index.html Run the same script with the NX_CUGRAPH_AUTOCONFIG environment variable set to True to enable the nx-cugraph backend. The output shows a much faster run time, typically around 5 seconds on a GPU. ```bash user@machine:/# NX_CUGRAPH_AUTOCONFIG=True ipython bc_demo.ipy CPU times: user 4.14 s, sys: 1.13 s, total: 5.27 s Wall time: 5.32 s ``` -------------------------------- ### Initialize a Graph from CSR data Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/cugraph/cugraph.from_adjlist/index.html This example demonstrates how to read a dataset, convert it to a CSR sparse matrix, and then initialize a cugraph.Graph using the CSR offsets and indices. ```python >>> pdf = pd.read_csv(datasets_path / 'karate.csv', delimiter=' ', ... dtype={0:'int32', 1:'int32', 2:'float32'}, ... header=None) >>> M = scipy.sparse.coo_matrix((pdf[2],(pdf[0],pdf[1]))) >>> M = M.tocsr() >>> offsets = pd.Series(M.indptr) >>> indices = pd.Series(M.indices) >>> G = cugraph.from_adjlist(offsets, indices, None) ``` -------------------------------- ### Install pylibwholegraph via pip for CUDA 13 Source: https://docs.nvidia.com/cugraph/latest/wholegraph/installation/getting_wholegraph/index.html Installs the 26.10 nightly Python package with a CUDA-major suffix. Use pylibwholegraph-cu12 on a supported CUDA 12 configuration. Installing pylibwholegraph also installs the matching libwholegraph wheel. ```bash python -m pip install \ --extra-index-url=https://pypi.nvidia.com \ --extra-index-url=https://pypi.anaconda.org/rapidsai-wheels-nightly/simple \ "pylibwholegraph-cu13==26.10.*" ``` -------------------------------- ### Computing node2vec random walks Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/plc/pylibcugraph.node2vec_random_walks/index.html This example demonstrates how to initialize a graph and compute node2vec random walks using pylibcugraph. ```python >>> import pylibcugraph, cupy, numpy >>> srcs = cupy.asarray([0, 1, 2], dtype=numpy.int32) >>> dsts = cupy.asarray([1, 2, 3], dtype=numpy.int32) >>> seeds = cupy.asarray([0, 0, 1], dtype=numpy.int32) >>> weights = cupy.asarray([1.0, 1.0, 1.0], dtype=numpy.float32) >>> resource_handle = pylibcugraph.ResourceHandle() >>> graph_props = pylibcugraph.GraphProperties( ... is_symmetric=False, is_multigraph=False) >>> G = pylibcugraph.SGGraph( ... resource_handle, graph_props, srcs, dsts, weight_array=weights, ... store_transposed=False, renumber=False, do_expensive_check=False) >>> (paths, weights) = pylibcugraph.node2vec_random_walks( ... resource_handle, G, seeds, 3, 1.0, 1.0) ``` -------------------------------- ### Install pylibwholegraph via Conda Source: https://docs.nvidia.com/cugraph/latest/wholegraph/installation/getting_wholegraph/index.html Installs the Python API and native dependency from the 26.10 nightly channel. Requires a CUDA version supported by the RAPIDS release and the installed NVIDIA driver. ```bash conda install \ -c rapidsai-nightly -c conda-forge \ pylibwholegraph=26.10 cuda-version=13.3 ``` -------------------------------- ### Perform BFS using pylibcugraph Source: https://docs.nvidia.com/cugraph/latest/api_docs/api/plc/pylibcugraph.bfs/index.html This example demonstrates how to load a graph from a CSV file, construct an SGGraph, and execute the BFS algorithm using pylibcugraph. ```python >>> M = cudf.read_csv(datasets_path / 'karate.csv', delimiter=' ', >>> dtype=['int32', 'int32', 'float32'], header=None) >>> G = cugraph.Graph() >>> G.from_cudf_edgelist(M, source='0', destination='1', edge_attr='2') >>> >>> handle = ResourceHandle() >>> >>> srcs = G.edgelist.edgelist_df['src'] >>> dsts = G.edgelist.edgelist_df['dst'] >>> weights = G.edgelist.edgelist_df['weights'] >>> >>> sg = SGGraph( >>> resource_handle = handle, >>> graph_properties = GraphProperties(is_multigraph=G.is_multigraph()), >>> src_array = srcs, >>> dst_array = dsts, >>> weight_array = weights, >>> store_transposed=False, >>> renumber=False, >>> do_expensive_check=do_expensive_check >>> ) >>> >>> res = pylibcugraph_bfs( >>> handle, >>> sg, >>> cudf.Series([0], dtype='int32'), >>> False, >>> 10, >>> True, >>> False >>> ) >>> >>> distances, predecessors, vertices = res >>> f>>> inal_results = cudf.DataFrame({ >>> 'distance': cudf.Series(distances), >>> 'vertex': cudf.Series(vertices), >>> 'predecessor': cudf.Series(predecessors), >>> }) ``` -------------------------------- ### cugraph_homogeneous_uniform_temporal_neighbor_sample Source: https://docs.nvidia.com/cugraph/latest/api_docs/cugraph_c/sampling/index.html Performs homogeneous uniform temporal neighborhood sampling. Samples the neighborhood around specified start vertices with a given fan-out, respecting temporal constraints defined by start and end times for each start vertex. ```APIDOC ## cugraph_homogeneous_uniform_temporal_neighbor_sample ### Description Performs homogeneous uniform temporal neighborhood sampling. Samples the neighborhood around specified start vertices with a given fan-out, respecting temporal constraints defined by start and end times for each start vertex. ### Signature cugraph_error_code_t cugraph_homogeneous_uniform_temporal_neighbor_sample(const cugraph_resource_handle_t *handle, cugraph_rng_state_t *rng_state, cugraph_graph_t *graph, const char *temporal_property_name, const cugraph_type_erased_device_array_view_t *start_vertices, const cugraph_type_erased_device_array_view_t *starting_vertex_start_times, const cugraph_type_erased_device_array_view_t *starting_vertex_end_times, const cugraph_type_erased_device_array_view_t *starting_vertex_label_offsets, const cugraph_type_erased_host_array_view_t *fan_out, const cugraph_sampling_options_t *sampling_options, bool_t do_expensive_check, cugraph_sample_result_t **result, cugraph_error_t **error) ### Parameters - **handle** (const cugraph_resource_handle_t*) - [in] Handle for accessing resources - **rng_state** (cugraph_rng_state_t*) - [inout] State of the random number generator, updated with each call - **graph** (cugraph_graph_t*) - [in] Pointer to graph. NOTE: Graph might be modified if the storage needs to be transposed - **temporal_property_name** (const char*) - [in] Name of the temporal property to use for sampling - **start_vertices** (const cugraph_type_erased_device_array_view_t*) - [in] Device array of start vertices for the sampling - **starting_vertex_start_times** (const cugraph_type_erased_device_array_view_t*) - [in] Device array of start times for each start vertex - **starting_vertex_end_times** (const cugraph_type_erased_device_array_view_t*) - [in] Device array of end times for each start vertex - **starting_vertex_label_offsets** (const cugraph_type_erased_device_array_view_t*) - [in] Device array of the offsets for each label in the seed list. This parameter is only used with the retain_seeds option. - **fan_out** (const cugraph_type_erased_host_array_view_t*) - [in] Host array defining the fan out at each step in the sampling algorithm. We only support fan_out values of type INT32 - **sampling_options** (const cugraph_sampling_options_t*) - [in] Opaque pointer defining the sampling options. - **do_expensive_check** (bool_t) - [in] A flag to run expensive checks for input arguments (if set to true) - **result** (cugraph_sample_result_t**) - [out] Output from the uniform_neighbor_sample call - **error** (cugraph_error_t**) - [out] Pointer to an error object storing details of any error. Will be populated if error code is not CUGRAPH_SUCCESS ### Returns - **cugraph_error_code_t** - error code ```