Skip to content

Commit

Permalink
Add two other version of wcc for compatiblity (#2223)
Browse files Browse the repository at this point in the history
* add two other version of wcc for compatiblity
* add tests
  • Loading branch information
siyuan0322 committed Nov 16, 2022
1 parent 2fbc4ad commit 92f7da3
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 1 deletion.
7 changes: 7 additions & 0 deletions coordinator/gscoordinator/builtin/app/.gs_conf.yaml
Expand Up @@ -38,6 +38,13 @@ app:
- grape::ImmutableEdgecutFragment
- gs::ArrowProjectedFragment
- gs::DynamicProjectedFragment
- algo: wcc_auto
type: cpp_pie
class_name: grape::WCCAuto
src: wcc/wcc_auto.h
compatible_graph:
- grape::ImmutableEdgecutFragment
- gs::ArrowProjectedFragment
- algo: cdlp
type: cpp_pie
class_name: grape::CDLP
Expand Down
2 changes: 2 additions & 0 deletions python/graphscope/analytical/app/__init__.py
Expand Up @@ -54,3 +54,5 @@
from graphscope.analytical.app.triangles import triangles
from graphscope.analytical.app.voterank import voterank
from graphscope.analytical.app.wcc import wcc
from graphscope.analytical.app.wcc import wcc_auto
from graphscope.analytical.app.wcc import wcc_projected
62 changes: 61 additions & 1 deletion python/graphscope/analytical/app/wcc.py
Expand Up @@ -22,7 +22,7 @@
from graphscope.framework.app import not_compatible_for
from graphscope.framework.app import project_to_simple

__all__ = ["wcc"]
__all__ = ["wcc", "wcc_auto", "wcc_projected"]

logger = logging.getLogger("graphscope")

Expand All @@ -31,6 +31,8 @@
@not_compatible_for("arrow_property", "dynamic_property")
def wcc(graph):
"""Evaluate weakly connected components on the `graph`.
This is an optimized version of WCC.
Note this cannot be compiled against a property graph that has multiple labels.
Args:
graph (:class:`graphscope.Graph`): A simple graph.
Expand Down Expand Up @@ -61,3 +63,61 @@ def wcc(graph):
return AppAssets(
algo="wcc", context="vertex_data", cmake_extra_options=cmake_extra_options
)(graph)


@project_to_simple
@not_compatible_for("arrow_property", "dynamic_property")
def wcc_projected(graph):
"""Evaluate weakly connected components on the `graph`.
This is a naive version of WCC.
Args:
graph (:class:`graphscope.Graph`): A simple graph.
Returns:
:class:`graphscope.framework.context.VertexDataContextDAGNode`:
A context with each vertex assigned with the component ID, evaluated in eager mode.
Examples:
.. code:: python
>>> import graphscope
>>> from graphscope.dataset import load_p2p_network
>>> sess = graphscope.session(cluster_type="hosts", mode="eager")
>>> g = load_p2p_network(sess)
>>> # project to a simple graph (if needed)
>>> pg = g.project(vertices={"host": ["id"]}, edges={"connect": ["dist"]})
>>> c = graphscope.wcc_projected(pg)
>>> sess.close()
"""
return AppAssets(algo="wcc_projected", context="vertex_data")(graph)


@project_to_simple
@not_compatible_for("arrow_property", "dynamic_property")
def wcc_auto(graph):
"""Evaluate weakly connected components on the `graph`.
This is an auto parallel version of WCC.
Args:
graph (:class:`graphscope.Graph`): A simple graph.
Returns:
:class:`graphscope.framework.context.VertexDataContextDAGNode`:
A context with each vertex assigned with the component ID, evaluated in eager mode.
Examples:
.. code:: python
>>> import graphscope
>>> from graphscope.dataset import load_p2p_network
>>> sess = graphscope.session(cluster_type="hosts", mode="eager")
>>> g = load_p2p_network(sess)
>>> # project to a simple graph (if needed)
>>> pg = g.project(vertices={"host": ["id"]}, edges={"connect": ["dist"]})
>>> c = graphscope.wcc_auto(pg)
>>> sess.close()
"""
return AppAssets(algo="wcc_auto", context="vertex_data")(graph)
11 changes: 11 additions & 0 deletions python/graphscope/tests/unittest/test_app.py
Expand Up @@ -430,3 +430,14 @@ def test_app_on_local_vm_graph(
.to_numpy(dtype=int)
)
assert r2 is not None


def test_wcc_on_flatten_graph(arrow_modern_graph):
ctx = graphscope.wcc_auto(arrow_modern_graph)
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)
df = ctx.to_dataframe({"node": "v.id", "r": "r"})
# The component id is all 0
assert sum(df.r.values) == 0

0 comments on commit 92f7da3

Please sign in to comment.