cugraph.experimental.PropertyGraph.extract_subgraph#

PropertyGraph.extract_subgraph(create_using=None, selection=None, edge_weight_property=None, default_edge_weight=None, check_multi_edges=True, renumber_graph=True, add_edge_data=True)[source]#

Return a subgraph of the overall PropertyGraph containing vertices and edges that match a selection.

Parameters:
create_usingtype or instance of cugraph.Graph or PropertyGraph, optional

Creates a Graph to return using the type specified. If an instance is specified, the type of the instance is used to construct the return Graph, and all relevant attributes set on the instance are copied to the return Graph (eg. directed). If not specified the returned Graph will be a directed cugraph.MultiGraph instance.

selectionPropertySelection, optional

A PropertySelection returned from one or more calls to select_vertices() and/or select_edges(), used for creating a Graph with only the selected properties. If not specified the returned Graph will have all properties. Note, this could result in a Graph with multiple edges, which may not be supported based on the value of create_using.

edge_weight_propertystring, optional

The name of the property whose values will be used as weights on the returned Graph. If not specified, the returned Graph will be unweighted. Ignored for PropertyGraph return type.

default_edge_weightfloat64, optional

Value that replaces empty weight property fields. Ignored for PropertyGraph return type.

check_multi_edgesbool (default True)

When True and create_using argument is given and not a MultiGraph, this will perform an expensive check to verify that the edges in the edge dataframe do not form a multigraph with duplicate edges. Ignored for PropertyGraph return type.

renumber_graphbool (default True)

If True, return a Graph that has been renumbered for use by graph algorithms. If False, the returned graph will need to be manually renumbered prior to calling graph algos. Ignored for PropertyGraph return type.

add_edge_databool (default True)

If True, add meta data about the edges contained in the extracted graph which are required for future calls to annotate_dataframe(). Ignored for PropertyGraph return type.

Returns:
A Graph instance of the same type as create_using containing only the
vertices and edges resulting from applying the selection to the set of
vertex and edge property data.

Examples

>>> import cugraph
>>> from cugraph.experimental import PropertyGraph
>>> from cugraph.experimental import PropertyGraph
>>> df = cudf.DataFrame(columns=["src", "dst", "some_property"],
...                     data=[(99, 22, "a"),
...                           (98, 34, "b"),
...                           (97, 56, "c"),
...                           (96, 88, "d"),
...                          ])
>>> pG = PropertyGraph()
>>> pG.add_edge_data(df, type_name="etype", vertex_col_names=("src", "dst"))
>>> vert_df = cudf.DataFrame({"vert_id": [99, 22, 98, 34, 97, 56, 96, 88],
...                           "v_prop": [1, 2, 3, 4, 5, 6, 7, 8]})
>>> pG.add_vertex_data(vert_df, type_name="vtype", vertex_col_name="vert_id")
>>> selection = pG.select_edges("(_TYPE_ == 'etype') & (some_property == 'd')")
>>> G = pG.extract_subgraph(selection=selection,
...                         create_using=cugraph.Graph(directed=True),
...                         renumber_graph=False)
>>> print (G.edges())
src  dst
0   96   88