Skip to content

Commit

Permalink
Remove Dummy Edge Weights, Support Specifying Edge Ids/Edge Types/Wei…
Browse files Browse the repository at this point in the history
…ghts Separately (#3495)

Closes #3486 
Merge after #3513 - Merged

Authors:
  - Alex Barghi (https://github.com/alexbarghi-nv)
  - Chuck Hastings (https://github.com/ChuckHastings)

Approvers:
  - Rick Ratzel (https://github.com/rlratzel)
  - Seunghwa Kang (https://github.com/seunghwak)
  - Ray Douglass (https://github.com/raydouglass)

URL: #3495
  • Loading branch information
alexbarghi-nv authored May 9, 2023
1 parent 2c32a4d commit c6bacd5
Show file tree
Hide file tree
Showing 25 changed files with 376 additions and 205 deletions.
4 changes: 2 additions & 2 deletions conda/environments/all_cuda-118_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ dependencies:
- doxygen
- fsspec[http]>=0.6.0
- gcc_linux-64=11.*
- gmock=1.10.0
- gmock>=1.13.0
- graphviz
- gtest=1.10.0
- gtest>=1.13.0
- ipython
- libcudf=23.6.*
- libcugraphops=23.6.*
Expand Down
2 changes: 1 addition & 1 deletion conda/recipes/libcugraph/conda_build_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ nccl_version:
- ">=2.9.9"

gtest_version:
- "=1.10.0"
- ">=1.13.0"

cuda_profiler_api_version:
- ">=11.8.86,<12"
Expand Down
12 changes: 6 additions & 6 deletions cpp/src/c_api/graph_mg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,19 +338,19 @@ extern "C" cugraph_error_code_t cugraph_mg_graph_create(
weight_type = cugraph_data_type_id_t::FLOAT32;
}

CAPI_EXPECTS((edge_type_ids == nullptr) || (p_edge_ids->type_ == edge_type),
CAPI_EXPECTS((edge_ids == nullptr) || (p_edge_ids->type_ == edge_type),
CUGRAPH_INVALID_INPUT,
"Invalid input arguments: Edge id type must match edge (src/dst) type",
"Invalid input arguments: Edge id type must match edge type",
*error);

CAPI_EXPECTS((edge_type_ids == nullptr) || (p_edge_type_ids->size_ == p_src->size_),
CAPI_EXPECTS((edge_ids == nullptr) || (p_edge_ids->size_ == p_src->size_),
CUGRAPH_INVALID_INPUT,
"Invalid input arguments: src size != edge prop size",
"Invalid input arguments: src size != edge id prop size",
*error);

CAPI_EXPECTS((edge_ids == nullptr) || (p_edge_ids->size_ == p_src->size_),
CAPI_EXPECTS((edge_type_ids == nullptr) || (p_edge_type_ids->size_ == p_src->size_),
CUGRAPH_INVALID_INPUT,
"Invalid input arguments: src size != edge prop size",
"Invalid input arguments: src size != edge type prop size",
*error);

cugraph_data_type_id_t edge_type_id_type;
Expand Down
27 changes: 10 additions & 17 deletions cpp/src/c_api/graph_sg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,26 +513,19 @@ extern "C" cugraph_error_code_t cugraph_sg_graph_create(
weight_type = cugraph_data_type_id_t::FLOAT32;
}

// FIXME: The combination of edge_ids != nullptr, edge_type_ids == nullptr
// logically should be valid, but the code will currently break if
// that is that is specified
CAPI_EXPECTS(
(edge_type_ids == nullptr && edge_ids == nullptr) ||
(edge_type_ids != nullptr && edge_ids != nullptr),
CUGRAPH_INVALID_INPUT,
"Invalid input arguments: either none or both of edge ids and edge types must be provided.",
*error);
CAPI_EXPECTS((edge_ids == nullptr) || (p_edge_ids->type_ == edge_type),
CUGRAPH_INVALID_INPUT,
"Invalid input arguments: Edge id type must match edge type",
*error);

CAPI_EXPECTS(
(edge_type_ids == nullptr && edge_ids == nullptr) || (p_edge_ids->type_ == edge_type),
CUGRAPH_INVALID_INPUT,
"Invalid input arguments: Edge id type must match edge (src/dst) type",
*error);
CAPI_EXPECTS((edge_ids == nullptr) || (p_edge_ids->size_ == p_src->size_),
CUGRAPH_INVALID_INPUT,
"Invalid input arguments: src size != edge id prop size",
*error);

CAPI_EXPECTS((edge_type_ids == nullptr && edge_ids == nullptr) ||
(p_edge_ids->size_ == p_src->size_ && p_edge_type_ids->size_ == p_dst->size_),
CAPI_EXPECTS((edge_type_ids == nullptr) || (p_edge_type_ids->size_ == p_src->size_),
CUGRAPH_INVALID_INPUT,
"Invalid input arguments: src size != edge prop size",
"Invalid input arguments: src size != edge type prop size",
*error);

cugraph_data_type_id_t edge_type_id_type = cugraph_data_type_id_t::INT32;
Expand Down
4 changes: 2 additions & 2 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ dependencies:
packages:
- c-compiler
- cxx-compiler
- gmock=1.10.0
- gtest=1.10.0
- gmock>=1.13.0
- gtest>=1.13.0
- libcugraphops=23.6.*
- libraft-headers=23.6.*
- libraft=23.6.*
Expand Down
7 changes: 4 additions & 3 deletions python/cugraph/cugraph/community/egonet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021-2022, NVIDIA CORPORATION.
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -132,13 +132,14 @@ def ego_graph(G, n, radius=1, center=True, undirected=None, distance=None):
df = cudf.DataFrame()
df["src"] = source
df["dst"] = destination
df["weight"] = weight
if weight is not None:
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'
# FIXME: The original 'src' and 'dst' are not stored in 'simpleGraph'
src_names = "src"
dst_names = "dst"

Expand Down
5 changes: 4 additions & 1 deletion python/cugraph/cugraph/dask/community/egonet.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def convert_to_cudf(cp_arrays):
df = cudf.DataFrame()
df["src"] = cp_src
df["dst"] = cp_dst
df["weight"] = cp_weight
if cp_weight is None:
df["weight"] = None
else:
df["weight"] = cp_weight

offsets = cudf.Series(cp_offsets)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ def convert_to_cudf(cp_arrays, weight_t, with_edge_properties, return_offsets=Fa
df[dst_n] = cupy_destinations
df[indices_n] = cupy_indices

if weight_t == "int32":
df.indices = df.indices.astype("int32")
elif weight_t == "int64":
df.indices = df.indices.astype("int64")
if cupy_indices is not None:
if weight_t == "int32":
df.indices = df.indices.astype("int32")
elif weight_t == "int64":
df.indices = df.indices.astype("int64")

return df

Expand Down
11 changes: 5 additions & 6 deletions python/cugraph/cugraph/dask/traversal/sssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import cudf
import dask_cudf
from pylibcugraph import sssp as pylibcugraph_sssp, ResourceHandle
import warnings


def _call_plc_sssp(
Expand Down Expand Up @@ -102,12 +101,12 @@ def sssp(input_graph, source, cutoff=None, check_source=True):

# FIXME: Implement a better way to check if the graph is weighted similar
# to 'simpleGraph'
if len(input_graph.edgelist.edgelist_df.columns) != 3:
warning_msg = (
"'SSSP' requires the input graph to be weighted: Unweighted "
"graphs will not be supported in the next release."
if not input_graph.weighted:
err_msg = (
"'SSSP' requires the input graph to be weighted."
"'BFS' should be used instead of 'SSSP' for unweighted graphs."
)
warnings.warn(warning_msg, PendingDeprecationWarning)
raise ValueError(err_msg)

client = default_client()

Expand Down
13 changes: 8 additions & 5 deletions python/cugraph/cugraph/sampling/uniform_neighbor_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,16 @@ def uniform_neighbor_sample(
df["sources"] = sources
df["destinations"] = destinations

df["indices"] = indices
if weight_t == "int32":
df["indices"] = indices.astype("int32")
elif weight_t == "int64":
df["indices"] = indices.astype("int64")
if indices is None:
df["indices"] = None
else:
df["indices"] = indices
if weight_t == "int32":
df["indices"] = indices.astype("int32")
elif weight_t == "int64":
df["indices"] = indices.astype("int64")
else:
df["indices"] = indices

if G.renumbered:
df = G.unrenumber(df, "sources", preserve_order=True)
Expand Down
18 changes: 15 additions & 3 deletions python/cugraph/cugraph/structure/convert_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,22 @@ def from_edgelist(

if df_type is cudf.DataFrame:
return from_cudf_edgelist(
df, source, destination, edge_attr, create_using, renumber
df,
source,
destination,
edge_attr=edge_attr,
create_using=create_using,
renumber=renumber,
)

elif (pd is not None) and (df_type is pd.DataFrame):
return from_pandas_edgelist(
df, source, destination, edge_attr, create_using, renumber
df,
source,
destination,
edge_attr=edge_attr,
create_using=create_using,
renumber=renumber,
)

elif df_type is dask_cudf.core.DataFrame:
Expand All @@ -99,7 +109,9 @@ def from_edgelist(
"(or subclass) type or instance, got: "
f"{type(create_using)}"
)
G.from_dask_cudf_edgelist(df, source, destination, edge_attr, renumber)
G.from_dask_cudf_edgelist(
df, source, destination, edge_attr=edge_attr, renumber=renumber
)
return G

else:
Expand Down
85 changes: 72 additions & 13 deletions python/cugraph/cugraph/structure/graph_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def from_cudf_edgelist(
source="source",
destination="destination",
edge_attr=None,
weight=None,
edge_id=None,
edge_type=None,
renumber=True,
store_transposed=False,
legacy_renum_only=False,
Expand Down Expand Up @@ -137,8 +140,21 @@ def from_cudf_edgelist(
destination : str or array-like, optional (default='destination')
destination column name or array of column names
edge_attr : str or None, optional (default=None)
the weights column name.
edge_attr : str or List[str], optional (default=None)
Names of the edge attributes. Can either be a single string
representing the weight column name, or a list of length 3
holding [weight, edge_id, edge_type]. If this argument is
provided, then the weight/edge_id/edge_type arguments must
be left empty.
weight : str, optional (default=None)
Name of the weight column in the input dataframe.
edge_id : str, optional (default=None)
Name of the edge id column in the input dataframe.
edge_type : str, optional (default=None)
Name of the edge type column in the input dataframe.
renumber : bool, optional (default=True)
Indicate whether or not to renumber the source and destination
Expand Down Expand Up @@ -176,6 +192,9 @@ def from_cudf_edgelist(
source=source,
destination=destination,
edge_attr=edge_attr,
weight=weight,
edge_id=edge_id,
edge_type=edge_type,
renumber=renumber,
store_transposed=store_transposed,
legacy_renum_only=legacy_renum_only,
Expand Down Expand Up @@ -254,6 +273,9 @@ def from_dask_cudf_edgelist(
source="source",
destination="destination",
edge_attr=None,
weight=None,
edge_id=None,
edge_type=None,
renumber=True,
store_transposed=False,
legacy_renum_only=False,
Expand All @@ -280,8 +302,21 @@ def from_dask_cudf_edgelist(
destination : str, optional (default='destination')
Destination column name or array of column names
edge_attr : str, optional (default=None)
Weights column name
edge_attr : str or List[str], optional (default=None)
Names of the edge attributes. Can either be a single string
representing the weight column name, or a list of length 3
holding [weight, edge_id, edge_type]. If this argument is
provided, then the weight/edge_id/edge_type arguments must
be left empty.
weight : str, optional (default=None)
Name of the weight column in the input dataframe.
edge_id : str, optional (default=None)
Name of the edge id column in the input dataframe.
edge_type : str, optional (default=None)
Name of the edge type column in the input dataframe.
renumber : bool, optional (default=True)
If source and destination indices are not in range 0 to V where V
Expand All @@ -308,12 +343,15 @@ def from_dask_cudf_edgelist(
raise RuntimeError("Graph already has values")
self._Impl._simpleDistributedGraphImpl__from_edgelist(
input_ddf,
source,
destination,
edge_attr,
renumber,
store_transposed,
legacy_renum_only,
source=source,
destination=destination,
edge_attr=edge_attr,
weight=weight,
edge_id=edge_id,
edge_type=edge_type,
renumber=renumber,
store_transposed=store_transposed,
legacy_renum_only=legacy_renum_only,
)

# Move to Compat Module
Expand All @@ -323,6 +361,9 @@ def from_pandas_edgelist(
source="source",
destination="destination",
edge_attr=None,
weight=None,
edge_id=None,
edge_type=None,
renumber=True,
):
"""
Expand All @@ -334,7 +375,9 @@ def from_pandas_edgelist(
of vertices. If the input vertices are a single column of integers
in the range [0, V), renumbering can be disabled and the original
external vertex ids will be used.
If weights are present, edge_attr argument is the weights column name.
Weights, edge ids, and edge types can be passed through either the
edge_attr argument or individually as separate keyword arguments.
All three are optional.
Parameters
----------
Expand All @@ -347,8 +390,21 @@ def from_pandas_edgelist(
destination : str or array-like, optional (default='destination')
Destination column name or array of column names
edge_attr : str or None, optional (default=None)
The weights column name
edge_attr : str or List[str], optional (default=None)
Names of the edge attributes. Can either be a single string
representing the weight column name, or a list of length 3
holding [weight, edge_id, edge_type]. If this argument is
provided, then the weight/edge_id/edge_type arguments must
be left empty.
weight : str, optional (default=None)
Name of the weight column in the input dataframe.
edge_id : str, optional (default=None)
Name of the edge id column in the input dataframe.
edge_type : str, optional (default=None)
Name of the edge type column in the input dataframe.
renumber : bool, optional (default=True)
Indicate whether or not to renumber the source and destination
Expand Down Expand Up @@ -376,6 +432,9 @@ def from_pandas_edgelist(
source=source,
destination=destination,
edge_attr=edge_attr,
weight=weight,
edge_id=edge_id,
edge_type=edge_type,
renumber=renumber,
)

Expand Down
Loading

0 comments on commit c6bacd5

Please sign in to comment.