Analytical App¶
AppAssets¶

class
graphscope.framework.app.
AppAssets
(algo, gar=None, **kwargs)[source]¶ A class holds the bytes of the gar resource.
Assets includes name (for builtin algorithm), and gar (for user defined algorithm), and its type (one of cpp_pie, cython_pie, cython_pregel.
The instance of this class can be passed to init
graphscope.App
.
algo
¶ Name of the algorithm
 Type
str

type
¶ Type of the algorithm
 Type
str

gar
¶ Byte content of user defined algorithm
 Type
bytes

signature
¶ Unique identifier of this assets.
 Type
str

__init__
(algo, gar=None, **kwargs)[source]¶ Init assets of the algorithm.
 Parameters
algo (str) – Represent specific algo inside resource.
gar (bytes or BytesIO, optional) – The bytes that encodes the application’s source code. Default to None
kwargs – Other params, e.g. vd_type and md_type in cython app.

__weakref__
¶ list of weak references to the object (if defined)

property
algo
¶ Algorithm name, e.g. sssp, pagerank.
 Returns
Algorithm name of this asset.
 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 (
Graph
) – A graph instance. Raises
InvalidArgumentError –
gs_conf.yaml
not exist in gar resource.  App is not compatible with graph or  Algo not found in gar resource.
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 :rtype: str

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

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.
 Return type
VertexDataContext
Examples:
import graphscope as gs s = gs.session() g = s.load_from('The parameters for loading a graph...') pg = g.project_to_simple(v_label='vlabel', e_label='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.
 Return type
VertexDataContext
Examples:
import graphscope as gs s = gs.session() g = s.load_from('The parameters for loading a graph...') pg = g.project_to_simple(v_label='vlabel', e_label='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.
 Return type
VertexDataContext
Examples:
import graphscope as gs s = gs.session() g = s.load_from('The parameters for loading a graph...') pg = g.project_to_simple(v_label='vlabel', e_label='elabel', v_prop=None, e_prop='distance') 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.
 Return type
VertexDataContext
Examples:
import graphscope as gs s = gs.session() g = s.load_from('The parameters for loading a graph...') pg = g.project_to_simple(v_label='vlabel', e_label='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.
 Return type
VertexDataContext
Examples:
import graphscope as gs s = gs.session() g = s.load_from('The parameters for loading a graph...') pg = g.project_to_simple(v_label='vlabel', e_label='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.
 Return type
VertexDataContext
Examples:
import graphscope as gs s = gs.session() g = s.load_from('The parameters for loading a graph...') pg = g.project_to_simple(v_label='vlabel', e_label='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.
 Return type
VertexDataContext
Examples:
import graphscope as gs s = gs.session() g = s.load_from('The parameters for loading a graph...') pg = g.project_to_simple(v_label="vlabel", e_label="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.
 Return type
VertexDataContext
Examples:
import graphscope as gs s = gs.session() g = s.load_from('The parameters for loading a graph...') pg = g.project_to_simple(v_label='vlabel', e_label='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.
 Return type
VertexPropertyContext
Examples:
import graphscope as gs s = gs.session() g = s.load_from('The parameters for loading a graph...') pg = g.project_to_simple(v_label='vlabel', e_label='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.
 Return type
VertexDataContext
Examples:
import graphscope as gs s = gs.session() g = s.load_from('The parameters for loading a graph...') pg = g.project_to_simple(v_label='vlabel', e_label='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.
 Return type
VertexDatacontext
Examples:
import graphscope as gs s = gs.session() g = s.load_from('The parameters for loading a graph...') pg = g.project_to_simple(v_label='vlabel', e_label='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.
 Return type
LabeledVertexPropertyContext
Examples:
import graphscope as gs s = gs.session() g = s.load_from('The parameters for loading a graph...') 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.
 Return type
VertexDataContext
Examples:
import graphscope as gs s = gs.session() g = s.load_from('The parameters for loading a graph...') pg = g.project_to_simple(v_label='vlabel', e_label='elabel') r = gs.triangles(pg) s.close()
App object¶

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

key
¶ Identifier of the app, associated with the dynamic library path. set by analytical engine after library is built.
 Type
str

signature
¶ Combination of app_assets’s and graph’s signature.
 Type
str

session_id
¶ Session id of the session that associated with the app.
 Type
str

algo
¶ Algorithm name of app_assets.
 Type
str

gar
¶ Gar content of app_assets.
 Type
str

__init__
(graph, app_assets: graphscope.framework.app.AppAssets)[source]¶  Create an application using given
gar
file, or given application class name.
 Parameters
graph (
Graph
) – AGraph
instance.app_assets – A
AppAssets
instance.
 Raises
TypeError – The type of app_assets incorrect.
 Create an application using given

__weakref__
¶ list of weak references to the object (if defined)

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

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

property
key
¶ A unique identifier of App.

loaded
()[source]¶  Since key is only set by engine after it load the app, and unset to None when unload,
we can use the key to detect whether the app is loaded.
 Returns
The app is loaded or not.
 Return type
bool

property
session_id
¶ Return the session_id, which is copied from the graph.
 Returns
Id of the session which loaded the app.
 Return type
str

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

Functions¶

Load an app from gar. 