cugraph.subgraph#

cugraph.subgraph(G: Union[Graph, Graph], vertices: Union[Series, DataFrame]) Union[Graph, Graph][source]#

Compute a subgraph of the existing graph including only the specified vertices. This algorithm works with both directed and undirected graphs and does not actually traverse the edges, but instead simply pulls out any edges that are incident on vertices that are both contained in the vertices list.

If no subgraph can be extracted from the vertices provided, a ‘None’ value will be returned.

Parameters:
Gcugraph.Graph or networkx.Graph

The current implementation only supports weighted graphs.

Deprecated since version 24.12: Accepting a networkx.Graph is deprecated and will be removed in a future version. For networkx.Graph use networkx directly with the nx-cugraph backend. See: https://rapids.ai/nx-cugraph/

verticescudf.Series or cudf.DataFrame

Specifies the vertices of the induced subgraph. For multi-column vertices, vertices should be provided as a cudf.DataFrame

Returns:
Sgcugraph.Graph or networkx.Graph

A graph object containing the subgraph induced by the given vertex set.

Examples

>>> from cugraph.datasets import karate
>>> G = karate.get_graph(download=True)
>>> verts = np.zeros(3, dtype=np.int32)
>>> verts[0] = 0
>>> verts[1] = 1
>>> verts[2] = 2
>>> sverts = cudf.Series(verts)
>>> Sg = cugraph.subgraph(G, sverts)