Analytical App¶
AppAssets¶

class
graphscope.framework.app.
AppAssets
(algo, context=None, gar=None)[source]¶ A class represents a app assert node in a DAG that holds the bytes of the gar resource.
Assets includes an algorithm name, and gar (for user defined algorithm), a context type (one of ‘tensor’, ‘vertex_data’, ‘vertex_property’, ‘labeled_vertex_data’, ‘dynamic_vertex_data’, ‘labeled_vertex_property’), and its type (one of cpp_pie, cython_pie, cython_pregel),
The instance of this class can be passed to init
graphscope.framework.app.AppDAGNode

__init__
(algo, context=None, gar=None)[source]¶ Init assets of the algorithm.
 Parameters
algo (str) – Represent specific algo inside resource.
context (str) – Type of context that hold the calculation results.
will get from gar if param is None. Defaults to None. (It) –
gar (bytes or BytesIO, optional) – The bytes that encodes the application’s source code. Defaults to None.

property
algo
¶ Algorithm name, e.g. sssp, pagerank.
 Returns
Algorithm name of this asset.
 Return type
str

property
context_type
¶ Context type, e.g. vertex_property, labeled_vertex_data.
 Returns
Type of the app context.
 Return type
str

property
gar
¶ Gar resource.
 Returns
gar resource of this asset.
 Return type
bytes

is_compatible
(graph)[source]¶ Determine if this algorithm can run on this type of graph.
 Parameters
graph (
GraphDAGNode
) – A graph instance. Raises
InvalidArgumentError –
App is not compatible with graph
ScannerError –
Yaml file format is incorrect.

property
signature
¶ Generate a signature of the app assets by its algo name (and gar resources).
Used to uniquely identify a app assets.
 Returns
signature of this assets
 Return type
str

property
type
¶ Algorithm type, one of cpp_pie, cython_pie or cython_pregel.
 Returns
Algorithm type of this asset.
 Return type
str

App object¶

class
graphscope.framework.app.
AppDAGNode
(graph, app_assets: graphscope.framework.app.AppAssets)[source]¶ A class represents a app node in a DAG.
In GraphScope, an app node binding a concrete graph node that query executed on.

class
graphscope.framework.app.
App
(app_node, key)[source]¶ An application that can run on graphs and produce results.
Analytical engine will build the app dynamic library when instantiate a app instance. And the dynamic library will be reused if subsequent app’s signature matches one of previous ones.

property
key
¶ A unique identifier of App.

property
signature
¶ Signature is computed by all critical components of the App.

property
Functions¶

Load an app from gar. 
BuiltIn apps¶

graphscope.
bfs
(graph, src=0)[source]¶ Breadth first search from the src on projected simple graph.
 Parameters
graph (
Graph
) – A projected simple graph.src (int, optional) – Source vertex of breadth first search. Defaults to 0.
 Returns
A context with each vertex with a distance from the source, evaluated in eager mode.
 Return type
Examples:
import graphscope as gs sess = gs.session() g = sess.g() pg = g.project(vertices={"vlabel": []}, edges={"elabel": []}) r = gs.bfs(pg, 6) # use 6 as source vertex s.close()

graphscope.
pagerank
(graph, delta=0.85, max_round=10)[source]¶ Evalute PageRank on a graph.
 Parameters
graph (Graph) – A projected simple graph.
delta (float, optional) – Dumping factor. Defaults to 0.85.
max_round (int, optional) – Maximum number of rounds. Defaults to 10.
 Returns
A context with each vertex assigned with the pagerank value, evaluated in eager mode.
 Return type
Examples:
import graphscope as gs sess = gs.session() g = sess.g() pg = g.project(vertices={"vlabel": []}, edges={"elabel": []}) r = gs.pagerank(pg, delta=0.85, max_round=10) s.close()

graphscope.
sssp
(graph, src=0)[source]¶ Compute single source shortest path on the graph.
 Parameters
graph (
Graph
) – A projected simple graph.src (int, optional) – The source vertex. Defaults to 0.
 Returns
A context with each vertex assigned with the shortest distance from the src, evaluated in eager mode.
 Return type
Examples:
import graphscope as gs sess = gs.session() g = sess.g() pg = g.project(vertices={"vlabel": []}, edges={"elabel": []}) r = gs.sssp(pg, src=0) s.close()

graphscope.
wcc
(graph)[source]¶ Evaluate weakly connected components on the graph.
 Parameters
graph (
Graph
) – A projected simple graph. Returns
A context with each vertex assigned with the component ID, evaluated in eager mode.
 Return type
Examples:
import graphscope as gs sess = gs.session() g = sess.g() pg = g.project(vertices={"vlabel": []}, edges={"elabel": []}) r = gs.wcc(pg) s.close()

graphscope.
cdlp
(graph, max_round=10)[source]¶ Evaluate Community Detection with Label Propagation.
 Parameters
graph (
Graph
) – A projected simple graph.max_round (int, optional) – Maximum rounds. Defaults to 10.
 Returns
A context with each vertex assigned with a community ID, evaluated in eager mode.
 Return type
Examples:
import graphscope as gs sess = gs.session() g = sess.g() pg = g.project(vertices={"vlabel": []}, edges={"elabel": []}) r = gs.cdlp(g, max_round=10) s.close()

graphscope.
clustering
(graph)[source]¶ Local clustering coefficient of a node in a Graph is the fraction of pairs of the node’s neighbors that are adjacent to each other.
 Parameters
graph (
Graph
) – A projected simple graph. Returns
A context with each vertex assigned the computed clustering value, evaluated in eager mode.
 Return type
Examples:
import graphscope as gs sess = gs.session() g = sess.g() pg = g.project(vertices={"vlabel": []}, edges={"elabel": []}) r = gs.clustering(pg) s.close()

graphscope.
degree_centrality
(graph, centrality_type='both')[source]¶ The degree centrality values are normalized by dividing by the maximum possible degree in a simple graph n1 where n is the number of nodes in G.
 Parameters
graph (
Graph
) – A projected simple graph.centrality_type (str, optional) – Available options are in/out/both. Defaults to “both”.
 Returns
A context with each vertex assigned with the computed degree centrality, evaluated in eager mode.
 Return type
Examples:
import graphscope as gs sess = gs.session() g = sess.g() pg = g.project(vertices={"vlabel": []}, edges={"elabel": []}) r = gs.degree_centrality(pg, centrality_type="both") s.close()

graphscope.
eigenvector_centrality
(graph, tolerance=1e06, max_round=100)[source]¶ Compute the eigenvector centrality for the graph. See more about eigenvector centrality here: https://networkx.org/documentation/networkx1.10/reference/generated/networkx.algorithms.centrality.eigenvector_centrality.html
 Parameters
graph (
Graph
) – A projected simple graph.tolerance (float, optional) – Defaults to 1e06.
max_round (int, optional) – Defaults to 100.
 Returns
A context with each vertex assigned with a gvcentrality, evaluated in eager mode.
 Return type
Examples:
import graphscope as gs sess = gs.session() g = sess.g() pg = g.project(vertices={"vlabel": []}, edges={"elabel": []}) r = gs.eigenvector_centrality(pg) s.close()

graphscope.
hits
(graph, tolerance=0.01, max_round=100, normalized=True)[source]¶ Compute HITS on graph.
HyperlinkInduced Topic Search (HITS; also known as hubs and authorities) is a link analysis algorithm that rates Web pages. See more here: https://en.wikipedia.org/wiki/HITS_algorithm
 Parameters
graph (
Graph
) – A projected simple graph.tolerance (float, optional) – Defaults to 0.01.
max_round (int, optional) – Defaults to 100.
normalized (bool, optional) – Whether to normalize the result to 01. Defaults to True.
 Returns
A context with each vertex assigned with the HITS value, evaluated in eager mode.
 Return type
Examples:
import graphscope as gs sess = gs.session() g = sess.g() pg = g.project(vertices={"vlabel": []}, edges={"elabel": []}) r = gs.hits(pg) s.close()

graphscope.
k_core
(graph, k: int)[source]¶ Kcores of the graph are connected components that are left after all vertices of degree less than k have been removed.
 Parameters
graph (
Graph
) – A projected simple graph.k (int) – The k for kcore.
 Returns
 A context with each vertex assigned with a boolean:
1 if the vertex satisfies kcore, otherwise 0.
Evaluated in eager mode.
 Return type
Examples:
import graphscope as gs sess = gs.session() g = sess.g() pg = g.project(vertices={"vlabel": []}, edges={"elabel": []}) r = gs.k_core(pg) s.close()

graphscope.
katz_centrality
(graph, alpha=0.1, beta=1.0, tolerance=1e06, max_round=100, normalized=True)[source]¶ Compute the Katz centrality.
See more details for Katz centrality here: https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.centrality.katz_centrality_numpy.html
 Parameters
graph (
Graph
) – A projected simple graph.alpha (float, optional) – Auttenuation factor. Defaults to 0.1.
beta (float, optional) – Weight attributed to the immediate neighborhood. Defaults to 1.0.
tolerance (float, optional) – Error tolerance. Defaults to 1e06.
max_round (int, optional) – Maximun number of rounds. Defaults to 100.
normalized (bool, optional) – Whether to normalize result values. Defaults to True.
 Returns
A context with each vertex assigned with the computed katz_centrality, evaluated in eager mode.
 Return type
Examples:
import graphscope as gs sess = gs.session() g = sess.g() pg = g.project(vertices={"vlabel": []}, edges={"elabel": []}) r = gs.katz_centrality(pg) s.close()

graphscope.
lpa
(graph, max_round=10)[source]¶ Evaluate (multi) label propagation on a property graph.
 Parameters
graph (
Graph
) – A property graph.max_round (int, optional) – Maximum number of rounds. Defaults to 10.
 Returns
A context with each vertex, following an array of propagated labels, evaluated in eager mode.
 Return type
graphscope.framework.context.LabeledVertexPropertyContextDAGNode
Examples:
import graphscope as gs sess = gs.session() g = sess.g() r = gs.lpa(g) s.close()

graphscope.
triangles
(graph)[source]¶ Evaluate triangle counting of the graph G.
 Parameters
graph (
Graph
) – A projected simple graph. Returns
A context with each vertex assigned with the triangle counting result, evaluated in eager mode.
 Return type
Examples:
import graphscope as gs sess = gs.session() g = sess.g() pg = g.project(vertices={"vlabel": []}, edges={"elabel": []}) r = gs.triangles(pg) s.close()

graphscope.
louvain
(graph, min_progress=1000, progress_tries=1)[source]¶ Compute best partition on the graph by louvain.
 Parameters
graph (
Graph
) – A projected simple undirected graph.min_progress – The minimum delta X required to be considered progress, where X is the number of nodes that have changed their community on a particular pass. Delta X is then the difference in number of nodes that changed communities on the current pass compared to the previous pass.
progress_tries – number of times the min_progress setting is not met before exiting form the current level and compressing the graph.
 Returns
A context with each vertex assigned with id of community it belongs to, evaluated in eager mode.
 Return type
References
[1] Blondel, V.D. et al. Fast unfolding of communities in large networks. J. Stat. Mech 10008, 112(2008).
[2] https://github.com/Sotera/distributedgraphanalytics
[3] https://sotera.github.io/distributedgraphanalytics/louvain/
Notes
louvain now only support undirected graph. If input graph is directed graph, louvain would raise a InvalidArgumentError.
Examples:
import graphscope as gs s = gs.session() g = s.g(directed=False) g = g.add_vertices('The parameters for loading a graph...') g = g.add_edges('The parameters for loading a graph...') pg = g.project(vertices={"vlabel": []}, edges={"elabel": ["weight"]}) r = gs.louvain(pg) s.close()