cuGraph#

cuGraph 是一个利用 Nvidia RAPIDS 生态系统的 GPU 加速图库。PyGraphistry 提供了一个更流畅的接口,可以使用 cuGraph 方法丰富和转换您的数据,而无需样板代码。

graphistry.plugins.cugraph.compute_cugraph(self, alg, out_col=None, params={}, kind='Graph', directed=True, G=None)#

在图上运行cugraph算法。有关算法参数,请参阅cuGraph文档。

Parameters:
  • alg (str) – 算法名称

  • out_col (可选[str]) – 节点表输出列名,默认为 alg 参数

  • params (dict) – 传递给cuGraph的算法参数,作为kwargs

  • kind (CuGraphKind) – 使用的cugraph类型

  • directed (bool) – 图是否为有向图

  • G (可选[cugraph.Graph]) – 使用的cugraph图;如果为None,则使用self

  • self (Plottable)

Returns:

Plottable

Return type:

Plottable

Example: Pass params to cugraph
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['c','c','e','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.compute_cugraph('betweenness_centrality', params={'k': 2})
assert 'betweenness_centrality' in g2._nodes.columns
Example: Pagerank
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['c','c','e','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.compute_cugraph('pagerank')
assert 'pagerank' in g2._nodes.columns
Example: Personalized Pagerank
::

edges = pd.DataFrame({‘s’: [‘a’,’b’,’c’,’d’], ‘d’: [‘c’,’c’,’e’,’e’]}) g = graphistry.edges(edges, ‘s’, ‘d’) g2 = g.compute_cugraph(‘pagerank’, params={‘personalization’: cudf.DataFrame({‘vertex’: [‘a’], ‘values’: [1]})}) assert ‘pagerank’ in g2._nodes.columns

Example: Katz centrality with rename
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['c','c','e','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.compute_cugraph('katz_centrality', out_col='katz_centrality_renamed')
assert 'katz_centrality_renamed' in g2._nodes.columns
graphistry.plugins.cugraph.compute_cugraph_core(self, alg, out_col=None, params={}, kind='Graph', directed=True, G=None)#

在图上运行cugraph算法。有关算法参数,请参阅cuGraph文档。

Parameters:
  • alg (str) – 算法名称

  • out_col (可选[str]) – 节点表输出列名,默认为 alg 参数

  • params (dict) – 传递给cuGraph的算法参数,作为kwargs

  • kind (CuGraphKind) – 使用的cugraph类型

  • directed (bool) – 图是否为有向图

  • G (可选[cugraph.Graph]) – 使用的cugraph图;如果为None,则使用self

  • self (Plottable)

Returns:

Plottable

Return type:

Plottable

Example: Pass params to cugraph
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['c','c','e','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.compute_cugraph('betweenness_centrality', params={'k': 2})
assert 'betweenness_centrality' in g2._nodes.columns
Example: Pagerank
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['c','c','e','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.compute_cugraph('pagerank')
assert 'pagerank' in g2._nodes.columns
Example: Personalized Pagerank
::

edges = pd.DataFrame({‘s’: [‘a’,’b’,’c’,’d’], ‘d’: [‘c’,’c’,’e’,’e’]}) g = graphistry.edges(edges, ‘s’, ‘d’) g2 = g.compute_cugraph(‘pagerank’, params={‘personalization’: cudf.DataFrame({‘vertex’: [‘a’], ‘values’: [1]})}) assert ‘pagerank’ in g2._nodes.columns

Example: Katz centrality with rename
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['c','c','e','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.compute_cugraph('katz_centrality', out_col='katz_centrality_renamed')
assert 'katz_centrality_renamed' in g2._nodes.columns
graphistry.plugins.cugraph.df_to_gdf(df)#
Parameters:

df (任意)

graphistry.plugins.cugraph.from_cugraph(self, G, node_attributes=None, edge_attributes=None, load_nodes=True, load_edges=True, merge_if_existing=True)#

如果绑定了ID,请在返回的图中使用相同的ID。

如果节点/边非空,则使用现有拓扑并合并G的属性,而不是返回G的拓扑

Parameters:
  • node_attributes (列表[字符串] | )

  • edge_attributes (列表[字符串] | )

  • load_nodes (bool)

  • load_edges (bool)

  • merge_if_existing (bool)

Return type:

Plottable

graphistry.plugins.cugraph.layout_cugraph(self, layout='force_atlas2', params={}, kind='Graph', directed=True, G=None, bind_position=True, x_out_col='x', y_out_col='y', play=0)#

使用cuGraph算法布局图形。有关布局列表,请参阅cugraph文档(目前仅支持force_atlas2)。

Parameters:
  • 布局 (str) – cugraph布局方法的名称,例如force_atlas2

  • params (dict) – 传递给底层cugraph方法的任何命名参数

  • kind (CuGraphKind) – cugraph图的类型

  • directed (bool) – 在转换为cugraph时,是否是有向的。(默认值为True)

  • G (可选[任意]) – 要布局的cugraph图(G)。如果为None,则使用当前图。

  • bind_position (bool) – 是否调用 bind(point_x=, point_y=)(默认为 True)

  • x_out_col (str) – 写入x位置的属性。(默认值为‘x’)

  • y_out_col (str) – 写入x位置的属性。(默认值为‘y’)

  • play (可选[str]) – 如果定义,设置 settings(url_params={‘play’: play})。(默认值为 0)

  • self (Plottable)

Returns:

绘图仪

Return type:

绘图仪

Example: ForceAtlas2 layout
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g.layout_cugraph().plot()
Example: Change which column names are generated
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.layout_cugraph('force_atlas2', x_out_col='my_x', y_out_col='my_y')
assert 'my_x' in g2._nodes
assert g2._point_x == 'my_x'
g2.plot()
Example: Pass parameters to layout methods
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.layout_cugraph('forceatlas_2', params={'lin_log_mode': True, 'prevent_overlapping': True})
g2.plot()
graphistry.plugins.cugraph.layout_cugraph_core(self, layout='force_atlas2', params={}, kind='Graph', directed=True, G=None, bind_position=True, x_out_col='x', y_out_col='y', play=0)#

使用cuGraph算法布局图形。有关布局列表,请参阅cugraph文档(目前仅支持force_atlas2)。

Parameters:
  • 布局 (str) – cugraph布局方法的名称,例如force_atlas2

  • params (dict) – 传递给底层cugraph方法的任何命名参数

  • kind (CuGraphKind) – cugraph图的类型

  • directed (bool) – 在转换为cugraph时,是否是有向的。(默认值为True)

  • G (可选[任意]) – 要布局的cugraph图(G)。如果为None,则使用当前图。

  • bind_position (bool) – 是否调用 bind(point_x=, point_y=)(默认为 True)

  • x_out_col (str) – 写入x位置的属性。(默认值为‘x’)

  • y_out_col (str) – 用于写入x位置的属性。(默认值为‘y’)

  • play (可选[str]) – 如果定义,设置 settings(url_params={‘play’: play})。(默认值为 0)

  • self (Plottable)

Returns:

绘图仪

Return type:

绘图仪

Example: ForceAtlas2 layout
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g.layout_cugraph().plot()
Example: Change which column names are generated
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.layout_cugraph('force_atlas2', x_out_col='my_x', y_out_col='my_y')
assert 'my_x' in g2._nodes
assert g2._point_x == 'my_x'
g2.plot()
Example: Pass parameters to layout methods
import graphistry, pandas as pd
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g2 = g.layout_cugraph('forceatlas_2', params={'lin_log_mode': True, 'prevent_overlapping': True})
g2.plot()
graphistry.plugins.cugraph.to_cugraph(self, directed=True, include_nodes=True, node_attributes=None, edge_attributes=None, kind='Graph')#

将当前图转换为cugraph.Graph对象

要分配边权重,请使用 g.bind(edge_weight=’some_col’).to_cugraph()

从pandas、cudf或dask_cudf数据框中加载

Parameters:
  • self (Plottable)

  • directed (bool)

  • include_nodes (bool)

  • node_attributes (列表[字符串] | )

  • edge_attributes (列表[字符串] | )

  • 类型 (字面量['Graph', 'MultiGraph', 'BiPartiteGraph'])

常量

graphistry.plugins.cugraph.compute_algs: List[str] = ['betweenness_centrality', 'katz_centrality', 'ecg', 'leiden', 'louvain', 'spectralBalancedCutClustering', 'spectralModularityMaximizationClustering', 'connected_components', 'strongly_connected_components', 'core_number', 'hits', 'pagerank', 'bfs', 'bfs_edges', 'sssp', 'shortest_path', 'shortest_path_length', 'batched_ego_graphs', 'edge_betweenness_centrality', 'jaccard', 'jaccard_w', 'overlap', 'overlap_coefficient', 'overlap_w', 'sorensen', 'sorensen_coefficient', 'sorensen_w', 'ego_graph', 'k_core', 'minimum_spanning_tree']#

内置可变序列。

如果没有给出参数,构造函数将创建一个新的空列表。 如果指定了参数,则它必须是一个可迭代对象。

graphistry.plugins.cugraph.layout_algs: List[str] = ['force_atlas2']#

内置可变序列。

如果没有给出参数,构造函数将创建一个新的空列表。 如果指定了参数,则它必须是一个可迭代对象。

graphistry.plugins_types.cugraph_types.CuGraphKind#

Literal['Graph', 'MultiGraph', 'BiPartiteGraph'] 的别名