Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update egonet implementation #2874

Merged
merged 76 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
725a8a6
move egonet back from legacy directory, the original implementation i…
ChuckHastings Oct 28, 2022
7c7bad3
some simple edits
ChuckHastings Oct 28, 2022
155fd24
Finished coding C API for egonet
ChuckHastings Oct 31, 2022
adada88
rename variables appropriately
jnke2016 Nov 1, 2022
7194bdc
define the 'vertex_pairs' and 'induced_subgraph' methods by leveragin…
jnke2016 Nov 1, 2022
e3059b3
define 'extract_ego' function in the PLC API by leveraging the CAPI
jnke2016 Nov 1, 2022
8647fd1
add PLC implementation of 'egonet'
jnke2016 Nov 1, 2022
11ab13c
update docstrings
jnke2016 Nov 2, 2022
5de024b
merge latest cugraph changes
jnke2016 Nov 12, 2022
2fdf310
undo changes to community_algorithms header file
jnke2016 Nov 12, 2022
61cdfcf
fix merge conflict
jnke2016 Nov 12, 2022
e7cdfa7
remove legacy egonet
jnke2016 Nov 14, 2022
770a461
temporarily skip batch_ego_graphs tests to debug
jnke2016 Nov 14, 2022
5b8e438
update python implementation of egonet
jnke2016 Nov 14, 2022
3413a7b
add helper type and function
jnke2016 Nov 14, 2022
95b7da5
temporarily cast the vertex dtype
jnke2016 Nov 14, 2022
b74179f
temporarily cast the vertex dtype
jnke2016 Nov 14, 2022
64d70e5
leverage helper functions to debug
jnke2016 Nov 14, 2022
181be1f
add temporary helper functions to debug
jnke2016 Nov 14, 2022
d137116
fix style
jnke2016 Nov 14, 2022
181ba6d
add mg egonet
jnke2016 Nov 14, 2022
31e8d4b
return the offsets array even if unused
jnke2016 Nov 14, 2022
5fb853d
add MG implementation of egonet
jnke2016 Nov 14, 2022
2dab871
fix style
jnke2016 Nov 14, 2022
f70ca2c
undo change to copyright
jnke2016 Nov 14, 2022
6178cd6
update docstrings
jnke2016 Nov 14, 2022
dd15a81
undo changes to tests
jnke2016 Nov 14, 2022
9cee9d3
update docstrings
jnke2016 Nov 14, 2022
b5111d6
remove unused datasets object
jnke2016 Nov 14, 2022
3d5dc37
undo changes to nx_factory
jnke2016 Nov 14, 2022
420777f
fix type return for weight
jnke2016 Nov 14, 2022
13eaf42
remove unnecessary checks
jnke2016 Nov 14, 2022
54f3499
match the seeds to the vertex type
jnke2016 Nov 14, 2022
89ca664
enable tests that were previously skipped
jnke2016 Nov 14, 2022
6a311e2
add dtype for offsets array
jnke2016 Nov 14, 2022
c69db7c
remove debug prints, remove temporary function calls
jnke2016 Nov 14, 2022
e6c1a3f
remove temporary debug functions, undo changes to these files
jnke2016 Nov 14, 2022
166acd1
remove debug print, match seeds to vertex dtype
jnke2016 Nov 14, 2022
b6d31f4
import missing function
jnke2016 Nov 14, 2022
8e054db
remove redundant deallocation of pointer
jnke2016 Nov 14, 2022
d97130e
map appropriate python type to offsets ctype
jnke2016 Nov 14, 2022
68bb735
fix typo
jnke2016 Nov 14, 2022
6af2299
update docstrings example
jnke2016 Nov 14, 2022
6f97292
fix style
jnke2016 Nov 14, 2022
cbaa850
fix merge conflict
jnke2016 Nov 14, 2022
5f40b3b
update docstrings, support directed graphs
jnke2016 Nov 14, 2022
7175e48
update docstrings, remove unused input parameters, support directed g…
jnke2016 Nov 14, 2022
779bf4f
fix typo
jnke2016 Nov 14, 2022
09efec3
debugging MG egonet issues
ChuckHastings Nov 15, 2022
8d45eab
Merge remote-tracking branch 'upstream/debug_egonet' into branch-22.1…
jnke2016 Nov 15, 2022
ab01f33
add an mg python implementation of egonet leveraging PLC
jnke2016 Nov 16, 2022
f921185
add python tests for mg egonet
jnke2016 Nov 16, 2022
b659eb5
add helper function, update docstrings
jnke2016 Nov 16, 2022
19c4a70
update comments
jnke2016 Nov 16, 2022
4622b4b
fix style
jnke2016 Nov 16, 2022
293b7c7
fix typo
jnke2016 Nov 16, 2022
84772b2
fix typo
jnke2016 Nov 16, 2022
456a0c3
Update build.sh
galipremsagar Nov 16, 2022
bb3542e
Update build.sh
galipremsagar Nov 16, 2022
66eb4ef
update env variable
jnke2016 Nov 16, 2022
66e19d1
undo changes
jnke2016 Nov 16, 2022
379c3bc
Merge remote-tracking branch 'upstream/patch-2' into branch-22.12_fea…
jnke2016 Nov 16, 2022
8b40446
fix destination dtype
jnke2016 Nov 16, 2022
05cca2a
update docstrings, return appropriate error message
jnke2016 Nov 16, 2022
4a3fb60
skip MG egonet tests on single GPU
jnke2016 Nov 16, 2022
c738d25
add fixme
jnke2016 Nov 16, 2022
1fdadfa
fix style
jnke2016 Nov 16, 2022
ec063a9
Merge remote-tracking branch 'upstream/branch-22.12' into branch-22.1…
jnke2016 Nov 16, 2022
556dbb7
simplify type check
jnke2016 Nov 17, 2022
9984802
simplify type check
jnke2016 Nov 17, 2022
167c8ed
fix typo
jnke2016 Nov 17, 2022
4cc3ff9
refactor consolidation function
jnke2016 Nov 17, 2022
9f8d284
reset index
jnke2016 Nov 17, 2022
eed37f2
remove unsued import and variable
jnke2016 Nov 17, 2022
2f6a5bf
undo changes to docstrings and type check
jnke2016 Nov 17, 2022
95fbd46
fix style
jnke2016 Nov 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/cpu/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export UCX_PY_VERSION='0.29.*'

# Whether to keep `dask/label/dev` channel in the env. If INSTALL_DASK_MAIN=0,
# `dask/label/dev` channel is removed.
export INSTALL_DASK_MAIN=0
export INSTALL_DASK_MAIN=1

################################################################################
# SETUP - Check environment
Expand Down
2 changes: 1 addition & 1 deletion ci/gpu/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export UCX_PY_VERSION='0.29.*'

# Whether to keep `dask/label/dev` channel in the env. If INSTALL_DASK_MAIN=0,
# `dask/label/dev` channel is removed.
export INSTALL_DASK_MAIN=0
export INSTALL_DASK_MAIN=1

################################################################################
# SETUP - Check environment
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/c_api/extract_ego.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ struct extract_ego_functor : public cugraph::c_api::abstract_functor {
result_ = new cugraph::c_api::cugraph_induced_subgraph_result_t{
new cugraph::c_api::cugraph_type_erased_device_array_t(src, graph_->vertex_type_),
new cugraph::c_api::cugraph_type_erased_device_array_t(dst, graph_->edge_type_),
jnke2016 marked this conversation as resolved.
Show resolved Hide resolved
wgt ? new cugraph::c_api::cugraph_type_erased_device_array_t(*wgt, graph_->edge_type_)
wgt ? new cugraph::c_api::cugraph_type_erased_device_array_t(*wgt, graph_->weight_type_)
: NULL,
new cugraph::c_api::cugraph_type_erased_device_array_t(edge_offsets,
data_type_id_t::SIZE_T)};
Expand Down
2 changes: 1 addition & 1 deletion python/cugraph/cugraph/community/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# =============================================================================

set(cython_sources
ecg_wrapper.pyx egonet_wrapper.pyx
ecg_wrapper.pyx
ktruss_subgraph_wrapper.pyx
leiden_wrapper.pyx
spectral_clustering_wrapper.pyx
Expand Down
23 changes: 0 additions & 23 deletions python/cugraph/cugraph/community/egonet.pxd

This file was deleted.

106 changes: 83 additions & 23 deletions python/cugraph/cugraph/community/egonet.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from cugraph.community import egonet_wrapper
import cudf
from cugraph.utilities import (
ensure_cugraph_obj,
is_nx_graph_type,
)
from cugraph.utilities import cugraph_to_nx

import cudf

from pylibcugraph import ego_graph as pylibcugraph_ego_graph

from pylibcugraph import ResourceHandle
import warnings


def _convert_graph_to_output_type(G, input_type):
"""
Expand All @@ -44,7 +49,7 @@ def _convert_df_series_to_output_type(df, offsets, input_type):
return df, offsets


def ego_graph(G, n, radius=1, center=True, undirected=False, distance=None):
def ego_graph(G, n, radius=1, center=True, undirected=None, distance=None):
"""
Compute the induced subgraph of neighbors centered at node n,
within a given radius.
Expand All @@ -68,10 +73,10 @@ def ego_graph(G, n, radius=1, center=True, undirected=False, distance=None):
Defaults to True. False is not supported

undirected: bool, optional
Defaults to False. True is not supported
This parameter is here for NetworkX compatibility and ignored
jnke2016 marked this conversation as resolved.
Show resolved Hide resolved

distance: key, optional (default=None)
Distances are counted in hops from n. Other cases are not supported.
This parameter is here for NetworkX compatibility and ignored
jnke2016 marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
Expand All @@ -86,21 +91,54 @@ def ego_graph(G, n, radius=1, center=True, undirected=False, distance=None):
>>> ego_graph = cugraph.ego_graph(G, 1, radius=2)

"""

(G, input_type) = ensure_cugraph_obj(G, nx_weight_attr="weight")
result_graph = type(G)()

if G.renumbered is True:
if isinstance(n, cudf.DataFrame):
n = G.lookup_internal_vertex_id(n, n.columns)
else:
n = G.lookup_internal_vertex_id(cudf.Series([n]))
result_graph = type(G)()
jnke2016 marked this conversation as resolved.
Show resolved Hide resolved

df, offsets = egonet_wrapper.egonet(G, n, radius)
if undirected is not None:
warning_msg = (
"The parameter 'undirected' is deprecated and "
"will be removed in the next release"
)
warnings.warn(warning_msg, PendingDeprecationWarning)

if n is not None:
if isinstance(n, int):
n = [n]
if isinstance(n, list):
n = cudf.Series(n)

if G.renumbered is True:
if isinstance(n, cudf.DataFrame):
n = G.lookup_internal_vertex_id(n, n.columns)
else:
n = G.lookup_internal_vertex_id(n)

# Match the seed to the vertex dtype
n_type = G.edgelist.edgelist_df["src"].dtype
n = n.astype(n_type)
do_expensive_check = False

source, destination, weight, _ = pylibcugraph_ego_graph(
resource_handle=ResourceHandle(),
graph=G._plc_graph,
source_vertices=n,
radius=radius,
do_expensive_check=do_expensive_check,
)

df = cudf.DataFrame()
df["src"] = source
df["dst"] = destination
df["weight"] = weight

if G.renumbered:
df, src_names = G.unrenumber(df, "src", get_column_names=True)
df, dst_names = G.unrenumber(df, "dst", get_column_names=True)
else:
# FIXME: THe original 'src' and 'dst' are not stored in 'simpleGraph'
src_names = "src"
dst_names = "dst"

if G.edgelist.weights:
result_graph.from_cudf_edgelist(
Expand All @@ -111,9 +149,7 @@ def ego_graph(G, n, radius=1, center=True, undirected=False, distance=None):
return _convert_graph_to_output_type(result_graph, input_type)


def batched_ego_graphs(
G, seeds, radius=1, center=True, undirected=False, distance=None
):
def batched_ego_graphs(G, seeds, radius=1, center=True, undirected=None, distance=None):
"""
Compute the induced subgraph of neighbors for each node in seeds
within a given radius.
Expand Down Expand Up @@ -160,13 +196,37 @@ def batched_ego_graphs(

(G, input_type) = ensure_cugraph_obj(G, nx_weight_attr="weight")

if G.renumbered is True:
if isinstance(seeds, cudf.DataFrame):
seeds = G.lookup_internal_vertex_id(seeds, seeds.columns)
else:
seeds = G.lookup_internal_vertex_id(cudf.Series(seeds))

df, offsets = egonet_wrapper.egonet(G, seeds, radius)
if seeds is not None:
if isinstance(seeds, int):
seeds = [seeds]
if isinstance(seeds, list):
seeds = cudf.Series(seeds)

if G.renumbered is True:
if isinstance(seeds, cudf.DataFrame):
seeds = G.lookup_internal_vertex_id(seeds, seeds.columns)
else:
seeds = G.lookup_internal_vertex_id(seeds)

# Match the seed to the vertex dtype
seeds_type = G.edgelist.edgelist_df["src"].dtype
seeds = seeds.astype(seeds_type)

do_expensive_check = False
source, destination, weight, offset = pylibcugraph_ego_graph(
resource_handle=ResourceHandle(),
graph=G._plc_graph,
source_vertices=seeds,
radius=radius,
do_expensive_check=do_expensive_check,
)

offsets = cudf.Series(offset)

df = cudf.DataFrame()
df["src"] = source
df["dst"] = destination
df["weight"] = weight

if G.renumbered:
df = G.unrenumber(df, "src", preserve_order=True)
Expand Down
126 changes: 0 additions & 126 deletions python/cugraph/cugraph/community/egonet_wrapper.pyx

This file was deleted.

1 change: 1 addition & 0 deletions python/cugraph/cugraph/dask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .common.read_utils import get_n_workers
from .community.louvain import louvain
from .community.triangle_count import triangle_count
from .community.egonet import ego_graph
from .centrality.katz_centrality import katz_centrality
from .components.connectivity import weakly_connected_components
from .sampling.uniform_neighbor_sample import uniform_neighbor_sample
Expand Down
Loading