diff --git a/README-zh.md b/README-zh.md index aead21b88524..062409dc0068 100644 --- a/README-zh.md +++ b/README-zh.md @@ -132,7 +132,7 @@ GraphScope 以属性图(property graph)建模图数据。属性图中,点 请下载数据并将其解压缩到本地的挂载目录(在本例中为`〜/test_data`)。 ```python -g = graphscope.Graph(sess) +g = sess.g() g = ( g.add_vertices("/testingdata/ogbn_mag_small/paper.csv", label="paper") .add_vertices("/testingdata/ogbn_mag_small/author.csv", label="author") diff --git a/README.md b/README.md index 941a19621671..8eff7d4e1ace 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ To load this graph to GraphScope, one may use the code below with the [data file ```python -g = graphscope.Graph(sess) +g = sess.g() g = ( g.add_vertices("/testingdata/ogbn_mag_small/paper.csv", label="paper") .add_vertices("/testingdata/ogbn_mag_small/author.csv", label="author") diff --git a/demo/node_classification_on_citation.ipynb b/demo/node_classification_on_citation.ipynb index 312106f381bf..a8ce5641c595 100644 --- a/demo/node_classification_on_citation.ipynb +++ b/demo/node_classification_on_citation.ipynb @@ -63,7 +63,7 @@ " Returns:\n", " :class:`graphscope.Graph`: A Graph object which graph type is ArrowProperty\n", " \"\"\"\n", - " graph = Graph(sess)\n", + " graph = sess.g()\n", " graph = (\n", " graph.add_vertices(os.path.join(prefix, \"paper.csv\"), \"paper\")\n", " .add_vertices(os.path.join(prefix, \"author.csv\"), \"author\")\n", diff --git a/docs/analytics_engine.rst b/docs/analytics_engine.rst index e44ecdcd405d..a06bb33d157a 100644 --- a/docs/analytics_engine.rst +++ b/docs/analytics_engine.rst @@ -304,7 +304,7 @@ To run your own algorithms, you may trigger it in place where you defined it. import graphscope sess = graphscope.session() - g = graphscope.Graph(sess) + g = sess.g() # load my algorithm my_app = SSSP_Pregel() diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 1563d903093e..ed9471edb70a 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -112,7 +112,7 @@ To load this graph to GraphScope, one may use the code below. .. code:: python - g = graphscope.Graph(sess) + g = sess.g() g = ( g.add_vertices("paper.csv", label="paper") .add_vertices("author.csv", label="author") diff --git a/docs/loading_graph.rst b/docs/loading_graph.rst index f10e4c878bcf..fa6f10013acd 100644 --- a/docs/loading_graph.rst +++ b/docs/loading_graph.rst @@ -10,32 +10,27 @@ in which the edges/vertices are labeled and each label may have many properties. Building a Graph ------------------------- -To load a property graph to GraphScope, we provide a class `Graph`, and several methods: +To load a property graph to GraphScope, we provide a method `g()` defined in `Session`. + +First, we create a session, then a graph instance inside that session. .. code:: python - def add_vertices(self, vertices, label="_", properties=[], vid_field=0): - pass + sess = graphscope.session() + graph = sess.g() - def add_edges(self, edges, label="_", properties=[], src_label=None, dst_label=None, src_field=0, dst_field=1): - pass +The class `Graph` has several methods: - def remove_vertices(self, label): +.. code:: python + + def add_vertices(self, vertices, label="_", properties=[], vid_field=0): pass - def remove_edges(self, label, src_label=None, dst_label=None): + def add_edges(self, edges, label="_", properties=[], src_label=None, dst_label=None, src_field=0, dst_field=1): pass These methods helps users to construct the schema of the property graph iteratively. -First, we create a session, then a graph instance inside that session. - -.. code:: python - - sess = graphscope.session() - graph = graphscope.Graph(sess) - - We can add a kind of vertices to graph. The parameters contain: @@ -168,7 +163,7 @@ If there is only one vertex label in the graph, the label of vertices can be omi GraphScope will infer the source and destination vertex label is that very label. .. code:: python - graph = graphscope.Graph(sess) + graph = sess.g() graph = graph.add_vertices("file:///home/admin/student.v", label="student") graph = graph.add_edges("file:///home/admin/group.e", label="group") # GraphScope will assign `src_label` and `dst_label` to `student` automatically. @@ -183,7 +178,7 @@ It only serve the most simple cases. .. code:: python - graph = graphscope.Graph(sess) + graph = sess.g() graph.add_edges("file:///home/admin/group.e", label="group") # After loaded, the graph will have an vertex label called `_`, and an edge label called `group`. @@ -200,7 +195,7 @@ Let's make the example complete: .. code:: python sess = graphscope.session() - graph = graphscope.Graph(sess) + graph = sess.g() graph = graph.add_vertices( "/home/admin/student.v", @@ -247,7 +242,7 @@ from pandas dataframes or numpy ndarrays. # use a dataframe as datasource, properties omitted, col_0/col_1 will be used as src/dst by default. # (for vertices, col_0 will be used as vertex_id by default) - graph = graphscope.Graph(sess).add_vertices(df_v).add_edges(df_e) + graph = sess.g().add_vertices(df_v).add_edges(df_e) Or load from numpy ndarrays @@ -259,7 +254,7 @@ Or load from numpy ndarrays array_e = [df_e[col].values for col in ['leader_student_id', 'member_student_id', 'member_size']] array_v = [df_v[col].values for col in ['student_id', 'lesson_nums', 'avg_score']] - graph = graphscope.Graph(sess).add_vertices(array_v).add_edges(array_e) + graph = sess.g().add_vertices(array_v).add_edges(array_e) Graphs from Given Location @@ -288,96 +283,4 @@ directly be passed to corresponding storage class. Like `host` and `port` to `HD User can implement customized driver to support additional data sources. Take `ossfs `_ as an example, User need to subclass `AbstractFileSystem`, which is used as resolve to specific protocol scheme, and `AbstractBufferFile` to do read and write. The only methods user need to override is ``_upload_chunk``, -``_initiate_upload`` and ``_fetch_range``. In the end user need to use ``fsspec.register_implementation('protocol_name', 'protocol_file_system')`` to register corresponding resolver. - - -Understand the lazy evaluation of graph. ---------------------------------------- - -Graphs in GraphScope are not loaded until used. -When we say **used**, we means that anything related to the remote is touched, such as -the `key` of the graph, the `vineyard_id`, the complete schema with data types, or -applications is quering the query, etc. - -When building graph iteratively, graph itself will store some basic schema, user are free to -inspect the basic schema without trigger the loading process by `print(graph)`. -Let's see an example: - -.. 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") - # This will not actually load the graph. - print(graph) - # But these will load the graph, cause more detailed information can only be known after loading. - print(graph.key) - print(graph.schema) - graphscope.sssp(graph, src=6) - # call `loaded` also will automatically load the graph. - assert graph.loaded() == True - - -Thanks to the lazy evaluation of graph loading, we can remove some vertices or edges before the actually loading, -but we cannot remove after the graph is loaded. - -.. code:: python - - sess = graphscope.session() - graph = graphscope.Graph(sess) - - 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") - - # inspect the schema without loading - print(graph) - - # the related edge must be removed before an vertex is removed. - # graph = graph.remove_vertices("teacher") # Error, cause some edges is rely on that vertex. - - # src_label and dst_label is used to filter edges. When not specified, means remove the edge label entirely. - graph = graph.remove_edges("group", src_label="teacher", dst_label="student") - - # Now we can remove the vertex - graph = graph.remove_vertices("teacher") - - print(graph) - - # Trigger the loading. - print(graph.key) - - # Now the remove is forbidden. - # graph = graph.remove_edges("group") - - -But we can add more vertices and edges to a loaded graph. -The adding is also lazy evaluated, so we can even remove unprocessed vertices and edges. - -.. 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) # trigger the loading - - # Add more vertices and edges to a loaded graph. - - 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) # does not trigger the loading. - - # So we can remove unprocessed vertices or edges - graph = graph.remove_edges("group", src_label="teacher", dst_label="student") - graph = graph.remove_vertices("teacher") - - # But cannot remove the labels that are in loaded graph. - # graph = graph.remove_edges("group", src_label="student", dst_label="student") \ No newline at end of file +``_initiate_upload`` and ``_fetch_range``. In the end user need to use ``fsspec.register_implementation('protocol_name', 'protocol_file_system')`` to register corresponding resolver. \ No newline at end of file diff --git a/docs/zh/analytics_engine.rst b/docs/zh/analytics_engine.rst index 35d2bb44b200..3f8337d4f937 100644 --- a/docs/zh/analytics_engine.rst +++ b/docs/zh/analytics_engine.rst @@ -280,7 +280,7 @@ GraphScope 图分析引擎内置了许多常用的图分析算法,包括连通 import graphscope sess = graphscope.session() - g = graphscope.Graph(sess) + g = sess.g() # 加载自己的算法 my_app = SSSP_Pregel() @@ -301,7 +301,7 @@ GraphScope 图分析引擎内置了许多常用的图分析算法,包括连通 import graphscope sess = graphscope.session() - g = graphscope.Graph(sess) + g = sess.g() # 从gar包中加载自己的算法 my_app = load_app('SSSP_Pregel', 'file:///var/graphscope/udf/my_sssp_pregel.gar') diff --git a/docs/zh/getting_started.rst b/docs/zh/getting_started.rst index 565e4d6ddf06..efdffeca8ccf 100644 --- a/docs/zh/getting_started.rst +++ b/docs/zh/getting_started.rst @@ -98,7 +98,7 @@ GraphScope 以属性图(property graph)建模图数据。属性图中,点 .. code:: python - g = graphscope.Graph(sess) + g = sess.g() g = ( g.add_vertices("paper.csv", label="paper") .add_vertices("author.csv", label="author") diff --git a/docs/zh/loading_graph.rst b/docs/zh/loading_graph.rst index 5e6c1bdbe5f3..d4263ea63374 100644 --- a/docs/zh/loading_graph.rst +++ b/docs/zh/loading_graph.rst @@ -32,7 +32,7 @@ GraphScope 以 .. code:: python sess = graphscope.session() - graph = graphscope.Graph(sess) + graph = sess.g() 我们可以向图内添加一个点标签。相关的参数含义如下: @@ -165,7 +165,7 @@ GraphScope 以 GraphScope 将会推断起始点标签和终点标签为这一个点标签。 .. code:: python - graph = graphscope.Graph(sess) + graph = sess.g() graph = graph.add_vertices("file:///home/admin/student.v", label="student") graph = graph.add_edges("file:///home/admin/group.e", label="group") # GraphScope 会将 `src_label` 和 `dst_label` 自动赋值为 `student`. @@ -176,7 +176,7 @@ GraphScope 将会推断起始点标签和终点标签为这一个点标签。 .. code:: python - graph = graphscope.Graph(sess) + graph = sess.g() graph.add_edges("file:///home/admin/group.e", label="group") # 载图后,图中将会包含一个点标签,名为 `_`, 和一个边标签,名为 `group`. @@ -192,7 +192,7 @@ GraphScope 将会推断起始点标签和终点标签为这一个点标签。 .. code:: python sess = graphscope.session() - graph = graphscope.Graph(sess) + graph = sess.g() graph = graph.add_vertices( "/home/admin/student.v", @@ -274,91 +274,3 @@ GraphScope 将会推断起始点标签和终点标签为这一个点标签。 用户可以方便的实现自己的driver来支持更多的数据源,比如参照 `ossfs `_ 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 = 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) - # 这一步将会触发载图,因为有些信息只有在载入图后才能获得 - print(graph.key) - print(graph.schema) - graphscope.sssp(graph, src=6) - # 调用 `loaded()` 也会自动触发载图 - assert graph.loaded() == True - -得益于惰性的载图,我们可以在真正载图前去除一些点或边标签,以解决偶尔写错的情况。 -但是当图已经被载入后,便不可以去除。 - -.. code:: python - - sess = graphscope.session() - graph = graphscope.Graph(sess) - - 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") diff --git a/python/graphscope/__init__.py b/python/graphscope/__init__.py index 133601b25586..8214e816153c 100644 --- a/python/graphscope/__init__.py +++ b/python/graphscope/__init__.py @@ -20,13 +20,13 @@ from graphscope.analytical.udf import declare from graphscope.analytical.udf.types import Vertex from graphscope.client.session import Session +from graphscope.client.session import g from graphscope.client.session import get_default_session from graphscope.client.session import get_option from graphscope.client.session import session from graphscope.client.session import set_option from graphscope.framework.errors import * from graphscope.framework.graph import Graph -from graphscope.framework.graph import g from graphscope.framework.graph_builder import load_from from graphscope.version import __version__ diff --git a/python/graphscope/analytical/app/bfs.py b/python/graphscope/analytical/app/bfs.py index bb781b45a97e..739ab2b2298a 100644 --- a/python/graphscope/analytical/app/bfs.py +++ b/python/graphscope/analytical/app/bfs.py @@ -40,7 +40,7 @@ def bfs(graph, src=0): import graphscope as gs sess = gs.session() - g = gs.Graph(sess) + 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() @@ -66,7 +66,7 @@ def property_bfs(graph, src=0): import graphscope as gs sess = gs.session() - g = gs.Graph(sess) + g = sess.g() r = gs.property_bfs(g, 6) # use 6 as source vertex s.close() diff --git a/python/graphscope/analytical/app/cdlp.py b/python/graphscope/analytical/app/cdlp.py index 804ec744a18d..f68762b63e78 100644 --- a/python/graphscope/analytical/app/cdlp.py +++ b/python/graphscope/analytical/app/cdlp.py @@ -40,7 +40,7 @@ def cdlp(graph, max_round=10): import graphscope as gs sess = gs.session() - g = gs.Graph(sess) + g = sess.g() pg = g.project_to_simple(v_label='vlabel', e_label='elabel') r = gs.cdlp(g, max_round=10) s.close() diff --git a/python/graphscope/analytical/app/clustering.py b/python/graphscope/analytical/app/clustering.py index 02cc302304df..e054bc34e72c 100644 --- a/python/graphscope/analytical/app/clustering.py +++ b/python/graphscope/analytical/app/clustering.py @@ -41,7 +41,7 @@ def clustering(graph): import graphscope as gs sess = gs.session() - g = gs.Graph(sess) + g = sess.g() pg = g.project_to_simple(v_label='vlabel', e_label='elabel') r = gs.clustering(pg) s.close() diff --git a/python/graphscope/analytical/app/degree_centrality.py b/python/graphscope/analytical/app/degree_centrality.py index 07ef49c9b2d2..2fb26cad3b21 100644 --- a/python/graphscope/analytical/app/degree_centrality.py +++ b/python/graphscope/analytical/app/degree_centrality.py @@ -43,7 +43,7 @@ def degree_centrality(graph, centrality_type="both"): import graphscope as gs sess = gs.session() - g = gs.Graph(sess) + g = sess.g() pg = g.project_to_simple(v_label="vlabel", e_label="elabel") r = gs.degree_centrality(pg, centrality_type="both") s.close() diff --git a/python/graphscope/analytical/app/eigenvector_centrality.py b/python/graphscope/analytical/app/eigenvector_centrality.py index 98bfd65bc3e5..f8b8577d6856 100644 --- a/python/graphscope/analytical/app/eigenvector_centrality.py +++ b/python/graphscope/analytical/app/eigenvector_centrality.py @@ -43,7 +43,7 @@ def eigenvector_centrality(graph, tolerance=1e-06, max_round=100): import graphscope as gs sess = gs.session() - g = gs.Graph(sess) + g = sess.g() pg = g.project_to_simple(v_label='vlabel', e_label='elabel') r = gs.eigenvector_centrality(pg) s.close() diff --git a/python/graphscope/analytical/app/hits.py b/python/graphscope/analytical/app/hits.py index dba4bf15ed6f..1a1d8d9de67c 100644 --- a/python/graphscope/analytical/app/hits.py +++ b/python/graphscope/analytical/app/hits.py @@ -46,7 +46,7 @@ def hits(graph, tolerance=0.01, max_round=100, normalized=True): import graphscope as gs sess = gs.session() - g = gs.Graph(sess) + g = sess.g() pg = g.project_to_simple(v_label='vlabel', e_label='elabel') r = gs.hits(pg) s.close() diff --git a/python/graphscope/analytical/app/k_core.py b/python/graphscope/analytical/app/k_core.py index 9d923b9c1867..cb4ce2687fa9 100644 --- a/python/graphscope/analytical/app/k_core.py +++ b/python/graphscope/analytical/app/k_core.py @@ -42,7 +42,7 @@ def k_core(graph, k: int): import graphscope as gs sess = gs.session() - g = gs.Graph(sess) + g = sess.g() pg = g.project_to_simple(v_label='vlabel', e_label='elabel') r = gs.k_core(pg) s.close() diff --git a/python/graphscope/analytical/app/k_shell.py b/python/graphscope/analytical/app/k_shell.py index c06ff68a137e..4dc8799082cd 100644 --- a/python/graphscope/analytical/app/k_shell.py +++ b/python/graphscope/analytical/app/k_shell.py @@ -42,7 +42,7 @@ def k_shell(graph, k: int): import graphscope as gs sess = gs.session() - g = gs.Graph(sess) + g = sess.g() pg = g.project_to_simple(v_label='vlabel', e_label='elabel') r = gs.k_shell(pg) s.close() diff --git a/python/graphscope/analytical/app/katz_centrality.py b/python/graphscope/analytical/app/katz_centrality.py index 9466d4bfbda4..3b1b2f661bed 100644 --- a/python/graphscope/analytical/app/katz_centrality.py +++ b/python/graphscope/analytical/app/katz_centrality.py @@ -49,7 +49,7 @@ def katz_centrality( import graphscope as gs sess = gs.session() - g = gs.Graph(sess) + g = sess.g() pg = g.project_to_simple(v_label='vlabel', e_label='elabel') r = gs.katz_centrality(pg) s.close() diff --git a/python/graphscope/analytical/app/lpa.py b/python/graphscope/analytical/app/lpa.py index c09c66d4ed82..e286e365f4cc 100644 --- a/python/graphscope/analytical/app/lpa.py +++ b/python/graphscope/analytical/app/lpa.py @@ -40,7 +40,7 @@ def lpa(graph, max_round=10): import graphscope as gs sess = gs.session() - g = gs.Graph(sess) + g = sess.g() r = gs.lpa(g) s.close() diff --git a/python/graphscope/analytical/app/pagerank.py b/python/graphscope/analytical/app/pagerank.py index e62071048bf7..4fa09fb204bf 100644 --- a/python/graphscope/analytical/app/pagerank.py +++ b/python/graphscope/analytical/app/pagerank.py @@ -41,7 +41,7 @@ def pagerank(graph, delta=0.85, max_round=10): import graphscope as gs sess = gs.session() - g = gs.Graph(sess) + 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() diff --git a/python/graphscope/analytical/app/sssp.py b/python/graphscope/analytical/app/sssp.py index 86e489b3a86e..48c1f49894cf 100644 --- a/python/graphscope/analytical/app/sssp.py +++ b/python/graphscope/analytical/app/sssp.py @@ -42,7 +42,7 @@ def sssp(graph, src=0): import graphscope as gs sess = gs.session() - g = gs.Graph(sess) + 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() diff --git a/python/graphscope/analytical/app/triangles.py b/python/graphscope/analytical/app/triangles.py index 0796353d3f48..a34327626b67 100644 --- a/python/graphscope/analytical/app/triangles.py +++ b/python/graphscope/analytical/app/triangles.py @@ -39,7 +39,7 @@ def triangles(graph): import graphscope as gs sess = gs.session() - g = gs.Graph(sess) + g = sess.g() pg = g.project_to_simple(v_label='vlabel', e_label='elabel') r = gs.triangles(pg) s.close() diff --git a/python/graphscope/analytical/app/wcc.py b/python/graphscope/analytical/app/wcc.py index 2033f407f9bc..65a87c4f21b8 100644 --- a/python/graphscope/analytical/app/wcc.py +++ b/python/graphscope/analytical/app/wcc.py @@ -39,7 +39,7 @@ def wcc(graph): import graphscope as gs sess = gs.session() - g = gs.Graph(sess) + g = sess.g() pg = g.project_to_simple(v_label='vlabel', e_label='elabel') r = gs.wcc(pg) s.close() diff --git a/python/graphscope/client/session.py b/python/graphscope/client/session.py index 453bc89c089d..c091d54a0a86 100755 --- a/python/graphscope/client/session.py +++ b/python/graphscope/client/session.py @@ -56,6 +56,7 @@ from graphscope.framework.errors import K8sError from graphscope.framework.errors import LearningEngineInternalError from graphscope.framework.errors import check_argument +from graphscope.framework.graph import Graph from graphscope.framework.operation import Operation from graphscope.interactive.query import InteractiveQuery from graphscope.interactive.query import InteractiveQueryStatus @@ -105,14 +106,14 @@ class Session(object): >>> # use session object explicitly >>> sess = gs.session() - >>> g = gs.Graph(sess) + >>> g = sess.g() >>> pg = g.project_to_simple('v', 'e', None, 'dist') >>> r = s.sssp(g, 4) >>> s.close() >>> # or use a session as default >>> s = gs.session().as_default() - >>> g = gs.Graph() + >>> g = g() >>> pg = g.project_to_simple('v', 'e', None, 'dist') >>> r = gs.sssp(pg, 4) >>> s.close() @@ -801,6 +802,9 @@ def get_config(self): """Get configuration of the session.""" return self._config_params + def g(self, incoming_data=None, oid_type="int64", directed=True, generate_eid=True): + return Graph(self, incoming_data, oid_type, directed, generate_eid) + def load_from(self, *args, **kwargs): """Load a graph within the session. See more information in :meth:`graphscope.load_from`. @@ -1312,3 +1316,7 @@ def get_controller(self, default): _default_session_stack = _DefaultSessionStack() # pylint: disable=protected-access + + +def g(incoming_data=None, oid_type="int64", directed=True, generate_eid=True): + return get_default_session().g(incoming_data, oid_type, directed, generate_eid) diff --git a/python/graphscope/dataset/ldbc.py b/python/graphscope/dataset/ldbc.py index 100d1f5e9a60..686a92cf47c0 100644 --- a/python/graphscope/dataset/ldbc.py +++ b/python/graphscope/dataset/ldbc.py @@ -34,7 +34,7 @@ def load_ldbc(sess, prefix, directed=True): Returns: :class:`graphscope.Graph`: A Graph object which graph type is ArrowProperty """ - graph = Graph(sess, directed=directed) + graph = sess.g(directed=directed) graph = ( graph.add_vertices( Loader(os.path.join(prefix, "comment_0_0.csv"), delimiter="|"), diff --git a/python/graphscope/dataset/modern_graph.py b/python/graphscope/dataset/modern_graph.py index a25a829153b4..dadaff0569cf 100644 --- a/python/graphscope/dataset/modern_graph.py +++ b/python/graphscope/dataset/modern_graph.py @@ -36,7 +36,7 @@ def load_modern_graph(sess, prefix, directed=True): Returns: :class:`graphscope.Graph`: A Graph object which graph type is ArrowProperty """ - graph = Graph(sess, directed=directed) + graph = sess.g(directed=directed) graph = ( graph.add_vertices( Loader(os.path.join(prefix, "person.csv"), delimiter="|"), diff --git a/python/graphscope/dataset/ogbn_mag.py b/python/graphscope/dataset/ogbn_mag.py index 2971f2a1676e..83b7d3678bd6 100644 --- a/python/graphscope/dataset/ogbn_mag.py +++ b/python/graphscope/dataset/ogbn_mag.py @@ -36,7 +36,7 @@ def load_ogbn_mag(sess, prefix): Returns: :class:`graphscope.Graph`: A Graph object which graph type is ArrowProperty """ - graph = Graph(sess) + graph = sess.g() graph = ( graph.add_vertices(os.path.join(prefix, "paper.csv"), "paper") .add_vertices(os.path.join(prefix, "author.csv"), "author") diff --git a/python/graphscope/deploy/tests/test_demo_script.py b/python/graphscope/deploy/tests/test_demo_script.py index 3f0a8ef5e6af..27377e9da5a1 100644 --- a/python/graphscope/deploy/tests/test_demo_script.py +++ b/python/graphscope/deploy/tests/test_demo_script.py @@ -315,7 +315,7 @@ def test_add_vertices_edges(gs_session_distributed, modern_graph_data_dir): def test_serialize_roundtrip(gs_session_distributed, p2p_property_dir): - graph = Graph(gs_session_distributed, generate_eid=False) + graph = gs_session_distributed.g(generate_eid=False) graph = graph.add_vertices(f"{p2p_property_dir}/p2p-31_property_v_0", "person") graph = graph.add_edges( f"{p2p_property_dir}/p2p-31_property_e_0", diff --git a/python/graphscope/experimental/nx/tests/test_nx.py b/python/graphscope/experimental/nx/tests/test_nx.py index fbad58bab65e..9fa298e7e538 100644 --- a/python/graphscope/experimental/nx/tests/test_nx.py +++ b/python/graphscope/experimental/nx/tests/test_nx.py @@ -22,9 +22,9 @@ import graphscope import graphscope.experimental.nx as nx +from graphscope.client.session import g from graphscope.framework.errors import AnalyticalEngineInternalError from graphscope.framework.errors import InvalidArgumentError -from graphscope.framework.graph import g from graphscope.framework.loader import Loader from graphscope.proto import types_pb2 @@ -41,7 +41,7 @@ def graphscope_session(): def ldbc_sample_single_label(prefix, directed): - graph = graphscope.Graph(directed=directed) + graph = graphscope.g(directed=directed) graph = graph.add_vertices( Loader(os.path.join(prefix, "comment_0_0.csv"), delimiter="|"), "comment" ) @@ -53,7 +53,7 @@ def ldbc_sample_single_label(prefix, directed): def ldbc_sample_multi_labels(prefix, directed): - graph = graphscope.Graph(directed=directed) + graph = graphscope.g(directed=directed) graph = ( graph.add_vertices( Loader(os.path.join(prefix, "comment_0_0.csv"), delimiter="|"), "comment" @@ -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( diff --git a/python/graphscope/framework/graph.py b/python/graphscope/framework/graph.py index 35e044788149..efdef40aa633 100644 --- a/python/graphscope/framework/graph.py +++ b/python/graphscope/framework/graph.py @@ -25,12 +25,10 @@ import vineyard -from graphscope.client.session import get_default_session from graphscope.config import GSConfig as gs_config from graphscope.framework import dag_utils from graphscope.framework import graph_utils from graphscope.framework import utils -from graphscope.framework.errors import InvalidArgumentError from graphscope.framework.errors import check_argument from graphscope.framework.graph_schema import GraphSchema from graphscope.framework.graph_utils import EdgeLabel @@ -57,7 +55,7 @@ class Graph(object): >>> import graphscope as gs >>> from graphscope.framework.loader import Loader >>> sess = gs.session() - >>> graph = Graph(sess) + >>> graph = sess.g() >>> graph = graph.add_vertices("person.csv","person") >>> graph = graph.add_vertices("software.csv", "software") >>> graph = graph.add_edges("knows.csv", "knows", src_label="person", dst_label="person") @@ -68,7 +66,7 @@ class Graph(object): def __init__( self, - session=None, + session, incoming_data=None, oid_type="int64", directed=True, @@ -90,8 +88,6 @@ def __init__( self._graph_type = types_pb2.ARROW_PROPERTY self._vineyard_id = 0 self._schema = GraphSchema() - if session is None: - session = get_default_session() self._session = session self._detached = False @@ -921,74 +917,3 @@ def add_edges( relations, func, ) - - def remove_vertices(self, label): - if label not in self._v_labels: - raise ValueError(f"label {label} not in vertices.") - if label not in self._unsealed_vertices: - raise ValueError( - "Remove vertices from a loaded graph doesn't supported yet" - ) - # Check whether safe to remove - for rel in self._e_relationships: - for sub_rel in rel: - if label in sub_rel: - raise ValueError( - f"Vertex {label} has usage in relation {sub_rel}, please remove that edge first." - ) - unsealed_vertices = deepcopy(self._unsealed_vertices) - v_labels = deepcopy(self._v_labels) - unsealed_vertices.pop(label) - v_labels.remove(label) - return self._construct_graph( - unsealed_vertices, - self._unsealed_edges, - v_labels, - self._e_labels, - self._e_relationships, - ) - - def remove_edges(self, label, src_label=None, dst_label=None): - if label not in self._e_labels: - raise ValueError(f"label {label} not in edges") - if label not in self._unsealed_edges: - raise ValueError("Remove edges from a loaded graph doesn't supported yet") - - unsealed_edges = deepcopy(self._unsealed_edges) - e_labels = deepcopy(self._e_labels) - relations = deepcopy(self._e_relationships) - # Calculate the items to remove - remove_list = [] - - label_idx = e_labels.index(label) - for rel in relations[label_idx]: - for sub_rel in rel: - if src_label is None or src_label == sub_rel[0]: - if dst_label is None or dst_label == sub_rel[1]: - remove_list.append(sub_rel) - if not remove_list: - raise ValueError("Cannot find edges to remove.") - - # Remove the edge label - if src_label is None and dst_label is None: - unsealed_edges.pop(label) - e_labels.pop(label_idx) - relations.pop(label_idx) - else: - cur_label = unsealed_edges[label] - for sub_rel in remove_list: - cur_label.sub_labels.pop(sub_rel) - relations[label_idx].remove(sub_rel) - # Remove entire label if no relations still exists. - if not relations[label_idx]: - unsealed_edges.pop(label) - e_labels.pop(label_idx) - relations.pop(label_idx) - - return self._construct_graph( - self._unsealed_vertices, unsealed_edges, self._v_labels, e_labels, relations - ) - - -def g(incoming_data): - return Graph(incoming_data=incoming_data) diff --git a/python/graphscope/framework/graph_builder.py b/python/graphscope/framework/graph_builder.py index f192f07c8bac..b0b76934d21f 100644 --- a/python/graphscope/framework/graph_builder.py +++ b/python/graphscope/framework/graph_builder.py @@ -176,7 +176,7 @@ def load_from( if sess is None: raise ValueError("No default session found.") if isinstance(edges, (Graph, nx.Graph, *VineyardObjectTypes)): - return Graph(sess, edges) + return sess.g(edges) oid_type = utils.normalize_data_type_str(oid_type) if oid_type not in ("int64_t", "std::string"): raise ValueError("oid_type can only be int64_t or string.") @@ -184,5 +184,5 @@ def load_from( e_labels = normalize_parameter_edges(edges) config = assemble_op_config(v_labels, e_labels, oid_type, directed, generate_eid) op = dag_utils.create_graph(sess.session_id, types_pb2.ARROW_PROPERTY, attrs=config) - graph = Graph(sess, op) + graph = sess.g(op) return graph diff --git a/python/graphscope/interactive/query.py b/python/graphscope/interactive/query.py index 6f980b09439e..71b0f34c2a18 100644 --- a/python/graphscope/interactive/query.py +++ b/python/graphscope/interactive/query.py @@ -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)) ) diff --git a/python/tests/conftest.py b/python/tests/conftest.py index df22a3e91251..7ad6651ff3f0 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -117,7 +117,7 @@ def twitter_e_1_1_1(): @pytest.fixture(scope="module") def arrow_property_graph(graphscope_session): - g = Graph(graphscope_session, generate_eid=False) + g = graphscope_session.g(generate_eid=False) g = g.add_vertices(f"{new_property_dir}/twitter_v_0", "v0") g = g.add_vertices(f"{new_property_dir}/twitter_v_1", "v1") g = g.add_edges(f"{new_property_dir}/twitter_e_0_0_0", "e0", ["weight"], "v0", "v0") @@ -135,7 +135,7 @@ def arrow_property_graph(graphscope_session): @pytest.fixture(scope="module") def arrow_property_graph_only_from_efile(graphscope_session): - g = Graph(graphscope_session, generate_eid=False) + g = graphscope_session.g(generate_eid=False) g = g.add_edges(f"{new_property_dir}/twitter_e_0_0_0", "e0", ["weight"], "v0", "v0") g = g.add_edges(f"{new_property_dir}/twitter_e_0_1_0", "e0", ["weight"], "v0", "v1") g = g.add_edges(f"{new_property_dir}/twitter_e_1_0_0", "e0", ["weight"], "v1", "v0") @@ -151,7 +151,7 @@ def arrow_property_graph_only_from_efile(graphscope_session): @pytest.fixture(scope="module") def arrow_property_graph_undirected(graphscope_session): - g = Graph(graphscope_session, directed=False, generate_eid=False) + g = graphscope_session.g(directed=False, generate_eid=False) g = g.add_vertices(f"{new_property_dir}/twitter_v_0", "v0") g = g.add_vertices(f"{new_property_dir}/twitter_v_1", "v1") g = g.add_edges(f"{new_property_dir}/twitter_e_0_0_0", "e0", ["weight"], "v0", "v0") @@ -169,7 +169,7 @@ def arrow_property_graph_undirected(graphscope_session): @pytest.fixture(scope="module") def arrow_property_graph_lpa(graphscope_session): - g = Graph(graphscope_session, generate_eid=False) + g = graphscope_session.g(generate_eid=False) g = g.add_vertices(f"{property_dir}/lpa_dataset/lpa_3000_v_0", "v0") g = g.add_vertices(f"{property_dir}/lpa_dataset/lpa_3000_v_1", "v1") g = g.add_edges( @@ -193,7 +193,7 @@ def arrow_project_undirected_graph(arrow_property_graph_undirected): @pytest.fixture(scope="module") def p2p_property_graph(graphscope_session): - g = Graph(graphscope_session, generate_eid=False) + g = graphscope_session.g(generate_eid=False) g = g.add_vertices(f"{property_dir}/p2p-31_property_v_0", "person") g = g.add_edges( f"{property_dir}/p2p-31_property_e_0", @@ -207,7 +207,7 @@ def p2p_property_graph(graphscope_session): @pytest.fixture(scope="module") def p2p_property_graph_string(graphscope_session): - g = Graph(graphscope_session, oid_type="string", generate_eid=False) + g = graphscope_session.g(oid_type="string", generate_eid=False) g = g.add_vertices(f"{property_dir}/p2p-31_property_v_0", "person") g = g.add_edges( f"{property_dir}/p2p-31_property_e_0", @@ -221,7 +221,7 @@ def p2p_property_graph_string(graphscope_session): @pytest.fixture(scope="module") def p2p_property_graph_undirected(graphscope_session): - g = Graph(graphscope_session, directed=False, generate_eid=False) + g = graphscope_session.g(directed=False, generate_eid=False) g = g.add_vertices(f"{property_dir}/p2p-31_property_v_0", "person") g = g.add_edges( f"{property_dir}/p2p-31_property_e_0", diff --git a/python/tests/test_create_graph.py b/python/tests/test_create_graph.py index 1ee837ebae6e..b6f79915709b 100644 --- a/python/tests/test_create_graph.py +++ b/python/tests/test_create_graph.py @@ -162,7 +162,7 @@ def test_dict_in_dict_form_loader_deprecated( def test_complete_form_loader(graphscope_session, student_group_e, student_v): # a complete form for loading from ev files. # types are inferred from Loader. - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_vertices( student_v, "student", ["name", "lesson_nums", "avg_score"], "student_id" ) @@ -206,7 +206,7 @@ def test_complete_form_loader_deprecated( def test_properties_omitted_loader(graphscope_session, student_group_e, student_v): - graph = Graph(graphscope_session, generate_eid=False) + graph = graphscope_session.g(generate_eid=False) graph = graph.add_vertices(student_v, "student", [], "student_id") graph = graph.add_edges(student_group_e, "group", []) assert len(graph.schema.vertex_properties[0]) == 4 @@ -216,7 +216,7 @@ def test_properties_omitted_loader(graphscope_session, student_group_e, student_ def test_properties_omitted_loader_with_generate_eid( graphscope_session, student_group_e, student_v ): - graph = Graph(graphscope_session, generate_eid=True) + graph = graphscope_session.g(generate_eid=True) graph = graph.add_vertices(student_v, "student", [], "student_id") graph = graph.add_edges(student_group_e, "group", []) assert len(graph.schema.vertex_properties[0]) == 4 @@ -226,7 +226,7 @@ def test_properties_omitted_loader_with_generate_eid( def test_loader_with_specified_data_type( graphscope_session, student_group_e, student_v ): - graph = Graph(graphscope_session, oid_type="string", generate_eid=False) + graph = graphscope_session.g(oid_type="string", generate_eid=False) graph = graph.add_vertices( student_v, "student", @@ -245,7 +245,7 @@ def test_loader_with_specified_data_type( def test_multi_src_dst_edge_loader( graphscope_session, student_group_e, teacher_group_e, student_v, teacher_v ): - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_vertices( student_v, "student", ["name", "lesson_nums", "avg_score"], "student_id" ) @@ -275,7 +275,7 @@ def test_multi_src_dst_edge_loader( def test_vid_omitted_form_loader(graphscope_session, student_group_e, student_v): # vid can be omit, the first column will be used as vid; - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_vertices( student_v, "student", ["name", "lesson_nums", "avg_score"] ) @@ -294,7 +294,7 @@ def test_vid_omitted_form_loader(graphscope_session, student_group_e, student_v) def test_v_property_omitted_form_loader(graphscope_session, student_group_e, student_v): # properties for v can be omit, all columns will be load, # the first one used as vid by # default. default vlabel would be '_'; - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_vertices(student_v, "student") graph = graph.add_edges( student_group_e, @@ -308,13 +308,13 @@ def test_v_property_omitted_form_loader(graphscope_session, student_group_e, stu def test_vertices_omitted_form_loader(graphscope_session, student_group_e): # vertices can be omit. - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_edges(student_group_e) assert graph.loaded() def test_all_omitted_form_loader(graphscope_session, student_group_e): - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_edges(student_group_e, "group") assert graph.loaded() @@ -322,21 +322,21 @@ def test_all_omitted_form_loader(graphscope_session, student_group_e): def test_multiple_e_all_omitted_form_loader( graphscope_session, student_group_e, friend_e ): - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_edges(student_group_e, "group") graph = graph.add_edges(friend_e, "friend") assert graph.loaded() def test_load_from_numpy(graphscope_session, student_group_e_array, student_v_array): - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_vertices(student_v_array) graph = graph.add_edges(student_group_e_array) assert graph.loaded() def test_load_from_pandas(graphscope_session, student_group_e_df, student_v_df): - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_vertices(student_v_df) graph = graph.add_edges(student_group_e_df) assert graph.loaded() @@ -351,7 +351,7 @@ def test_errors_on_files( graphscope_session, vineyard.ObjectName("non_exist_vy_name") )._ensure_loaded() return - graph = Graph(graphscope_session) + graph = graphscope_session.g() with pytest.raises(AnalyticalEngineInternalError, match="IOError"): non_existing_file = "file:///abc" graph.add_edges(Loader(non_existing_file))._ensure_loaded() @@ -368,7 +368,7 @@ def test_errors_on_files( def test_error_on_non_default_and_non_existing_v_label( graphscope_session, student_group_e, student_v ): - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_vertices(student_v, "student") with pytest.raises(ValueError, match="src label or dst_label not existed in graph"): graph = graph.add_edges(student_group_e, "group", src_label="v", dst_label="v") @@ -379,7 +379,7 @@ def test_error_on_non_default_and_non_existing_v_label( def test_error_on_src_dst_refer_to_same_col(graphscope_session, student_group_e): - graph = Graph(graphscope_session) + graph = graphscope_session.g() with pytest.raises(AssertionError, match="cannot refer to the same field"): graph = graph.add_edges( student_group_e, @@ -394,7 +394,7 @@ def test_error_on_src_dst_refer_to_same_col(graphscope_session, student_group_e) def test_error_on_ambigious_default_label( graphscope_session, student_group_e, student_v, teacher_v ): - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_vertices(student_v, "student") graph = graph.add_vertices(teacher_v, "teacher") @@ -403,7 +403,7 @@ def test_error_on_ambigious_default_label( def test_error_on_duplicate_labels(graphscope_session, student_group_e, student_v): - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_vertices(student_v, "student") with pytest.raises(ValueError, match="Label student already existed in graph"): graph = graph.add_vertices(student_v, "student") @@ -421,7 +421,7 @@ def test_load_complex_graph( teacher_v, lesson_v, ): - graph = Graph(graphscope_session, oid_type="string") + graph = graphscope_session.g(oid_type="string") graph = graph.add_vertices( student_v, "student", ["name", "lesson_nums", "avg_score"], "student_id" ) @@ -468,7 +468,7 @@ def test_load_complex_graph_by_index( teacher_v, lesson_v, ): - graph = Graph(graphscope_session, oid_type="string") + graph = graphscope_session.g(oid_type="string") graph = graph.add_vertices( student_v, "student", ["name", "lesson_nums", "avg_score"], 0 ) @@ -515,7 +515,7 @@ def test_Load_complex_graph_variants( teacher_v_oss, lesson_v_mars, ): - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_vertices( student_v_array, "student", ["name", "lesson_nums", "avg_score"], "student_id" ) diff --git a/python/tests/test_graph.py b/python/tests/test_graph.py index 0f79e481a6b6..b23dfe176de6 100644 --- a/python/tests/test_graph.py +++ b/python/tests/test_graph.py @@ -43,7 +43,7 @@ def test_graph_schema(arrow_property_graph): def test_load_graph_copy(graphscope_session, arrow_property_graph): g = arrow_property_graph - g2 = Graph(graphscope_session, g) + g2 = graphscope_session.g(g) assert g.key != g2.key assert g.vineyard_id != g2.vineyard_id assert str(g.schema) == str(g2.schema) @@ -51,7 +51,7 @@ def test_load_graph_copy(graphscope_session, arrow_property_graph): g2.unload() assert not g2.loaded() # test load from vineyard's graph - g3 = Graph(graphscope_session, vineyard.ObjectID(g.vineyard_id)) + g3 = graphscope_session.g(vineyard.ObjectID(g.vineyard_id)) assert g3.loaded() @@ -132,10 +132,10 @@ def test_error_relationship_on_project_to_simple(arrow_modern_graph): def test_unload(graphscope_session): - graph = Graph(graphscope_session) + graph = graphscope_session.g() prefix = os.path.expandvars("${GS_TEST_DIR}/property") graph = ( - Graph(graphscope_session) + graphscope_session.g() .add_vertices(f"{prefix}/p2p-31_property_v_0", "person") .add_edges(f"{prefix}/p2p-31_property_e_0", "knows") ) @@ -151,7 +151,7 @@ def test_unload(graphscope_session): with pytest.raises(RuntimeError, match="The graph is not loaded"): graph.project_to_simple(v_label="person", e_label="knows") with pytest.raises(AssertionError): - g2 = Graph(graphscope_session, graph) + g2 = graphscope_session.g(graph) with pytest.raises(RuntimeError, match="The graph is not loaded"): property_sssp(graph, src=6) @@ -176,7 +176,7 @@ def test_error_on_project_to_simple_wrong_graph_type_2(dynamic_property_graph): def test_error_on_operation_on_graph(graphscope_session): - g = Graph(graphscope_session) + g = graphscope_session.g() with pytest.raises(RuntimeError, match="Empty graph"): g.project_to_simple(v_label=0, v_prop=0, e_label=0, e_prop=0) @@ -345,7 +345,7 @@ def test_project_to_simple_string_eprop(graphscope_session): def test_add_vertices_edges(graphscope_session): prefix = os.path.expandvars("${GS_TEST_DIR}/modern_graph") - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_vertices(Loader(f"{prefix}/person.csv", delimiter="|"), "person") graph = graph.add_edges(Loader(f"{prefix}/knows.csv", delimiter="|"), "knows") @@ -385,9 +385,10 @@ def test_add_vertices_edges(graphscope_session): assert graph.schema.edge_labels == ["knows", "created"] +@pytest.mark.skip("use project to simulate remove.") def test_error_on_remove_vertices_edges(graphscope_session): prefix = os.path.expandvars("${GS_TEST_DIR}/modern_graph") - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_vertices(Loader(f"{prefix}/person.csv", delimiter="|"), "person") graph = graph.add_edges(Loader(f"{prefix}/knows.csv", delimiter="|"), "knows") @@ -422,10 +423,11 @@ def test_error_on_remove_vertices_edges(graphscope_session): graph = graph.remove_edges("knows") +@pytest.mark.skip("use project to simulate remove.") def test_remove_vertices_edges(graphscope_session): prefix = os.path.expandvars("${GS_TEST_DIR}/modern_graph") graph = ( - Graph(graphscope_session) + graphscope_session.g() .add_vertices(Loader(f"{prefix}/person.csv", delimiter="|"), "person") .add_edges(Loader(f"{prefix}/knows.csv", delimiter="|"), "knows") ) @@ -448,7 +450,7 @@ def test_remove_vertices_edges(graphscope_session): def test_multiple_add_vertices_edges(graphscope_session): prefix = os.path.expandvars("${GS_TEST_DIR}/modern_graph") - graph = Graph(graphscope_session) + graph = graphscope_session.g() graph = graph.add_vertices(Loader(f"{prefix}/person.csv", delimiter="|"), "person") graph = graph.add_edges(Loader(f"{prefix}/knows.csv", delimiter="|"), "knows") graph = graph.add_vertices( diff --git a/python/tests/test_load_from_vineyard.py b/python/tests/test_load_from_vineyard.py index 6551b1d9fe81..7fb10bbec8bf 100644 --- a/python/tests/test_load_from_vineyard.py +++ b/python/tests/test_load_from_vineyard.py @@ -46,7 +46,7 @@ def student_group_e(data_dir=os.path.expandvars("${GS_TEST_DIR}/property_graph") @pytest.mark.skip("requires vineyard's io adaptors installed properly") def test_p2p(graphscope_session, p2p_31_e, p2p_31_v): - graph = graphscope.Graph(graphscope_session) + graph = graphscope.graphscope_session.g() graph = graph.add_vertices(Loader(p2p_31_v, session=graphscope_session), "person") graph = graph.add_edges(Loader(p2p_31_e, session=graphscope_session), "knows") assert graph.schema is not None @@ -54,7 +54,7 @@ def test_p2p(graphscope_session, p2p_31_e, p2p_31_v): @pytest.mark.skip("requires vineyard's io adaptors installed properly") def test_group(graphscope_session, student_group_e, student_v): - graph = graphscope.Graph(graphscope_session) + graph = graphscope.graphscope_session.g() graph = graph.add_vertices(Loader(student_v, session=graphscope_session), "student") graph = graph.add_edges( Loader(student_group_e, session=graphscope_session), "group" diff --git a/python/tests/test_scalability.py b/python/tests/test_scalability.py index 6fe821b45cf0..524cb142d088 100644 --- a/python/tests/test_scalability.py +++ b/python/tests/test_scalability.py @@ -31,7 +31,7 @@ def p2p_property_graph(num_workers, directed=True): graphscope.set_option(show_log=True) graphscope.set_option(initializing_interactive_engine=False) sess = graphscope.session(num_workers=num_workers, run_on_local=True) - graph = graphscope.Graph(sess, directed=directed) + graph = sess.g(directed=directed) graph = graph.add_vertices("{}/p2p-31_property_v_0".format(data_dir), "person") graph = graph.add_edges("{}/p2p-31_property_e_0".format(data_dir), "knows") return sess, graph diff --git a/tutorials/2_loading_graphs.ipynb b/tutorials/2_loading_graphs.ipynb index fc841058ae96..affa0f0cd1f3 100644 --- a/tutorials/2_loading_graphs.ipynb +++ b/tutorials/2_loading_graphs.ipynb @@ -84,7 +84,7 @@ "source": [ "### Create a graph instance\n", "\n", - "`Graph` takes an `Session` as argument, stands for the graph is created within that session." + "We use an method `g()` defined in `Session` to create a graph." ] }, { @@ -93,7 +93,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)" + "graph = sess.g()" ] }, { @@ -120,7 +120,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(\n", " # source file for vertices labeled as person; \n", " Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"),\n", @@ -158,7 +158,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"), \"person\")" ] }, @@ -177,7 +177,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"))" ] }, @@ -207,7 +207,7 @@ "outputs": [], "source": [ "# a kind of edge with label \"knows\"\n", - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"), label=\"person\")\n", "graph = graph.add_edges(\n", " # the data source, in this case, is a file location.\n", @@ -242,7 +242,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"), label=\"person\")\n", "graph = graph.add_edges(\n", " Loader(\"/home/jovyan/datasets/ldbc_sample/person_knows_person_0_0.csv\", delimieter=\"|\"),\n", @@ -267,7 +267,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"), label=\"person\")\n", "graph = graph.add_edges(\n", " Loader(\"/home/jovyan/datasets/ldbc_sample/person_knows_person_0_0.csv\", delimieter=\"|\"),\n", @@ -290,7 +290,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"), label=\"person\")\n", "graph = graph.add_edges(\n", " Loader(\"/home/jovyan/datasets/ldbc_sample/person_knows_person_0_0.csv\", delimieter=\"|\"),\n", @@ -318,7 +318,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_edges(\n", " Loader(\"/home/jovyan/datasets/ldbc_sample/person_knows_person_0_0.csv\", delimieter=\"|\"),\n", " \"knows\"\n", @@ -338,7 +338,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"), label=\"person\")\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/post_0_0.csv\", delimiter=\"|\"), label=\"post\")\n", "\n", @@ -397,7 +397,7 @@ "outputs": [], "source": [ "graph = (\n", - " Graph(sess)\n", + " sess.g()\n", " .add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"), \"person\")\n", " .add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/comment_0_0.csv\", delimiter=\"|\"), \"comment\")\n", " .add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/post_0_0.csv\", delimiter=\"|\"), \"post\")\n", @@ -569,7 +569,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(\n", " Loader(\"s3://datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\", key='testing', secret='testing', client_kwargs={\n", " \"endpoint_url\": \"http://192.168.0.222:5000\"\n", @@ -640,7 +640,7 @@ "source": [ "# use a dataframe as datasource, properties omitted, col_0/col_1 will be used as src/dst by default.\n", "# (for vertices, col_0 will be used as vertex_id by default)\n", - "graph = Graph(sess).add_vertices(df_student).add_edges(df_group)" + "graph = sess.g().add_vertices(df_student).add_edges(df_group)" ] }, { @@ -659,7 +659,7 @@ "array_group = [df_group[col].values for col in ['leader_id', 'member_id', 'group_size']]\n", "array_student = [df_student[col].values for col in ['student_id', 'avg_score']]\n", "\n", - "graph = Graph(sess).add_vertices(array_student).add_edges(array_group)" + "graph = sess.g().add_vertices(array_student).add_edges(array_group)" ] }, { @@ -700,4 +700,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file diff --git a/tutorials/3_builtin_analytical_algorithms.ipynb b/tutorials/3_builtin_analytical_algorithms.ipynb index 3fbfc062afcc..cb080a2ec743 100644 --- a/tutorials/3_builtin_analytical_algorithms.ipynb +++ b/tutorials/3_builtin_analytical_algorithms.ipynb @@ -50,7 +50,7 @@ "graphscope.set_option(show_log=True) # enable logging\n", "sess = graphscope.session(k8s_volumes=k8s_volumes)\n", "\n", - "graph = graphscope.Graph(sess, directed=False)\n", + "graph = sess.g(directed=False)\n", "graph = graph.add_vertices(\"/home/jovyan/datasets/property/p2p-31_property_v_0\", label=\"person\")\n", "graph = graph.add_edges(\"/home/jovyan/datasets/property/p2p-31_property_v_0\", label=\"knows\")" ] diff --git a/tutorials/4_writing_your_own_algorithms.ipynb b/tutorials/4_writing_your_own_algorithms.ipynb index 08edd5a97adc..f626024cbfff 100644 --- a/tutorials/4_writing_your_own_algorithms.ipynb +++ b/tutorials/4_writing_your_own_algorithms.ipynb @@ -304,7 +304,7 @@ "\n", "sess = graphscope.session(k8s_volumes=k8s_volumes)\n", "\n", - "graph = graphscope.Graph(sess, directed=False)\n", + "graph = sess.g(directed=False)\n", "graph = graph.add_vertices(\"/home/jovyan/datasets/property/p2p-31_property_v_0\", label=\"person\")\n", "graph = graph.add_edges(\"/home/jovyan/datasets/property/p2p-31_property_v_0\", label=\"knows\")" ] diff --git a/tutorials/5_interactive_query_with_gremlin.ipynb b/tutorials/5_interactive_query_with_gremlin.ipynb index 7c19ddcb1ec9..26e1ac12bbe6 100644 --- a/tutorials/5_interactive_query_with_gremlin.ipynb +++ b/tutorials/5_interactive_query_with_gremlin.ipynb @@ -41,7 +41,7 @@ "graphscope.set_option(show_log=True) # enable logging\n", "session = graphscope.session(k8s_volumes=k8s_volumes) # create a session\n", "\n", - "modern_graph = graphscope.Graph(sess)\n", + "modern_graph = sess.g()\n", "modern_graph = modern_graph.add_vertices(\n", " Loader(\"/home/jovyan/datasets/modern_graph_2/person.csv\", delimiter=\"|\"),\n", " label=\"person\"\n", diff --git a/tutorials/6_unsupervised_learning_with_graphsage.ipynb b/tutorials/6_unsupervised_learning_with_graphsage.ipynb index 4ad26c47e5c5..fd4266e4c7c0 100644 --- a/tutorials/6_unsupervised_learning_with_graphsage.ipynb +++ b/tutorials/6_unsupervised_learning_with_graphsage.ipynb @@ -57,7 +57,7 @@ "sess = graphscope.session(k8s_volumes=k8s_volumes)\n", "\n", "# loading ppi graph\n", - "graph = graphscope.Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(\"/home/jovyan/datasets/ppi/node.csv\", \"protein\")\n", "graph = graph.add_edges(\"/home/jovyan/datasets/ppi/edge.csv\", \"link\")" ] diff --git a/tutorials/7_supervised_learning_with_gcn.ipynb b/tutorials/7_supervised_learning_with_gcn.ipynb index f947b1beb9f6..51ceeecb4eba 100644 --- a/tutorials/7_supervised_learning_with_gcn.ipynb +++ b/tutorials/7_supervised_learning_with_gcn.ipynb @@ -58,7 +58,7 @@ "sess = graphscope.session(k8s_volumes=k8s_volumes)\n", "\n", "# loading cora graph\n", - "graph = graphscope.Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(\"/home/jovyan/datasets/cora/node.csv\", \"paper\")\n", "graph = graph.add_edges(\"/home/jovyan/datasets/cora/edge.csv\", \"cites\")" ] diff --git a/tutorials/zh/2_loading_graphs.ipynb b/tutorials/zh/2_loading_graphs.ipynb index 23f80ebd35f3..3755cbb6fded 100644 --- a/tutorials/zh/2_loading_graphs.ipynb +++ b/tutorials/zh/2_loading_graphs.ipynb @@ -95,7 +95,7 @@ "source": [ "### 建立图\n", "\n", - "图的构造函数包括一个会话,表示图建立在这个会话内。" + "我们使用定义在 `Session` 内的函数 `g()` 来初始化一张图。" ] }, { @@ -104,7 +104,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)" + "graph = sess.g()" ] }, { @@ -132,7 +132,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(\n", " # source file for vertices labeled as person; \n", " Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"),\n", @@ -171,7 +171,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"), \"person\")" ] }, @@ -190,7 +190,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"))" ] }, @@ -223,7 +223,7 @@ "outputs": [], "source": [ "# a kind of edge with label \"knows\"\n", - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"), label=\"person\")\n", "graph = graph.add_edges(\n", " # the data source, in this case, is a file location.\n", @@ -258,7 +258,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"), label=\"person\")\n", "graph = graph.add_edges(\n", " Loader(\"/home/jovyan/datasets/ldbc_sample/person_knows_person_0_0.csv\", delimieter=\"|\"),\n", @@ -283,7 +283,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"), label=\"person\")\n", "graph = graph.add_edges(\n", " Loader(\"/home/jovyan/datasets/ldbc_sample/person_knows_person_0_0.csv\", delimieter=\"|\"),\n", @@ -306,7 +306,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"), label=\"person\")\n", "graph = graph.add_edges(\n", " Loader(\"/home/jovyan/datasets/ldbc_sample/person_knows_person_0_0.csv\", delimieter=\"|\"),\n", @@ -334,7 +334,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_edges(\n", " Loader(\"/home/jovyan/datasets/ldbc_sample/person_knows_person_0_0.csv\", delimieter=\"|\"),\n", " \"knows\"\n", @@ -354,7 +354,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"), label=\"person\")\n", "graph = graph.add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/post_0_0.csv\", delimiter=\"|\"), label=\"post\")\n", "\n", @@ -415,7 +415,7 @@ "outputs": [], "source": [ "graph = (\n", - " Graph(sess)\n", + " sess.g()\n", " .add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\"), \"person\")\n", " .add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/comment_0_0.csv\", delimiter=\"|\"), \"comment\")\n", " .add_vertices(Loader(\"/home/jovyan/datasets/ldbc_sample/post_0_0.csv\", delimiter=\"|\"), \"post\")\n", @@ -494,7 +494,7 @@ "metadata": {}, "outputs": [], "source": [ - "deserialized_graph = graph.load_from('/tmp/seri', sess)" + "deserialized_graph = Graph.load_from('/tmp/seri', sess)" ] }, { @@ -589,7 +589,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(\n", " Loader(\"s3://datasets/ldbc_sample/person_0_0.csv\", delimiter=\"|\", key='testing', secret='testing', client_kwargs={\n", " \"endpoint_url\": \"http://192.168.0.222:5000\"\n", @@ -660,7 +660,7 @@ "source": [ "# use a dataframe as datasource, properties omitted, col_0/col_1 will be used as src/dst by default.\n", "# (for vertices, col_0 will be used as vertex_id by default)\n", - "graph = Graph(sess).add_vertices(df_student).add_edges(df_group)" + "graph = sess.g().add_vertices(df_student).add_edges(df_group)" ] }, { @@ -679,7 +679,7 @@ "array_group = [df_group[col].values for col in ['leader_id', 'member_id', 'group_size']]\n", "array_student = [df_student[col].values for col in ['student_id', 'avg_score']]\n", "\n", - "graph = Graph(sess).add_vertices(array_student).add_edges(array_group)" + "graph = sess.g().add_vertices(array_student).add_edges(array_group)" ] }, { @@ -720,4 +720,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file diff --git a/tutorials/zh/3_builtin_analytical_algorithms.ipynb b/tutorials/zh/3_builtin_analytical_algorithms.ipynb index 76aaac375dd5..1f4a640afdf8 100644 --- a/tutorials/zh/3_builtin_analytical_algorithms.ipynb +++ b/tutorials/zh/3_builtin_analytical_algorithms.ipynb @@ -51,7 +51,7 @@ "graphscope.set_option(show_log=True) # enable logging\n", "sess = graphscope.session(k8s_volumes=k8s_volumes)\n", "\n", - "graph = graphscope.Graph(sess, directed=False)\n", + "graph = sess.g(directed=False)\n", "graph = graph.add_vertices(\"/home/jovyan/datasets/property/p2p-31_property_v_0\", label=\"person\")\n", "graph = graph.add_edges(\"/home/jovyan/datasets/property/p2p-31_property_v_0\", label=\"knows\")" ] diff --git a/tutorials/zh/4_writing_your_own_algorithms.ipynb b/tutorials/zh/4_writing_your_own_algorithms.ipynb index ce9ce3b1faea..db65175f286e 100644 --- a/tutorials/zh/4_writing_your_own_algorithms.ipynb +++ b/tutorials/zh/4_writing_your_own_algorithms.ipynb @@ -293,7 +293,7 @@ "\n", "sess = graphscope.session(k8s_volumes=k8s_volumes)\n", "\n", - "graph = graphscope.Graph(sess, directed=False)\n", + "graph = sess.g(directed=False)\n", "graph = graph.add_vertices(\"/home/jovyan/datasets/property/p2p-31_property_v_0\", label=\"person\")\n", "graph = graph.add_edges(\"/home/jovyan/datasets/property/p2p-31_property_v_0\", label=\"knows\")" ] diff --git a/tutorials/zh/5_interactive_query_with_gremlin.ipynb b/tutorials/zh/5_interactive_query_with_gremlin.ipynb index a381a3006eae..4ee08fc44ccc 100644 --- a/tutorials/zh/5_interactive_query_with_gremlin.ipynb +++ b/tutorials/zh/5_interactive_query_with_gremlin.ipynb @@ -38,7 +38,7 @@ "}\n", "graphscope.set_option(show_log=True) # enable logging\n", "session = graphscope.session(k8s_volumes=k8s_volumes) # create a session\n", - "modern_graph = graphscope.Graph(sess)\n", + "modern_graph = sess.g()\n", "modern_graph = modern_graph.add_vertices(\n", " Loader(\"/home/jovyan/datasets/modern_graph_2/person.csv\", delimiter=\"|\"),\n", " label=\"person\"\n", diff --git a/tutorials/zh/6_unsupervised_learning_with_graphsage.ipynb b/tutorials/zh/6_unsupervised_learning_with_graphsage.ipynb index 06c4f3a61b76..fb53839a8b5a 100644 --- a/tutorials/zh/6_unsupervised_learning_with_graphsage.ipynb +++ b/tutorials/zh/6_unsupervised_learning_with_graphsage.ipynb @@ -57,7 +57,7 @@ "sess = graphscope.session(k8s_volumes=k8s_volumes)\n", "\n", "# 加载PPI图数据\n", - "graph = graphscope.Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(\"/home/jovyan/datasets/ppi/node.csv\", \"protein\")\n", "graph = graph.add_edges(\"/home/jovyan/datasets/ppi/edge.csv\", \"link\")" ] diff --git a/tutorials/zh/7_supervised_learning_with_gcn.ipynb b/tutorials/zh/7_supervised_learning_with_gcn.ipynb index 9cc20b93e8ba..1cbf83ae523c 100644 --- a/tutorials/zh/7_supervised_learning_with_gcn.ipynb +++ b/tutorials/zh/7_supervised_learning_with_gcn.ipynb @@ -55,7 +55,7 @@ "sess = graphscope.session(k8s_volumes=k8s_volumes)\n", "\n", "# 载入cora图数据\n", - "graph = graphscope.Graph(sess)\n", + "graph = sess.g()\n", "graph = graph.add_vertices(\"/home/jovyan/datasets/cora/node.csv\", \"paper\")\n", "graph = graph.add_edges(\"/home/jovyan/datasets/cora/edge.csv\", \"cites\")" ]