Skip to content

Commit

Permalink
Merge branch 'main' into wl/revised_gae_arch
Browse files Browse the repository at this point in the history
  • Loading branch information
doudoubobo committed Mar 7, 2023
2 parents f154316 + e42dda9 commit a27a2d1
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 31 deletions.
6 changes: 3 additions & 3 deletions python/graphscope/analytical/app/wcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


@project_to_simple
@not_compatible_for("arrow_property", "dynamic_property")
@not_compatible_for("arrow_property", "dynamic_property", "directed")
def wcc(graph):
"""Evaluate weakly connected components on the `graph`.
This is an optimized version of WCC.
Expand Down Expand Up @@ -66,7 +66,7 @@ def wcc(graph):


@project_to_simple
@not_compatible_for("arrow_property", "dynamic_property")
@not_compatible_for("arrow_property", "dynamic_property", "directed")
def wcc_projected(graph):
"""Evaluate weakly connected components on the `graph`.
This is a naive version of WCC.
Expand Down Expand Up @@ -95,7 +95,7 @@ def wcc_projected(graph):


@project_to_simple
@not_compatible_for("arrow_property", "dynamic_property")
@not_compatible_for("arrow_property", "dynamic_property", "directed")
def wcc_auto(graph):
"""Evaluate weakly connected components on the `graph`.
This is an auto parallel version of WCC.
Expand Down
13 changes: 8 additions & 5 deletions python/graphscope/framework/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,23 @@ def wrapper(*args, **kwargs):
== graph_def_pb2.DYNAMIC_PROJECTED,
"arrow_flattened": graph.graph_type == graph_def_pb2.ARROW_FLATTENED,
"directed": graph.is_directed(),
"undirected": graph.is_directed() is False,
"undirected": not graph.is_directed(),
}
match = False
matched, tag = False, ""
try:
for t in graph_types:
match = match or terms[t]
if terms[t]:
matched, tag = True, t
break
except KeyError:
raise InvalidArgumentError(
"Use one or more of arrow_property,dynamic_property,"
"arrow_projected,dynamic_projected,arrow_flattened,directed,undirected",
)
if match:
if matched:
raise InvalidArgumentError(
"Not compatible for %s type" % " ".join(graph_types)
"Algorithm '%s' isn't compatible for '%s' graphs"
% (not_compatible_for_func.__name__, tag)
)
else:
return not_compatible_for_func(*args, **kwargs)
Expand Down
35 changes: 35 additions & 0 deletions python/graphscope/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ def arrow_modern_graph(graphscope_session):
del graph


@pytest.fixture(scope="module")
def arrow_modern_graph_undirected(graphscope_session):
graph = load_modern_graph(
graphscope_session,
prefix="{}/modern_graph".format(test_repo_dir),
directed=False,
)
yield graph
del graph


@pytest.fixture(scope="module")
def modern_person():
return "{}/modern_graph/person.csv".format(test_repo_dir)
Expand Down Expand Up @@ -444,6 +455,22 @@ def p2p_property_graph_undirected(graphscope_session):
del g


@pytest.fixture(scope="module")
def p2p_property_graph_undirected_string(graphscope_session):
g = graphscope_session.g(
oid_type="string", directed=False, generate_eid=False, retain_oid=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",
label="knows",
src_label="person",
dst_label="person",
)
yield g
del g


@pytest.fixture(scope="module")
def p2p_property_graph_undirected_local_vm(graphscope_session):
g = graphscope_session.g(
Expand Down Expand Up @@ -521,6 +548,14 @@ def p2p_project_directed_graph_string(p2p_property_graph_string):
yield pg


@pytest.fixture(scope="module")
def p2p_project_undirected_graph_string(p2p_property_graph_undirected_string):
pg = p2p_property_graph_undirected_string.project(
vertices={"person": ["weight"]}, edges={"knows": ["dist"]}
)
yield pg


@pytest.fixture(scope="module")
def p2p_project_directed_graph_int32(p2p_property_graph_int32):
pg = p2p_property_graph_int32.project(
Expand Down
14 changes: 7 additions & 7 deletions python/graphscope/tests/unittest/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_compatible_with_dynamic_graph(dynamic_property_graph):
# bfs
with pytest.raises(
InvalidArgumentError,
match="Not compatible for arrow_property dynamic_property type",
match="isn't compatible for",
):
bfs(dynamic_property_graph, src=4)

Expand Down Expand Up @@ -395,11 +395,11 @@ def test_app_on_undirected_graph(
assert is_simple_path(p2p_project_undirected_graph, [1, 10])


def test_run_app_on_string_oid_graph(p2p_project_directed_graph_string):
ctx = sssp(p2p_project_directed_graph_string, src="6")
def test_run_app_on_string_oid_graph(p2p_project_undirected_graph_string):
ctx = sssp(p2p_project_undirected_graph_string, src="6")
r1 = ctx.to_dataframe({"node": "v.id", "r": "r"})
assert r1[r1["node"] == "6"].r.values[0] == 0.0
ctx = wcc(p2p_project_directed_graph_string)
ctx = wcc(p2p_project_undirected_graph_string)
r1 = ctx.to_dataframe({"node": "v.id", "r": "r"})


Expand Down Expand Up @@ -445,12 +445,12 @@ def test_app_on_local_vm_graph(
assert r2 is not None


def test_wcc_on_flatten_graph(arrow_modern_graph):
ctx = graphscope.wcc_auto(arrow_modern_graph)
def test_wcc_on_flatten_graph(arrow_modern_graph_undirected):
ctx = graphscope.wcc_auto(arrow_modern_graph_undirected)
df = ctx.to_dataframe({"node": "v.id", "r": "r"})
# The component id is all 1
assert sum(df.r.values) == 6
ctx = graphscope.wcc_projected(arrow_modern_graph)
ctx = graphscope.wcc_projected(arrow_modern_graph_undirected)
df = ctx.to_dataframe({"node": "v.id", "r": "r"})
# The component id is all 0
assert sum(df.r.values) == 0
Expand Down
5 changes: 3 additions & 2 deletions python/graphscope/tests/unittest/test_create_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def test_Load_complex_graph_variants(


def test_local_vertex_map_e_file(graphscope_session, student_group_e):
graph = graphscope_session.g(vertex_map="local")
graph = graphscope_session.g(vertex_map="local", directed=False)
graph = graph.add_edges(student_group_e)
assert graph.schema is not None
ret = graphscope.wcc(graph)
Expand Down Expand Up @@ -600,6 +600,7 @@ def test_local_vertex_map_complete_form_loader(
)
},
vertex_map="local",
directed=False,
)
assert graph.schema is not None
ret = graphscope.wcc(graph)
Expand All @@ -608,7 +609,7 @@ def test_local_vertex_map_complete_form_loader(


def test_local_vertex_map_e_file_str(graphscope_session, student_group_e):
graph = graphscope_session.g(oid_type="str", vertex_map="local")
graph = graphscope_session.g(oid_type="str", vertex_map="local", directed=False)
graph = graph.add_edges(student_group_e)
assert graph.schema is not None
ret = graphscope.wcc(graph)
Expand Down
28 changes: 14 additions & 14 deletions python/graphscope/tests/unittest/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def test_project_subgraph(arrow_modern_graph):
RuntimeError,
match="Failed to project to simple graph as no vertex exists in this graph",
):
graphscope.wcc(sub_graph)
graphscope.pagerank(sub_graph)

# project a sub_graph only contain person nodes
sub_graph = graph.project(vertices={"person": None}, edges={})
Expand All @@ -448,7 +448,7 @@ def test_project_subgraph(arrow_modern_graph):
RuntimeError,
match="Failed to project to simple graph as no edge exists in this graph",
):
graphscope.wcc(sub_graph)
graphscope.pagerank(sub_graph)

graph = graph.project(
vertices={"person": None, "software": ["name", "id"]},
Expand All @@ -475,10 +475,10 @@ def test_project_subgraph(arrow_modern_graph):
assert not graph.schema.get_vertex_properties("person")
assert not graph.schema.get_edge_properties("knows")

ret = graphscope.wcc(graph)
graph = graph.add_column(ret, {"cc": "r"})
ret = graphscope.pagerank(graph)
graph = graph.add_column(ret, {"pr": "r"})
assert len(graph.schema.get_vertex_properties("person")) == 1
assert graph.schema.get_vertex_properties("person")[0].name == "cc"
assert graph.schema.get_vertex_properties("person")[0].name == "pr"


def test_error_on_project(arrow_property_graph, ldbc_graph):
Expand Down Expand Up @@ -536,27 +536,27 @@ def test_add_column(ldbc_graph, arrow_modern_graph):
)
sub_graph_4 = modern.project(vertices={"person": []}, edges={"knows": ["eid"]})

ret = graphscope.wcc(sub_graph_1)
ret = graphscope.pagerank(sub_graph_1)

# the ret can add to the graph queried on
g1 = sub_graph_1.add_column(ret, selector={"cc": "r"})
g1 = sub_graph_1.add_column(ret, selector={"pr": "r"})
assert g1.schema.get_vertex_properties("person")[0].id == 8
assert g1.schema.get_vertex_properties("person")[0].name == "cc"
assert g1.schema.get_vertex_properties("person")[0].name == "pr"
# the ret can add to the origin graph
g2 = ldbc.add_column(ret, selector={"cc": "r"})
g2 = ldbc.add_column(ret, selector={"pr": "r"})
assert g2.schema.get_vertex_properties("person")[8].id == 8
assert g2.schema.get_vertex_properties("person")[8].name == "cc"
assert g2.schema.get_vertex_properties("person")[8].name == "pr"
# the ret can add to the graph tha contain the same vertex label with sub_graph_1
g3 = sub_graph_2.add_column(ret, selector={"cc": "r"})
g3 = sub_graph_2.add_column(ret, selector={"pr": "r"})
assert g3.schema.get_vertex_properties("person")[8].id == 8
assert g3.schema.get_vertex_properties("person")[8].name == "cc"
assert g3.schema.get_vertex_properties("person")[8].name == "pr"
# the ret can not add to sub_graph_3
with pytest.raises(AnalyticalEngineInternalError):
g4 = sub_graph_3.add_column(ret, selector={"cc": "r"})
g4 = sub_graph_3.add_column(ret, selector={"pr": "r"})
print(g4.schema)
# the ret can not add to sub_graph_4
with pytest.raises(AnalyticalEngineInternalError):
g5 = sub_graph_4.add_column(ret, selector={"cc": "r"})
g5 = sub_graph_4.add_column(ret, selector={"pr": "r"})
print(g4.schema)


Expand Down

0 comments on commit a27a2d1

Please sign in to comment.