Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
siyuan0322 committed Mar 26, 2021
1 parent 3bdd487 commit 2fb567d
Show file tree
Hide file tree
Showing 17 changed files with 17 additions and 105 deletions.
88 changes: 0 additions & 88 deletions docs/zh/loading_graph.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,91 +274,3 @@ GraphScope 将会推断起始点标签和终点标签为这一个点标签。
用户可以方便的实现自己的driver来支持更多的数据源,比如参照 `ossfs <https://github.com/alibaba/libvineyard/blob/main/modules/io/adaptors/ossfs.py>`_ driver的实现方式。
用户需要继承 `AbstractFileSystem` 类用来做scheme对应的resolver, 以及 `AbstractBufferedFile`。用户仅需要实现 ``_upload_chunk``,
``_initiate_upload`` and ``_fetch_range`` 这几个方法就可以实现基本的read,write功能。最后通过 ``fsspec.register_implementation('protocol_name', 'protocol_file_system')`` 注册自定义的resolver。


理解惰性载图
----------

GraphScope 中的图直到被使用时才会被真正载入。
**被使用** 指任何涉及到远端的东西被用到时,比如图的 `key`, `vineyard_id`,完整的带有数据类型的图的定义,或者
是有应用在图上查询,等等。

当迭代式地建图时,图内部会存储一些基本的点标签,边标签信息,可以通过 `print(graph)` 来查看这些信息并不会触发载图过程。
来看一个例子

.. code:: python
sess = graphscope.session()
graph = sess.g()
graph = graph.add_vertices("/home/admin/student.v", "student")
graph = graph.add_edges( "file:///home/admin/group.e", "group", src_label="student", dst_label="student")
# 这里并不会真正载入图
print(graph)
# 这一步将会触发载图,因为有些信息只有在载入图后才能获得
print(graph.key)
print(graph.schema)
graphscope.sssp(graph, src=6)
# 调用 `loaded()` 也会自动触发载图
assert graph.loaded() == True
得益于惰性的载图,我们可以在真正载图前去除一些点或边标签,以解决偶尔写错的情况。
但是当图已经被载入后,便不可以去除。

.. code:: python
sess = graphscope.session()
graph = sess.g()
graph = graph.add_vertices("/home/admin/student.v", "student")
graph = graph.add_vertices( "/home/admin/teacher.v", "teacher")
graph = graph.add_edges("file:///home/admin/group.e", "group", src_label="student", dst_label="student")
graph = graph.add_edges("file:///home/admin/group_for_teacher_student.e", "group", src_label="teacher", dst_label="student")
# 查看基本的schema,不触发载图
print(graph)
# 不可以去除尚有被边引用的点
# graph = graph.remove_vertices("teacher") # 错误。存在边的起点或终点为这个点
# src_label 和 dst_label 可以被用来过滤边. 若没有指定,便去除整个边标签
graph = graph.remove_edges("group", src_label="teacher", dst_label="student")
# 现在我们可以去除点标签 `teacher`
graph = graph.remove_vertices("teacher")
print(graph)
# 触发载图
print(graph.key)
# 现在不可以再去除边
# graph = graph.remove_edges("group")
然而,我们可以再为已经载入的图添加点或边。
这一步仍然是惰性的,所以我们可以去除尚未被载入的点或边。

.. code:: python
sess = graphscope.session()
graph = graphscope.Graph(sess)
graph = graph.add_vertices("/home/admin/student.v", "student")
graph = graph.add_edges("file:///home/admin/group.e", "group", src_label="student", dst_label="student")
print(graph.key) # 触发载图
# 为载入的图加入更多点和边
graph = graph.add_vertices("/home/admin/teacher.v", "teacher")
graph = graph.add_edges("file:///home/admin/group_for_teacher_student.e", "group", src_label="teacher", dst_label="student")
print(graph) # 不触发载图
# 可以去除掉尚未被载入的点或边
graph = graph.remove_edges("group", src_label="teacher", dst_label="student")
graph = graph.remove_vertices("teacher")
# 但是不能去除原图中被载入的点或边
# graph = graph.remove_edges("group", src_label="student", dst_label="student")
4 changes: 2 additions & 2 deletions python/graphscope/analytical/app/bfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def bfs(graph, src=0):
import graphscope as gs
sess = gs.session()
g = gs.g()
g = sess.g()
pg = g.project_to_simple(v_label='vlabel', e_label='elabel')
r = gs.bfs(pg, 6) # use 6 as source vertex
s.close()
Expand All @@ -66,7 +66,7 @@ def property_bfs(graph, src=0):
import graphscope as gs
sess = gs.session()
g = gs.g()
g = sess.g()
r = gs.property_bfs(g, 6) # use 6 as source vertex
s.close()
Expand Down
2 changes: 1 addition & 1 deletion python/graphscope/analytical/app/cdlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def cdlp(graph, max_round=10):
import graphscope as gs
sess = gs.session()
g = gs.g()
g = sess.g()
pg = g.project_to_simple(v_label='vlabel', e_label='elabel')
r = gs.cdlp(g, max_round=10)
s.close()
Expand Down
2 changes: 1 addition & 1 deletion python/graphscope/analytical/app/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def clustering(graph):
import graphscope as gs
sess = gs.session()
g = gs.g()
g = sess.g()
pg = g.project_to_simple(v_label='vlabel', e_label='elabel')
r = gs.clustering(pg)
s.close()
Expand Down
2 changes: 1 addition & 1 deletion python/graphscope/analytical/app/degree_centrality.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def degree_centrality(graph, centrality_type="both"):
import graphscope as gs
sess = gs.session()
g = gs.g()
g = sess.g()
pg = g.project_to_simple(v_label="vlabel", e_label="elabel")
r = gs.degree_centrality(pg, centrality_type="both")
s.close()
Expand Down
2 changes: 1 addition & 1 deletion python/graphscope/analytical/app/eigenvector_centrality.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def eigenvector_centrality(graph, tolerance=1e-06, max_round=100):
import graphscope as gs
sess = gs.session()
g = gs.g()
g = sess.g()
pg = g.project_to_simple(v_label='vlabel', e_label='elabel')
r = gs.eigenvector_centrality(pg)
s.close()
Expand Down
2 changes: 1 addition & 1 deletion python/graphscope/analytical/app/hits.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def hits(graph, tolerance=0.01, max_round=100, normalized=True):
import graphscope as gs
sess = gs.session()
g = gs.g()
g = sess.g()
pg = g.project_to_simple(v_label='vlabel', e_label='elabel')
r = gs.hits(pg)
s.close()
Expand Down
2 changes: 1 addition & 1 deletion python/graphscope/analytical/app/k_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def k_core(graph, k: int):
import graphscope as gs
sess = gs.session()
g = gs.g()
g = sess.g()
pg = g.project_to_simple(v_label='vlabel', e_label='elabel')
r = gs.k_core(pg)
s.close()
Expand Down
2 changes: 1 addition & 1 deletion python/graphscope/analytical/app/k_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def k_shell(graph, k: int):
import graphscope as gs
sess = gs.session()
g = gs.g()
g = sess.g()
pg = g.project_to_simple(v_label='vlabel', e_label='elabel')
r = gs.k_shell(pg)
s.close()
Expand Down
2 changes: 1 addition & 1 deletion python/graphscope/analytical/app/katz_centrality.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def katz_centrality(
import graphscope as gs
sess = gs.session()
g = gs.g()
g = sess.g()
pg = g.project_to_simple(v_label='vlabel', e_label='elabel')
r = gs.katz_centrality(pg)
s.close()
Expand Down
2 changes: 1 addition & 1 deletion python/graphscope/analytical/app/lpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def lpa(graph, max_round=10):
import graphscope as gs
sess = gs.session()
g = gs.g()
g = sess.g()
r = gs.lpa(g)
s.close()
Expand Down
2 changes: 1 addition & 1 deletion python/graphscope/analytical/app/pagerank.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def pagerank(graph, delta=0.85, max_round=10):
import graphscope as gs
sess = gs.session()
g = gs.g()
g = sess.g()
pg = g.project_to_simple(v_label='vlabel', e_label='elabel')
r = gs.pagerank(pg, delta=0.85, max_round=10)
s.close()
Expand Down
2 changes: 1 addition & 1 deletion python/graphscope/analytical/app/sssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def sssp(graph, src=0):
import graphscope as gs
sess = gs.session()
g = gs.g()
g = sess.g()
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()
Expand Down
2 changes: 1 addition & 1 deletion python/graphscope/analytical/app/triangles.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def triangles(graph):
import graphscope as gs
sess = gs.session()
g = gs.g()
g = sess.g()
pg = g.project_to_simple(v_label='vlabel', e_label='elabel')
r = gs.triangles(pg)
s.close()
Expand Down
2 changes: 1 addition & 1 deletion python/graphscope/analytical/app/wcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def wcc(graph):
import graphscope as gs
sess = gs.session()
g = gs.g()
g = sess.g()
pg = g.project_to_simple(v_label='vlabel', e_label='elabel')
r = gs.wcc(pg)
s.close()
Expand Down
2 changes: 1 addition & 1 deletion python/graphscope/experimental/nx/tests/test_nx.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def ldbc_sample_multi_labels(prefix, directed):


def ldbc_sample_with_duplicated_oid(prefix, directed):
graph = graphscope.Graph(directed=directed)
graph = graphscope.g(directed=directed)
graph = graph.add_vertices(
Loader(os.path.join(prefix, "place_0_0.csv"), delimiter="|"), "place"
).add_vertices(
Expand Down
2 changes: 1 addition & 1 deletion python/graphscope/interactive/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def load_subgraph(name):

import graphscope

graph = graphscope.Graph(self._session, generate_eid=False)
graph = self._session.g(generate_eid=False)
graph = graph.add_vertices(
Loader(vineyard.ObjectName("__%s_vertex_stream" % name))
)
Expand Down

0 comments on commit 2fb567d

Please sign in to comment.