From b0247c8cdbef9e45de40083d4de97b779a082f5e Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Wed, 21 Jun 2023 02:01:10 -0700 Subject: [PATCH 01/62] add a plc implementation of the rmat generator following the CAPI path --- .../pylibcugraph/pylibcugraph/CMakeLists.txt | 1 + python/pylibcugraph/pylibcugraph/__init__.py | 2 + .../pylibcugraph/generate_rmat_edgelist.pyx | 238 ++++++++++++++++++ 3 files changed, 241 insertions(+) create mode 100644 python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx diff --git a/python/pylibcugraph/pylibcugraph/CMakeLists.txt b/python/pylibcugraph/pylibcugraph/CMakeLists.txt index 7c50456eb4d..78530a13487 100644 --- a/python/pylibcugraph/pylibcugraph/CMakeLists.txt +++ b/python/pylibcugraph/pylibcugraph/CMakeLists.txt @@ -27,6 +27,7 @@ set(cython_sources ecg.pyx egonet.pyx eigenvector_centrality.pyx + generate_rmat_edgelist.pyx graph_properties.pyx graphs.pyx hits.pyx diff --git a/python/pylibcugraph/pylibcugraph/__init__.py b/python/pylibcugraph/pylibcugraph/__init__.py index 5c03d8f98cc..61c1c50824e 100644 --- a/python/pylibcugraph/pylibcugraph/__init__.py +++ b/python/pylibcugraph/pylibcugraph/__init__.py @@ -81,6 +81,8 @@ from pylibcugraph.select_random_vertices import select_random_vertices +from pylibcugraph.generate_rmat_edgelist import generate_rmat_edgelist + from pylibcugraph import exceptions __version__ = "23.08.00" diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx new file mode 100644 index 00000000000..e90f6ee8873 --- /dev/null +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx @@ -0,0 +1,238 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Have cython use python 3 syntax +# cython: language_level = 3 + + +from pylibcugraph._cugraph_c.resource_handle cimport ( + cugraph_resource_handle_t, + data_type_id_t, + cugraph_data_type_id_t, + bool_t, +) +from pylibcugraph._cugraph_c.error cimport ( + cugraph_error_code_t, + cugraph_error_t, +) +from pylibcugraph._cugraph_c.array cimport ( + cugraph_type_erased_device_array_view_t, +) +from pylibcugraph._cugraph_c.graph_generators cimport ( + cugraph_generate_rmat_edgelist, + cugraph_generate_edge_weights, + cugraph_generate_edge_ids, + cugraph_generate_edge_types, + cugraph_coo_t, + cugraph_coo_get_sources, + cugraph_coo_get_destinations, + cugraph_coo_get_edge_weights, + cugraph_coo_get_edge_id, + cugraph_coo_get_edge_type, + cugraph_coo_free, +) +from pylibcugraph.resource_handle cimport ( + ResourceHandle, +) +from pylibcugraph.utils cimport ( + assert_success, + copy_to_cupy_array, +) +from pylibcugraph._cugraph_c.random cimport ( + cugraph_rng_state_t +) +from pylibcugraph.random cimport ( + CuGraphRandomState +) + + +def generate_rmat_edgelist(ResourceHandle resource_handle, + random_state, + size_t scale, + size_t num_edges, + double a, + double b, + double c, + bool_t clip_and_flip, + bool_t include_edge_weights, + minimum_weight, + maximum_weight, + bool_t include_edge_ids, + bool_t include_edge_types, + min_edge_type, + max_edge_type, + bool_t multi_gpu, + ): + """ + Generate RMAT edge list + + Parameters + ---------- + resource_handle : ResourceHandle + Handle to the underlying device resources needed for referencing data + and running algorithms. + + random_state : int , optional + Random state to use when generating samples. Optional argument, + defaults to a hash of process id, time, and hostname. + (See pylibcugraph.random.CuGraphRandomState) + + scale : size_t + Scale factor to set the number of vertices in the graph Vertex IDs have + values in [0, V), where V = 1 << 'scale' + + num_edges : size_t + Number of edges to generate + + a : double + Probability of the edge being in the first partition + The Graph 500 spec sets this value to 0.57 + + b : double + Probability of the edge being in the second partition + The Graph 500 spec sets this value to 0.19 + + c : double + Probability of the edge being in the third partition + The Graph 500 spec sets this value to 0.19 + + clip_and_flip : bool + Flag controlling whether to generate edges only in the lower triangular + part (including the diagonal) of the graph adjacency matrix + (if set to 'true') or not (if set to 'false). + + include_edge_weights : bool + Flag controlling whether to generate edges with weights + (if set to 'true') or not (if set to 'false'). + + minimum_weight : double + Minimum weight value to generate (if 'include_edge_weights' is 'true') + + maximum_weight : double + Maximum weight value to generate (if 'include_edge_weights' is 'true') + + include_edge_ids : bool + Flag controlling whether to generate edges with ids + (if set to 'true') or not (if set to 'false'). + + include_edge_types : bool + Flag controlling whether to generate edges with types + (if set to 'true') or not (if set to 'false'). + + min_edge_type : int, optional (default=0) + Minimum edge type to generate if 'include_edge_types' is 'true' + otherwise, this parameter is ignored. + + max_edge_type : int, optional (default=5) + Maximum edge type to generate if 'include_edge_types' is 'true' + otherwise, this paramter is ignored. + + multi_gpu : bool + Flag if the COO is being created on multiple GPUs + + + Returns + ------- + return a tuple containing the sources and destinations with their corresponding + weights, ids and types if the flags 'include_edge_weights', 'include_edge_ids' + and 'include_edge_types' are respectively set to 'true' + """ + + cdef cugraph_resource_handle_t* c_resource_handle_ptr = \ + resource_handle.c_resource_handle_ptr + + cdef cugraph_coo_t* result_coo_ptr + cdef cugraph_error_code_t error_code + cdef cugraph_error_t* error_ptr + + cg_rng_state = CuGraphRandomState(resource_handle, random_state) + + cdef cugraph_rng_state_t* rng_state_ptr = \ + cg_rng_state.rng_state_ptr + + error_code = cugraph_generate_rmat_edgelist(c_resource_handle_ptr, + rng_state_ptr, + scale, + num_edges, + a, + b, + c, + clip_and_flip, + &result_coo_ptr, + &error_ptr) + assert_success(error_code, error_ptr, "generate_rmat_edgelist") + + cdef cugraph_type_erased_device_array_view_t* \ + sources_view_ptr = cugraph_coo_get_sources(result_coo_ptr) + + cdef cugraph_type_erased_device_array_view_t* \ + destinations_view_ptr = cugraph_coo_get_destinations(result_coo_ptr) + + cdef cugraph_type_erased_device_array_view_t* edge_weights_view_ptr + + # FIXME: Remove hardcoded dtype + cdef cugraph_data_type_id_t dtype = data_type_id_t.FLOAT32 + + cupy_edge_weights = None + cupy_edge_ids = None + cupy_edge_types = None + + + if include_edge_weights: + error_code = cugraph_generate_edge_weights(c_resource_handle_ptr, + rng_state_ptr, + result_coo_ptr, + dtype, + minimum_weight, + maximum_weight, + &error_ptr) + assert_success(error_code, error_ptr, "generate_edge_weights") + + edge_weights_view_ptr = cugraph_coo_get_edge_weights(result_coo_ptr) + cupy_edge_weights = copy_to_cupy_array(c_resource_handle_ptr, edge_weights_view_ptr) + + + if include_edge_ids: + error_code = cugraph_generate_edge_ids(c_resource_handle_ptr, + result_coo_ptr, + multi_gpu, + &error_ptr) + + assert_success(error_code, error_ptr, "generate_edge_ids") + + edge_ids_view_ptr = cugraph_coo_get_edge_id(result_coo_ptr) + cupy_edge_ids = copy_to_cupy_array(c_resource_handle_ptr, edge_ids_view_ptr) + + if include_edge_types: + error_code = cugraph_generate_edge_types(c_resource_handle_ptr, + rng_state_ptr, + result_coo_ptr, + min_edge_type, + max_edge_type, + &error_ptr) + + assert_success(error_code, error_ptr, "generate_edge_types") + + edge_type_view_ptr = cugraph_coo_get_edge_type(result_coo_ptr) + cupy_edge_types = copy_to_cupy_array(c_resource_handle_ptr, edge_type_view_ptr) + + + + + + cupy_sources = copy_to_cupy_array(c_resource_handle_ptr, sources_view_ptr) + cupy_destinations = copy_to_cupy_array(c_resource_handle_ptr, destinations_view_ptr) + + cugraph_coo_free(result_coo_ptr) + + return cupy_sources, cupy_destinations, cupy_edge_weights, cupy_edge_ids, cupy_edge_types \ No newline at end of file From 90faff66fb6c96ec1703a80af15ffa1010acfd8c Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Wed, 21 Jun 2023 02:02:39 -0700 Subject: [PATCH 02/62] fix typo and import type --- .../pylibcugraph/_cugraph_c/graph_generators.pxd | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_generators.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_generators.pxd index 037aadd09cf..a99df7caf36 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_generators.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_generators.pxd @@ -16,6 +16,7 @@ from pylibcugraph._cugraph_c.resource_handle cimport ( cugraph_resource_handle_t, + cugraph_data_type_id_t, bool_t, ) from pylibcugraph._cugraph_c.error cimport ( @@ -95,7 +96,7 @@ cdef extern from "cugraph_c/graph_generators.h": double a, double b, double c, - bool clip_and_flip, + bool_t clip_and_flip, cugraph_coo_t** result, cugraph_error_t** error ) @@ -139,7 +140,7 @@ cdef extern from "cugraph_c/graph_generators.h": const cugraph_resource_handle_t* handle, cugraph_rng_state_t* rng_state, cugraph_coo_t* coo, - int32_t min_edge_type, - int32_t max_edge_type, + int min_edge_type, + int max_edge_type, cugraph_error_t** error ) From e896ce3e7d9db76f128094163cca9ee4cf1fa834 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Wed, 21 Jun 2023 02:04:44 -0700 Subject: [PATCH 03/62] define a new type 'cugraph_data_type_id_t' --- python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd index 633107a1acb..0330398d7ee 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd @@ -29,6 +29,8 @@ cdef extern from "cugraph_c/resource_handle.h": FLOAT32 FLOAT64 SIZE_T + + ctypedef data_type_id_t cugraph_data_type_id_t ctypedef int8_t byte_t From 66c14a094d052179cf199d7b522b32b01adc06df Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Wed, 21 Jun 2023 02:06:25 -0700 Subject: [PATCH 04/62] update sg rmat to follow the plc path and update docstings --- python/cugraph/cugraph/generators/rmat.py | 127 +++++++++++++++++++--- 1 file changed, 113 insertions(+), 14 deletions(-) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index e9f7515e92e..97f715de671 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -16,7 +16,10 @@ from cugraph.generators import rmat_wrapper from cugraph.dask.comms import comms as Comms +import cudf import cugraph +from pylibcugraph import generate_rmat_edgelist as pylibcugraph_generate_rmat_edgelist +from pylibcugraph import ResourceHandle _graph_types = [cugraph.Graph, cugraph.MultiGraph] @@ -111,6 +114,13 @@ def _sg_rmat( seed, clip_and_flip, scramble_vertex_ids, + include_edge_weights, + minimum_weight, + maximum_weight, + include_edge_ids, + include_edge_types, + min_edge_type, + max_edge_type, create_using=cugraph.Graph, ): """ @@ -118,9 +128,46 @@ def _sg_rmat( to initialize and return a cugraph Graph object specified with create_using. If create_using is None, returns the edgelist df as-is. """ - df = rmat_wrapper.generate_rmat_edgelist( - scale, num_edges, a, b, c, seed, clip_and_flip, scramble_vertex_ids + + # FIXME: add deprecation warning for the parameter 'seed' and rename it + # 'random_state' + random_state = seed + multi_gpu = False + src, dst, weights, edge_id, edge_type = pylibcugraph_generate_rmat_edgelist( + ResourceHandle(), + random_state, + scale, + num_edges, + a, + b, + c, + clip_and_flip, + include_edge_weights, + minimum_weight, + maximum_weight, + include_edge_ids, + include_edge_types, + min_edge_type, + max_edge_type, + multi_gpu, ) + + df = cudf.DataFrame() + df["src"] = src + df["dst"] = dst + + if include_edge_weights: + df["weights"] = weights + weights = "weights" + + if include_edge_ids: + df["edge_id"] = edge_id + edge_id = "edge_id" + + if include_edge_types: + df["edge_type"] = edge_type + edge_type = "edge_type" + if create_using is None: return df @@ -135,7 +182,9 @@ def _sg_rmat( "(or subclass) type or instance, got: " f"{type(create_using)}" ) - G.from_cudf_edgelist(df, source="src", destination="dst", renumber=False) + G.from_cudf_edgelist( + df, source="src", destination="dst", weight=weights, + edge_id=edge_id, edge_type=edge_type, renumber=False) return G @@ -149,6 +198,13 @@ def _mg_rmat( seed, clip_and_flip, scramble_vertex_ids, + include_edge_weights, + minimum_weight, + maximum_weight, + include_edge_ids, + include_edge_types, + min_edge_type, + max_edge_type, create_using=cugraph.Graph, ): """ @@ -254,12 +310,19 @@ def _calc_num_edges_per_worker(num_workers, num_edges): def rmat( scale, num_edges, - a, - b, - c, - seed, - clip_and_flip, - scramble_vertex_ids, + a=0.57, + b=0.19, + c=0.19, + seed=42, + clip_and_flip=False, + scramble_vertex_ids=False, + include_edge_weights=False, + minimum_weight=0.0, + maximum_weight=1.0, + include_edge_ids=False, + include_edge_types=False, + min_edge_type=0, + max_edge_type=5, create_using=cugraph.Graph, mg=False, ): @@ -276,31 +339,60 @@ def rmat( num_edges : int Number of edges to generate - a : float + a : float, optional (default=0.57) Probability of the edge being in the first partition The Graph 500 spec sets this value to 0.57 - b : float + b : float, optional (default=0.19) Probability of the edge being in the second partition The Graph 500 spec sets this value to 0.19 - c : float + c : float, optional (default=0.19) Probability of the edge being in the third partition The Graph 500 spec sets this value to 0.19 seed : int Seed value for the random number generator - clip_and_flip : bool + clip_and_flip : bool, optional (default=False) Flag controlling whether to generate edges only in the lower triangular part (including the diagonal) of the graph adjacency matrix (if set to 'true') or not (if set to 'false). - scramble_vertex_ids : bool + scramble_vertex_ids : bool, optional (default=False) Flag controlling whether to scramble vertex ID bits (if set to `true`) or not (if set to `false`); scrambling vertex ID bits breaks correlation between vertex ID values and vertex degrees. + + include_edge_weights : bool, optional (default=False) + Flag controlling whether to generate edges with weights + (if set to 'true') or not (if set to 'false'). + + minimum_weight : float, optional (default=0.0) + Minimum weight value to generate if 'include_edge_weights' is 'true' + otherwise, this parameter is ignored. + + maximum_weight : float, optional (default=1.0) + Maximum weight value to generate if 'include_edge_weights' is 'true' + otherwise, this parameter is ignored. + + include_edge_ids : bool, optional (default=False) + Flag controlling whether to generate edges with ids + (if set to 'true') or not (if set to 'false'). + + include_edge_types : bool, optional (default=False) + Flag controlling whether to generate edges with types + (if set to 'true') or not (if set to 'false'). + + # FIXME: update default values for 'min_edge_type' and 'max_edge_type' + min_edge_type : int, optional (default=0) + Minimum edge type to generate if 'include_edge_types' is 'true' + otherwise, this parameter is ignored. + + max_edge_type : int, optional (default=5) + Maximum edge type to generate if 'include_edge_types' is 'true' + otherwise, this paramter is ignored. create_using : cugraph Graph type or None The graph type to construct containing the generated edges and vertices. If None is specified, the @@ -373,6 +465,13 @@ def rmat( seed, clip_and_flip, scramble_vertex_ids, + include_edge_weights, + minimum_weight, + maximum_weight, + include_edge_ids, + include_edge_types, + min_edge_type, + max_edge_type, create_using, ) From 23cb2eba4e5e99f7938fd2e880bc6c111ea557fb Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Wed, 21 Jun 2023 08:51:27 -0700 Subject: [PATCH 05/62] add argument 'dtype' and remove the hardcoded one --- .../pylibcugraph/generate_rmat_edgelist.pyx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx index e90f6ee8873..7e6beb101fd 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx @@ -67,6 +67,7 @@ def generate_rmat_edgelist(ResourceHandle resource_handle, bool_t include_edge_weights, minimum_weight, maximum_weight, + dtype, bool_t include_edge_ids, bool_t include_edge_types, min_edge_type, @@ -121,6 +122,10 @@ def generate_rmat_edgelist(ResourceHandle resource_handle, maximum_weight : double Maximum weight value to generate (if 'include_edge_weights' is 'true') + dtype : string + The type of weight to generate ("FLOAT32" or "FLOAT64"), ignored unless + include_weights is true + include_edge_ids : bool Flag controlling whether to generate edges with ids (if set to 'true') or not (if set to 'false'). @@ -180,19 +185,23 @@ def generate_rmat_edgelist(ResourceHandle resource_handle, cdef cugraph_type_erased_device_array_view_t* edge_weights_view_ptr - # FIXME: Remove hardcoded dtype - cdef cugraph_data_type_id_t dtype = data_type_id_t.FLOAT32 - + cdef cugraph_data_type_id_t dtype_ + cupy_edge_weights = None cupy_edge_ids = None cupy_edge_types = None if include_edge_weights: + if dtype == "FLOAT32": + dtype_ = data_type_id_t.FLOAT32 + # The python API should have checked that an appropriate 'dtype' was passed + else: + dtype_ = data_type_id_t.FLOAT64 error_code = cugraph_generate_edge_weights(c_resource_handle_ptr, rng_state_ptr, result_coo_ptr, - dtype, + dtype_, minimum_weight, maximum_weight, &error_ptr) @@ -235,4 +244,4 @@ def generate_rmat_edgelist(ResourceHandle resource_handle, cugraph_coo_free(result_coo_ptr) - return cupy_sources, cupy_destinations, cupy_edge_weights, cupy_edge_ids, cupy_edge_types \ No newline at end of file + return cupy_sources, cupy_destinations, cupy_edge_weights, cupy_edge_ids, cupy_edge_types From 7fd1085026af674d44294d3a6cde7e7a0f208623 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Wed, 21 Jun 2023 08:53:29 -0700 Subject: [PATCH 06/62] add check for 'rmat' arguments --- python/cugraph/cugraph/generators/rmat.py | 53 +++++++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index 97f715de671..c5b6c0d0f09 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -33,6 +33,14 @@ def _ensure_args_rmat( seed, clip_and_flip, scramble_vertex_ids, + include_edge_weights, + minimum_weight, + maximum_weight, + dtype, + include_edge_ids, + include_edge_types, + min_edge_type, + max_edge_type, create_using, mg, ): @@ -67,6 +75,30 @@ def _ensure_args_rmat( raise ValueError("'scramble_vertex_ids' must be a bool") if not isinstance(seed, int): raise TypeError("'seed' must be an int") + if include_edge_weights: + if include_edge_weights not in [True, False]: + raise ValueError("'include_edge_weights' must be a bool") + if maximum_weight is None or minimum_weight is None: + raise ValueError( + "'maximum_weight' and 'minimum_weight' must not be 'None' " + "if 'include_edge_weights' is 'true'" + ) + if dtype not in ["FLOAT32", "FLOAT64"]: + raise ValueError( + "dtype must be either 'FLOAT32' or 'FLOAT64' if 'include_edge_weights' " + "is 'true'" + ) + if include_edge_ids: + if include_edge_ids not in [True, False]: + raise ValueError("'include_edge_ids' must be a bool") + if include_edge_types: + if include_edge_types not in [True, False]: + raise ValueError("'include_edge_types' must be a bool") + if min_edge_type is None and max_edge_type is None: + raise ValueError( + "'min_edge_type' and 'max_edge_type' must not be 'None' " + "if 'include_edge_types' is 'true'" + ) def _ensure_args_multi_rmat( @@ -117,6 +149,7 @@ def _sg_rmat( include_edge_weights, minimum_weight, maximum_weight, + dtype, include_edge_ids, include_edge_types, min_edge_type, @@ -145,6 +178,7 @@ def _sg_rmat( include_edge_weights, minimum_weight, maximum_weight, + dtype, include_edge_ids, include_edge_types, min_edge_type, @@ -201,6 +235,7 @@ def _mg_rmat( include_edge_weights, minimum_weight, maximum_weight, + dtype, include_edge_ids, include_edge_types, min_edge_type, @@ -317,12 +352,13 @@ def rmat( clip_and_flip=False, scramble_vertex_ids=False, include_edge_weights=False, - minimum_weight=0.0, - maximum_weight=1.0, + minimum_weight=None, + maximum_weight=None, + dtype=None, include_edge_ids=False, include_edge_types=False, - min_edge_type=0, - max_edge_type=5, + min_edge_type=None, + max_edge_type=None, create_using=cugraph.Graph, mg=False, ): @@ -439,6 +475,14 @@ def rmat( seed, clip_and_flip, scramble_vertex_ids, + include_edge_weights, + minimum_weight, + maximum_weight, + dtype, + include_edge_ids, + include_edge_types, + min_edge_type, + max_edge_type, create_using, mg, ) @@ -468,6 +512,7 @@ def rmat( include_edge_weights, minimum_weight, maximum_weight, + dtype, include_edge_ids, include_edge_types, min_edge_type, From fe97c892cc3bed76fb55b2c7a8f30745451f6696 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Wed, 21 Jun 2023 12:42:16 -0700 Subject: [PATCH 07/62] update mg rmat to follow the plc path and update docstings --- python/cugraph/cugraph/generators/rmat.py | 107 ++++++++++++++++++---- 1 file changed, 89 insertions(+), 18 deletions(-) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index c5b6c0d0f09..85432b5eadf 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from dask.distributed import default_client +from dask.distributed import default_client, wait import dask_cudf from cugraph.generators import rmat_wrapper @@ -223,6 +223,23 @@ def _sg_rmat( return G +def convert_to_cudf(cp_arrays): + cp_src, cp_dst, cp_edge_weights, cp_edge_ids, cp_edge_types = cp_arrays + + df = cudf.DataFrame() + df["src"] = cp_src + df["dst"] = cp_dst + + if cp_edge_weights is not None: + df["weights"] = cp_edge_weights + if cp_edge_ids is not None: + df["edge_id"] = cp_edge_ids + if cp_edge_types is not None: + df["edge_type"] = cp_edge_types + + return df + + def _mg_rmat( scale, num_edges, @@ -254,7 +271,7 @@ def _mg_rmat( worker_list = list(client.scheduler_info()["workers"].keys()) num_workers = len(worker_list) num_edges_list = _calc_num_edges_per_worker(num_workers, num_edges) - futures = [] + result = [] for (i, worker_num_edges) in enumerate(num_edges_list): unique_worker_seed = seed + i future = client.submit( @@ -268,11 +285,25 @@ def _mg_rmat( unique_worker_seed, clip_and_flip, scramble_vertex_ids, + include_edge_weights, + minimum_weight, + maximum_weight, + dtype, + include_edge_ids, + include_edge_types, + min_edge_type, + max_edge_type, workers=worker_list[i], ) - futures.append(future) + result.append(future) + + wait(result) - ddf = dask_cudf.from_delayed(futures) + cudf_result = [client.submit(convert_to_cudf, cp_arrays) for cp_arrays in result] + + wait(cudf_result) + + ddf = dask_cudf.from_delayed(cudf_result) if create_using is None: return ddf @@ -288,11 +319,28 @@ def _mg_rmat( "(or subclass) type or instance, got: " f"{type(create_using)}" ) - G.from_dask_cudf_edgelist(ddf, source="src", destination="dst") + + weights = None + edge_id = None + edge_type = None + + if "weights" in ddf.columns: + weights = "weights" + + if "edge_id" in ddf.columns: + edge_id = "edge_id" + + if "edge_type" in ddf.columns: + edge_type = "edge_type" + + G.from_dask_cudf_edgelist( + ddf, source="src", destination="dst", weight=weights, + edge_id=edge_id, edge_type=edge_type) return G + def _call_rmat( sID, scale, @@ -300,26 +348,42 @@ def _call_rmat( a, b, c, - unique_worker_seed, + random_state, clip_and_flip, scramble_vertex_ids, + include_edge_weights, + minimum_weight, + maximum_weight, + dtype, + include_edge_ids, + include_edge_types, + min_edge_type, + max_edge_type, ): """ Callable passed to dask client.submit calls that extracts the individual worker handle based on the dask session ID """ - handle = Comms.get_handle(sID) + multi_gpu = True - return rmat_wrapper.generate_rmat_edgelist( + return pylibcugraph_generate_rmat_edgelist( + ResourceHandle(Comms.get_handle(sID).getHandle()), + random_state, scale, num_edges_for_worker, a, b, c, - unique_worker_seed, clip_and_flip, - scramble_vertex_ids, - handle=handle, + include_edge_weights, + minimum_weight, + maximum_weight, + dtype, + include_edge_ids, + include_edge_types, + min_edge_type, + max_edge_type, + multi_gpu, ) @@ -388,7 +452,7 @@ def rmat( Probability of the edge being in the third partition The Graph 500 spec sets this value to 0.19 - seed : int + seed : int, optional (default=42) Seed value for the random number generator clip_and_flip : bool, optional (default=False) @@ -405,11 +469,11 @@ def rmat( Flag controlling whether to generate edges with weights (if set to 'true') or not (if set to 'false'). - minimum_weight : float, optional (default=0.0) + minimum_weight : float Minimum weight value to generate if 'include_edge_weights' is 'true' otherwise, this parameter is ignored. - maximum_weight : float, optional (default=1.0) + maximum_weight : float Maximum weight value to generate if 'include_edge_weights' is 'true' otherwise, this parameter is ignored. @@ -420,13 +484,12 @@ def rmat( include_edge_types : bool, optional (default=False) Flag controlling whether to generate edges with types (if set to 'true') or not (if set to 'false'). - - # FIXME: update default values for 'min_edge_type' and 'max_edge_type' - min_edge_type : int, optional (default=0) + + min_edge_type : int Minimum edge type to generate if 'include_edge_types' is 'true' otherwise, this parameter is ignored. - max_edge_type : int, optional (default=5) + max_edge_type : int Maximum edge type to generate if 'include_edge_types' is 'true' otherwise, this paramter is ignored. @@ -497,6 +560,14 @@ def rmat( seed, clip_and_flip, scramble_vertex_ids, + include_edge_weights, + minimum_weight, + maximum_weight, + dtype, + include_edge_ids, + include_edge_types, + min_edge_type, + max_edge_type, create_using, ) else: From 4ace0498d7d287befbb285982f3a6438f86e3377 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Thu, 22 Jun 2023 03:35:25 -0700 Subject: [PATCH 08/62] add plc implementation of multi_rmat generator --- .../pylibcugraph/pylibcugraph/CMakeLists.txt | 1 + python/pylibcugraph/pylibcugraph/__init__.py | 2 + .../pylibcugraph/generate_rmat_edgelists.pyx | 342 ++++++++++++++++++ 3 files changed, 345 insertions(+) create mode 100644 python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx diff --git a/python/pylibcugraph/pylibcugraph/CMakeLists.txt b/python/pylibcugraph/pylibcugraph/CMakeLists.txt index 78530a13487..6a09c3de0da 100644 --- a/python/pylibcugraph/pylibcugraph/CMakeLists.txt +++ b/python/pylibcugraph/pylibcugraph/CMakeLists.txt @@ -28,6 +28,7 @@ set(cython_sources egonet.pyx eigenvector_centrality.pyx generate_rmat_edgelist.pyx + generate_rmat_edgelists.pyx graph_properties.pyx graphs.pyx hits.pyx diff --git a/python/pylibcugraph/pylibcugraph/__init__.py b/python/pylibcugraph/pylibcugraph/__init__.py index 61c1c50824e..c39075ce3fb 100644 --- a/python/pylibcugraph/pylibcugraph/__init__.py +++ b/python/pylibcugraph/pylibcugraph/__init__.py @@ -83,6 +83,8 @@ from pylibcugraph.generate_rmat_edgelist import generate_rmat_edgelist +from pylibcugraph.generate_rmat_edgelists import generate_rmat_edgelists + from pylibcugraph import exceptions __version__ = "23.08.00" diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx new file mode 100644 index 00000000000..ad3e19fc0e4 --- /dev/null +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx @@ -0,0 +1,342 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Have cython use python 3 syntax +# cython: language_level = 3 + + +from pylibcugraph._cugraph_c.resource_handle cimport ( + cugraph_resource_handle_t, + data_type_id_t, + cugraph_data_type_id_t, + bool_t, +) +from pylibcugraph._cugraph_c.error cimport ( + cugraph_error_code_t, + cugraph_error_t, +) +from pylibcugraph._cugraph_c.array cimport ( + cugraph_type_erased_device_array_view_t, +) +from pylibcugraph._cugraph_c.graph_generators cimport ( + cugraph_generate_rmat_edgelists, + cugraph_generate_edge_weights, + cugraph_generate_edge_ids, + cugraph_generate_edge_types, + cugraph_coo_t, + cugraph_coo_list_t, + cugraph_generator_distribution_t, + cugraph_coo_get_sources, + cugraph_coo_get_destinations, + cugraph_coo_get_edge_weights, + cugraph_coo_get_edge_id, + cugraph_coo_get_edge_type, + cugraph_coo_list_size, + cugraph_coo_list_element, + cugraph_coo_free, + cugraph_coo_list_free, +) +from pylibcugraph.resource_handle cimport ( + ResourceHandle, +) +from pylibcugraph.utils cimport ( + assert_success, + copy_to_cupy_array, +) +from pylibcugraph._cugraph_c.random cimport ( + cugraph_rng_state_t +) +from pylibcugraph.random cimport ( + CuGraphRandomState +) + + +def generate_rmat_edgelists(ResourceHandle resource_handle, + random_state, + size_t n_edgelists, + size_t min_scale, + size_t max_scale, + size_t edge_factor, + size_distribution, + edge_distribution, + bool_t clip_and_flip, + bool_t include_edge_weights, + minimum_weight, + maximum_weight, + dtype, + bool_t include_edge_ids, + bool_t include_edge_types, + min_edge_type, + max_edge_type, + bool_t multi_gpu, + ): + """ + Generate RMAT edge list + + Parameters + ---------- + resource_handle : ResourceHandle + Handle to the underlying device resources needed for referencing data + and running algorithms. + + random_state : int , optional + Random state to use when generating samples. Optional argument, + defaults to a hash of process id, time, and hostname. + (See pylibcugraph.random.CuGraphRandomState) + + n_edgelists : size_t + Number of edge lists (graphs) to generate + + min_scale : size_t + Scale factor to set the minimum number of vertices in the graph + + max_scale : size_t + Scale factor to set the maximum number of vertices in the graph + + edge_factor : size_t + Average number of edges per vertex to generate + + size_distribution : int + Distribution of the graph sizes, impacts the scale parameter of the + R-MAT generator. + '0' for POWER_LAW distribution and '1' for UNIFORM distribution + + edge_distribution : int + Edges distribution for each graph, impacts how R-MAT parameters + a,b,c,d, are set. + '0' for POWER_LAW distribution and '1' for UNIFORM distribution + + clip_and_flip : bool + Flag controlling whether to generate edges only in the lower triangular + part (including the diagonal) of the graph adjacency matrix + (if set to 'true') or not (if set to 'false') + + include_edge_weights : bool + Flag controlling whether to generate edges with weights + (if set to 'true') or not (if set to 'false'). + + minimum_weight : double + Minimum weight value to generate (if 'include_edge_weights' is 'true') + + maximum_weight : double + Maximum weight value to generate (if 'include_edge_weights' is 'true') + + dtype : string + The type of weight to generate ("FLOAT32" or "FLOAT64"), ignored unless + include_weights is true + + include_edge_ids : bool + Flag controlling whether to generate edges with ids + (if set to 'true') or not (if set to 'false'). + + include_edge_types : bool + Flag controlling whether to generate edges with types + (if set to 'true') or not (if set to 'false'). + + min_edge_type : int + Minimum edge type to generate if 'include_edge_types' is 'true' + otherwise, this parameter is ignored. + + max_edge_type : int + Maximum edge type to generate if 'include_edge_types' is 'true' + otherwise, this paramter is ignored. + + + Returns + ------- + + """ + + cdef cugraph_resource_handle_t* c_resource_handle_ptr = \ + resource_handle.c_resource_handle_ptr + + cdef cugraph_coo_list_t* result_coo_list_ptr + cdef cugraph_error_code_t error_code + cdef cugraph_error_t* error_ptr + + cg_rng_state = CuGraphRandomState(resource_handle, random_state) + + cdef cugraph_rng_state_t* rng_state_ptr = \ + cg_rng_state.rng_state_ptr + + cdef cugraph_generator_distribution_t size_distribution_ + cdef cugraph_generator_distribution_t edge_distribution_ + + if size_distribution == 0: + size_distribution_ = cugraph_generator_distribution_t.POWER_LAW + else: + size_distribution_ = cugraph_generator_distribution_t.UNIFORM + + if edge_distribution == 0: + edge_distribution_ = cugraph_generator_distribution_t.POWER_LAW + else: + edge_distribution_ = cugraph_generator_distribution_t.UNIFORM + + error_code = cugraph_generate_rmat_edgelists(c_resource_handle_ptr, + rng_state_ptr, + n_edgelists, + min_scale, + max_scale, + edge_factor, + size_distribution_, + edge_distribution_, + clip_and_flip, + &result_coo_list_ptr, + &error_ptr) + assert_success(error_code, error_ptr, "generate_rmat_edgelists") + + cdef size_t size = cugraph_coo_list_size(result_coo_list_ptr) + + cdef cugraph_coo_t* result_coo_ptr + + cdef cugraph_type_erased_device_array_view_t* sources_view_ptr + cdef cugraph_type_erased_device_array_view_t* destinations_view_ptr + + cupy_edge_weights = None + cupy_edge_ids = None + cupy_edge_types = None + + edgelists = [] + + for index in range(size): + result_coo_ptr = cugraph_coo_list_element(result_coo_list_ptr, index) + sources_view_ptr = cugraph_coo_get_sources(result_coo_ptr) + + destinations_view_ptr = cugraph_coo_get_destinations(result_coo_ptr) + cupy_sources = copy_to_cupy_array(c_resource_handle_ptr, sources_view_ptr) + cupy_destinations = copy_to_cupy_array(c_resource_handle_ptr, destinations_view_ptr) + + if include_edge_weights: + if dtype == "FLOAT32": + dtype_ = data_type_id_t.FLOAT32 + # The python API should have checked that an appropriate 'dtype' was passed + else: + dtype_ = data_type_id_t.FLOAT64 + error_code = cugraph_generate_edge_weights(c_resource_handle_ptr, + rng_state_ptr, + result_coo_ptr, + dtype_, + minimum_weight, + maximum_weight, + &error_ptr) + assert_success(error_code, error_ptr, "generate_edge_weights") + + edge_weights_view_ptr = cugraph_coo_get_edge_weights(result_coo_ptr) + cupy_edge_weights = copy_to_cupy_array(c_resource_handle_ptr, edge_weights_view_ptr) + + + + if include_edge_ids: + error_code = cugraph_generate_edge_ids(c_resource_handle_ptr, + result_coo_ptr, + multi_gpu, + &error_ptr) + + assert_success(error_code, error_ptr, "generate_edge_ids") + + edge_ids_view_ptr = cugraph_coo_get_edge_id(result_coo_ptr) + cupy_edge_ids = copy_to_cupy_array(c_resource_handle_ptr, edge_ids_view_ptr) + + if include_edge_types: + error_code = cugraph_generate_edge_types(c_resource_handle_ptr, + rng_state_ptr, + result_coo_ptr, + min_edge_type, + max_edge_type, + &error_ptr) + + assert_success(error_code, error_ptr, "generate_edge_types") + + edge_type_view_ptr = cugraph_coo_get_edge_type(result_coo_ptr) + cupy_edge_types = copy_to_cupy_array(c_resource_handle_ptr, edge_type_view_ptr) + + + edgelists.append((cupy_sources, cupy_destinations, cupy_edge_weights, cupy_edge_ids, cupy_edge_types)) + + # FIXME: Does freeing 'result_coo_ptr' automatically free 'result_coo_list_ptr'? + cugraph_coo_free(result_coo_ptr) + + + return edgelists + + + """ + cdef cugraph_type_erased_device_array_view_t* \ + sources_view_ptr = cugraph_coo_get_sources(result_coo_ptr) + + cdef cugraph_type_erased_device_array_view_t* \ + destinations_view_ptr = cugraph_coo_get_destinations(result_coo_ptr) + + cdef cugraph_type_erased_device_array_view_t* edge_weights_view_ptr + + cdef cugraph_data_type_id_t dtype_ + + cupy_edge_weights = None + cupy_edge_ids = None + cupy_edge_types = None + + + if include_edge_weights: + if dtype == "FLOAT32": + dtype_ = data_type_id_t.FLOAT32 + # The python API should have checked that an appropriate 'dtype' was passed + else: + dtype_ = data_type_id_t.FLOAT64 + error_code = cugraph_generate_edge_weights(c_resource_handle_ptr, + rng_state_ptr, + result_coo_ptr, + dtype_, + minimum_weight, + maximum_weight, + &error_ptr) + assert_success(error_code, error_ptr, "generate_edge_weights") + + edge_weights_view_ptr = cugraph_coo_get_edge_weights(result_coo_ptr) + cupy_edge_weights = copy_to_cupy_array(c_resource_handle_ptr, edge_weights_view_ptr) + + + if include_edge_ids: + error_code = cugraph_generate_edge_ids(c_resource_handle_ptr, + result_coo_ptr, + multi_gpu, + &error_ptr) + + assert_success(error_code, error_ptr, "generate_edge_ids") + + edge_ids_view_ptr = cugraph_coo_get_edge_id(result_coo_ptr) + cupy_edge_ids = copy_to_cupy_array(c_resource_handle_ptr, edge_ids_view_ptr) + + if include_edge_types: + error_code = cugraph_generate_edge_types(c_resource_handle_ptr, + rng_state_ptr, + result_coo_ptr, + min_edge_type, + max_edge_type, + &error_ptr) + + assert_success(error_code, error_ptr, "generate_edge_types") + + edge_type_view_ptr = cugraph_coo_get_edge_type(result_coo_ptr) + cupy_edge_types = copy_to_cupy_array(c_resource_handle_ptr, edge_type_view_ptr) + + + + + + cupy_sources = copy_to_cupy_array(c_resource_handle_ptr, sources_view_ptr) + cupy_destinations = copy_to_cupy_array(c_resource_handle_ptr, destinations_view_ptr) + + cugraph_coo_free(result_coo_ptr) + + return cupy_sources, cupy_destinations, cupy_edge_weights, cupy_edge_ids, cupy_edge_types + """ From 7923a30d85b5db43d05aae1df8c29a946f3a68cd Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Thu, 22 Jun 2023 03:36:05 -0700 Subject: [PATCH 09/62] fix typo --- .../pylibcugraph/pylibcugraph/_cugraph_c/graph_generators.pxd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_generators.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_generators.pxd index a99df7caf36..dde28da994c 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_generators.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_generators.pxd @@ -83,7 +83,7 @@ cdef extern from "cugraph_c/graph_generators.h": ) cdef void \ - cugraph_list_coo_free( + cugraph_coo_list_free( cugraph_coo_list_t* coo_list ) From bcceb73b6827d07a674df2a186ea6c2905c48b6a Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Thu, 22 Jun 2023 03:36:52 -0700 Subject: [PATCH 10/62] update docstrings --- python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx index 7e6beb101fd..9b9c13f126b 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx @@ -134,11 +134,11 @@ def generate_rmat_edgelist(ResourceHandle resource_handle, Flag controlling whether to generate edges with types (if set to 'true') or not (if set to 'false'). - min_edge_type : int, optional (default=0) + min_edge_type : int Minimum edge type to generate if 'include_edge_types' is 'true' otherwise, this parameter is ignored. - max_edge_type : int, optional (default=5) + max_edge_type : int Maximum edge type to generate if 'include_edge_types' is 'true' otherwise, this paramter is ignored. From fb84d73075188fbce16bfe1ff7352662da123066 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Thu, 22 Jun 2023 03:38:39 -0700 Subject: [PATCH 11/62] refactor the python implementation of SG multi_rmat generator and update docstrings --- python/cugraph/cugraph/generators/rmat.py | 174 +++++++++++++++++----- 1 file changed, 137 insertions(+), 37 deletions(-) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index 85432b5eadf..f234cac8e25 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -19,30 +19,32 @@ import cudf import cugraph from pylibcugraph import generate_rmat_edgelist as pylibcugraph_generate_rmat_edgelist +from pylibcugraph import generate_rmat_edgelists as pylibcugraph_generate_rmat_edgelists from pylibcugraph import ResourceHandle _graph_types = [cugraph.Graph, cugraph.MultiGraph] def _ensure_args_rmat( - scale, - num_edges, - a, - b, - c, - seed, - clip_and_flip, - scramble_vertex_ids, - include_edge_weights, - minimum_weight, - maximum_weight, - dtype, - include_edge_ids, - include_edge_types, - min_edge_type, - max_edge_type, - create_using, - mg, + scale=None, + num_edges=None, + a=None, + b=None, + c=None, + seed=None, + clip_and_flip=None, + scramble_vertex_ids=None, + include_edge_weights=None, + minimum_weight=None, + maximum_weight=None, + dtype=None, + include_edge_ids=None, + include_edge_types=None, + min_edge_type=None, + max_edge_type=None, + create_using=None, + mg=None, + multi_rmat = False, ): """ Ensures the args passed in are usable for the rmat() API, raises the @@ -63,18 +65,20 @@ def _ensure_args_rmat( "(or subclass) type or instance, got: " f"{type(create_using)}" ) - if not isinstance(scale, int): - raise TypeError("'scale' must be an int") - if not isinstance(num_edges, int): - raise TypeError("'num_edges' must be an int") - if a + b + c > 1: - raise ValueError("a + b + c should be non-negative and no larger than 1.0") - if clip_and_flip not in [True, False]: - raise ValueError("'clip_and_flip' must be a bool") - if scramble_vertex_ids not in [True, False]: - raise ValueError("'scramble_vertex_ids' must be a bool") - if not isinstance(seed, int): - raise TypeError("'seed' must be an int") + + if multi_rmat is False: + if not isinstance(scale, int): + raise TypeError("'scale' must be an int") + if not isinstance(num_edges, int): + raise TypeError("'num_edges' must be an int") + if a + b + c > 1: + raise ValueError("a + b + c should be non-negative and no larger than 1.0") + if clip_and_flip not in [True, False]: + raise ValueError("'clip_and_flip' must be a bool") + if scramble_vertex_ids not in [True, False]: + raise ValueError("'scramble_vertex_ids' must be a bool") + if not isinstance(seed, int): + raise TypeError("'seed' must be an int") if include_edge_weights: if include_edge_weights not in [True, False]: raise ValueError("'include_edge_weights' must be a bool") @@ -599,9 +603,18 @@ def multi_rmat( edge_factor, size_distribution, edge_distribution, - seed, - clip_and_flip, - scramble_vertex_ids, + seed=42, + clip_and_flip=False, + scramble_vertex_ids=False, + include_edge_weights=False, + minimum_weight=None, + maximum_weight=None, + dtype=None, + include_edge_ids=False, + include_edge_types=False, + min_edge_type=None, + max_edge_type=None, + mg=False, ): """ Generate multiple Graph objects using a Recursive MATrix (R-MAT) graph @@ -643,6 +656,46 @@ def multi_rmat( Flag controlling whether to scramble vertex ID bits (if set to 'true') or not (if set to 'false'); scrambling vertx ID bits breaks correlation between vertex ID values and vertex degrees + + include_edge_weights : bool, optional (default=False) + Flag controlling whether to generate edges with weights + (if set to 'true') or not (if set to 'false'). + + minimum_weight : float + Minimum weight value to generate if 'include_edge_weights' is 'true' + otherwise, this parameter is ignored. + + maximum_weight : float + Maximum weight value to generate if 'include_edge_weights' is 'true' + otherwise, this parameter is ignored. + + include_edge_ids : bool, optional (default=False) + Flag controlling whether to generate edges with ids + (if set to 'true') or not (if set to 'false'). + + include_edge_types : bool, optional (default=False) + Flag controlling whether to generate edges with types + (if set to 'true') or not (if set to 'false'). + + min_edge_type : int + Minimum edge type to generate if 'include_edge_types' is 'true' + otherwise, this parameter is ignored. + + max_edge_type : int + Maximum edge type to generate if 'include_edge_types' is 'true' + otherwise, this paramter is ignored. + + create_using : cugraph Graph type or None The graph type to construct + containing the generated edges and vertices. If None is specified, the + edgelist cuDF DataFrame (or dask_cudf DataFrame for MG) is returned + as-is. This is useful for benchmarking Graph construction steps that + require raw data that includes potential self-loops, isolated vertices, + and duplicated edges. Default is cugraph.Graph. + + mg : bool, optional (default=False) + If True, R-MATs generation occurs across multiple GPUs. If False, only a + single GPU is used. Default is False (single-GPU) + # FIXME: multi GPU RMATs generation not supported yet. Returns ------- @@ -660,22 +713,69 @@ def multi_rmat( scramble_vertex_ids, ) - dfs = rmat_wrapper.generate_rmat_edgelists( + # FIXME: consolidate '_ensure_args_rmat' and '_ensure_args_multi_rmat' + # to have a single function check since both implementations share similar + # arguments now + _ensure_args_rmat( + include_edge_weights=include_edge_weights, + minimum_weight=minimum_weight, + maximum_weight=maximum_weight, + dtype=dtype, + include_edge_ids=include_edge_ids, + include_edge_types=include_edge_types, + min_edge_type=min_edge_type, + max_edge_type=max_edge_type, + multi_rmat = True, + ) + + edgelists = pylibcugraph_generate_rmat_edgelists( + ResourceHandle(), + seed, n_edgelists, min_scale, max_scale, edge_factor, size_distribution, edge_distribution, - seed, clip_and_flip, - scramble_vertex_ids, + include_edge_weights, + minimum_weight, + maximum_weight, + dtype, + include_edge_ids, + include_edge_types, + min_edge_type, + max_edge_type, + mg, ) + + dfs = [] + + for edgelist in edgelists: + src, dst, weights, edge_id, edge_type = edgelist + df = cudf.DataFrame() + df["src"] = src + df["dst"] = dst + if weights is not None: + df["weights"] = weights + weights = "weights" + + if edge_id is not None: + df["edge_id"] = edge_id + edge_id = "edge_id" + if edge_type is not None: + df["edge_type"] = edge_type + edge_type = "edge_type" + + dfs.append(df) + list_G = [] for df in dfs: G = cugraph.Graph() - G.from_cudf_edgelist(df, source="src", destination="dst") + G.from_cudf_edgelist( + df, source="src", destination="dst", weight=weights, + edge_id=edge_id, edge_type=edge_type) list_G.append(G) return list_G From a6bca54963c9cdb31efe8c3330bc0023a9cbe005 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Thu, 22 Jun 2023 03:39:57 -0700 Subject: [PATCH 12/62] fix style --- python/cugraph/cugraph/generators/rmat.py | 61 ++++++++++++++--------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index f234cac8e25..5c82dc63635 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -44,7 +44,7 @@ def _ensure_args_rmat( max_edge_type=None, create_using=None, mg=None, - multi_rmat = False, + multi_rmat=False, ): """ Ensures the args passed in are usable for the rmat() API, raises the @@ -65,7 +65,7 @@ def _ensure_args_rmat( "(or subclass) type or instance, got: " f"{type(create_using)}" ) - + if multi_rmat is False: if not isinstance(scale, int): raise TypeError("'scale' must be an int") @@ -197,11 +197,11 @@ def _sg_rmat( if include_edge_weights: df["weights"] = weights weights = "weights" - + if include_edge_ids: df["edge_id"] = edge_id edge_id = "edge_id" - + if include_edge_types: df["edge_type"] = edge_type edge_type = "edge_type" @@ -221,8 +221,14 @@ def _sg_rmat( f"{type(create_using)}" ) G.from_cudf_edgelist( - df, source="src", destination="dst", weight=weights, - edge_id=edge_id, edge_type=edge_type, renumber=False) + df, + source="src", + destination="dst", + weight=weights, + edge_id=edge_id, + edge_type=edge_type, + renumber=False, + ) return G @@ -240,7 +246,7 @@ def convert_to_cudf(cp_arrays): df["edge_id"] = cp_edge_ids if cp_edge_types is not None: df["edge_type"] = cp_edge_types - + return df @@ -323,28 +329,32 @@ def _mg_rmat( "(or subclass) type or instance, got: " f"{type(create_using)}" ) - + weights = None edge_id = None edge_type = None if "weights" in ddf.columns: weights = "weights" - + if "edge_id" in ddf.columns: edge_id = "edge_id" - + if "edge_type" in ddf.columns: edge_type = "edge_type" G.from_dask_cudf_edgelist( - ddf, source="src", destination="dst", weight=weights, - edge_id=edge_id, edge_type=edge_type) + ddf, + source="src", + destination="dst", + weight=weights, + edge_id=edge_id, + edge_type=edge_type, + ) return G - def _call_rmat( sID, scale, @@ -468,7 +478,7 @@ def rmat( Flag controlling whether to scramble vertex ID bits (if set to `true`) or not (if set to `false`); scrambling vertex ID bits breaks correlation between vertex ID values and vertex degrees. - + include_edge_weights : bool, optional (default=False) Flag controlling whether to generate edges with weights (if set to 'true') or not (if set to 'false'). @@ -476,7 +486,7 @@ def rmat( minimum_weight : float Minimum weight value to generate if 'include_edge_weights' is 'true' otherwise, this parameter is ignored. - + maximum_weight : float Maximum weight value to generate if 'include_edge_weights' is 'true' otherwise, this parameter is ignored. @@ -484,7 +494,7 @@ def rmat( include_edge_ids : bool, optional (default=False) Flag controlling whether to generate edges with ids (if set to 'true') or not (if set to 'false'). - + include_edge_types : bool, optional (default=False) Flag controlling whether to generate edges with types (if set to 'true') or not (if set to 'false'). @@ -656,7 +666,7 @@ def multi_rmat( Flag controlling whether to scramble vertex ID bits (if set to 'true') or not (if set to 'false'); scrambling vertx ID bits breaks correlation between vertex ID values and vertex degrees - + include_edge_weights : bool, optional (default=False) Flag controlling whether to generate edges with weights (if set to 'true') or not (if set to 'false'). @@ -664,7 +674,7 @@ def multi_rmat( minimum_weight : float Minimum weight value to generate if 'include_edge_weights' is 'true' otherwise, this parameter is ignored. - + maximum_weight : float Maximum weight value to generate if 'include_edge_weights' is 'true' otherwise, this parameter is ignored. @@ -672,7 +682,7 @@ def multi_rmat( include_edge_ids : bool, optional (default=False) Flag controlling whether to generate edges with ids (if set to 'true') or not (if set to 'false'). - + include_edge_types : bool, optional (default=False) Flag controlling whether to generate edges with types (if set to 'true') or not (if set to 'false'). @@ -725,7 +735,7 @@ def multi_rmat( include_edge_types=include_edge_types, min_edge_type=min_edge_type, max_edge_type=max_edge_type, - multi_rmat = True, + multi_rmat=True, ) edgelists = pylibcugraph_generate_rmat_edgelists( @@ -766,7 +776,7 @@ def multi_rmat( if edge_type is not None: df["edge_type"] = edge_type edge_type = "edge_type" - + dfs.append(df) list_G = [] @@ -774,8 +784,13 @@ def multi_rmat( for df in dfs: G = cugraph.Graph() G.from_cudf_edgelist( - df, source="src", destination="dst", weight=weights, - edge_id=edge_id, edge_type=edge_type) + df, + source="src", + destination="dst", + weight=weights, + edge_id=edge_id, + edge_type=edge_type, + ) list_G.append(G) return list_G From ab4109720b1effd3850b8b19aad98855f16670fd Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Thu, 22 Jun 2023 03:43:26 -0700 Subject: [PATCH 13/62] remove unsued import --- python/cugraph/cugraph/generators/rmat.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index 5c82dc63635..414eb0de12f 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -14,7 +14,6 @@ from dask.distributed import default_client, wait import dask_cudf -from cugraph.generators import rmat_wrapper from cugraph.dask.comms import comms as Comms import cudf import cugraph From d580117341937d6d8b2d8ec7cb8213c2ff71794e Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Thu, 22 Jun 2023 03:49:49 -0700 Subject: [PATCH 14/62] remove outdated code --- .../pylibcugraph/generate_rmat_edgelists.pyx | 73 ------------------- 1 file changed, 73 deletions(-) diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx index ad3e19fc0e4..6103b5f3302 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx @@ -265,78 +265,5 @@ def generate_rmat_edgelists(ResourceHandle resource_handle, # FIXME: Does freeing 'result_coo_ptr' automatically free 'result_coo_list_ptr'? cugraph_coo_free(result_coo_ptr) - return edgelists - - - """ - cdef cugraph_type_erased_device_array_view_t* \ - sources_view_ptr = cugraph_coo_get_sources(result_coo_ptr) - - cdef cugraph_type_erased_device_array_view_t* \ - destinations_view_ptr = cugraph_coo_get_destinations(result_coo_ptr) - - cdef cugraph_type_erased_device_array_view_t* edge_weights_view_ptr - - cdef cugraph_data_type_id_t dtype_ - - cupy_edge_weights = None - cupy_edge_ids = None - cupy_edge_types = None - - - if include_edge_weights: - if dtype == "FLOAT32": - dtype_ = data_type_id_t.FLOAT32 - # The python API should have checked that an appropriate 'dtype' was passed - else: - dtype_ = data_type_id_t.FLOAT64 - error_code = cugraph_generate_edge_weights(c_resource_handle_ptr, - rng_state_ptr, - result_coo_ptr, - dtype_, - minimum_weight, - maximum_weight, - &error_ptr) - assert_success(error_code, error_ptr, "generate_edge_weights") - - edge_weights_view_ptr = cugraph_coo_get_edge_weights(result_coo_ptr) - cupy_edge_weights = copy_to_cupy_array(c_resource_handle_ptr, edge_weights_view_ptr) - - - if include_edge_ids: - error_code = cugraph_generate_edge_ids(c_resource_handle_ptr, - result_coo_ptr, - multi_gpu, - &error_ptr) - - assert_success(error_code, error_ptr, "generate_edge_ids") - - edge_ids_view_ptr = cugraph_coo_get_edge_id(result_coo_ptr) - cupy_edge_ids = copy_to_cupy_array(c_resource_handle_ptr, edge_ids_view_ptr) - - if include_edge_types: - error_code = cugraph_generate_edge_types(c_resource_handle_ptr, - rng_state_ptr, - result_coo_ptr, - min_edge_type, - max_edge_type, - &error_ptr) - - assert_success(error_code, error_ptr, "generate_edge_types") - - edge_type_view_ptr = cugraph_coo_get_edge_type(result_coo_ptr) - cupy_edge_types = copy_to_cupy_array(c_resource_handle_ptr, edge_type_view_ptr) - - - - - - cupy_sources = copy_to_cupy_array(c_resource_handle_ptr, sources_view_ptr) - cupy_destinations = copy_to_cupy_array(c_resource_handle_ptr, destinations_view_ptr) - - cugraph_coo_free(result_coo_ptr) - - return cupy_sources, cupy_destinations, cupy_edge_weights, cupy_edge_ids, cupy_edge_types - """ From 4101ed1efecacf7f18796c3c65bc3776bb9d188d Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Thu, 22 Jun 2023 03:51:27 -0700 Subject: [PATCH 15/62] fix copyright --- python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd index 0330398d7ee..e9e74723e06 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-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 From 461ed7d6bbbb636ace9369a0c183be2a661dc83d Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Thu, 22 Jun 2023 08:18:54 -0700 Subject: [PATCH 16/62] add type of cython variable --- python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx index 6103b5f3302..676bb2e9140 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx @@ -206,6 +206,7 @@ def generate_rmat_edgelists(ResourceHandle resource_handle, cupy_edge_ids = None cupy_edge_types = None + cdef cugraph_data_type_id_t dtype_ edgelists = [] for index in range(size): From ece812ba34a722fadb8908ec8f151cbcc06048d5 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Sat, 24 Jun 2023 02:52:51 -0700 Subject: [PATCH 17/62] enable rmat generator to support 'scramble_vertex_ids', update docstrings and function calls --- cpp/include/cugraph/graph_generators.hpp | 24 +++++++-- cpp/include/cugraph_c/graph_generators.h | 8 +++ cpp/src/c_api/graph_generators.cpp | 11 ++++- cpp/src/generators/generate_rmat_edgelist.cu | 52 ++++++++++++++------ 4 files changed, 74 insertions(+), 21 deletions(-) diff --git a/cpp/include/cugraph/graph_generators.hpp b/cpp/include/cugraph/graph_generators.hpp index 4944e0f4917..39554979b91 100644 --- a/cpp/include/cugraph/graph_generators.hpp +++ b/cpp/include/cugraph/graph_generators.hpp @@ -66,6 +66,9 @@ namespace cugraph { * @param clip_and_flip Flag controlling whether to generate edges only in the lower triangular part * (including the diagonal) of the graph adjacency matrix (if set to `true`) or not (if set to * `false`). + * @param scramble_vertex_ids Flag controlling whether to scramble vertex ID bits (if set to `true`) + * or not (if set to `false`); scrambling vertex ID bits breaks correlation between vertex ID values + * and vertex degrees. * @return std::tuple, rmm::device_uvector> A tuple of * rmm::device_uvector objects for edge source vertex IDs and edge destination vertex IDs. */ @@ -78,7 +81,8 @@ std::tuple, rmm::device_uvector> generat double b = 0.19, double c = 0.19, uint64_t seed = 0, - bool clip_and_flip = false); + bool clip_and_flip = false, + bool scramble_vertex_ids = false); /** * @brief generate an edge list for an R-mat graph. @@ -113,6 +117,9 @@ std::tuple, rmm::device_uvector> generat * @param clip_and_flip Flag controlling whether to generate edges only in the lower triangular part * (including the diagonal) of the graph adjacency matrix (if set to `true`) or not (if set to * `false`). + * @param scramble_vertex_ids Flag controlling whether to scramble vertex ID bits (if set to `true`) + * or not (if set to `false`); scrambling vertex ID bits breaks correlation between vertex ID values + * and vertex degrees. * @return std::tuple, rmm::device_uvector> A tuple of * rmm::device_uvector objects for edge source vertex IDs and edge destination vertex IDs. */ @@ -125,7 +132,8 @@ std::tuple, rmm::device_uvector> generat double a = 0.57, double b = 0.19, double c = 0.19, - bool clip_and_flip = false); + bool clip_and_flip = false, + bool scramble_vertex_ids = false); /** * @brief generate an edge list for a bipartite R-mat graph. @@ -199,6 +207,9 @@ enum class generator_distribution_t { POWER_LAW = 0, UNIFORM }; * @param clip_and_flip Flag controlling whether to generate edges only in the lower triangular part * (including the diagonal) of the graph adjacency matrix (if set to `true`) or not (if set to * `false`). + * @param scramble_vertex_ids Flag controlling whether to scramble vertex ID bits (if set to `true`) + * or not (if set to `false`); scrambling vertex ID bits breaks correlation between vertex ID values + * and vertex degrees. * @return A vector of std::tuple, rmm::device_uvector> of *size @p n_edgelists, each vector element being a tuple of rmm::device_uvector objects for edge *source vertex IDs and edge destination vertex IDs. @@ -214,7 +225,8 @@ generate_rmat_edgelists( generator_distribution_t size_distribution = generator_distribution_t::POWER_LAW, generator_distribution_t edge_distribution = generator_distribution_t::POWER_LAW, uint64_t seed = 0, - bool clip_and_flip = false); + bool clip_and_flip = false, + bool scramble_vertex_ids = false); /** * @brief generate multiple edge lists using the R-mat graph generator. @@ -245,6 +257,9 @@ generate_rmat_edgelists( * @param clip_and_flip Flag controlling whether to generate edges only in the lower triangular part * (including the diagonal) of the graph adjacency matrix (if set to `true`) or not (if set to * `false`). + * @param scramble_vertex_ids Flag controlling whether to scramble vertex ID bits (if set to `true`) + * or not (if set to `false`); scrambling vertex ID bits breaks correlation between vertex ID values + * and vertex degrees. * @return A vector of std::tuple, rmm::device_uvector> of *size @p n_edgelists, each vector element being a tuple of rmm::device_uvector objects for edge *source vertex IDs and edge destination vertex IDs. @@ -260,7 +275,8 @@ generate_rmat_edgelists( size_t edge_factor = 16, generator_distribution_t size_distribution = generator_distribution_t::POWER_LAW, generator_distribution_t edge_distribution = generator_distribution_t::POWER_LAW, - bool clip_and_flip = false); + bool clip_and_flip = false, + bool scramble_vertex_ids = false); /** * @brief generate an edge list for path graph diff --git a/cpp/include/cugraph_c/graph_generators.h b/cpp/include/cugraph_c/graph_generators.h index 9da6ee48fc7..36cded27ba6 100644 --- a/cpp/include/cugraph_c/graph_generators.h +++ b/cpp/include/cugraph_c/graph_generators.h @@ -136,6 +136,9 @@ void cugraph_coo_list_free(cugraph_coo_list_t* coo_list); * @param [in] clip_and_flip Flag controlling whether to generate edges only in the lower * triangular part (including the diagonal) of the graph adjacency matrix (if set to `true`) or not * (if set to `false`). + * @param [in] scramble_vertex_ids Flag controlling whether to scramble vertex ID bits + * (if set to `true`) or not (if set to `false`); scrambling vertex ID bits breaks correlation + * between vertex ID values and vertex degrees. * @param [out] result Opaque pointer to generated coo * @param [out] error Pointer to an error object storing details of any error. Will * be populated if error code is not CUGRAPH_SUCCESS @@ -149,6 +152,7 @@ cugraph_error_code_t cugraph_generate_rmat_edgelist(const cugraph_resource_handl double b, double c, bool_t clip_and_flip, + bool_t scramble_vertex_ids, cugraph_coo_t** result, cugraph_error_t** error); @@ -172,6 +176,9 @@ cugraph_error_code_t cugraph_generate_rmat_edgelist(const cugraph_resource_handl * @param [in] clip_and_flip Flag controlling whether to generate edges only in the lower * triangular part (including the diagonal) of the graph adjacency matrix (if set to `true`) or not * (if set to `false`). + * @param [in] scramble_vertex_ids Flag controlling whether to scramble vertex ID bits + * (if set to `true`) or not (if set to `false`); scrambling vertex ID bits breaks correlation + * between vertex ID values and vertex degrees. * @param [out] result Opaque pointer to generated coo list * @param [out] error Pointer to an error object storing details of any error. Will * be populated if error code is not CUGRAPH_SUCCESS @@ -187,6 +194,7 @@ cugraph_error_code_t cugraph_generate_rmat_edgelists( cugraph_generator_distribution_t size_distribution, cugraph_generator_distribution_t edge_distribution, bool_t clip_and_flip, + bool_t scramble_vertex_ids, cugraph_coo_list_t** result, cugraph_error_t** error); diff --git a/cpp/src/c_api/graph_generators.cpp b/cpp/src/c_api/graph_generators.cpp index 38f91b3135b..e2de6043a46 100644 --- a/cpp/src/c_api/graph_generators.cpp +++ b/cpp/src/c_api/graph_generators.cpp @@ -56,6 +56,7 @@ cugraph_error_code_t cugraph_generate_rmat_edgelist(raft::handle_t const& handle double b, double c, bool_t clip_and_flip, + bool_t scramble_vertex_ids, cugraph::c_api::cugraph_coo_t** result, cugraph::c_api::cugraph_error_t** error) { @@ -90,6 +91,7 @@ cugraph_error_code_t cugraph_generate_rmat_edgelists( cugraph_generator_distribution_t size_distribution, cugraph_generator_distribution_t edge_distribution, bool_t clip_and_flip, + bool_t scramble_vertex_ids, cugraph::c_api::cugraph_coo_list_t** result, cugraph::c_api::cugraph_error_t** error) { @@ -103,7 +105,8 @@ cugraph_error_code_t cugraph_generate_rmat_edgelists( edge_factor, static_cast(size_distribution), static_cast(edge_distribution), - clip_and_flip); + clip_and_flip, + scramble_vertex_ids); *result = new cugraph::c_api::cugraph_coo_list_t; (*result)->list_.resize(tuple_vector.size()); @@ -200,6 +203,7 @@ extern "C" cugraph_error_code_t cugraph_generate_rmat_edgelist( double b, double c, bool_t clip_and_flip, + bool_t scramble_vertex_ids, cugraph_coo_t** result, cugraph_error_t** error) { @@ -219,6 +223,7 @@ extern "C" cugraph_error_code_t cugraph_generate_rmat_edgelist( b, c, clip_and_flip, + scramble_vertex_ids, reinterpret_cast(result), reinterpret_cast(error)); } else { @@ -232,6 +237,7 @@ extern "C" cugraph_error_code_t cugraph_generate_rmat_edgelist( b, c, clip_and_flip, + scramble_vertex_ids, reinterpret_cast(result), reinterpret_cast(error)); } @@ -247,6 +253,7 @@ extern "C" cugraph_error_code_t cugraph_generate_rmat_edgelists( cugraph_generator_distribution_t size_distribution, cugraph_generator_distribution_t edge_distribution, bool_t clip_and_flip, + bool_t scramble_vertex_ids, cugraph_coo_list_t** result, cugraph_error_t** error) { @@ -267,6 +274,7 @@ extern "C" cugraph_error_code_t cugraph_generate_rmat_edgelists( size_distribution, edge_distribution, clip_and_flip, + scramble_vertex_ids, reinterpret_cast(result), reinterpret_cast(error)); } else { @@ -281,6 +289,7 @@ extern "C" cugraph_error_code_t cugraph_generate_rmat_edgelists( size_distribution, edge_distribution, clip_and_flip, + scramble_vertex_ids, reinterpret_cast(result), reinterpret_cast(error)); } diff --git a/cpp/src/generators/generate_rmat_edgelist.cu b/cpp/src/generators/generate_rmat_edgelist.cu index 6789306ab21..7ff757789c1 100644 --- a/cpp/src/generators/generate_rmat_edgelist.cu +++ b/cpp/src/generators/generate_rmat_edgelist.cu @@ -42,7 +42,8 @@ std::tuple, rmm::device_uvector> generat double a, double b, double c, - bool clip_and_flip) + bool clip_and_flip, + bool scramble_vertex_ids) { CUGRAPH_EXPECTS((size_t{1} << scale) <= static_cast(std::numeric_limits::max()), "Invalid input argument: scale too large for vertex_t."); @@ -104,7 +105,14 @@ std::tuple, rmm::device_uvector> generat num_edges_generated += num_edges_to_generate; } - return std::make_tuple(std::move(srcs), std::move(dsts)); + if (scramble_vertex_ids) { + return cugraph::scramble_vertex_ids( + handle, std::move(srcs), std::move(dsts), scale); + } + else{ + return std::make_tuple(std::move(srcs), std::move(dsts)); + } + } template @@ -116,12 +124,13 @@ std::tuple, rmm::device_uvector> generat double b, double c, uint64_t seed, - bool clip_and_flip) + bool clip_and_flip, + bool scramble_vertex_ids) { raft::random::RngState rng_state(seed); return generate_rmat_edgelist( - handle, rng_state, scale, num_edges, a, b, c, clip_and_flip); + handle, rng_state, scale, num_edges, a, b, c, clip_and_flip, scramble_vertex_ids); } template @@ -134,7 +143,8 @@ generate_rmat_edgelists(raft::handle_t const& handle, size_t edge_factor, generator_distribution_t size_distribution, generator_distribution_t edge_distribution, - bool clip_and_flip) + bool clip_and_flip, + bool scramble_vertex_ids) { CUGRAPH_EXPECTS(min_scale > 0, "minimum graph scale is 1."); CUGRAPH_EXPECTS( @@ -182,7 +192,7 @@ generate_rmat_edgelists(raft::handle_t const& handle, for (size_t i = 0; i < n_edgelists; i++) { output.push_back(generate_rmat_edgelist( - handle, rng_state, scale[i], scale[i] * edge_factor, a, b, c, clip_and_flip)); + handle, rng_state, scale[i], scale[i] * edge_factor, a, b, c, clip_and_flip, scramble_vertex_ids)); } return output; } @@ -197,7 +207,8 @@ generate_rmat_edgelists(raft::handle_t const& handle, generator_distribution_t size_distribution, generator_distribution_t edge_distribution, uint64_t seed, - bool clip_and_flip) + bool clip_and_flip, + bool scramble_vertex_ids) { raft::random::RngState rng_state(seed); @@ -209,7 +220,8 @@ generate_rmat_edgelists(raft::handle_t const& handle, edge_factor, size_distribution, edge_distribution, - clip_and_flip); + clip_and_flip, + scramble_vertex_ids); } template std::tuple, rmm::device_uvector> @@ -220,7 +232,8 @@ generate_rmat_edgelist(raft::handle_t const& handle, double a, double b, double c, - bool clip_and_flip); + bool clip_and_flip, + bool scramble_vertex_ids); template std::tuple, rmm::device_uvector> generate_rmat_edgelist(raft::handle_t const& handle, @@ -230,7 +243,8 @@ generate_rmat_edgelist(raft::handle_t const& handle, double a, double b, double c, - bool clip_and_flip); + bool clip_and_flip, + bool scramble_vertex_ids); template std::vector, rmm::device_uvector>> generate_rmat_edgelists(raft::handle_t const& handle, @@ -241,7 +255,8 @@ generate_rmat_edgelists(raft::handle_t const& handle, size_t edge_factor, generator_distribution_t size_distribution, generator_distribution_t edge_distribution, - bool clip_and_flip); + bool clip_and_flip, + bool scramble_vertex_ids); template std::vector, rmm::device_uvector>> generate_rmat_edgelists(raft::handle_t const& handle, @@ -252,7 +267,8 @@ generate_rmat_edgelists(raft::handle_t const& handle, size_t edge_factor, generator_distribution_t size_distribution, generator_distribution_t edge_distribution, - bool clip_and_flip); + bool clip_and_flip, + bool scramble_vertex_ids); /* DEPRECATED */ template std::tuple, rmm::device_uvector> @@ -263,7 +279,8 @@ generate_rmat_edgelist(raft::handle_t const& handle, double b, double c, uint64_t seed, - bool clip_and_flip); + bool clip_and_flip, + bool scramble_vertex_ids); template std::tuple, rmm::device_uvector> generate_rmat_edgelist(raft::handle_t const& handle, @@ -273,7 +290,8 @@ generate_rmat_edgelist(raft::handle_t const& handle, double b, double c, uint64_t seed, - bool clip_and_flip); + bool clip_and_flip, + bool scramble_vertex_ids); template std::vector, rmm::device_uvector>> generate_rmat_edgelists(raft::handle_t const& handle, @@ -284,7 +302,8 @@ generate_rmat_edgelists(raft::handle_t const& handle, generator_distribution_t size_distribution, generator_distribution_t edge_distribution, uint64_t seed, - bool clip_and_flip); + bool clip_and_flip, + bool scramble_vertex_ids); template std::vector, rmm::device_uvector>> generate_rmat_edgelists(raft::handle_t const& handle, @@ -295,6 +314,7 @@ generate_rmat_edgelists(raft::handle_t const& handle, generator_distribution_t size_distribution, generator_distribution_t edge_distribution, uint64_t seed, - bool clip_and_flip); + bool clip_and_flip, + bool scramble_vertex_ids); } // namespace cugraph From d768ce7c45f9ab6d9576d3bb98cd0f1f2821d0c7 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Sun, 25 Jun 2023 00:24:54 -0700 Subject: [PATCH 18/62] enable 'scramble_vertex_ids' flag --- .../pylibcugraph/_cugraph_c/graph_generators.pxd | 2 ++ .../pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx | 7 +++++++ .../pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_generators.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_generators.pxd index dde28da994c..f6d62377443 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_generators.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_generators.pxd @@ -97,6 +97,7 @@ cdef extern from "cugraph_c/graph_generators.h": double b, double c, bool_t clip_and_flip, + bool_t scramble_vertex_ids, cugraph_coo_t** result, cugraph_error_t** error ) @@ -112,6 +113,7 @@ cdef extern from "cugraph_c/graph_generators.h": cugraph_generator_distribution_t size_distribution, cugraph_generator_distribution_t edge_distribution, bool_t clip_and_flip, + bool_t scramble_vertex_ids, cugraph_coo_list_t** result, cugraph_error_t** error ) diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx index 9b9c13f126b..07e185b626b 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx @@ -64,6 +64,7 @@ def generate_rmat_edgelist(ResourceHandle resource_handle, double b, double c, bool_t clip_and_flip, + bool_t scramble_vertex_ids, bool_t include_edge_weights, minimum_weight, maximum_weight, @@ -112,6 +113,11 @@ def generate_rmat_edgelist(ResourceHandle resource_handle, part (including the diagonal) of the graph adjacency matrix (if set to 'true') or not (if set to 'false). + scramble_vertex_ids : bool + Flag controlling whether to scramble vertex ID bits (if set to `true`) + or not (if set to `false`); scrambling vertex ID bits breaks + correlation between vertex ID values and vertex degrees. + include_edge_weights : bool Flag controlling whether to generate edges with weights (if set to 'true') or not (if set to 'false'). @@ -173,6 +179,7 @@ def generate_rmat_edgelist(ResourceHandle resource_handle, b, c, clip_and_flip, + scramble_vertex_ids, &result_coo_ptr, &error_ptr) assert_success(error_code, error_ptr, "generate_rmat_edgelist") diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx index 676bb2e9140..4c8338bba5d 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx @@ -70,6 +70,7 @@ def generate_rmat_edgelists(ResourceHandle resource_handle, size_distribution, edge_distribution, bool_t clip_and_flip, + bool_t scramble_vertex_ids, bool_t include_edge_weights, minimum_weight, maximum_weight, @@ -121,6 +122,11 @@ def generate_rmat_edgelists(ResourceHandle resource_handle, part (including the diagonal) of the graph adjacency matrix (if set to 'true') or not (if set to 'false') + scramble_vertex_ids : bool + Flag controlling whether to scramble vertex ID bits (if set to `true`) + or not (if set to `false`); scrambling vertex ID bits breaks + correlation between vertex ID values and vertex degrees. + include_edge_weights : bool Flag controlling whether to generate edges with weights (if set to 'true') or not (if set to 'false'). @@ -191,6 +197,7 @@ def generate_rmat_edgelists(ResourceHandle resource_handle, size_distribution_, edge_distribution_, clip_and_flip, + scramble_vertex_ids, &result_coo_list_ptr, &error_ptr) assert_success(error_code, error_ptr, "generate_rmat_edgelists") From 88ec8fa8a6b46646b09551ef4b417e8884a84a1b Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Sun, 25 Jun 2023 00:25:37 -0700 Subject: [PATCH 19/62] enable 'scramble_vertex_ids' flag and updaate docstrings --- python/cugraph/cugraph/generators/rmat.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index 414eb0de12f..7573cd241cf 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -178,6 +178,7 @@ def _sg_rmat( b, c, clip_and_flip, + scramble_vertex_ids, include_edge_weights, minimum_weight, maximum_weight, @@ -388,6 +389,7 @@ def _call_rmat( b, c, clip_and_flip, + scramble_vertex_ids, include_edge_weights, minimum_weight, maximum_weight, From 18ca6037c77f23e79ee70ac76f90b05404b8887c Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Sun, 25 Jun 2023 14:46:02 -0700 Subject: [PATCH 20/62] fix bug --- cpp/src/c_api/graph_generators.cpp | 2 +- python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/cpp/src/c_api/graph_generators.cpp b/cpp/src/c_api/graph_generators.cpp index e2de6043a46..adf49de7afe 100644 --- a/cpp/src/c_api/graph_generators.cpp +++ b/cpp/src/c_api/graph_generators.cpp @@ -62,7 +62,7 @@ cugraph_error_code_t cugraph_generate_rmat_edgelist(raft::handle_t const& handle { try { auto [src, dst] = cugraph::generate_rmat_edgelist( - handle, rng_state, scale, num_edges, a, b, c, clip_and_flip); + handle, rng_state, scale, num_edges, a, b, c, clip_and_flip, scramble_vertex_ids); *result = new cugraph::c_api::cugraph_coo_t{ std::make_unique(src, vertex_dtype), diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx index 07e185b626b..581d4658b6f 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx @@ -198,7 +198,6 @@ def generate_rmat_edgelist(ResourceHandle resource_handle, cupy_edge_ids = None cupy_edge_types = None - if include_edge_weights: if dtype == "FLOAT32": dtype_ = data_type_id_t.FLOAT32 From a932743070574e46acdcd4c75ad2a85b116eddcc Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Sun, 25 Jun 2023 14:54:40 -0700 Subject: [PATCH 21/62] fix style --- cpp/include/cugraph/graph_generators.hpp | 18 +++++++++--------- cpp/src/generators/generate_rmat_edgelist.cu | 18 +++++++++++------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/cpp/include/cugraph/graph_generators.hpp b/cpp/include/cugraph/graph_generators.hpp index 39554979b91..5e8e97c51a2 100644 --- a/cpp/include/cugraph/graph_generators.hpp +++ b/cpp/include/cugraph/graph_generators.hpp @@ -77,11 +77,11 @@ std::tuple, rmm::device_uvector> generat raft::handle_t const& handle, size_t scale, size_t num_edges, - double a = 0.57, - double b = 0.19, - double c = 0.19, - uint64_t seed = 0, - bool clip_and_flip = false, + double a = 0.57, + double b = 0.19, + double c = 0.19, + uint64_t seed = 0, + bool clip_and_flip = false, bool scramble_vertex_ids = false); /** @@ -129,10 +129,10 @@ std::tuple, rmm::device_uvector> generat raft::random::RngState& rng_state, size_t scale, size_t num_edges, - double a = 0.57, - double b = 0.19, - double c = 0.19, - bool clip_and_flip = false, + double a = 0.57, + double b = 0.19, + double c = 0.19, + bool clip_and_flip = false, bool scramble_vertex_ids = false); /** diff --git a/cpp/src/generators/generate_rmat_edgelist.cu b/cpp/src/generators/generate_rmat_edgelist.cu index 7ff757789c1..bcafd2661d5 100644 --- a/cpp/src/generators/generate_rmat_edgelist.cu +++ b/cpp/src/generators/generate_rmat_edgelist.cu @@ -106,13 +106,10 @@ std::tuple, rmm::device_uvector> generat } if (scramble_vertex_ids) { - return cugraph::scramble_vertex_ids( - handle, std::move(srcs), std::move(dsts), scale); - } - else{ + return cugraph::scramble_vertex_ids(handle, std::move(srcs), std::move(dsts), scale); + } else { return std::make_tuple(std::move(srcs), std::move(dsts)); } - } template @@ -191,8 +188,15 @@ generate_rmat_edgelists(raft::handle_t const& handle, } for (size_t i = 0; i < n_edgelists; i++) { - output.push_back(generate_rmat_edgelist( - handle, rng_state, scale[i], scale[i] * edge_factor, a, b, c, clip_and_flip, scramble_vertex_ids)); + output.push_back(generate_rmat_edgelist(handle, + rng_state, + scale[i], + scale[i] * edge_factor, + a, + b, + c, + clip_and_flip, + scramble_vertex_ids)); } return output; } From 7b99a16d219c2659db166b720bf96287b0bfce38 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 26 Jun 2023 09:04:28 -0700 Subject: [PATCH 22/62] pass default value of 'scramble_vertex_ids' --- cpp/tests/c_api/generate_rmat_test.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cpp/tests/c_api/generate_rmat_test.c b/cpp/tests/c_api/generate_rmat_test.c index 1738f080370..442031ff054 100644 --- a/cpp/tests/c_api/generate_rmat_test.c +++ b/cpp/tests/c_api/generate_rmat_test.c @@ -56,6 +56,7 @@ int test_rmat_generation() 0.19, 0.19, FALSE, + FALSE, &coo, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "generate_rmat_edgelist failed."); @@ -143,6 +144,7 @@ int test_rmat_list_generation() UNIFORM, POWER_LAW, FALSE, + FALSE, &coo_list, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "generate_rmat_edgelist failed."); From f863f21fa8ee0123c89338af43deb3fe4f1dd0a6 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 26 Jun 2023 09:05:38 -0700 Subject: [PATCH 23/62] update docstrings --- python/cugraph/cugraph/generators/rmat.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index 7573cd241cf..9ef579a4ea1 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -491,6 +491,10 @@ def rmat( maximum_weight : float Maximum weight value to generate if 'include_edge_weights' is 'true' otherwise, this parameter is ignored. + + dtype : string + The type of weight to generate ("FLOAT32" or "FLOAT64"), ignored unless + include_weights is true include_edge_ids : bool, optional (default=False) Flag controlling whether to generate edges with ids @@ -695,6 +699,10 @@ def multi_rmat( max_edge_type : int Maximum edge type to generate if 'include_edge_types' is 'true' otherwise, this paramter is ignored. + + dtype : string + The type of weight to generate ("FLOAT32" or "FLOAT64"), ignored unless + include_weights is true create_using : cugraph Graph type or None The graph type to construct containing the generated edges and vertices. If None is specified, the From 851d85b325de6bbf57135a4610332985bbe6aba0 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 26 Jun 2023 09:06:34 -0700 Subject: [PATCH 24/62] update tests for rmat generator --- .../cugraph/tests/generators/test_rmat.py | 243 +++++++++++++++++- 1 file changed, 236 insertions(+), 7 deletions(-) diff --git a/python/cugraph/cugraph/tests/generators/test_rmat.py b/python/cugraph/cugraph/tests/generators/test_rmat.py index f52190f1576..633f4b30803 100644 --- a/python/cugraph/cugraph/tests/generators/test_rmat.py +++ b/python/cugraph/cugraph/tests/generators/test_rmat.py @@ -18,6 +18,7 @@ from cugraph.generators import rmat import cugraph +from cupy.sparse import coo_matrix, triu, tril ############################################################################## @@ -26,9 +27,42 @@ _scale_test_ids = [f"scale={x}" for x in _scale_values] _graph_types = [cugraph.Graph, None, int] _graph_test_ids = [f"create_using={getattr(x,'__name__',str(x))}" for x in _graph_types] +_clip_and_flip = [False, True] +_clip_and_flip_test_ids = [f"clip_and_flip={x}" for x in _clip_and_flip] +_scramble_vertex_ids=[False, True] +_scramble_vertex_ids_test_ids = [f"scramble_vertex_ids={x}" for x in _scramble_vertex_ids] +_include_edge_weights = [False, True] +_include_edge_weights_test_ids = [f"include_edge_weights={x}" for x in _include_edge_weights] +_dtype = [None, "FLOAT32", "FLOAT64", "INT32"] +_dtype_test_ids = [f"_dtype={x}" for x in _dtype] +_min_max_weight_values = [[None, None], [0, 1], [2, 5]] +_min_max_weight_values_test_ids = [f"min_max_weight_values={x}" for x in _min_max_weight_values] +_include_edge_ids = [False, True] +_include_edge_ids_test_ids = [f"include_edge_ids={x}" for x in _include_edge_ids] +_include_edge_types = [False, True] +_include_edge_types_test_ids = [f"include_edge_types={x}" for x in _include_edge_types] +_min_max_edge_type_values = [[None, None], [0, 1], [2, 5]] +_min_max_edge_type_values_test_ids = [f"min_max_edge_type_values={x}" for x in _min_max_edge_type_values] -def _call_rmat(scale, num_edges, create_using, mg=False): + + + +def _call_rmat( + scale, + num_edges, + create_using, + clip_and_flip=False, + scramble_vertex_ids=False, + include_edge_weights=False, + dtype=None, + minimum_weight=None, + maximum_weight=None, + include_edge_ids=False, + include_edge_types=False, + min_edge_type=None, + max_edge_type=None, + mg=False): """ Simplifies calling RMAT by requiring only specific args that are varied by these tests and hard-coding all others. @@ -40,28 +74,222 @@ def _call_rmat(scale, num_edges, create_using, mg=False): b=0.19, # from Graph500 c=0.19, # from Graph500 seed=24, - clip_and_flip=False, - scramble_vertex_ids=True, + clip_and_flip=clip_and_flip, + scramble_vertex_ids=scramble_vertex_ids, create_using=create_using, + include_edge_weights=include_edge_weights, + minimum_weight=minimum_weight, + maximum_weight=maximum_weight, + dtype=dtype, + include_edge_ids=include_edge_ids, + include_edge_types=include_edge_types, + min_edge_type=min_edge_type, + max_edge_type=max_edge_type, mg=mg, ) ############################################################################### + + +@pytest.mark.sg +@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") +@pytest.mark.parametrize("include_edge_weights", _include_edge_weights, ids=_include_edge_weights_test_ids) +@pytest.mark.parametrize("dtype", _dtype, ids=_dtype_test_ids) +@pytest.mark.parametrize("min_max_weight", _min_max_weight_values, ids=_min_max_weight_values_test_ids) +@pytest.mark.parametrize("scramble_vertex_ids", _scramble_vertex_ids, ids=_scramble_vertex_ids_test_ids) +def test_rmat_edge_weights(include_edge_weights, dtype, min_max_weight, scramble_vertex_ids): + """ + Verifies that the edge weights returned by rmat() are valid and raises an exception otherwise or if + invalid values are passed to 'dtype', 'minimum_weight' or 'maximum_weight'. + + """ + scale = 2 + num_edges = (2**scale) * 4 + create_using = None # Returns the edgelist from RMAT + minimum_weight, maximum_weight = min_max_weight + + if include_edge_weights: + if minimum_weight is None or maximum_weight is None or dtype not in ["FLOAT32", "FLOAT64"]: + with pytest.raises(ValueError): + _call_rmat( + scale, + num_edges, + create_using, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_weights=include_edge_weights, + dtype=dtype, + minimum_weight=minimum_weight, + maximum_weight=maximum_weight) + else: + df = _call_rmat( + scale, + num_edges, + create_using, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_weights=include_edge_weights, + dtype=dtype, + minimum_weight=minimum_weight, + maximum_weight=maximum_weight) + + # Check that there is a 'weights' column + assert "weights" in df.columns + + edge_weights_err1 = df.query("{} - weights < 0.0001".format(maximum_weight)) + edge_weights_err2 = df.query("{} - weights > -0.0001".format(minimum_weight)) + + # Check that edge weights values are between 'minimum_weight' and 'maximum_weight + assert len(edge_weights_err1) == 0 + assert len(edge_weights_err2) == 0 + else: + df = _call_rmat( + scale, + num_edges, + create_using, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_weights=include_edge_weights, + dtype=dtype, + minimum_weight=minimum_weight, + maximum_weight=maximum_weight) + assert len(df.columns) == 2 + + @pytest.mark.sg @pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") @pytest.mark.parametrize("scale", _scale_values, ids=_scale_test_ids) -def test_rmat_edgelist(scale): +@pytest.mark.parametrize("include_edge_ids", _include_edge_ids, ids=_include_edge_ids_test_ids) +@pytest.mark.parametrize("scramble_vertex_ids", _scramble_vertex_ids, ids=_scramble_vertex_ids_test_ids) +def test_rmat_edge_ids(scale, include_edge_ids, scramble_vertex_ids): + """ + Verifies that the edge ids returned by rmat() are valid and raises an exception otherwise. + + """ + num_edges = (2**scale) * 4 + create_using = None # Returns the edgelist from RMAT + df = _call_rmat( + scale, + num_edges, + create_using, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_ids=include_edge_ids) + + if include_edge_ids: + assert "edge_id" in df.columns + df["index"] = df.index + edge_id_err = df.query("index != edge_id") + assert len(edge_id_err) == 0 + + else: + assert len(df.columns) == 2 + + +@pytest.mark.sg +@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") +@pytest.mark.parametrize("include_edge_types", [_include_edge_types[0]], ids=[_include_edge_types_test_ids[0]]) +@pytest.mark.parametrize("min_max_edge_type", _min_max_edge_type_values, ids=_min_max_edge_type_values_test_ids) +@pytest.mark.parametrize("scramble_vertex_ids", _scramble_vertex_ids, ids=_scramble_vertex_ids_test_ids) +def test_rmat_edge_types(include_edge_types, min_max_edge_type, scramble_vertex_ids): """ - Verifies that the edgelist returned by rmat() is valid based on inputs. + Verifies that the edge types returned by rmat() are valid and raises an exception otherwise or if + invalid values are passed to 'min_edge_type' or 'max_edge_type'. + """ + scale = 2 + num_edges = (2**scale) * 4 + create_using = None # Returns the edgelist from RMAT + min_edge_type, max_edge_type = min_max_edge_type + + if include_edge_types: + if min_edge_type is None or max_edge_type is None: + with pytest.raises(ValueError): + _call_rmat( + scale, + num_edges, + create_using, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_types=include_edge_types, + min_edge_type=min_edge_type, + max_edge_type=max_edge_type) + else: + df = _call_rmat( + scale, + num_edges, + create_using, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_types=include_edge_types, + min_edge_type=min_edge_type, + max_edge_type=max_edge_type) + + # Check that there is an 'edge_type' column + assert "edge_type" in df.columns + edge_types_err1 = df.query("{} < edge_type".format(max_edge_type)) + edge_types_err2 = df.query("{} > edge_type".format(min_edge_type)) + # Check that edge weights values are between 'min_edge_type' and 'max_edge_type' + assert len(edge_types_err1) == 0 + assert len(edge_types_err2 ) == 0 + else: + df = _call_rmat( + scale, + num_edges, + create_using, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_types=include_edge_types, + min_edge_type=min_edge_type, + max_edge_type=max_edge_type) + assert len(df.columns) == 2 + + +@pytest.mark.sg +@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") +@pytest.mark.parametrize("scale", [2, 4, 8], ids=_scale_test_ids) +@pytest.mark.parametrize("include_edge_weights", _include_edge_weights, ids=_include_edge_weights_test_ids) +@pytest.mark.parametrize("clip_and_flip", _clip_and_flip, ids=_clip_and_flip_test_ids) +@pytest.mark.parametrize("scramble_vertex_ids", [False], ids=[_scramble_vertex_ids_test_ids[0]]) +def test_rmat_clip_and_flip(scale, include_edge_weights, clip_and_flip, scramble_vertex_ids): + """ + Verifies that there are edges only in the lower triangular part of the adjacency matrix + when 'clip_and_flip' is set to 'true'. + + # FIXME: 'scramble_vertex_ids' nullifies the effect of 'clip_and_flip' therefore, both + # flags should not be set to 'True'. + + """ num_edges = (2**scale) * 4 create_using = None # Returns the edgelist from RMAT + minimum_weight = 0 + maximum_weight = 1 + dtype = "FLOAT32" + df = _call_rmat( + scale, + num_edges, + create_using, + clip_and_flip=clip_and_flip, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_weights=include_edge_weights, + dtype=dtype, + minimum_weight=minimum_weight, + maximum_weight=maximum_weight) - df = _call_rmat(scale, num_edges, create_using) - assert len(df) == num_edges + if not include_edge_weights: + df["weights"] = 1 + # cupy coo_matrix only support 'float32', 'float64', 'complex64' and 'complex128'. + df["weights"] = df["weights"].astype("float32") + dim = df[["src", "dst"]].max().max() + 1 + src = df["src"].to_cupy() + dst = df["dst"].to_cupy() + weights = df["weights"].to_cupy() + adj_matrix = coo_matrix((weights, (src, dst)), shape=(dim, dim)).toarray() + + upper_coo = triu(adj_matrix) + diag = tril(upper_coo) + + if clip_and_flip: + # Except the diagonal, There should be no edge in the upper triangular part of + # the graph adjacency matrix. + assert diag.nnz == upper_coo.nnz + @pytest.mark.sg @pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") @@ -70,6 +298,7 @@ def test_rmat_return_type(graph_type): """ Verifies that the return type returned by rmat() is valid (or the proper exception is raised) based on inputs. + """ scale = 2 num_edges = (2**scale) * 4 From 60aac1819245d961f0b4f2e1b203aa2d63251907 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 26 Jun 2023 09:09:28 -0700 Subject: [PATCH 25/62] fix style --- python/cugraph/cugraph/generators/rmat.py | 4 +- .../cugraph/tests/generators/test_rmat.py | 224 +++++++++++------- 2 files changed, 138 insertions(+), 90 deletions(-) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index 9ef579a4ea1..304dd9ae682 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -491,7 +491,7 @@ def rmat( maximum_weight : float Maximum weight value to generate if 'include_edge_weights' is 'true' otherwise, this parameter is ignored. - + dtype : string The type of weight to generate ("FLOAT32" or "FLOAT64"), ignored unless include_weights is true @@ -699,7 +699,7 @@ def multi_rmat( max_edge_type : int Maximum edge type to generate if 'include_edge_types' is 'true' otherwise, this paramter is ignored. - + dtype : string The type of weight to generate ("FLOAT32" or "FLOAT64"), ignored unless include_weights is true diff --git a/python/cugraph/cugraph/tests/generators/test_rmat.py b/python/cugraph/cugraph/tests/generators/test_rmat.py index 633f4b30803..0daf7efbd5b 100644 --- a/python/cugraph/cugraph/tests/generators/test_rmat.py +++ b/python/cugraph/cugraph/tests/generators/test_rmat.py @@ -29,40 +29,46 @@ _graph_test_ids = [f"create_using={getattr(x,'__name__',str(x))}" for x in _graph_types] _clip_and_flip = [False, True] _clip_and_flip_test_ids = [f"clip_and_flip={x}" for x in _clip_and_flip] -_scramble_vertex_ids=[False, True] -_scramble_vertex_ids_test_ids = [f"scramble_vertex_ids={x}" for x in _scramble_vertex_ids] +_scramble_vertex_ids = [False, True] +_scramble_vertex_ids_test_ids = [ + f"scramble_vertex_ids={x}" for x in _scramble_vertex_ids +] _include_edge_weights = [False, True] -_include_edge_weights_test_ids = [f"include_edge_weights={x}" for x in _include_edge_weights] +_include_edge_weights_test_ids = [ + f"include_edge_weights={x}" for x in _include_edge_weights +] _dtype = [None, "FLOAT32", "FLOAT64", "INT32"] _dtype_test_ids = [f"_dtype={x}" for x in _dtype] _min_max_weight_values = [[None, None], [0, 1], [2, 5]] -_min_max_weight_values_test_ids = [f"min_max_weight_values={x}" for x in _min_max_weight_values] +_min_max_weight_values_test_ids = [ + f"min_max_weight_values={x}" for x in _min_max_weight_values +] _include_edge_ids = [False, True] _include_edge_ids_test_ids = [f"include_edge_ids={x}" for x in _include_edge_ids] _include_edge_types = [False, True] _include_edge_types_test_ids = [f"include_edge_types={x}" for x in _include_edge_types] _min_max_edge_type_values = [[None, None], [0, 1], [2, 5]] -_min_max_edge_type_values_test_ids = [f"min_max_edge_type_values={x}" for x in _min_max_edge_type_values] - - - +_min_max_edge_type_values_test_ids = [ + f"min_max_edge_type_values={x}" for x in _min_max_edge_type_values +] def _call_rmat( - scale, - num_edges, - create_using, - clip_and_flip=False, - scramble_vertex_ids=False, - include_edge_weights=False, - dtype=None, - minimum_weight=None, - maximum_weight=None, - include_edge_ids=False, - include_edge_types=False, - min_edge_type=None, - max_edge_type=None, - mg=False): + scale, + num_edges, + create_using, + clip_and_flip=False, + scramble_vertex_ids=False, + include_edge_weights=False, + dtype=None, + minimum_weight=None, + maximum_weight=None, + include_edge_ids=False, + include_edge_types=False, + min_edge_type=None, + max_edge_type=None, + mg=False, +): """ Simplifies calling RMAT by requiring only specific args that are varied by these tests and hard-coding all others. @@ -94,11 +100,19 @@ def _call_rmat( @pytest.mark.sg @pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") -@pytest.mark.parametrize("include_edge_weights", _include_edge_weights, ids=_include_edge_weights_test_ids) +@pytest.mark.parametrize( + "include_edge_weights", _include_edge_weights, ids=_include_edge_weights_test_ids +) @pytest.mark.parametrize("dtype", _dtype, ids=_dtype_test_ids) -@pytest.mark.parametrize("min_max_weight", _min_max_weight_values, ids=_min_max_weight_values_test_ids) -@pytest.mark.parametrize("scramble_vertex_ids", _scramble_vertex_ids, ids=_scramble_vertex_ids_test_ids) -def test_rmat_edge_weights(include_edge_weights, dtype, min_max_weight, scramble_vertex_ids): +@pytest.mark.parametrize( + "min_max_weight", _min_max_weight_values, ids=_min_max_weight_values_test_ids +) +@pytest.mark.parametrize( + "scramble_vertex_ids", _scramble_vertex_ids, ids=_scramble_vertex_ids_test_ids +) +def test_rmat_edge_weights( + include_edge_weights, dtype, min_max_weight, scramble_vertex_ids +): """ Verifies that the edge weights returned by rmat() are valid and raises an exception otherwise or if invalid values are passed to 'dtype', 'minimum_weight' or 'maximum_weight'. @@ -110,7 +124,11 @@ def test_rmat_edge_weights(include_edge_weights, dtype, min_max_weight, scramble minimum_weight, maximum_weight = min_max_weight if include_edge_weights: - if minimum_weight is None or maximum_weight is None or dtype not in ["FLOAT32", "FLOAT64"]: + if ( + minimum_weight is None + or maximum_weight is None + or dtype not in ["FLOAT32", "FLOAT64"] + ): with pytest.raises(ValueError): _call_rmat( scale, @@ -120,45 +138,54 @@ def test_rmat_edge_weights(include_edge_weights, dtype, min_max_weight, scramble include_edge_weights=include_edge_weights, dtype=dtype, minimum_weight=minimum_weight, - maximum_weight=maximum_weight) + maximum_weight=maximum_weight, + ) else: df = _call_rmat( - scale, - num_edges, - create_using, - scramble_vertex_ids=scramble_vertex_ids, - include_edge_weights=include_edge_weights, - dtype=dtype, - minimum_weight=minimum_weight, - maximum_weight=maximum_weight) + scale, + num_edges, + create_using, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_weights=include_edge_weights, + dtype=dtype, + minimum_weight=minimum_weight, + maximum_weight=maximum_weight, + ) # Check that there is a 'weights' column assert "weights" in df.columns - + edge_weights_err1 = df.query("{} - weights < 0.0001".format(maximum_weight)) - edge_weights_err2 = df.query("{} - weights > -0.0001".format(minimum_weight)) + edge_weights_err2 = df.query( + "{} - weights > -0.0001".format(minimum_weight) + ) # Check that edge weights values are between 'minimum_weight' and 'maximum_weight assert len(edge_weights_err1) == 0 assert len(edge_weights_err2) == 0 else: df = _call_rmat( - scale, - num_edges, - create_using, - scramble_vertex_ids=scramble_vertex_ids, - include_edge_weights=include_edge_weights, - dtype=dtype, - minimum_weight=minimum_weight, - maximum_weight=maximum_weight) + scale, + num_edges, + create_using, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_weights=include_edge_weights, + dtype=dtype, + minimum_weight=minimum_weight, + maximum_weight=maximum_weight, + ) assert len(df.columns) == 2 @pytest.mark.sg @pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") @pytest.mark.parametrize("scale", _scale_values, ids=_scale_test_ids) -@pytest.mark.parametrize("include_edge_ids", _include_edge_ids, ids=_include_edge_ids_test_ids) -@pytest.mark.parametrize("scramble_vertex_ids", _scramble_vertex_ids, ids=_scramble_vertex_ids_test_ids) +@pytest.mark.parametrize( + "include_edge_ids", _include_edge_ids, ids=_include_edge_ids_test_ids +) +@pytest.mark.parametrize( + "scramble_vertex_ids", _scramble_vertex_ids, ids=_scramble_vertex_ids_test_ids +) def test_rmat_edge_ids(scale, include_edge_ids, scramble_vertex_ids): """ Verifies that the edge ids returned by rmat() are valid and raises an exception otherwise. @@ -167,27 +194,38 @@ def test_rmat_edge_ids(scale, include_edge_ids, scramble_vertex_ids): num_edges = (2**scale) * 4 create_using = None # Returns the edgelist from RMAT df = _call_rmat( - scale, - num_edges, - create_using, - scramble_vertex_ids=scramble_vertex_ids, - include_edge_ids=include_edge_ids) - + scale, + num_edges, + create_using, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_ids=include_edge_ids, + ) + if include_edge_ids: assert "edge_id" in df.columns df["index"] = df.index edge_id_err = df.query("index != edge_id") assert len(edge_id_err) == 0 - + else: assert len(df.columns) == 2 @pytest.mark.sg @pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") -@pytest.mark.parametrize("include_edge_types", [_include_edge_types[0]], ids=[_include_edge_types_test_ids[0]]) -@pytest.mark.parametrize("min_max_edge_type", _min_max_edge_type_values, ids=_min_max_edge_type_values_test_ids) -@pytest.mark.parametrize("scramble_vertex_ids", _scramble_vertex_ids, ids=_scramble_vertex_ids_test_ids) +@pytest.mark.parametrize( + "include_edge_types", + [_include_edge_types[0]], + ids=[_include_edge_types_test_ids[0]], +) +@pytest.mark.parametrize( + "min_max_edge_type", + _min_max_edge_type_values, + ids=_min_max_edge_type_values_test_ids, +) +@pytest.mark.parametrize( + "scramble_vertex_ids", _scramble_vertex_ids, ids=_scramble_vertex_ids_test_ids +) def test_rmat_edge_types(include_edge_types, min_max_edge_type, scramble_vertex_ids): """ Verifies that the edge types returned by rmat() are valid and raises an exception otherwise or if @@ -209,17 +247,19 @@ def test_rmat_edge_types(include_edge_types, min_max_edge_type, scramble_vertex_ scramble_vertex_ids=scramble_vertex_ids, include_edge_types=include_edge_types, min_edge_type=min_edge_type, - max_edge_type=max_edge_type) + max_edge_type=max_edge_type, + ) else: df = _call_rmat( - scale, - num_edges, - create_using, - scramble_vertex_ids=scramble_vertex_ids, - include_edge_types=include_edge_types, - min_edge_type=min_edge_type, - max_edge_type=max_edge_type) - + scale, + num_edges, + create_using, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_types=include_edge_types, + min_edge_type=min_edge_type, + max_edge_type=max_edge_type, + ) + # Check that there is an 'edge_type' column assert "edge_type" in df.columns edge_types_err1 = df.query("{} < edge_type".format(max_edge_type)) @@ -227,26 +267,33 @@ def test_rmat_edge_types(include_edge_types, min_max_edge_type, scramble_vertex_ # Check that edge weights values are between 'min_edge_type' and 'max_edge_type' assert len(edge_types_err1) == 0 - assert len(edge_types_err2 ) == 0 + assert len(edge_types_err2) == 0 else: df = _call_rmat( - scale, - num_edges, - create_using, - scramble_vertex_ids=scramble_vertex_ids, - include_edge_types=include_edge_types, - min_edge_type=min_edge_type, - max_edge_type=max_edge_type) + scale, + num_edges, + create_using, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_types=include_edge_types, + min_edge_type=min_edge_type, + max_edge_type=max_edge_type, + ) assert len(df.columns) == 2 @pytest.mark.sg @pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") @pytest.mark.parametrize("scale", [2, 4, 8], ids=_scale_test_ids) -@pytest.mark.parametrize("include_edge_weights", _include_edge_weights, ids=_include_edge_weights_test_ids) +@pytest.mark.parametrize( + "include_edge_weights", _include_edge_weights, ids=_include_edge_weights_test_ids +) @pytest.mark.parametrize("clip_and_flip", _clip_and_flip, ids=_clip_and_flip_test_ids) -@pytest.mark.parametrize("scramble_vertex_ids", [False], ids=[_scramble_vertex_ids_test_ids[0]]) -def test_rmat_clip_and_flip(scale, include_edge_weights, clip_and_flip, scramble_vertex_ids): +@pytest.mark.parametrize( + "scramble_vertex_ids", [False], ids=[_scramble_vertex_ids_test_ids[0]] +) +def test_rmat_clip_and_flip( + scale, include_edge_weights, clip_and_flip, scramble_vertex_ids +): """ Verifies that there are edges only in the lower triangular part of the adjacency matrix when 'clip_and_flip' is set to 'true'. @@ -261,15 +308,16 @@ def test_rmat_clip_and_flip(scale, include_edge_weights, clip_and_flip, scramble maximum_weight = 1 dtype = "FLOAT32" df = _call_rmat( - scale, - num_edges, - create_using, - clip_and_flip=clip_and_flip, - scramble_vertex_ids=scramble_vertex_ids, - include_edge_weights=include_edge_weights, - dtype=dtype, - minimum_weight=minimum_weight, - maximum_weight=maximum_weight) + scale, + num_edges, + create_using, + clip_and_flip=clip_and_flip, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_weights=include_edge_weights, + dtype=dtype, + minimum_weight=minimum_weight, + maximum_weight=maximum_weight, + ) if not include_edge_weights: df["weights"] = 1 @@ -289,7 +337,7 @@ def test_rmat_clip_and_flip(scale, include_edge_weights, clip_and_flip, scramble # Except the diagonal, There should be no edge in the upper triangular part of # the graph adjacency matrix. assert diag.nnz == upper_coo.nnz - + @pytest.mark.sg @pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") From 6eb8520ea89e3c3e05cf1878012a6870db99bee5 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 26 Jun 2023 09:18:03 -0700 Subject: [PATCH 26/62] fix style --- .../cugraph/tests/generators/test_rmat.py | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/python/cugraph/cugraph/tests/generators/test_rmat.py b/python/cugraph/cugraph/tests/generators/test_rmat.py index 0daf7efbd5b..bf96ddeb270 100644 --- a/python/cugraph/cugraph/tests/generators/test_rmat.py +++ b/python/cugraph/cugraph/tests/generators/test_rmat.py @@ -114,8 +114,9 @@ def test_rmat_edge_weights( include_edge_weights, dtype, min_max_weight, scramble_vertex_ids ): """ - Verifies that the edge weights returned by rmat() are valid and raises an exception otherwise or if - invalid values are passed to 'dtype', 'minimum_weight' or 'maximum_weight'. + Verifies that the edge weights returned by rmat() are valid and raises an + exception otherwise or if invalid values are passed to 'dtype', 'minimum_weight' + or 'maximum_weight'. """ scale = 2 @@ -160,7 +161,8 @@ def test_rmat_edge_weights( "{} - weights > -0.0001".format(minimum_weight) ) - # Check that edge weights values are between 'minimum_weight' and 'maximum_weight + # Check that edge weights values are between 'minimum_weight' + # and 'maximum_weight. assert len(edge_weights_err1) == 0 assert len(edge_weights_err2) == 0 else: @@ -188,7 +190,8 @@ def test_rmat_edge_weights( ) def test_rmat_edge_ids(scale, include_edge_ids, scramble_vertex_ids): """ - Verifies that the edge ids returned by rmat() are valid and raises an exception otherwise. + Verifies that the edge ids returned by rmat() are valid and raises an + exception otherwise. """ num_edges = (2**scale) * 4 @@ -228,8 +231,9 @@ def test_rmat_edge_ids(scale, include_edge_ids, scramble_vertex_ids): ) def test_rmat_edge_types(include_edge_types, min_max_edge_type, scramble_vertex_ids): """ - Verifies that the edge types returned by rmat() are valid and raises an exception otherwise or if - invalid values are passed to 'min_edge_type' or 'max_edge_type'. + Verifies that the edge types returned by rmat() are valid and raises an + exception otherwise or if invalid values are passed to 'min_edge_type' or + 'max_edge_type'. """ scale = 2 @@ -265,7 +269,8 @@ def test_rmat_edge_types(include_edge_types, min_max_edge_type, scramble_vertex_ edge_types_err1 = df.query("{} < edge_type".format(max_edge_type)) edge_types_err2 = df.query("{} > edge_type".format(min_edge_type)) - # Check that edge weights values are between 'min_edge_type' and 'max_edge_type' + # Check that edge weights values are between 'min_edge_type' + # and 'max_edge_type'. assert len(edge_types_err1) == 0 assert len(edge_types_err2) == 0 else: @@ -295,11 +300,11 @@ def test_rmat_clip_and_flip( scale, include_edge_weights, clip_and_flip, scramble_vertex_ids ): """ - Verifies that there are edges only in the lower triangular part of the adjacency matrix - when 'clip_and_flip' is set to 'true'. + Verifies that there are edges only in the lower triangular part of + the adjacency matrix when 'clip_and_flip' is set to 'true'. - # FIXME: 'scramble_vertex_ids' nullifies the effect of 'clip_and_flip' therefore, both - # flags should not be set to 'True'. + FIXME: 'scramble_vertex_ids' nullifies the effect of 'clip_and_flip' therefore + both flags should not be set to 'True'. """ num_edges = (2**scale) * 4 @@ -321,7 +326,8 @@ def test_rmat_clip_and_flip( if not include_edge_weights: df["weights"] = 1 - # cupy coo_matrix only support 'float32', 'float64', 'complex64' and 'complex128'. + # cupy coo_matrix only support 'float32', 'float64', 'complex64' + # and 'complex128'. df["weights"] = df["weights"].astype("float32") dim = df[["src", "dst"]].max().max() + 1 From d8ea00870eb508d463f4f56681dc772d0ea7c353 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Wed, 28 Jun 2023 02:39:08 -0700 Subject: [PATCH 27/62] update docs and consolidate parameter check's functions --- python/cugraph/cugraph/generators/rmat.py | 120 +++++++++------------- 1 file changed, 46 insertions(+), 74 deletions(-) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index 304dd9ae682..dc1c7ce4078 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -30,6 +30,12 @@ def _ensure_args_rmat( a=None, b=None, c=None, + n_edgelists=None, + min_scale=None, + max_scale=None, + edge_factor=None, + size_distribution=None, + edge_distribution=None, seed=None, clip_and_flip=None, scramble_vertex_ids=None, @@ -46,8 +52,8 @@ def _ensure_args_rmat( multi_rmat=False, ): """ - Ensures the args passed in are usable for the rmat() API, raises the - appropriate exception if incorrect, else returns None. + Ensures the args passed in are usable for the rmat() or multi rmat() API, + raises the appropriate exception if incorrect, else returns None. """ if create_using is not None: if isinstance(create_using, cugraph.Graph): @@ -65,19 +71,8 @@ def _ensure_args_rmat( f"{type(create_using)}" ) - if multi_rmat is False: - if not isinstance(scale, int): - raise TypeError("'scale' must be an int") - if not isinstance(num_edges, int): - raise TypeError("'num_edges' must be an int") - if a + b + c > 1: - raise ValueError("a + b + c should be non-negative and no larger than 1.0") - if clip_and_flip not in [True, False]: - raise ValueError("'clip_and_flip' must be a bool") - if scramble_vertex_ids not in [True, False]: - raise ValueError("'scramble_vertex_ids' must be a bool") - if not isinstance(seed, int): - raise TypeError("'seed' must be an int") + if not isinstance(seed, int): + raise TypeError("'seed' must be an int") if include_edge_weights: if include_edge_weights not in [True, False]: raise ValueError("'include_edge_weights' must be a bool") @@ -102,42 +97,31 @@ def _ensure_args_rmat( "'min_edge_type' and 'max_edge_type' must not be 'None' " "if 'include_edge_types' is 'true'" ) - - -def _ensure_args_multi_rmat( - n_edgelists, - min_scale, - max_scale, - edge_factor, - size_distribution, - edge_distribution, - seed, - clip_and_flip, - scramble_vertex_ids, -): - """ - Ensures the args passed in are usable for the multi_rmat() API, raises the - appropriate exception if incorrect, else returns None. - - """ - if not isinstance(n_edgelists, int): - raise TypeError("'n_edgelists' must be an int") - if not isinstance(min_scale, int): - raise TypeError("'min_scale' must be an int") - if not isinstance(max_scale, int): - raise TypeError("'max_scale' must be an int") - if not isinstance(edge_factor, int): - raise TypeError("'edge_factor' must be an int") - if size_distribution not in [0, 1]: - raise TypeError("'size_distribution' must be either 0 or 1") - if edge_distribution not in [0, 1]: - raise TypeError("'edge_distribution' must be either 0 or 1") - if clip_and_flip not in [True, False]: - raise ValueError("'clip_and_flip' must be a bool") - if scramble_vertex_ids not in [True, False]: - raise ValueError("'scramble_vertex_ids' must be a bool") - if not isinstance(seed, int): - raise TypeError("'seed' must be an int") + + if multi_rmat: + if not isinstance(n_edgelists, int): + raise TypeError("'n_edgelists' must be an int") + if not isinstance(min_scale, int): + raise TypeError("'min_scale' must be an int") + if not isinstance(max_scale, int): + raise TypeError("'max_scale' must be an int") + if not isinstance(edge_factor, int): + raise TypeError("'edge_factor' must be an int") + if size_distribution not in [0, 1]: + raise TypeError("'size_distribution' must be either 0 or 1") + if edge_distribution not in [0, 1]: + raise TypeError("'edge_distribution' must be either 0 or 1") + else: + if not isinstance(scale, int): + raise TypeError("'scale' must be an int") + if not isinstance(num_edges, int): + raise TypeError("'num_edges' must be an int") + if a + b + c > 1: + raise ValueError("a + b + c should be non-negative and no larger than 1.0") + if clip_and_flip not in [True, False]: + raise ValueError("'clip_and_flip' must be a bool") + if scramble_vertex_ids not in [True, False]: + raise ValueError("'scramble_vertex_ids' must be a bool") def _sg_rmat( @@ -525,7 +509,7 @@ def rmat( Returns ------- - instance of cugraph.Graph + instance of cugraph.Graph or cudf or dask_cudf DataFrame Examples -------- @@ -704,13 +688,6 @@ def multi_rmat( The type of weight to generate ("FLOAT32" or "FLOAT64"), ignored unless include_weights is true - create_using : cugraph Graph type or None The graph type to construct - containing the generated edges and vertices. If None is specified, the - edgelist cuDF DataFrame (or dask_cudf DataFrame for MG) is returned - as-is. This is useful for benchmarking Graph construction steps that - require raw data that includes potential self-loops, isolated vertices, - and duplicated edges. Default is cugraph.Graph. - mg : bool, optional (default=False) If True, R-MATs generation occurs across multiple GPUs. If False, only a single GPU is used. Default is False (single-GPU) @@ -720,22 +697,14 @@ def multi_rmat( ------- list of cugraph.Graph instances """ - _ensure_args_multi_rmat( - n_edgelists, - min_scale, - max_scale, - edge_factor, - size_distribution, - edge_distribution, - seed, - clip_and_flip, - scramble_vertex_ids, - ) - - # FIXME: consolidate '_ensure_args_rmat' and '_ensure_args_multi_rmat' - # to have a single function check since both implementations share similar - # arguments now _ensure_args_rmat( + n_edgelists=n_edgelists, + min_scale=min_scale, + max_scale=max_scale, + edge_factor=edge_factor, + size_distribution=size_distribution, + edge_distribution=edge_distribution, + seed=seed, include_edge_weights=include_edge_weights, minimum_weight=minimum_weight, maximum_weight=maximum_weight, @@ -745,6 +714,8 @@ def multi_rmat( min_edge_type=min_edge_type, max_edge_type=max_edge_type, multi_rmat=True, + clip_and_flip=clip_and_flip, + scramble_vertex_ids=scramble_vertex_ids, ) edgelists = pylibcugraph_generate_rmat_edgelists( @@ -757,6 +728,7 @@ def multi_rmat( size_distribution, edge_distribution, clip_and_flip, + scramble_vertex_ids, include_edge_weights, minimum_weight, maximum_weight, From eaa76a992d3f2dbdbb4542455b0bab873ca7bcc9 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Sun, 9 Jul 2023 00:40:56 -0700 Subject: [PATCH 28/62] do not ignore deprecated warning --- python/cugraph/cugraph/tests/generators/test_rmat.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/python/cugraph/cugraph/tests/generators/test_rmat.py b/python/cugraph/cugraph/tests/generators/test_rmat.py index bf96ddeb270..5a02dfe7147 100644 --- a/python/cugraph/cugraph/tests/generators/test_rmat.py +++ b/python/cugraph/cugraph/tests/generators/test_rmat.py @@ -99,7 +99,6 @@ def _call_rmat( @pytest.mark.sg -@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") @pytest.mark.parametrize( "include_edge_weights", _include_edge_weights, ids=_include_edge_weights_test_ids ) @@ -180,7 +179,6 @@ def test_rmat_edge_weights( @pytest.mark.sg -@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") @pytest.mark.parametrize("scale", _scale_values, ids=_scale_test_ids) @pytest.mark.parametrize( "include_edge_ids", _include_edge_ids, ids=_include_edge_ids_test_ids @@ -215,7 +213,6 @@ def test_rmat_edge_ids(scale, include_edge_ids, scramble_vertex_ids): @pytest.mark.sg -@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") @pytest.mark.parametrize( "include_edge_types", [_include_edge_types[0]], @@ -287,7 +284,6 @@ def test_rmat_edge_types(include_edge_types, min_max_edge_type, scramble_vertex_ @pytest.mark.sg -@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") @pytest.mark.parametrize("scale", [2, 4, 8], ids=_scale_test_ids) @pytest.mark.parametrize( "include_edge_weights", _include_edge_weights, ids=_include_edge_weights_test_ids @@ -346,7 +342,6 @@ def test_rmat_clip_and_flip( @pytest.mark.sg -@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") @pytest.mark.parametrize("graph_type", _graph_types, ids=_graph_test_ids) def test_rmat_return_type(graph_type): """ From 222a851ddee5c8edcd253e35edadc0b3001d7758 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Sun, 9 Jul 2023 01:45:24 -0700 Subject: [PATCH 29/62] pass argument by keyword --- python/cugraph/cugraph/generators/rmat.py | 36 +++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index dc1c7ce4078..2929b126d23 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -533,24 +533,24 @@ def rmat( """ _ensure_args_rmat( - scale, - num_edges, - a, - b, - c, - seed, - clip_and_flip, - scramble_vertex_ids, - include_edge_weights, - minimum_weight, - maximum_weight, - dtype, - include_edge_ids, - include_edge_types, - min_edge_type, - max_edge_type, - create_using, - mg, + scale=scale, + num_edges=num_edges, + a=a, + b=b, + c=c, + seed=seed, + clip_and_flip=clip_and_flip, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_weights=include_edge_weights, + minimum_weight=minimum_weight, + maximum_weight=maximum_weight, + dtype=dtype, + include_edge_ids=include_edge_ids, + include_edge_types=include_edge_types, + min_edge_type=min_edge_type, + max_edge_type=max_edge_type, + create_using=create_using, + mg=mg, ) if mg: From b6da671a60de02f6b4306a2aa829cfd05bd0339c Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Sun, 9 Jul 2023 02:12:00 -0700 Subject: [PATCH 30/62] update tests docstrings --- .../cugraph/tests/generators/test_rmat.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/python/cugraph/cugraph/tests/generators/test_rmat.py b/python/cugraph/cugraph/tests/generators/test_rmat.py index 5a02dfe7147..da8e11a0008 100644 --- a/python/cugraph/cugraph/tests/generators/test_rmat.py +++ b/python/cugraph/cugraph/tests/generators/test_rmat.py @@ -113,9 +113,8 @@ def test_rmat_edge_weights( include_edge_weights, dtype, min_max_weight, scramble_vertex_ids ): """ - Verifies that the edge weights returned by rmat() are valid and raises an - exception otherwise or if invalid values are passed to 'dtype', 'minimum_weight' - or 'maximum_weight'. + Verifies that the edge weights returned by rmat() are valid. Also verifies that + valid values are passed to 'dtype', 'minimum_weight' and 'maximum_weight'. """ scale = 2 @@ -188,8 +187,7 @@ def test_rmat_edge_weights( ) def test_rmat_edge_ids(scale, include_edge_ids, scramble_vertex_ids): """ - Verifies that the edge ids returned by rmat() are valid and raises an - exception otherwise. + Verifies that the edge ids returned by rmat() are valid. """ num_edges = (2**scale) * 4 @@ -215,8 +213,8 @@ def test_rmat_edge_ids(scale, include_edge_ids, scramble_vertex_ids): @pytest.mark.sg @pytest.mark.parametrize( "include_edge_types", - [_include_edge_types[0]], - ids=[_include_edge_types_test_ids[0]], + _include_edge_types, + ids=_include_edge_types_test_ids, ) @pytest.mark.parametrize( "min_max_edge_type", @@ -228,9 +226,8 @@ def test_rmat_edge_ids(scale, include_edge_ids, scramble_vertex_ids): ) def test_rmat_edge_types(include_edge_types, min_max_edge_type, scramble_vertex_ids): """ - Verifies that the edge types returned by rmat() are valid and raises an - exception otherwise or if invalid values are passed to 'min_edge_type' or - 'max_edge_type'. + Verifies that the edge types returned by rmat() are valid and that valid values + are passed for 'min_edge_type' and 'max_edge_type'. """ scale = 2 From 29f702a7ec58c305ad889f895424a8620a4d956e Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Sun, 9 Jul 2023 02:14:46 -0700 Subject: [PATCH 31/62] rename variable --- python/cugraph/cugraph/generators/rmat.py | 114 +++++++++++----------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index 2929b126d23..60f673888b9 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -45,8 +45,8 @@ def _ensure_args_rmat( dtype=None, include_edge_ids=None, include_edge_types=None, - min_edge_type=None, - max_edge_type=None, + min_edge_type_value=None, + max_edge_type_value=None, create_using=None, mg=None, multi_rmat=False, @@ -79,12 +79,12 @@ def _ensure_args_rmat( if maximum_weight is None or minimum_weight is None: raise ValueError( "'maximum_weight' and 'minimum_weight' must not be 'None' " - "if 'include_edge_weights' is 'true'" + "if 'include_edge_weights' is True" ) if dtype not in ["FLOAT32", "FLOAT64"]: raise ValueError( "dtype must be either 'FLOAT32' or 'FLOAT64' if 'include_edge_weights' " - "is 'true'" + "is True" ) if include_edge_ids: if include_edge_ids not in [True, False]: @@ -92,10 +92,10 @@ def _ensure_args_rmat( if include_edge_types: if include_edge_types not in [True, False]: raise ValueError("'include_edge_types' must be a bool") - if min_edge_type is None and max_edge_type is None: + if min_edge_type_value is None and max_edge_type_value is None: raise ValueError( - "'min_edge_type' and 'max_edge_type' must not be 'None' " - "if 'include_edge_types' is 'true'" + "'min_edge_type_value' and 'max_edge_type_value' must not be 'None' " + "if 'include_edge_types' is True" ) if multi_rmat: @@ -139,8 +139,8 @@ def _sg_rmat( dtype, include_edge_ids, include_edge_types, - min_edge_type, - max_edge_type, + min_edge_type_value, + max_edge_type_value, create_using=cugraph.Graph, ): """ @@ -169,8 +169,8 @@ def _sg_rmat( dtype, include_edge_ids, include_edge_types, - min_edge_type, - max_edge_type, + min_edge_type_value, + max_edge_type_value, multi_gpu, ) @@ -249,8 +249,8 @@ def _mg_rmat( dtype, include_edge_ids, include_edge_types, - min_edge_type, - max_edge_type, + min_edge_type_value, + max_edge_type_value, create_using=cugraph.Graph, ): """ @@ -285,8 +285,8 @@ def _mg_rmat( dtype, include_edge_ids, include_edge_types, - min_edge_type, - max_edge_type, + min_edge_type_value, + max_edge_type_value, workers=worker_list[i], ) result.append(future) @@ -355,8 +355,8 @@ def _call_rmat( dtype, include_edge_ids, include_edge_types, - min_edge_type, - max_edge_type, + min_edge_type_value, + max_edge_type_value, ): """ Callable passed to dask client.submit calls that extracts the individual @@ -380,8 +380,8 @@ def _call_rmat( dtype, include_edge_ids, include_edge_types, - min_edge_type, - max_edge_type, + min_edge_type_value, + max_edge_type_value, multi_gpu, ) @@ -420,8 +420,8 @@ def rmat( dtype=None, include_edge_ids=False, include_edge_types=False, - min_edge_type=None, - max_edge_type=None, + min_edge_type_value=None, + max_edge_type_value=None, create_using=cugraph.Graph, mg=False, ): @@ -432,7 +432,7 @@ def rmat( Parameters ---------- scale : int - Scale factor to set the number of vertices in the graph Vertex IDs have + Scale factor to set the number of vertices in the graph. Vertex IDs have values in [0, V), where V = 1 << 'scale' num_edges : int @@ -457,7 +457,7 @@ def rmat( clip_and_flip : bool, optional (default=False) Flag controlling whether to generate edges only in the lower triangular part (including the diagonal) of the graph adjacency matrix - (if set to 'true') or not (if set to 'false). + (if set to True) or not (if set to 'false). scramble_vertex_ids : bool, optional (default=False) Flag controlling whether to scramble vertex ID bits (if set to `true`) @@ -466,14 +466,14 @@ def rmat( include_edge_weights : bool, optional (default=False) Flag controlling whether to generate edges with weights - (if set to 'true') or not (if set to 'false'). + (if set to True) or not (if set to False). minimum_weight : float - Minimum weight value to generate if 'include_edge_weights' is 'true' + Minimum weight value to generate if 'include_edge_weights' is True otherwise, this parameter is ignored. maximum_weight : float - Maximum weight value to generate if 'include_edge_weights' is 'true' + Maximum weight value to generate if 'include_edge_weights' is True otherwise, this parameter is ignored. dtype : string @@ -482,18 +482,18 @@ def rmat( include_edge_ids : bool, optional (default=False) Flag controlling whether to generate edges with ids - (if set to 'true') or not (if set to 'false'). + (if set to True) or not (if set to False). include_edge_types : bool, optional (default=False) Flag controlling whether to generate edges with types - (if set to 'true') or not (if set to 'false'). + (if set to True) or not (if set to False). - min_edge_type : int - Minimum edge type to generate if 'include_edge_types' is 'true' + min_edge_type_value : int + Minimum edge type to generate if 'include_edge_types' is True otherwise, this parameter is ignored. - max_edge_type : int - Maximum edge type to generate if 'include_edge_types' is 'true' + max_edge_type_value : int + Maximum edge type to generate if 'include_edge_types' is True otherwise, this paramter is ignored. create_using : cugraph Graph type or None The graph type to construct @@ -547,8 +547,8 @@ def rmat( dtype=dtype, include_edge_ids=include_edge_ids, include_edge_types=include_edge_types, - min_edge_type=min_edge_type, - max_edge_type=max_edge_type, + min_edge_type_value=min_edge_type_value, + max_edge_type_value=max_edge_type_value, create_using=create_using, mg=mg, ) @@ -569,8 +569,8 @@ def rmat( dtype, include_edge_ids, include_edge_types, - min_edge_type, - max_edge_type, + min_edge_type_value, + max_edge_type_value, create_using, ) else: @@ -589,8 +589,8 @@ def rmat( dtype, include_edge_ids, include_edge_types, - min_edge_type, - max_edge_type, + min_edge_type_value, + max_edge_type_value, create_using, ) @@ -611,8 +611,8 @@ def multi_rmat( dtype=None, include_edge_ids=False, include_edge_types=False, - min_edge_type=None, - max_edge_type=None, + min_edge_type_value=None, + max_edge_type_value=None, mg=False, ): """ @@ -646,42 +646,42 @@ def multi_rmat( seed : int Seed value for the random number generator - clip_and_flip : bool + clip_and_flip : bool, optional (default=False) Flag controlling whether to generate edges only in the lower triangular part (including the diagonal) of the graph adjacency matrix - (if set to 'true') or not (if set to 'false') + (if set to True) or not (if set to False) scramble_vertex_ids : bool - Flag controlling whether to scramble vertex ID bits (if set to 'true') - or not (if set to 'false'); scrambling vertx ID bits breaks correlation + Flag controlling whether to scramble vertex ID bits (if set to True) + or not (if set to False); scrambling vertx ID bits breaks correlation between vertex ID values and vertex degrees include_edge_weights : bool, optional (default=False) Flag controlling whether to generate edges with weights - (if set to 'true') or not (if set to 'false'). + (if set to True) or not (if set to '). minimum_weight : float - Minimum weight value to generate if 'include_edge_weights' is 'true' + Minimum weight value to generate if 'include_edge_weights' is True otherwise, this parameter is ignored. maximum_weight : float - Maximum weight value to generate if 'include_edge_weights' is 'true' + Maximum weight value to generate if 'include_edge_weights' is True otherwise, this parameter is ignored. include_edge_ids : bool, optional (default=False) Flag controlling whether to generate edges with ids - (if set to 'true') or not (if set to 'false'). + (if set to True) or not (if set to False). include_edge_types : bool, optional (default=False) Flag controlling whether to generate edges with types - (if set to 'true') or not (if set to 'false'). + (if set to True) or not (if set to False). - min_edge_type : int - Minimum edge type to generate if 'include_edge_types' is 'true' + min_edge_type_value : int + Minimum edge type to generate if 'include_edge_types' is True otherwise, this parameter is ignored. - max_edge_type : int - Maximum edge type to generate if 'include_edge_types' is 'true' + max_edge_type_value : int + Maximum edge type to generate if 'include_edge_types' is True otherwise, this paramter is ignored. dtype : string @@ -711,8 +711,8 @@ def multi_rmat( dtype=dtype, include_edge_ids=include_edge_ids, include_edge_types=include_edge_types, - min_edge_type=min_edge_type, - max_edge_type=max_edge_type, + min_edge_type_value=min_edge_type_value, + max_edge_type_value=max_edge_type_value, multi_rmat=True, clip_and_flip=clip_and_flip, scramble_vertex_ids=scramble_vertex_ids, @@ -735,8 +735,8 @@ def multi_rmat( dtype, include_edge_ids, include_edge_types, - min_edge_type, - max_edge_type, + min_edge_type_value, + max_edge_type_value, mg, ) From fad3d83faacb28c43886ed76e31ac133d5c3716b Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Sun, 9 Jul 2023 02:15:32 -0700 Subject: [PATCH 32/62] remove legacy rmat --- .../cugraph/cugraph/generators/CMakeLists.txt | 22 --- python/cugraph/cugraph/generators/rmat.pxd | 53 ------ .../cugraph/generators/rmat_wrapper.pyx | 165 ------------------ 3 files changed, 240 deletions(-) delete mode 100644 python/cugraph/cugraph/generators/CMakeLists.txt delete mode 100644 python/cugraph/cugraph/generators/rmat.pxd delete mode 100644 python/cugraph/cugraph/generators/rmat_wrapper.pyx diff --git a/python/cugraph/cugraph/generators/CMakeLists.txt b/python/cugraph/cugraph/generators/CMakeLists.txt deleted file mode 100644 index 037e5254f21..00000000000 --- a/python/cugraph/cugraph/generators/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# ============================================================================= -# Copyright (c) 2022, 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 -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software distributed under the License -# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express -# or implied. See the License for the specific language governing permissions and limitations under -# the License. -# ============================================================================= - -set(cython_sources rmat_wrapper.pyx) -set(linked_libraries cugraph::cugraph) -rapids_cython_create_modules( - CXX - SOURCE_FILES "${cython_sources}" - LINKED_LIBRARIES "${linked_libraries}" MODULE_PREFIX generators_ - ASSOCIATED_TARGETS cugraph -) diff --git a/python/cugraph/cugraph/generators/rmat.pxd b/python/cugraph/cugraph/generators/rmat.pxd deleted file mode 100644 index 7c3a4165e3e..00000000000 --- a/python/cugraph/cugraph/generators/rmat.pxd +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright (c) 2021-2022, 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 -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from libcpp.memory cimport unique_ptr -from libcpp cimport bool -from libcpp.vector cimport vector -from libcpp.utility cimport pair - -from rmm._lib.device_buffer cimport device_buffer - -from pylibraft.common.handle cimport handle_t -from cugraph.structure.graph_utilities cimport graph_generator_t - - -cdef extern from "cugraph/graph_generators.hpp" namespace "cugraph": - ctypedef enum generator_distribution_t: - POWER_LAW "cugraph::generator_distribution_t::POWER_LAW" - UNIFORM "cugraph::generator_distribution_t::UNIFORM" - - -cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": - cdef unique_ptr[graph_generator_t] call_generate_rmat_edgelist[vertex_t] ( - const handle_t &handle, - size_t scale, - size_t num_edges, - double a, - double b, - double c, - int seed, - bool clip_and_flip, - bool scramble_vertex_ids) except + - - cdef vector[pair[unique_ptr[device_buffer], unique_ptr[device_buffer]]] call_generate_rmat_edgelists[vertex_t]( - const handle_t &handle, - size_t n_edgelists, - size_t min_scale, - size_t max_scale, - size_t edge_factor, - generator_distribution_t size_distribution, - generator_distribution_t edge_distribution, - int seed, - bool clip_and_flip, - bool scramble_vertex_ids) except + diff --git a/python/cugraph/cugraph/generators/rmat_wrapper.pyx b/python/cugraph/cugraph/generators/rmat_wrapper.pyx deleted file mode 100644 index 7f1e7f5a219..00000000000 --- a/python/cugraph/cugraph/generators/rmat_wrapper.pyx +++ /dev/null @@ -1,165 +0,0 @@ -# Copyright (c) 2021-2022, 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 -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from libc.stdint cimport uintptr_t -from libcpp cimport bool -from libcpp.memory cimport unique_ptr -from libcpp.vector cimport vector -from libcpp.utility cimport move, pair -from cython.operator cimport dereference as deref -import numpy as np - -from rmm._lib.device_buffer cimport device_buffer -import cudf - -from pylibraft.common.handle cimport handle_t -from cugraph.structure.graph_utilities cimport graph_generator_t -from cugraph.generators.rmat cimport (call_generate_rmat_edgelist, - call_generate_rmat_edgelists, - generator_distribution_t, - UNIFORM, - POWER_LAW, - ) -from cugraph.structure.graph_primtypes cimport move_device_buffer_to_column - - -def generate_rmat_edgelist( - scale, - num_edges, - a, - b, - c, - seed, - clip_and_flip, - scramble_vertex_ids, - handle=None -): - - vertex_t = np.dtype("int32") - if (2**scale) > (2**31 - 1): - vertex_t = np.dtype("int64") - - cdef unique_ptr[handle_t] handle_ptr - cdef size_t handle_size_t - - if handle is None: - handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get() - else: - handle_size_t = handle.getHandle() - handle_ = handle_size_t - - cdef unique_ptr[graph_generator_t] gg_ret_ptr - - if (vertex_t==np.dtype("int32")): - gg_ret_ptr = move(call_generate_rmat_edgelist[int]( deref(handle_), - scale, - num_edges, - a, - b, - c, - seed, - clip_and_flip, - scramble_vertex_ids)) - else: # (vertex_t == np.dtype("int64")) - gg_ret_ptr = move(call_generate_rmat_edgelist[long]( deref(handle_), - scale, - num_edges, - a, - b, - c, - seed, - clip_and_flip, - scramble_vertex_ids)) - - gg_ret = move(gg_ret_ptr.get()[0]) - - set_source = move_device_buffer_to_column(move(gg_ret.d_source), vertex_t) - set_destination = move_device_buffer_to_column(move(gg_ret.d_destination), vertex_t) - - df = cudf.DataFrame() - df['src'] = set_source - df['dst'] = set_destination - - return df - - -def generate_rmat_edgelists( - n_edgelists, - min_scale, - max_scale, - edge_factor, - size_distribution, - edge_distribution, - seed, - clip_and_flip, - scramble_vertex_ids - ): - - vertex_t = np.dtype("int32") - if (2**max_scale) > (2**31 - 1): - vertex_t = np.dtype("int64") - - cdef unique_ptr[handle_t] handle_ptr - handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get() - - cdef generator_distribution_t s_distribution - cdef generator_distribution_t e_distribution - if size_distribution == 0: - s_distribution= POWER_LAW - else : - s_distribution= UNIFORM - if edge_distribution == 0: - e_distribution= POWER_LAW - else : - e_distribution= UNIFORM - - cdef vector[pair[unique_ptr[device_buffer], unique_ptr[device_buffer]]] gg_ret_ptr - - if (vertex_t==np.dtype("int32")): - gg_ret_ptr = move(call_generate_rmat_edgelists[int]( deref(handle_), - n_edgelists, - min_scale, - max_scale, - edge_factor, - s_distribution, - e_distribution, - seed, - clip_and_flip, - scramble_vertex_ids)) - else: # (vertex_t == np.dtype("int64")) - gg_ret_ptr = move(call_generate_rmat_edgelists[long]( deref(handle_), - n_edgelists, - min_scale, - max_scale, - edge_factor, - s_distribution, - e_distribution, - seed, - clip_and_flip, - scramble_vertex_ids)) - list_df = [] - - for i in range(n_edgelists): - set_source = move_device_buffer_to_column(move(gg_ret_ptr[i].first), vertex_t) - set_destination = move_device_buffer_to_column(move(gg_ret_ptr[i].second), vertex_t) - - df = cudf.DataFrame() - df['src'] = set_source - df['dst'] = set_destination - - list_df.append(df) - - #Return a list of dataframes - return list_df From 083a8ac66f8fb8cc5aa4df8d1b8c5bc8c7570c15 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Sun, 9 Jul 2023 02:17:04 -0700 Subject: [PATCH 33/62] remove cython.cu --- cpp/include/cugraph/utilities/cython.hpp | 71 ---------- cpp/src/utilities/cython.cu | 167 ----------------------- 2 files changed, 238 deletions(-) delete mode 100644 cpp/include/cugraph/utilities/cython.hpp delete mode 100644 cpp/src/utilities/cython.cu diff --git a/cpp/include/cugraph/utilities/cython.hpp b/cpp/include/cugraph/utilities/cython.hpp deleted file mode 100644 index 2573752cb98..00000000000 --- a/cpp/include/cugraph/utilities/cython.hpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2020-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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include -#include - -#include - -#include - -namespace cugraph { -namespace cython { - -struct graph_generator_t { - std::unique_ptr d_source; - std::unique_ptr d_destination; -}; - -// Wrapper for calling graph generator -template -std::unique_ptr call_generate_rmat_edgelist(raft::handle_t const& handle, - size_t scale, - size_t num_edges, - double a, - double b, - double c, - uint64_t seed, - bool clip_and_flip, - bool scramble_vertex_ids); -template -std::vector, std::unique_ptr>> -call_generate_rmat_edgelists(raft::handle_t const& handle, - size_t n_edgelists, - size_t min_scale, - size_t max_scale, - size_t edge_factor, - cugraph::generator_distribution_t size_distribution, - cugraph::generator_distribution_t edge_distribution, - uint64_t seed, - bool clip_and_flip, - bool scramble_vertex_ids); - -// Helper for setting up subcommunicators, typically called as part of the -// user-initiated comms initialization in Python. -// -// raft::handle_t& handle -// Raft handle for which the new subcommunicators will be created. The -// subcommunicators will then be accessible from the handle passed to the -// parallel processes. -// -// size_t row_comm_size -// Number of items in a partition row (ie. pcols), needed for creating the -// appropriate number of subcommunicator instances. -void init_subcomms(raft::handle_t& handle, size_t row_comm_size); - -} // namespace cython -} // namespace cugraph diff --git a/cpp/src/utilities/cython.cu b/cpp/src/utilities/cython.cu deleted file mode 100644 index 36e231ad570..00000000000 --- a/cpp/src/utilities/cython.cu +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2020-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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include - -#include - -#include -#include - -namespace cugraph { -namespace cython { - -// Wrapper for graph generate_rmat_edgelist() -// to expose the API to cython -// enum class generator_distribution_t { POWER_LAW = 0, UNIFORM }; -template -std::unique_ptr call_generate_rmat_edgelist(raft::handle_t const& handle, - size_t scale, - size_t num_edges, - double a, - double b, - double c, - uint64_t seed, - bool clip_and_flip, - bool scramble_vertex_ids) -{ - auto src_dst_tuple = cugraph::generate_rmat_edgelist( - handle, scale, num_edges, a, b, c, seed, clip_and_flip); - - if (scramble_vertex_ids) { - src_dst_tuple = cugraph::scramble_vertex_ids( - handle, std::move(std::get<0>(src_dst_tuple)), std::move(std::get<1>(src_dst_tuple)), scale); - } - - graph_generator_t gg_vals{ - std::make_unique(std::get<0>(src_dst_tuple).release()), - std::make_unique(std::get<1>(src_dst_tuple).release())}; - - return std::make_unique(std::move(gg_vals)); -} - -template -std::vector, std::unique_ptr>> -call_generate_rmat_edgelists(raft::handle_t const& handle, - size_t n_edgelists, - size_t min_scale, - size_t max_scale, - size_t edge_factor, - cugraph::generator_distribution_t size_distribution, - cugraph::generator_distribution_t edge_distribution, - uint64_t seed, - bool clip_and_flip, - bool scramble_vertex_ids) -{ - auto src_dst_vec_tuple = cugraph::generate_rmat_edgelists(handle, - n_edgelists, - min_scale, - max_scale, - edge_factor, - size_distribution, - edge_distribution, - seed, - clip_and_flip); - - if (scramble_vertex_ids) { - std::for_each(src_dst_vec_tuple.begin(), - src_dst_vec_tuple.end(), - [&handle, max_scale, seed](auto& src_dst_tuple) { - src_dst_tuple = - cugraph::scramble_vertex_ids(handle, - std::move(std::get<0>(src_dst_tuple)), - std::move(std::get<1>(src_dst_tuple)), - max_scale); - }); - } - - std::vector, std::unique_ptr>> - gg_vec; - - std::transform( - src_dst_vec_tuple.begin(), - src_dst_vec_tuple.end(), - std::back_inserter(gg_vec), - [](auto& tpl_dev_uvec) { - return std::make_pair( - std::move(std::make_unique(std::get<0>(tpl_dev_uvec).release())), - std::move(std::make_unique(std::get<1>(tpl_dev_uvec).release()))); - }); - - return gg_vec; -} - -// Helper for setting up subcommunicators -void init_subcomms(raft::handle_t& handle, size_t row_comm_size) -{ - partition_manager::init_subcomm(handle, row_comm_size); -} - -template std::unique_ptr call_generate_rmat_edgelist( - raft::handle_t const& handle, - size_t scale, - size_t num_edges, - double a, - double b, - double c, - uint64_t seed, - bool clip_and_flip, - bool scramble_vertex_ids); - -template std::unique_ptr call_generate_rmat_edgelist( - raft::handle_t const& handle, - size_t scale, - size_t num_edges, - double a, - double b, - double c, - uint64_t seed, - bool clip_and_flip, - bool scramble_vertex_ids); - -template std::vector< - std::pair, std::unique_ptr>> -call_generate_rmat_edgelists(raft::handle_t const& handle, - size_t n_edgelists, - size_t min_scale, - size_t max_scale, - size_t edge_factor, - cugraph::generator_distribution_t size_distribution, - cugraph::generator_distribution_t edge_distribution, - uint64_t seed, - bool clip_and_flip, - bool scramble_vertex_ids); - -template std::vector< - std::pair, std::unique_ptr>> -call_generate_rmat_edgelists(raft::handle_t const& handle, - size_t n_edgelists, - size_t min_scale, - size_t max_scale, - size_t edge_factor, - cugraph::generator_distribution_t size_distribution, - cugraph::generator_distribution_t edge_distribution, - uint64_t seed, - bool clip_and_flip, - bool scramble_vertex_ids); - -} // namespace cython -} // namespace cugraph From e448ddd4668363b9749413ae5b44053eac2ae076 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Sun, 9 Jul 2023 02:18:42 -0700 Subject: [PATCH 34/62] fix style --- python/cugraph/cugraph/generators/rmat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index 60f673888b9..e686158196c 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -97,7 +97,7 @@ def _ensure_args_rmat( "'min_edge_type_value' and 'max_edge_type_value' must not be 'None' " "if 'include_edge_types' is True" ) - + if multi_rmat: if not isinstance(n_edgelists, int): raise TypeError("'n_edgelists' must be an int") From 9244fca05e1746ac3826b3f8b2d1562807499756 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 10 Jul 2023 07:49:25 -0700 Subject: [PATCH 35/62] remove cython.cu from CMakeLists --- cpp/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 996e654734f..e72f332facc 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -192,7 +192,6 @@ set(CUGRAPH_SOURCES src/community/detail/mis_mg.cu src/detail/utility_wrappers.cu src/structure/graph_view_mg.cu - src/utilities/cython.cu src/utilities/path_retrieval.cu src/structure/legacy/graph.cu src/linear_assignment/legacy/hungarian.cu From 046454aebfa5c59b80fc8ec10f39c7542a0338c9 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 10 Jul 2023 08:49:05 -0700 Subject: [PATCH 36/62] update checks --- python/cugraph/cugraph/generators/rmat.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index e686158196c..b486dc4cbf3 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -74,8 +74,8 @@ def _ensure_args_rmat( if not isinstance(seed, int): raise TypeError("'seed' must be an int") if include_edge_weights: - if include_edge_weights not in [True, False]: - raise ValueError("'include_edge_weights' must be a bool") + if not isinstance(include_edge_weights, bool): + raise TypeError("'include_edge_weights' must be a bool") if maximum_weight is None or minimum_weight is None: raise ValueError( "'maximum_weight' and 'minimum_weight' must not be 'None' " @@ -87,11 +87,11 @@ def _ensure_args_rmat( "is True" ) if include_edge_ids: - if include_edge_ids not in [True, False]: - raise ValueError("'include_edge_ids' must be a bool") + if not isinstance(include_edge_ids, bool): + raise TypeError("'include_edge_ids' must be a bool") if include_edge_types: - if include_edge_types not in [True, False]: - raise ValueError("'include_edge_types' must be a bool") + if not isinstance(include_edge_types, bool): + raise TypeError("'include_edge_types' must be a bool") if min_edge_type_value is None and max_edge_type_value is None: raise ValueError( "'min_edge_type_value' and 'max_edge_type_value' must not be 'None' " @@ -118,10 +118,10 @@ def _ensure_args_rmat( raise TypeError("'num_edges' must be an int") if a + b + c > 1: raise ValueError("a + b + c should be non-negative and no larger than 1.0") - if clip_and_flip not in [True, False]: - raise ValueError("'clip_and_flip' must be a bool") - if scramble_vertex_ids not in [True, False]: - raise ValueError("'scramble_vertex_ids' must be a bool") + if not isinstance(clip_and_flip , bool): + raise TypeError("'clip_and_flip' must be a bool") + if not isinstance(scramble_vertex_ids, bool): + raise TypeError("'scramble_vertex_ids' must be a bool") def _sg_rmat( From be60f7b31511cc4dc44afe7ab564ef0054fcb021 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 10 Jul 2023 08:50:18 -0700 Subject: [PATCH 37/62] update tests --- python/cugraph/cugraph/tests/generators/test_rmat.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/python/cugraph/cugraph/tests/generators/test_rmat.py b/python/cugraph/cugraph/tests/generators/test_rmat.py index da8e11a0008..acec6d81a01 100644 --- a/python/cugraph/cugraph/tests/generators/test_rmat.py +++ b/python/cugraph/cugraph/tests/generators/test_rmat.py @@ -286,18 +286,15 @@ def test_rmat_edge_types(include_edge_types, min_max_edge_type, scramble_vertex_ "include_edge_weights", _include_edge_weights, ids=_include_edge_weights_test_ids ) @pytest.mark.parametrize("clip_and_flip", _clip_and_flip, ids=_clip_and_flip_test_ids) -@pytest.mark.parametrize( - "scramble_vertex_ids", [False], ids=[_scramble_vertex_ids_test_ids[0]] -) def test_rmat_clip_and_flip( - scale, include_edge_weights, clip_and_flip, scramble_vertex_ids + scale, include_edge_weights, clip_and_flip ): """ Verifies that there are edges only in the lower triangular part of the adjacency matrix when 'clip_and_flip' is set to 'true'. - FIXME: 'scramble_vertex_ids' nullifies the effect of 'clip_and_flip' therefore - both flags should not be set to 'True'. + Note: 'scramble_vertex_ids' nullifies the effect of 'clip_and_flip' therefore + both flags should not be set to 'True' in order to test the former """ num_edges = (2**scale) * 4 @@ -310,7 +307,7 @@ def test_rmat_clip_and_flip( num_edges, create_using, clip_and_flip=clip_and_flip, - scramble_vertex_ids=scramble_vertex_ids, + scramble_vertex_ids=False, include_edge_weights=include_edge_weights, dtype=dtype, minimum_weight=minimum_weight, From d4bdbfeacd76b931cb6398ef772c44eb1d50999d Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 10 Jul 2023 08:57:24 -0700 Subject: [PATCH 38/62] remove generators from the CMakeLists --- python/cugraph/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/python/cugraph/CMakeLists.txt b/python/cugraph/CMakeLists.txt index f405ad4f360..48815792553 100644 --- a/python/cugraph/CMakeLists.txt +++ b/python/cugraph/CMakeLists.txt @@ -87,7 +87,6 @@ add_subdirectory(cugraph/community) add_subdirectory(cugraph/components) add_subdirectory(cugraph/dask/comms) add_subdirectory(cugraph/dask/structure) -add_subdirectory(cugraph/generators) add_subdirectory(cugraph/internals) add_subdirectory(cugraph/layout) add_subdirectory(cugraph/linear_assignment) From afdc879f99b94d464980ff43b17460303637a138 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 10 Jul 2023 09:42:24 -0700 Subject: [PATCH 39/62] update docstrings --- .../pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx index 4c8338bba5d..ab59698485d 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx @@ -82,7 +82,7 @@ def generate_rmat_edgelists(ResourceHandle resource_handle, bool_t multi_gpu, ): """ - Generate RMAT edge list + Generate multiple RMAT edge list Parameters ---------- @@ -160,7 +160,9 @@ def generate_rmat_edgelists(ResourceHandle resource_handle, Returns ------- - + return a list of tuple containing the sources and destinations with their + corresponding weights, ids and types if the flags 'include_edge_weights', + 'include_edge_ids' and 'include_edge_types' are respectively set to 'true' """ cdef cugraph_resource_handle_t* c_resource_handle_ptr = \ From aae26600844dcf22162f551113f429e123424507 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 10 Jul 2023 15:52:14 -0700 Subject: [PATCH 40/62] directly call 'init_subcomm' from 'partition_manager.hpp' --- python/cugraph/cugraph/dask/comms/comms.pxd | 8 +++----- python/cugraph/cugraph/dask/comms/comms_wrapper.pyx | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/python/cugraph/cugraph/dask/comms/comms.pxd b/python/cugraph/cugraph/dask/comms/comms.pxd index 3f8f8c2ca59..2c761140896 100644 --- a/python/cugraph/cugraph/dask/comms/comms.pxd +++ b/python/cugraph/cugraph/dask/comms/comms.pxd @@ -18,8 +18,6 @@ from pylibraft.common.handle cimport * - -cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": - - cdef void init_subcomms(handle_t &handle, - size_t row_comm_size) +cdef extern from "cugraph/partition_manager.hpp" namespace "cugraph::partition_manager": + cdef void init_subcomm(handle_t &handle, + size_t row_comm_size) diff --git a/python/cugraph/cugraph/dask/comms/comms_wrapper.pyx b/python/cugraph/cugraph/dask/comms/comms_wrapper.pyx index 7995c756eef..103d81efdd6 100644 --- a/python/cugraph/cugraph/dask/comms/comms_wrapper.pyx +++ b/python/cugraph/cugraph/dask/comms/comms_wrapper.pyx @@ -18,10 +18,10 @@ from pylibraft.common.handle cimport * -from cugraph.dask.comms.comms cimport init_subcomms as c_init_subcomms +from cugraph.dask.comms.comms cimport init_subcomm as c_init_subcomm def init_subcomms(handle, row_comm_size): cdef size_t handle_size_t = handle.getHandle() handle_ = handle_size_t - c_init_subcomms(handle_[0], row_comm_size) + c_init_subcomm(handle_[0], row_comm_size) From 2223c751f2f2c1647cfd5705c9289857c8db4ec6 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 10 Jul 2023 15:53:02 -0700 Subject: [PATCH 41/62] rename argument --- .../cugraph/tests/generators/test_rmat.py | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/python/cugraph/cugraph/tests/generators/test_rmat.py b/python/cugraph/cugraph/tests/generators/test_rmat.py index acec6d81a01..dce1761e65f 100644 --- a/python/cugraph/cugraph/tests/generators/test_rmat.py +++ b/python/cugraph/cugraph/tests/generators/test_rmat.py @@ -65,8 +65,8 @@ def _call_rmat( maximum_weight=None, include_edge_ids=False, include_edge_types=False, - min_edge_type=None, - max_edge_type=None, + min_edge_type_value=None, + max_edge_type_value=None, mg=False, ): """ @@ -89,8 +89,8 @@ def _call_rmat( dtype=dtype, include_edge_ids=include_edge_ids, include_edge_types=include_edge_types, - min_edge_type=min_edge_type, - max_edge_type=max_edge_type, + min_edge_type_value=min_edge_type_value, + max_edge_type_value=max_edge_type_value, mg=mg, ) @@ -217,26 +217,26 @@ def test_rmat_edge_ids(scale, include_edge_ids, scramble_vertex_ids): ids=_include_edge_types_test_ids, ) @pytest.mark.parametrize( - "min_max_edge_type", + "min_max_edge_type_value", _min_max_edge_type_values, ids=_min_max_edge_type_values_test_ids, ) @pytest.mark.parametrize( "scramble_vertex_ids", _scramble_vertex_ids, ids=_scramble_vertex_ids_test_ids ) -def test_rmat_edge_types(include_edge_types, min_max_edge_type, scramble_vertex_ids): +def test_rmat_edge_types(include_edge_types, min_max_edge_type_value, scramble_vertex_ids): """ Verifies that the edge types returned by rmat() are valid and that valid values - are passed for 'min_edge_type' and 'max_edge_type'. + are passed for 'min_edge_type_value' and 'max_edge_type_value'. """ scale = 2 num_edges = (2**scale) * 4 create_using = None # Returns the edgelist from RMAT - min_edge_type, max_edge_type = min_max_edge_type + min_edge_type_value, max_edge_type_value = min_max_edge_type_value if include_edge_types: - if min_edge_type is None or max_edge_type is None: + if min_edge_type_value is None or max_edge_type_value is None: with pytest.raises(ValueError): _call_rmat( scale, @@ -244,8 +244,8 @@ def test_rmat_edge_types(include_edge_types, min_max_edge_type, scramble_vertex_ create_using, scramble_vertex_ids=scramble_vertex_ids, include_edge_types=include_edge_types, - min_edge_type=min_edge_type, - max_edge_type=max_edge_type, + min_edge_type_value=min_edge_type_value, + max_edge_type_value=max_edge_type_value, ) else: df = _call_rmat( @@ -254,17 +254,17 @@ def test_rmat_edge_types(include_edge_types, min_max_edge_type, scramble_vertex_ create_using, scramble_vertex_ids=scramble_vertex_ids, include_edge_types=include_edge_types, - min_edge_type=min_edge_type, - max_edge_type=max_edge_type, + min_edge_type_value=min_edge_type_value, + max_edge_type_value=max_edge_type_value, ) # Check that there is an 'edge_type' column assert "edge_type" in df.columns - edge_types_err1 = df.query("{} < edge_type".format(max_edge_type)) - edge_types_err2 = df.query("{} > edge_type".format(min_edge_type)) + edge_types_err1 = df.query("{} < edge_type".format(max_edge_type_value)) + edge_types_err2 = df.query("{} > edge_type".format(min_edge_type_value)) - # Check that edge weights values are between 'min_edge_type' - # and 'max_edge_type'. + # Check that edge weights values are between 'min_edge_type_value' + # and 'max_edge_type_value'. assert len(edge_types_err1) == 0 assert len(edge_types_err2) == 0 else: @@ -274,8 +274,8 @@ def test_rmat_edge_types(include_edge_types, min_max_edge_type, scramble_vertex_ create_using, scramble_vertex_ids=scramble_vertex_ids, include_edge_types=include_edge_types, - min_edge_type=min_edge_type, - max_edge_type=max_edge_type, + min_edge_type_value=min_edge_type_value, + max_edge_type_value=max_edge_type_value, ) assert len(df.columns) == 2 From d8af0271e54c263c8f4d19e000c5d0c8b9634142 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 10 Jul 2023 15:53:59 -0700 Subject: [PATCH 42/62] fix style --- python/cugraph/cugraph/generators/rmat.py | 2 +- python/cugraph/cugraph/tests/generators/test_rmat.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index b486dc4cbf3..8f9b7cbc873 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -118,7 +118,7 @@ def _ensure_args_rmat( raise TypeError("'num_edges' must be an int") if a + b + c > 1: raise ValueError("a + b + c should be non-negative and no larger than 1.0") - if not isinstance(clip_and_flip , bool): + if not isinstance(clip_and_flip, bool): raise TypeError("'clip_and_flip' must be a bool") if not isinstance(scramble_vertex_ids, bool): raise TypeError("'scramble_vertex_ids' must be a bool") diff --git a/python/cugraph/cugraph/tests/generators/test_rmat.py b/python/cugraph/cugraph/tests/generators/test_rmat.py index dce1761e65f..0923222273c 100644 --- a/python/cugraph/cugraph/tests/generators/test_rmat.py +++ b/python/cugraph/cugraph/tests/generators/test_rmat.py @@ -224,7 +224,9 @@ def test_rmat_edge_ids(scale, include_edge_ids, scramble_vertex_ids): @pytest.mark.parametrize( "scramble_vertex_ids", _scramble_vertex_ids, ids=_scramble_vertex_ids_test_ids ) -def test_rmat_edge_types(include_edge_types, min_max_edge_type_value, scramble_vertex_ids): +def test_rmat_edge_types( + include_edge_types, min_max_edge_type_value, scramble_vertex_ids +): """ Verifies that the edge types returned by rmat() are valid and that valid values are passed for 'min_edge_type_value' and 'max_edge_type_value'. @@ -286,9 +288,7 @@ def test_rmat_edge_types(include_edge_types, min_max_edge_type_value, scramble_v "include_edge_weights", _include_edge_weights, ids=_include_edge_weights_test_ids ) @pytest.mark.parametrize("clip_and_flip", _clip_and_flip, ids=_clip_and_flip_test_ids) -def test_rmat_clip_and_flip( - scale, include_edge_weights, clip_and_flip -): +def test_rmat_clip_and_flip(scale, include_edge_weights, clip_and_flip): """ Verifies that there are edges only in the lower triangular part of the adjacency matrix when 'clip_and_flip' is set to 'true'. From 63c99331da292afed6a9943e283de40c7ed413df Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Tue, 11 Jul 2023 04:49:27 -0700 Subject: [PATCH 43/62] update docstrings and copyright --- python/cugraph/cugraph/dask/comms/comms.pxd | 2 +- python/cugraph/cugraph/generators/rmat.py | 48 +++++++++++---------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/python/cugraph/cugraph/dask/comms/comms.pxd b/python/cugraph/cugraph/dask/comms/comms.pxd index 2c761140896..0b363dc047d 100644 --- a/python/cugraph/cugraph/dask/comms/comms.pxd +++ b/python/cugraph/cugraph/dask/comms/comms.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-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 diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index 8f9b7cbc873..b3cb1baec00 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -16,6 +16,8 @@ from cugraph.dask.comms import comms as Comms import cudf +import numpy as np +import cupy as cp import cugraph from pylibcugraph import generate_rmat_edgelist as pylibcugraph_generate_rmat_edgelist from pylibcugraph import generate_rmat_edgelists as pylibcugraph_generate_rmat_edgelists @@ -81,10 +83,10 @@ def _ensure_args_rmat( "'maximum_weight' and 'minimum_weight' must not be 'None' " "if 'include_edge_weights' is True" ) - if dtype not in ["FLOAT32", "FLOAT64"]: + if dtype not in [np.float32, np.float64, cp.float32, cp.float64]: raise ValueError( - "dtype must be either 'FLOAT32' or 'FLOAT64' if 'include_edge_weights' " - "is True" + "dtype must be either numpy or cupy 'float32' or 'float64' if " + "'include_edge_weights' is True." ) if include_edge_ids: if not isinstance(include_edge_ids, bool): @@ -433,26 +435,26 @@ def rmat( ---------- scale : int Scale factor to set the number of vertices in the graph. Vertex IDs have - values in [0, V), where V = 1 << 'scale' + values in [0, V), where V = 1 << 'scale'. num_edges : int Number of edges to generate a : float, optional (default=0.57) Probability of the edge being in the first partition - The Graph 500 spec sets this value to 0.57 + The Graph 500 spec sets this value to 0.57. b : float, optional (default=0.19) Probability of the edge being in the second partition - The Graph 500 spec sets this value to 0.19 + The Graph 500 spec sets this value to 0.19. c : float, optional (default=0.19) Probability of the edge being in the third partition - The Graph 500 spec sets this value to 0.19 + The Graph 500 spec sets this value to 0.19. seed : int, optional (default=42) - Seed value for the random number generator + Seed value for the random number generator. clip_and_flip : bool, optional (default=False) Flag controlling whether to generate edges only in the lower triangular @@ -476,9 +478,9 @@ def rmat( Maximum weight value to generate if 'include_edge_weights' is True otherwise, this parameter is ignored. - dtype : string - The type of weight to generate ("FLOAT32" or "FLOAT64"), ignored unless - include_weights is true + dtype : numpy.float32, numpy.float64, cupy.float32, cupy.float64 + The type of weight to generate which is ignored unless + include_weights is true. include_edge_ids : bool, optional (default=False) Flag controlling whether to generate edges with ids @@ -505,7 +507,7 @@ def rmat( mg : bool, optional (default=False) If True, R-MAT generation occurs across multiple GPUs. If False, only a - single GPU is used. Default is False (single-GPU) + single GPU is used. Default is False (single-GPU). Returns ------- @@ -622,13 +624,13 @@ def multi_rmat( Parameters ---------- n_edgelists : int - Number of edge lists (graphs) to generate + Number of edge lists (graphs) to generate. min_scale : int - Scale factor to set the minimum number of vertices in the graph + Scale factor to set the minimum number of vertices in the graph. max_scale : int - Scale factor to set the maximum number of vertices in the graph + Scale factor to set the maximum number of vertices in the graph. edge_factor : int Average number of edges per vertex to generate @@ -636,25 +638,25 @@ def multi_rmat( size_distribution : int Distribution of the graph sizes, impacts the scale parameter of the R-MAT generator. - '0' for POWER_LAW distribution and '1' for UNIFORM distribution + '0' for POWER_LAW distribution and '1' for UNIFORM distribution. edge_distribution : int Edges distribution for each graph, impacts how R-MAT parameters a,b,c,d, are set. - '0' for POWER_LAW distribution and '1' for UNIFORM distribution + '0' for POWER_LAW distribution and '1' for UNIFORM distribution. seed : int - Seed value for the random number generator + Seed value for the random number generator. clip_and_flip : bool, optional (default=False) Flag controlling whether to generate edges only in the lower triangular part (including the diagonal) of the graph adjacency matrix - (if set to True) or not (if set to False) + (if set to True) or not (if set to False). scramble_vertex_ids : bool Flag controlling whether to scramble vertex ID bits (if set to True) or not (if set to False); scrambling vertx ID bits breaks correlation - between vertex ID values and vertex degrees + between vertex ID values and vertex degrees. include_edge_weights : bool, optional (default=False) Flag controlling whether to generate edges with weights @@ -684,9 +686,9 @@ def multi_rmat( Maximum edge type to generate if 'include_edge_types' is True otherwise, this paramter is ignored. - dtype : string - The type of weight to generate ("FLOAT32" or "FLOAT64"), ignored unless - include_weights is true + dtype : numpy.float32, numpy.float64, cupy.float32, cupy.float64 + The type of weight to generate which is ignored unless + include_weights is true. mg : bool, optional (default=False) If True, R-MATs generation occurs across multiple GPUs. If False, only a From 03c07d80be0feb2eee03302843fcf8a834d7f455 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Tue, 11 Jul 2023 05:10:01 -0700 Subject: [PATCH 44/62] update, rename and leverage util function --- python/pylibcugraph/pylibcugraph/bfs.pyx | 4 ++-- .../pylibcugraph/pylibcugraph/core_number.pyx | 2 +- .../pylibcugraph/eigenvector_centrality.pyx | 2 +- .../pylibcugraph/generate_rmat_edgelist.pyx | 9 +++------ .../pylibcugraph/generate_rmat_edgelists.pyx | 9 +++------ python/pylibcugraph/pylibcugraph/graphs.pyx | 2 +- python/pylibcugraph/pylibcugraph/hits.pyx | 6 +++--- .../pylibcugraph/katz_centrality.pyx | 4 ++-- python/pylibcugraph/pylibcugraph/node2vec.pyx | 4 ++-- python/pylibcugraph/pylibcugraph/pagerank.pyx | 2 +- .../pylibcugraph/personalized_pagerank.pyx | 2 +- .../pylibcugraph/testing/type_utils.pyx | 16 ++++++++-------- .../pylibcugraph/triangle_count.pyx | 4 ++-- .../pylibcugraph/two_hop_neighbors.pyx | 2 +- .../pylibcugraph/uniform_neighbor_sample.pyx | 12 ++++++------ .../pylibcugraph/uniform_random_walks.pyx | 4 ++-- python/pylibcugraph/pylibcugraph/utils.pxd | 2 +- python/pylibcugraph/pylibcugraph/utils.pyx | 17 ++++++++--------- .../weakly_connected_components.pyx | 2 +- 19 files changed, 49 insertions(+), 56 deletions(-) diff --git a/python/pylibcugraph/pylibcugraph/bfs.pyx b/python/pylibcugraph/pylibcugraph/bfs.pyx index b9d17f15cc5..03493093b91 100644 --- a/python/pylibcugraph/pylibcugraph/bfs.pyx +++ b/python/pylibcugraph/pylibcugraph/bfs.pyx @@ -47,7 +47,7 @@ from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, assert_CAI_type, - get_c_type_from_numpy_type, + get_c_type_from_numpy_cupy_type, ) from pylibcugraph._cugraph_c.graph cimport ( cugraph_graph_t, @@ -167,7 +167,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, cugraph_type_erased_device_array_view_create( cai_sources_ptr, len(sources), - get_c_type_from_numpy_type(sources.dtype)) + get_c_type_from_numpy_cupy_type(sources.dtype)) cdef cugraph_paths_result_t* result_ptr diff --git a/python/pylibcugraph/pylibcugraph/core_number.pyx b/python/pylibcugraph/pylibcugraph/core_number.pyx index 7d0c42f7dd0..e4189fa1c68 100644 --- a/python/pylibcugraph/pylibcugraph/core_number.pyx +++ b/python/pylibcugraph/pylibcugraph/core_number.pyx @@ -48,7 +48,7 @@ from pylibcugraph.graphs cimport ( from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, - get_c_type_from_numpy_type, + get_c_type_from_numpy_cupy_type, ) def core_number(ResourceHandle resource_handle, diff --git a/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx b/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx index 88612c242e2..9779a954c85 100644 --- a/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx +++ b/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx @@ -50,7 +50,7 @@ from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, assert_CAI_type, - get_c_type_from_numpy_type, + get_c_type_from_numpy_cupy_type, ) diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx index 581d4658b6f..667bcd6ee27 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx @@ -47,6 +47,7 @@ from pylibcugraph.resource_handle cimport ( from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, + get_c_type_from_numpy_cupy_type, ) from pylibcugraph._cugraph_c.random cimport ( cugraph_rng_state_t @@ -199,15 +200,11 @@ def generate_rmat_edgelist(ResourceHandle resource_handle, cupy_edge_types = None if include_edge_weights: - if dtype == "FLOAT32": - dtype_ = data_type_id_t.FLOAT32 - # The python API should have checked that an appropriate 'dtype' was passed - else: - dtype_ = data_type_id_t.FLOAT64 + dtype = get_c_type_from_numpy_cupy_type(dtype) error_code = cugraph_generate_edge_weights(c_resource_handle_ptr, rng_state_ptr, result_coo_ptr, - dtype_, + dtype, minimum_weight, maximum_weight, &error_ptr) diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx index ab59698485d..858f38f1a3c 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx @@ -52,6 +52,7 @@ from pylibcugraph.resource_handle cimport ( from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, + get_c_type_from_numpy_cupy_type, ) from pylibcugraph._cugraph_c.random cimport ( cugraph_rng_state_t @@ -227,15 +228,11 @@ def generate_rmat_edgelists(ResourceHandle resource_handle, cupy_destinations = copy_to_cupy_array(c_resource_handle_ptr, destinations_view_ptr) if include_edge_weights: - if dtype == "FLOAT32": - dtype_ = data_type_id_t.FLOAT32 - # The python API should have checked that an appropriate 'dtype' was passed - else: - dtype_ = data_type_id_t.FLOAT64 + dtype = get_c_type_from_numpy_cupy_type(dtype) error_code = cugraph_generate_edge_weights(c_resource_handle_ptr, rng_state_ptr, result_coo_ptr, - dtype_, + dtype, minimum_weight, maximum_weight, &error_ptr) diff --git a/python/pylibcugraph/pylibcugraph/graphs.pyx b/python/pylibcugraph/pylibcugraph/graphs.pyx index dfbbf09129b..eaf27c8d247 100644 --- a/python/pylibcugraph/pylibcugraph/graphs.pyx +++ b/python/pylibcugraph/pylibcugraph/graphs.pyx @@ -54,7 +54,7 @@ from pylibcugraph.graph_properties cimport ( from pylibcugraph.utils cimport ( assert_success, assert_CAI_type, - get_c_type_from_numpy_type, + get_c_type_from_numpy_cupy_type, create_cugraph_type_erased_device_array_view_from_py_obj, ) diff --git a/python/pylibcugraph/pylibcugraph/hits.pyx b/python/pylibcugraph/pylibcugraph/hits.pyx index 7c472f54866..85beb364be0 100644 --- a/python/pylibcugraph/pylibcugraph/hits.pyx +++ b/python/pylibcugraph/pylibcugraph/hits.pyx @@ -51,7 +51,7 @@ from pylibcugraph.utils cimport ( assert_success, assert_CAI_type, copy_to_cupy_array, - get_c_type_from_numpy_type + get_c_type_from_numpy_cupy_type ) @@ -132,7 +132,7 @@ def hits(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_initial_hubs_guess_vertices_ptr, len(initial_hubs_guess_vertices), - get_c_type_from_numpy_type(initial_hubs_guess_vertices.dtype)) + get_c_type_from_numpy_cupy_type(initial_hubs_guess_vertices.dtype)) if initial_hubs_guess_values is not None: assert_CAI_type(initial_hubs_guess_values, "initial_hubs_guess_values") @@ -144,7 +144,7 @@ def hits(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_initial_hubs_guess_values_ptr, len(initial_hubs_guess_values), - get_c_type_from_numpy_type(initial_hubs_guess_values.dtype)) + get_c_type_from_numpy_cupy_type(initial_hubs_guess_values.dtype)) cdef cugraph_resource_handle_t* c_resource_handle_ptr = \ resource_handle.c_resource_handle_ptr diff --git a/python/pylibcugraph/pylibcugraph/katz_centrality.pyx b/python/pylibcugraph/pylibcugraph/katz_centrality.pyx index 0f08e690f92..37078cb806e 100644 --- a/python/pylibcugraph/pylibcugraph/katz_centrality.pyx +++ b/python/pylibcugraph/pylibcugraph/katz_centrality.pyx @@ -50,7 +50,7 @@ from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, assert_CAI_type, - get_c_type_from_numpy_type, + get_c_type_from_numpy_cupy_type, ) @@ -123,7 +123,7 @@ def katz_centrality(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_betas_ptr, len(betas), - get_c_type_from_numpy_type(betas.dtype)) + get_c_type_from_numpy_cupy_type(betas.dtype)) else: betas_ptr = NULL diff --git a/python/pylibcugraph/pylibcugraph/node2vec.pyx b/python/pylibcugraph/pylibcugraph/node2vec.pyx index a550070e7a7..192193c94f3 100644 --- a/python/pylibcugraph/pylibcugraph/node2vec.pyx +++ b/python/pylibcugraph/pylibcugraph/node2vec.pyx @@ -51,7 +51,7 @@ from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, assert_CAI_type, - get_c_type_from_numpy_type, + get_c_type_from_numpy_cupy_type, ) @@ -147,7 +147,7 @@ def node2vec(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_seed_ptr, len(seed_array), - get_c_type_from_numpy_type(seed_array.dtype)) + get_c_type_from_numpy_cupy_type(seed_array.dtype)) error_code = cugraph_node2vec(c_resource_handle_ptr, c_graph_ptr, diff --git a/python/pylibcugraph/pylibcugraph/pagerank.pyx b/python/pylibcugraph/pylibcugraph/pagerank.pyx index a5022072b4c..f0db84db7f7 100644 --- a/python/pylibcugraph/pylibcugraph/pagerank.pyx +++ b/python/pylibcugraph/pylibcugraph/pagerank.pyx @@ -51,7 +51,7 @@ from pylibcugraph.utils cimport ( assert_success, assert_CAI_type, copy_to_cupy_array, - get_c_type_from_numpy_type, + get_c_type_from_numpy_cupy_type, create_cugraph_type_erased_device_array_view_from_py_obj, ) from pylibcugraph.exceptions import FailedToConvergeError diff --git a/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx b/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx index e60e7fa2c3e..4dd6506286c 100644 --- a/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx +++ b/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx @@ -51,7 +51,7 @@ from pylibcugraph.utils cimport ( assert_success, assert_CAI_type, copy_to_cupy_array, - get_c_type_from_numpy_type, + get_c_type_from_numpy_cupy_type, create_cugraph_type_erased_device_array_view_from_py_obj, ) from pylibcugraph.exceptions import FailedToConvergeError diff --git a/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx b/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx index 6defb4c6b43..78fbd40fd32 100644 --- a/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx +++ b/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx @@ -39,7 +39,7 @@ from pylibcugraph.resource_handle cimport ( from pylibcugraph.utils cimport ( assert_success, assert_CAI_type, - get_c_type_from_numpy_type, + get_c_type_from_numpy_cupy_type, ) from pylibcugraph._cugraph_c.array cimport ( cugraph_type_erased_device_array_view_t, @@ -111,13 +111,13 @@ def create_sampling_result(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_srcs_ptr, len(device_sources), - get_c_type_from_numpy_type(device_sources.dtype)) + get_c_type_from_numpy_cupy_type(device_sources.dtype)) ) cdef cugraph_type_erased_device_array_view_t* c_dsts_view_ptr = ( cugraph_type_erased_device_array_view_create( cai_dsts_ptr, len(device_destinations), - get_c_type_from_numpy_type(device_destinations.dtype)) + get_c_type_from_numpy_cupy_type(device_destinations.dtype)) ) cdef cugraph_type_erased_device_array_view_t* c_weight_ptr = NULL if device_weights is not None: @@ -125,7 +125,7 @@ def create_sampling_result(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_weights_ptr, len(device_weights), - get_c_type_from_numpy_type(device_weights.dtype) + get_c_type_from_numpy_cupy_type(device_weights.dtype) ) ) cdef cugraph_type_erased_device_array_view_t* c_edge_id_ptr = NULL @@ -134,7 +134,7 @@ def create_sampling_result(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_edge_ids_ptr, len(device_edge_id), - get_c_type_from_numpy_type(device_edge_id.dtype) + get_c_type_from_numpy_cupy_type(device_edge_id.dtype) ) ) cdef cugraph_type_erased_device_array_view_t* c_edge_type_ptr = NULL @@ -143,7 +143,7 @@ def create_sampling_result(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_edge_types_ptr, len(device_edge_type), - get_c_type_from_numpy_type(device_edge_type.dtype) + get_c_type_from_numpy_cupy_type(device_edge_type.dtype) ) ) @@ -153,7 +153,7 @@ def create_sampling_result(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_hop_ptr, len(device_hop), - get_c_type_from_numpy_type(device_hop.dtype) + get_c_type_from_numpy_cupy_type(device_hop.dtype) ) ) @@ -163,7 +163,7 @@ def create_sampling_result(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_batch_id_ptr, len(device_batch_label), - get_c_type_from_numpy_type(device_batch_label.dtype) + get_c_type_from_numpy_cupy_type(device_batch_label.dtype) ) ) diff --git a/python/pylibcugraph/pylibcugraph/triangle_count.pyx b/python/pylibcugraph/pylibcugraph/triangle_count.pyx index e26b2a291cf..068b9888c7b 100644 --- a/python/pylibcugraph/pylibcugraph/triangle_count.pyx +++ b/python/pylibcugraph/pylibcugraph/triangle_count.pyx @@ -50,7 +50,7 @@ from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, assert_CAI_type, - get_c_type_from_numpy_type, + get_c_type_from_numpy_cupy_type, ) @@ -109,7 +109,7 @@ def triangle_count(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_start_ptr, len(start_list), - get_c_type_from_numpy_type(start_list.dtype)) + get_c_type_from_numpy_cupy_type(start_list.dtype)) else: start_ptr = NULL diff --git a/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx b/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx index 649f7980747..2163d79a528 100644 --- a/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx +++ b/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx @@ -48,7 +48,7 @@ from pylibcugraph.utils cimport ( assert_success, assert_CAI_type, copy_to_cupy_array, - get_c_type_from_numpy_type, + get_c_type_from_numpy_cupy_type, create_cugraph_type_erased_device_array_view_from_py_obj ) diff --git a/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx b/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx index a3f5dfb273f..c9e5006b65a 100644 --- a/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx +++ b/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx @@ -58,7 +58,7 @@ from pylibcugraph.utils cimport ( copy_to_cupy_array, assert_CAI_type, assert_AI_type, - get_c_type_from_numpy_type, + get_c_type_from_numpy_cupy_type, ) from pylibcugraph.internal_types.sampling_result cimport ( SamplingResult, @@ -172,7 +172,7 @@ def uniform_neighbor_sample(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_start_ptr, len(start_list), - get_c_type_from_numpy_type(start_list.dtype)) + get_c_type_from_numpy_cupy_type(start_list.dtype)) cdef cugraph_type_erased_device_array_view_t* batch_id_ptr = NULL if batch_id_list is not None: @@ -180,7 +180,7 @@ def uniform_neighbor_sample(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_batch_id_ptr, len(batch_id_list), - get_c_type_from_numpy_type(batch_id_list.dtype) + get_c_type_from_numpy_cupy_type(batch_id_list.dtype) ) cdef cugraph_type_erased_device_array_view_t* label_list_ptr = NULL @@ -189,7 +189,7 @@ def uniform_neighbor_sample(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_label_list_ptr, len(label_list), - get_c_type_from_numpy_type(label_list.dtype) + get_c_type_from_numpy_cupy_type(label_list.dtype) ) cdef cugraph_type_erased_device_array_view_t* label_to_output_comm_rank_ptr = NULL @@ -198,14 +198,14 @@ def uniform_neighbor_sample(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_label_to_output_comm_rank_ptr, len(label_to_output_comm_rank), - get_c_type_from_numpy_type(label_to_output_comm_rank.dtype) + get_c_type_from_numpy_cupy_type(label_to_output_comm_rank.dtype) ) cdef cugraph_type_erased_host_array_view_t* fan_out_ptr = \ cugraph_type_erased_host_array_view_create( ai_fan_out_ptr, len(h_fan_out), - get_c_type_from_numpy_type(h_fan_out.dtype)) + get_c_type_from_numpy_cupy_type(h_fan_out.dtype)) cg_rng_state = CuGraphRandomState(resource_handle, random_state) diff --git a/python/pylibcugraph/pylibcugraph/uniform_random_walks.pyx b/python/pylibcugraph/pylibcugraph/uniform_random_walks.pyx index 4883fc9e6b1..e3f20cd45f4 100644 --- a/python/pylibcugraph/pylibcugraph/uniform_random_walks.pyx +++ b/python/pylibcugraph/pylibcugraph/uniform_random_walks.pyx @@ -57,7 +57,7 @@ from pylibcugraph.utils cimport ( copy_to_cupy_array, assert_CAI_type, assert_AI_type, - get_c_type_from_numpy_type, + get_c_type_from_numpy_cupy_type, ) @@ -108,7 +108,7 @@ def uniform_random_walks(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_start_ptr, len(start_vertices), - get_c_type_from_numpy_type(start_vertices.dtype)) + get_c_type_from_numpy_cupy_type(start_vertices.dtype)) error_code = cugraph_uniform_random_walks( c_resource_handle_ptr, diff --git a/python/pylibcugraph/pylibcugraph/utils.pxd b/python/pylibcugraph/pylibcugraph/utils.pxd index 7fc140e9aed..bc722402f2d 100644 --- a/python/pylibcugraph/pylibcugraph/utils.pxd +++ b/python/pylibcugraph/pylibcugraph/utils.pxd @@ -37,7 +37,7 @@ cdef assert_AI_type(obj, var_name, allow_None=*) cdef get_numpy_type_from_c_type(data_type_id_t c_type) -cdef get_c_type_from_numpy_type(numpy_type) +cdef get_c_type_from_numpy_cupy_type(numpy_type) cdef get_c_weight_type_from_numpy_edge_ids_type(numpy_type) diff --git a/python/pylibcugraph/pylibcugraph/utils.pyx b/python/pylibcugraph/pylibcugraph/utils.pyx index a9fc8fce711..4bac701e8d8 100644 --- a/python/pylibcugraph/pylibcugraph/utils.pyx +++ b/python/pylibcugraph/pylibcugraph/utils.pyx @@ -122,19 +122,18 @@ cdef get_numpy_type_from_c_type(data_type_id_t c_type): raise RuntimeError("Internal error: got invalid data type enum value " f"from C: {c_type}") - -cdef get_c_type_from_numpy_type(numpy_type): - if numpy_type == numpy.int32: +cdef get_c_type_from_numpy_cupy_type(numpy_cupy_type): + if numpy_cupy_type in [numpy.int32, cupy.int32]: return data_type_id_t.INT32 - elif numpy_type == numpy.int64: + elif numpy_cupy_type in [numpy.int64, cupy.int64]: return data_type_id_t.INT64 - elif numpy_type == numpy.float32: + elif numpy_cupy_type in [numpy.float32, cupy.float32]: return data_type_id_t.FLOAT32 - elif numpy_type == numpy.float64: + elif numpy_cupy_type in [numpy.float64, cupy.float64]: return data_type_id_t.FLOAT64 else: raise RuntimeError("Internal error: got invalid data type enum value " - f"from Numpy: {numpy_type}") + f"from Numpy/Cupy: {numpy_cupy_type}") cdef get_c_weight_type_from_numpy_edge_ids_type(numpy_type): if numpy_type == numpy.int32: @@ -207,7 +206,7 @@ cdef copy_to_cupy_array_ids( cdef cugraph_type_erased_device_array_view_t* cupy_array_view_ptr = \ cugraph_type_erased_device_array_view_create( - cupy_array_ptr, array_size, get_c_type_from_numpy_type(cupy_array.dtype)) + cupy_array_ptr, array_size, get_c_type_from_numpy_cupy_type(cupy_array.dtype)) cdef cugraph_error_t* error_ptr error_code = cugraph_type_erased_device_array_view_copy( @@ -231,7 +230,7 @@ cdef cugraph_type_erased_device_array_view_t* \ view_ptr = cugraph_type_erased_device_array_view_create( cai_ptr, len(python_obj), - get_c_type_from_numpy_type(python_obj.dtype)) + get_c_type_from_numpy_cupy_type(python_obj.dtype)) return view_ptr diff --git a/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx b/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx index abd78aa8c10..a522a7c2385 100644 --- a/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx +++ b/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx @@ -51,7 +51,7 @@ from pylibcugraph.utils cimport ( assert_success, assert_CAI_type, copy_to_cupy_array, - get_c_type_from_numpy_type, + get_c_type_from_numpy_cupy_type, create_cugraph_type_erased_device_array_view_from_py_obj, ) From 8f493aa3a9529357258c2032e580fbcd7749c645 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Tue, 11 Jul 2023 06:04:09 -0700 Subject: [PATCH 45/62] update tests --- python/cugraph/cugraph/tests/generators/test_rmat.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/cugraph/cugraph/tests/generators/test_rmat.py b/python/cugraph/cugraph/tests/generators/test_rmat.py index 0923222273c..6baf8d48179 100644 --- a/python/cugraph/cugraph/tests/generators/test_rmat.py +++ b/python/cugraph/cugraph/tests/generators/test_rmat.py @@ -19,6 +19,8 @@ from cugraph.generators import rmat import cugraph from cupy.sparse import coo_matrix, triu, tril +import numpy as np +import cupy as cp ############################################################################## @@ -38,6 +40,7 @@ f"include_edge_weights={x}" for x in _include_edge_weights ] _dtype = [None, "FLOAT32", "FLOAT64", "INT32"] +_dtype = [np.float32, cp.float32, None, "FLOAT64"] _dtype_test_ids = [f"_dtype={x}" for x in _dtype] _min_max_weight_values = [[None, None], [0, 1], [2, 5]] _min_max_weight_values_test_ids = [ @@ -126,7 +129,7 @@ def test_rmat_edge_weights( if ( minimum_weight is None or maximum_weight is None - or dtype not in ["FLOAT32", "FLOAT64"] + or dtype not in [np.float32, np.float64, cp.float32, cp.float64] ): with pytest.raises(ValueError): _call_rmat( @@ -301,7 +304,7 @@ def test_rmat_clip_and_flip(scale, include_edge_weights, clip_and_flip): create_using = None # Returns the edgelist from RMAT minimum_weight = 0 maximum_weight = 1 - dtype = "FLOAT32" + dtype = np.float32 df = _call_rmat( scale, num_edges, From f8517a1433488f27c46985b0bb541f9a7c8171dd Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Tue, 11 Jul 2023 06:20:05 -0700 Subject: [PATCH 46/62] update copyright --- python/cugraph/cugraph/dask/comms/comms_wrapper.pyx | 2 +- python/pylibcugraph/pylibcugraph/core_number.pyx | 2 +- python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx | 2 +- python/pylibcugraph/pylibcugraph/hits.pyx | 2 +- python/pylibcugraph/pylibcugraph/katz_centrality.pyx | 2 +- python/pylibcugraph/pylibcugraph/node2vec.pyx | 2 +- python/pylibcugraph/pylibcugraph/triangle_count.pyx | 2 +- python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx | 2 +- python/pylibcugraph/pylibcugraph/uniform_random_walks.pyx | 2 +- python/pylibcugraph/pylibcugraph/utils.pxd | 2 +- python/pylibcugraph/pylibcugraph/utils.pyx | 2 +- .../pylibcugraph/pylibcugraph/weakly_connected_components.pyx | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/python/cugraph/cugraph/dask/comms/comms_wrapper.pyx b/python/cugraph/cugraph/dask/comms/comms_wrapper.pyx index 103d81efdd6..bbd462c442f 100644 --- a/python/cugraph/cugraph/dask/comms/comms_wrapper.pyx +++ b/python/cugraph/cugraph/dask/comms/comms_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-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 diff --git a/python/pylibcugraph/pylibcugraph/core_number.pyx b/python/pylibcugraph/pylibcugraph/core_number.pyx index e4189fa1c68..a7b33f60c44 100644 --- a/python/pylibcugraph/pylibcugraph/core_number.pyx +++ b/python/pylibcugraph/pylibcugraph/core_number.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-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 diff --git a/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx b/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx index 9779a954c85..7ec20a778ab 100644 --- a/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx +++ b/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-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 diff --git a/python/pylibcugraph/pylibcugraph/hits.pyx b/python/pylibcugraph/pylibcugraph/hits.pyx index 85beb364be0..2bca2fd534d 100644 --- a/python/pylibcugraph/pylibcugraph/hits.pyx +++ b/python/pylibcugraph/pylibcugraph/hits.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-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 diff --git a/python/pylibcugraph/pylibcugraph/katz_centrality.pyx b/python/pylibcugraph/pylibcugraph/katz_centrality.pyx index 37078cb806e..1000c1ef16f 100644 --- a/python/pylibcugraph/pylibcugraph/katz_centrality.pyx +++ b/python/pylibcugraph/pylibcugraph/katz_centrality.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-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 diff --git a/python/pylibcugraph/pylibcugraph/node2vec.pyx b/python/pylibcugraph/pylibcugraph/node2vec.pyx index 192193c94f3..4eb7966e84d 100644 --- a/python/pylibcugraph/pylibcugraph/node2vec.pyx +++ b/python/pylibcugraph/pylibcugraph/node2vec.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-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 diff --git a/python/pylibcugraph/pylibcugraph/triangle_count.pyx b/python/pylibcugraph/pylibcugraph/triangle_count.pyx index 068b9888c7b..b6dc0f41fa6 100644 --- a/python/pylibcugraph/pylibcugraph/triangle_count.pyx +++ b/python/pylibcugraph/pylibcugraph/triangle_count.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-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 diff --git a/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx b/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx index 2163d79a528..b2e7e1ebefc 100644 --- a/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx +++ b/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-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 diff --git a/python/pylibcugraph/pylibcugraph/uniform_random_walks.pyx b/python/pylibcugraph/pylibcugraph/uniform_random_walks.pyx index e3f20cd45f4..c19dd5a5d4c 100644 --- a/python/pylibcugraph/pylibcugraph/uniform_random_walks.pyx +++ b/python/pylibcugraph/pylibcugraph/uniform_random_walks.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-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 diff --git a/python/pylibcugraph/pylibcugraph/utils.pxd b/python/pylibcugraph/pylibcugraph/utils.pxd index bc722402f2d..e3ec2dcc8f4 100644 --- a/python/pylibcugraph/pylibcugraph/utils.pxd +++ b/python/pylibcugraph/pylibcugraph/utils.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-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 diff --git a/python/pylibcugraph/pylibcugraph/utils.pyx b/python/pylibcugraph/pylibcugraph/utils.pyx index 4bac701e8d8..e27eaf4b406 100644 --- a/python/pylibcugraph/pylibcugraph/utils.pyx +++ b/python/pylibcugraph/pylibcugraph/utils.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-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 diff --git a/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx b/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx index a522a7c2385..dcb2abc61b4 100644 --- a/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx +++ b/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-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 From 890b53b050e7d1cc8270ce7173caeceb83d7ce80 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Tue, 11 Jul 2023 07:09:57 -0700 Subject: [PATCH 47/62] remove reference of legacy wcc in plc layer --- .../pylibcugraph/pylibcugraph/components/_connectivity.pxd | 7 ------- 1 file changed, 7 deletions(-) diff --git a/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd b/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd index 205df45f4a4..16426eb9b76 100644 --- a/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd +++ b/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd @@ -30,10 +30,3 @@ cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": const GraphCSRView[VT,ET,WT] &graph, cugraph_cc_t connect_type, VT *labels) except + - -cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": - cdef void call_wcc[vertex_t, weight_t]( - const handle_t &handle, - const graph_container_t &g, - vertex_t *identifiers) except + - From 64fb07f406a32b9c5d40eb5923f5bda2899f5c00 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Tue, 11 Jul 2023 07:16:39 -0700 Subject: [PATCH 48/62] rename argument to match python API --- .../pylibcugraph/generate_rmat_edgelist.pyx | 12 ++++++------ .../pylibcugraph/generate_rmat_edgelists.pyx | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx index 667bcd6ee27..1efb14a0ad4 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx @@ -72,8 +72,8 @@ def generate_rmat_edgelist(ResourceHandle resource_handle, dtype, bool_t include_edge_ids, bool_t include_edge_types, - min_edge_type, - max_edge_type, + min_edge_type_value, + max_edge_type_value, bool_t multi_gpu, ): """ @@ -141,11 +141,11 @@ def generate_rmat_edgelist(ResourceHandle resource_handle, Flag controlling whether to generate edges with types (if set to 'true') or not (if set to 'false'). - min_edge_type : int + min_edge_type_value : int Minimum edge type to generate if 'include_edge_types' is 'true' otherwise, this parameter is ignored. - max_edge_type : int + max_edge_type_value : int Maximum edge type to generate if 'include_edge_types' is 'true' otherwise, this paramter is ignored. @@ -229,8 +229,8 @@ def generate_rmat_edgelist(ResourceHandle resource_handle, error_code = cugraph_generate_edge_types(c_resource_handle_ptr, rng_state_ptr, result_coo_ptr, - min_edge_type, - max_edge_type, + min_edge_type_value, + max_edge_type_value, &error_ptr) assert_success(error_code, error_ptr, "generate_edge_types") diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx index 858f38f1a3c..93df9e33b4e 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx @@ -78,8 +78,8 @@ def generate_rmat_edgelists(ResourceHandle resource_handle, dtype, bool_t include_edge_ids, bool_t include_edge_types, - min_edge_type, - max_edge_type, + min_edge_type_value, + max_edge_type_value, bool_t multi_gpu, ): """ @@ -150,11 +150,11 @@ def generate_rmat_edgelists(ResourceHandle resource_handle, Flag controlling whether to generate edges with types (if set to 'true') or not (if set to 'false'). - min_edge_type : int + min_edge_type_value : int Minimum edge type to generate if 'include_edge_types' is 'true' otherwise, this parameter is ignored. - max_edge_type : int + max_edge_type_value : int Maximum edge type to generate if 'include_edge_types' is 'true' otherwise, this paramter is ignored. @@ -258,8 +258,8 @@ def generate_rmat_edgelists(ResourceHandle resource_handle, error_code = cugraph_generate_edge_types(c_resource_handle_ptr, rng_state_ptr, result_coo_ptr, - min_edge_type, - max_edge_type, + min_edge_type_value, + max_edge_type_value, &error_ptr) assert_success(error_code, error_ptr, "generate_edge_types") From 745a3857a3eca24af9088399c2019ace14280506 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Tue, 11 Jul 2023 07:17:54 -0700 Subject: [PATCH 49/62] remove unused import and variable --- python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx | 6 +----- .../pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx | 3 --- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx index 1efb14a0ad4..0909073e687 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx @@ -17,8 +17,6 @@ from pylibcugraph._cugraph_c.resource_handle cimport ( cugraph_resource_handle_t, - data_type_id_t, - cugraph_data_type_id_t, bool_t, ) from pylibcugraph._cugraph_c.error cimport ( @@ -192,9 +190,7 @@ def generate_rmat_edgelist(ResourceHandle resource_handle, destinations_view_ptr = cugraph_coo_get_destinations(result_coo_ptr) cdef cugraph_type_erased_device_array_view_t* edge_weights_view_ptr - - cdef cugraph_data_type_id_t dtype_ - + cupy_edge_weights = None cupy_edge_ids = None cupy_edge_types = None diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx index 93df9e33b4e..22cc00ecf0b 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx @@ -17,8 +17,6 @@ from pylibcugraph._cugraph_c.resource_handle cimport ( cugraph_resource_handle_t, - data_type_id_t, - cugraph_data_type_id_t, bool_t, ) from pylibcugraph._cugraph_c.error cimport ( @@ -216,7 +214,6 @@ def generate_rmat_edgelists(ResourceHandle resource_handle, cupy_edge_ids = None cupy_edge_types = None - cdef cugraph_data_type_id_t dtype_ edgelists = [] for index in range(size): From 18cdb5ee5bcc397bc3a385e778c56b222465baab Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Tue, 11 Jul 2023 09:32:06 -0700 Subject: [PATCH 50/62] add test coverage for rmat in the plc layer --- .../pylibcugraph/tests/test_rmat.py | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 python/pylibcugraph/pylibcugraph/tests/test_rmat.py diff --git a/python/pylibcugraph/pylibcugraph/tests/test_rmat.py b/python/pylibcugraph/pylibcugraph/tests/test_rmat.py new file mode 100644 index 00000000000..f5c3f6fed9a --- /dev/null +++ b/python/pylibcugraph/pylibcugraph/tests/test_rmat.py @@ -0,0 +1,119 @@ +# Copyright (c) 2022-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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import gc + +import pytest +import cupy as cp +import numpy as np +import cudf + +from pylibcugraph import ( + SGGraph, + ResourceHandle, + GraphProperties, +) +from pylibcugraph import generate_rmat_edgelist + +# ============================================================================= +# Pytest fixtures +# ============================================================================= +# fixtures used in this test module are defined in conftest.py + + +# ============================================================================= +# Tests +# ============================================================================= + + +def check_edges(result, srcs, dsts, weights, num_verts, num_edges, num_seeds): + result_srcs, result_dsts, result_indices = result + + h_src_arr = srcs + h_dst_arr = dsts + h_wgt_arr = weights + + if isinstance(h_src_arr, cp.ndarray): + h_src_arr = h_src_arr.get() + if isinstance(h_dst_arr, cp.ndarray): + h_dst_arr = h_dst_arr.get() + if isinstance(h_wgt_arr, cp.ndarray): + h_wgt_arr = h_wgt_arr.get() + + h_result_srcs = result_srcs.get() + h_result_dsts = result_dsts.get() + h_result_indices = result_indices.get() + + # Following the C validation, we will check that all edges are part of the + # graph + M = np.zeros((num_verts, num_verts), dtype=np.float32) + + # Construct the adjacency matrix + for idx in range(num_edges): + M[h_dst_arr[idx]][h_src_arr[idx]] = h_wgt_arr[idx] + + for edge in range(len(h_result_indices)): + assert M[h_result_dsts[edge]][h_result_srcs[edge]] == h_result_indices[edge] + + +def check_results(result, scale, num_edges, include_edge_ids, + include_edge_weights, include_edge_types): + + h_src_arr, h_dst_arr, h_wgt_arr, h_ids_arr, h_types_arr = result + + if include_edge_weights: + assert h_wgt_arr is not None + if include_edge_ids: + assert h_ids_arr is not None + if include_edge_types: + assert h_types_arr is not None + + +# TODO: Coverage for the MG implementation +@pytest.mark.parametrize("scale", [2, 4, 8]) +@pytest.mark.parametrize("num_edges", [4, 16, 32]) +@pytest.mark.parametrize("clip_and_flip", [False, True]) +@pytest.mark.parametrize("scramble_vertex_ids", [False, True]) +@pytest.mark.parametrize("include_edge_weights", [False, True]) +@pytest.mark.parametrize("include_edge_types", [False, True]) +@pytest.mark.parametrize("include_edge_ids", [False, True]) +def test_rmat( + scale, num_edges, clip_and_flip, scramble_vertex_ids, include_edge_weights, + include_edge_types, include_edge_ids +): + + resource_handle = ResourceHandle() + + result = generate_rmat_edgelist( + resource_handle=resource_handle, + random_state=42, + scale=scale, + num_edges=num_edges, + a=0.57, + b=0.19, + c=0.19, + clip_and_flip=clip_and_flip, + scramble_vertex_ids=scramble_vertex_ids, + include_edge_weights=include_edge_weights, + minimum_weight=0, + maximum_weight=1, + dtype=cp.float32, + include_edge_ids=include_edge_ids, + include_edge_types=include_edge_types, + min_edge_type_value=2, + max_edge_type_value=5, + multi_gpu=False, + ) + check_results( + result, scale, num_edges, include_edge_ids, + include_edge_weights, include_edge_types) From ee628c1547ae8336bce98ee33e0cfe756acccac0 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Tue, 11 Jul 2023 13:56:03 -0700 Subject: [PATCH 51/62] remove outdated reference of cython.cu --- .../cugraph/structure/graph_utilities.pxd | 6 --- .../pylibcugraph/components/_connectivity.pxd | 1 - .../structure/graph_utilities.pxd | 53 ------------------- 3 files changed, 60 deletions(-) delete mode 100644 python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd diff --git a/python/cugraph/cugraph/structure/graph_utilities.pxd b/python/cugraph/cugraph/structure/graph_utilities.pxd index 0bf0f829d1b..5085aa42216 100644 --- a/python/cugraph/cugraph/structure/graph_utilities.pxd +++ b/python/cugraph/cugraph/structure/graph_utilities.pxd @@ -26,12 +26,6 @@ from rmm._lib.device_buffer cimport device_buffer from pylibraft.common.handle cimport handle_t -# C++ graph utilities -cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": - cdef cppclass graph_generator_t: - unique_ptr[device_buffer] d_source - unique_ptr[device_buffer] d_destination - cdef extern from "" namespace "std" nogil: cdef device_buffer move(device_buffer) cdef unique_ptr[device_buffer] move(unique_ptr[device_buffer]) diff --git a/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd b/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd index 16426eb9b76..b89520709d9 100644 --- a/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd +++ b/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd @@ -17,7 +17,6 @@ # cython: language_level = 3 from pylibcugraph.structure.graph_primtypes cimport * -from pylibcugraph.structure.graph_utilities cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": diff --git a/python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd b/python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd deleted file mode 100644 index d9532cd4190..00000000000 --- a/python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright (c) 2021-2022, 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 -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# cython: profile=False -# distutils: language = c++ -# cython: embedsignature = True -# cython: language_level = 3 - - -from pylibraft.common.handle cimport * -from libcpp cimport bool - - -cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": - - ctypedef enum numberTypeEnum: - int32Type "cugraph::cython::numberTypeEnum::int32Type" - int64Type "cugraph::cython::numberTypeEnum::int64Type" - floatType "cugraph::cython::numberTypeEnum::floatType" - doubleType "cugraph::cython::numberTypeEnum::doubleType" - - cdef cppclass graph_container_t: - pass - - cdef void populate_graph_container( - graph_container_t &graph_container, - handle_t &handle, - void *src_vertices, - void *dst_vertices, - void *weights, - void *vertex_partition_offsets, - void *segment_offsets, - size_t num_segments, - numberTypeEnum vertexType, - numberTypeEnum edgeType, - numberTypeEnum weightType, - size_t num_local_edges, - size_t num_global_vertices, - size_t num_global_edges, - bool is_weighted, - bool is_symmetric, - bool transposed, - bool multi_gpu) except + From 962d931b1984f8789474263fe6b270e3253e7187 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Tue, 11 Jul 2023 13:58:29 -0700 Subject: [PATCH 52/62] remove unused import --- .../pylibcugraph/tests/test_rmat.py | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/python/pylibcugraph/pylibcugraph/tests/test_rmat.py b/python/pylibcugraph/pylibcugraph/tests/test_rmat.py index f5c3f6fed9a..61970fc8e9a 100644 --- a/python/pylibcugraph/pylibcugraph/tests/test_rmat.py +++ b/python/pylibcugraph/pylibcugraph/tests/test_rmat.py @@ -11,17 +11,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import gc import pytest import cupy as cp import numpy as np -import cudf from pylibcugraph import ( - SGGraph, ResourceHandle, - GraphProperties, ) from pylibcugraph import generate_rmat_edgelist @@ -66,9 +62,10 @@ def check_edges(result, srcs, dsts, weights, num_verts, num_edges, num_seeds): assert M[h_result_dsts[edge]][h_result_srcs[edge]] == h_result_indices[edge] -def check_results(result, scale, num_edges, include_edge_ids, - include_edge_weights, include_edge_types): - +def check_results( + result, scale, num_edges, include_edge_ids, include_edge_weights, include_edge_types +): + h_src_arr, h_dst_arr, h_wgt_arr, h_ids_arr, h_types_arr = result if include_edge_weights: @@ -77,7 +74,7 @@ def check_results(result, scale, num_edges, include_edge_ids, assert h_ids_arr is not None if include_edge_types: assert h_types_arr is not None - + # TODO: Coverage for the MG implementation @pytest.mark.parametrize("scale", [2, 4, 8]) @@ -88,12 +85,17 @@ def check_results(result, scale, num_edges, include_edge_ids, @pytest.mark.parametrize("include_edge_types", [False, True]) @pytest.mark.parametrize("include_edge_ids", [False, True]) def test_rmat( - scale, num_edges, clip_and_flip, scramble_vertex_ids, include_edge_weights, - include_edge_types, include_edge_ids + scale, + num_edges, + clip_and_flip, + scramble_vertex_ids, + include_edge_weights, + include_edge_types, + include_edge_ids, ): resource_handle = ResourceHandle() - + result = generate_rmat_edgelist( resource_handle=resource_handle, random_state=42, @@ -115,5 +117,10 @@ def test_rmat( multi_gpu=False, ) check_results( - result, scale, num_edges, include_edge_ids, - include_edge_weights, include_edge_types) + result, + scale, + num_edges, + include_edge_ids, + include_edge_weights, + include_edge_types, + ) From 58daee139ae549260a22fd39212f82824c8d19fa Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Wed, 12 Jul 2023 05:23:49 -0700 Subject: [PATCH 53/62] add support for string and rename function --- python/pylibcugraph/pylibcugraph/utils.pyx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/python/pylibcugraph/pylibcugraph/utils.pyx b/python/pylibcugraph/pylibcugraph/utils.pyx index e27eaf4b406..70bef89f4cf 100644 --- a/python/pylibcugraph/pylibcugraph/utils.pyx +++ b/python/pylibcugraph/pylibcugraph/utils.pyx @@ -122,18 +122,20 @@ cdef get_numpy_type_from_c_type(data_type_id_t c_type): raise RuntimeError("Internal error: got invalid data type enum value " f"from C: {c_type}") -cdef get_c_type_from_numpy_cupy_type(numpy_cupy_type): - if numpy_cupy_type in [numpy.int32, cupy.int32]: + +cdef get_c_type_from_numpy_type(numpy_type): + dt = numpy.dtype(numpy_type) + if dt == numpy.int32: return data_type_id_t.INT32 - elif numpy_cupy_type in [numpy.int64, cupy.int64]: + elif dt == numpy.int64: return data_type_id_t.INT64 - elif numpy_cupy_type in [numpy.float32, cupy.float32]: + elif dt == numpy.float32: return data_type_id_t.FLOAT32 - elif numpy_cupy_type in [numpy.float64, cupy.float64]: + elif dt == numpy.float64: return data_type_id_t.FLOAT64 else: raise RuntimeError("Internal error: got invalid data type enum value " - f"from Numpy/Cupy: {numpy_cupy_type}") + f"from Numpy: {numpy_type}") cdef get_c_weight_type_from_numpy_edge_ids_type(numpy_type): if numpy_type == numpy.int32: @@ -206,7 +208,7 @@ cdef copy_to_cupy_array_ids( cdef cugraph_type_erased_device_array_view_t* cupy_array_view_ptr = \ cugraph_type_erased_device_array_view_create( - cupy_array_ptr, array_size, get_c_type_from_numpy_cupy_type(cupy_array.dtype)) + cupy_array_ptr, array_size, get_c_type_from_numpy_type(cupy_array.dtype)) cdef cugraph_error_t* error_ptr error_code = cugraph_type_erased_device_array_view_copy( @@ -230,7 +232,7 @@ cdef cugraph_type_erased_device_array_view_t* \ view_ptr = cugraph_type_erased_device_array_view_create( cai_ptr, len(python_obj), - get_c_type_from_numpy_cupy_type(python_obj.dtype)) + get_c_type_from_numpy_type(python_obj.dtype)) return view_ptr From 12f55d669d140ceb4462c56fc5f525ad72eaaeeb Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Wed, 12 Jul 2023 05:47:39 -0700 Subject: [PATCH 54/62] remove unused import, undo function name change --- python/pylibcugraph/pylibcugraph/bfs.pyx | 6 +++--- .../pylibcugraph/pylibcugraph/core_number.pyx | 4 ++-- .../pylibcugraph/eigenvector_centrality.pyx | 4 ++-- .../pylibcugraph/generate_rmat_edgelist.pyx | 4 ++-- .../pylibcugraph/generate_rmat_edgelists.pyx | 4 ++-- python/pylibcugraph/pylibcugraph/graphs.pyx | 17 ----------------- python/pylibcugraph/pylibcugraph/hits.pyx | 6 +++--- .../pylibcugraph/katz_centrality.pyx | 6 ++---- python/pylibcugraph/pylibcugraph/node2vec.pyx | 5 ++--- python/pylibcugraph/pylibcugraph/pagerank.pyx | 6 ------ .../pylibcugraph/personalized_pagerank.pyx | 6 ------ .../pylibcugraph/testing/type_utils.pyx | 16 ++++++++-------- .../pylibcugraph/triangle_count.pyx | 5 ++--- .../pylibcugraph/two_hop_neighbors.pyx | 3 --- .../pylibcugraph/uniform_neighbor_sample.pyx | 19 ++++++------------- .../pylibcugraph/uniform_random_walks.pyx | 12 ++---------- python/pylibcugraph/pylibcugraph/utils.pxd | 4 ++-- .../weakly_connected_components.pyx | 4 ---- 18 files changed, 38 insertions(+), 93 deletions(-) diff --git a/python/pylibcugraph/pylibcugraph/bfs.pyx b/python/pylibcugraph/pylibcugraph/bfs.pyx index 03493093b91..1b0a41e82f7 100644 --- a/python/pylibcugraph/pylibcugraph/bfs.pyx +++ b/python/pylibcugraph/pylibcugraph/bfs.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023, NVIDIA CORPORATION. +# Copyright (c) 2022, 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 @@ -47,7 +47,7 @@ from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, assert_CAI_type, - get_c_type_from_numpy_cupy_type, + get_c_type_from_numpy_type, ) from pylibcugraph._cugraph_c.graph cimport ( cugraph_graph_t, @@ -167,7 +167,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, cugraph_type_erased_device_array_view_create( cai_sources_ptr, len(sources), - get_c_type_from_numpy_cupy_type(sources.dtype)) + get_c_type_from_numpy_type(sources.dtype)) cdef cugraph_paths_result_t* result_ptr diff --git a/python/pylibcugraph/pylibcugraph/core_number.pyx b/python/pylibcugraph/pylibcugraph/core_number.pyx index a7b33f60c44..7d0c42f7dd0 100644 --- a/python/pylibcugraph/pylibcugraph/core_number.pyx +++ b/python/pylibcugraph/pylibcugraph/core_number.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023, NVIDIA CORPORATION. +# Copyright (c) 2022, 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 @@ -48,7 +48,7 @@ from pylibcugraph.graphs cimport ( from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, - get_c_type_from_numpy_cupy_type, + get_c_type_from_numpy_type, ) def core_number(ResourceHandle resource_handle, diff --git a/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx b/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx index 7ec20a778ab..88612c242e2 100644 --- a/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx +++ b/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023, NVIDIA CORPORATION. +# Copyright (c) 2022, 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 @@ -50,7 +50,7 @@ from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, assert_CAI_type, - get_c_type_from_numpy_cupy_type, + get_c_type_from_numpy_type, ) diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx index 0909073e687..d09d60ff15b 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelist.pyx @@ -45,7 +45,7 @@ from pylibcugraph.resource_handle cimport ( from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, - get_c_type_from_numpy_cupy_type, + get_c_type_from_numpy_type, ) from pylibcugraph._cugraph_c.random cimport ( cugraph_rng_state_t @@ -196,7 +196,7 @@ def generate_rmat_edgelist(ResourceHandle resource_handle, cupy_edge_types = None if include_edge_weights: - dtype = get_c_type_from_numpy_cupy_type(dtype) + dtype = get_c_type_from_numpy_type(dtype) error_code = cugraph_generate_edge_weights(c_resource_handle_ptr, rng_state_ptr, result_coo_ptr, diff --git a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx index 22cc00ecf0b..d5a89f8a222 100644 --- a/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx +++ b/python/pylibcugraph/pylibcugraph/generate_rmat_edgelists.pyx @@ -50,7 +50,7 @@ from pylibcugraph.resource_handle cimport ( from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, - get_c_type_from_numpy_cupy_type, + get_c_type_from_numpy_type, ) from pylibcugraph._cugraph_c.random cimport ( cugraph_rng_state_t @@ -225,7 +225,7 @@ def generate_rmat_edgelists(ResourceHandle resource_handle, cupy_destinations = copy_to_cupy_array(c_resource_handle_ptr, destinations_view_ptr) if include_edge_weights: - dtype = get_c_type_from_numpy_cupy_type(dtype) + dtype = get_c_type_from_numpy_type(dtype) error_code = cugraph_generate_edge_weights(c_resource_handle_ptr, rng_state_ptr, result_coo_ptr, diff --git a/python/pylibcugraph/pylibcugraph/graphs.pyx b/python/pylibcugraph/pylibcugraph/graphs.pyx index eaf27c8d247..49b9747f0b3 100644 --- a/python/pylibcugraph/pylibcugraph/graphs.pyx +++ b/python/pylibcugraph/pylibcugraph/graphs.pyx @@ -14,37 +14,21 @@ # Have cython use python 3 syntax # cython: language_level = 3 -from libc.stdint cimport uintptr_t - -from pylibcugraph._cugraph_c.resource_handle cimport ( - bool_t, - cugraph_resource_handle_t, - data_type_id_t, -) from pylibcugraph._cugraph_c.error cimport ( cugraph_error_code_t, cugraph_error_t, ) from pylibcugraph._cugraph_c.array cimport ( cugraph_type_erased_device_array_view_t, - cugraph_type_erased_device_array_view_create, cugraph_type_erased_device_array_view_free, ) from pylibcugraph._cugraph_c.graph cimport ( - cugraph_graph_t, cugraph_sg_graph_create, cugraph_mg_graph_create, cugraph_sg_graph_create_from_csr, - cugraph_graph_properties_t, cugraph_sg_graph_free, cugraph_mg_graph_free, ) -from pylibcugraph._cugraph_c.graph cimport ( - cugraph_graph_t, - cugraph_mg_graph_create, - cugraph_graph_properties_t, - cugraph_mg_graph_free, -) from pylibcugraph.resource_handle cimport ( ResourceHandle, ) @@ -54,7 +38,6 @@ from pylibcugraph.graph_properties cimport ( from pylibcugraph.utils cimport ( assert_success, assert_CAI_type, - get_c_type_from_numpy_cupy_type, create_cugraph_type_erased_device_array_view_from_py_obj, ) diff --git a/python/pylibcugraph/pylibcugraph/hits.pyx b/python/pylibcugraph/pylibcugraph/hits.pyx index 2bca2fd534d..4524a4f70df 100644 --- a/python/pylibcugraph/pylibcugraph/hits.pyx +++ b/python/pylibcugraph/pylibcugraph/hits.pyx @@ -51,7 +51,7 @@ from pylibcugraph.utils cimport ( assert_success, assert_CAI_type, copy_to_cupy_array, - get_c_type_from_numpy_cupy_type + get_c_type_from_numpy_type ) @@ -132,7 +132,7 @@ def hits(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_initial_hubs_guess_vertices_ptr, len(initial_hubs_guess_vertices), - get_c_type_from_numpy_cupy_type(initial_hubs_guess_vertices.dtype)) + get_c_type_from_numpy_type(initial_hubs_guess_vertices.dtype)) if initial_hubs_guess_values is not None: assert_CAI_type(initial_hubs_guess_values, "initial_hubs_guess_values") @@ -144,7 +144,7 @@ def hits(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_initial_hubs_guess_values_ptr, len(initial_hubs_guess_values), - get_c_type_from_numpy_cupy_type(initial_hubs_guess_values.dtype)) + get_c_type_from_numpy_type(initial_hubs_guess_values.dtype)) cdef cugraph_resource_handle_t* c_resource_handle_ptr = \ resource_handle.c_resource_handle_ptr diff --git a/python/pylibcugraph/pylibcugraph/katz_centrality.pyx b/python/pylibcugraph/pylibcugraph/katz_centrality.pyx index 1000c1ef16f..fc78ca89e87 100644 --- a/python/pylibcugraph/pylibcugraph/katz_centrality.pyx +++ b/python/pylibcugraph/pylibcugraph/katz_centrality.pyx @@ -18,7 +18,6 @@ from libc.stdint cimport uintptr_t from pylibcugraph._cugraph_c.resource_handle cimport ( bool_t, - data_type_id_t, cugraph_resource_handle_t, ) from pylibcugraph._cugraph_c.error cimport ( @@ -49,8 +48,7 @@ from pylibcugraph.graphs cimport ( from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, - assert_CAI_type, - get_c_type_from_numpy_cupy_type, + get_c_type_from_numpy_type, ) @@ -123,7 +121,7 @@ def katz_centrality(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_betas_ptr, len(betas), - get_c_type_from_numpy_cupy_type(betas.dtype)) + get_c_type_from_numpy_type(betas.dtype)) else: betas_ptr = NULL diff --git a/python/pylibcugraph/pylibcugraph/node2vec.pyx b/python/pylibcugraph/pylibcugraph/node2vec.pyx index 4eb7966e84d..d0ab3f22b00 100644 --- a/python/pylibcugraph/pylibcugraph/node2vec.pyx +++ b/python/pylibcugraph/pylibcugraph/node2vec.pyx @@ -18,7 +18,6 @@ from libc.stdint cimport uintptr_t from pylibcugraph._cugraph_c.resource_handle cimport ( bool_t, - data_type_id_t, cugraph_resource_handle_t, ) from pylibcugraph._cugraph_c.error cimport ( @@ -51,7 +50,7 @@ from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, assert_CAI_type, - get_c_type_from_numpy_cupy_type, + get_c_type_from_numpy_type, ) @@ -147,7 +146,7 @@ def node2vec(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_seed_ptr, len(seed_array), - get_c_type_from_numpy_cupy_type(seed_array.dtype)) + get_c_type_from_numpy_type(seed_array.dtype)) error_code = cugraph_node2vec(c_resource_handle_ptr, c_graph_ptr, diff --git a/python/pylibcugraph/pylibcugraph/pagerank.pyx b/python/pylibcugraph/pylibcugraph/pagerank.pyx index f0db84db7f7..f831d844338 100644 --- a/python/pylibcugraph/pylibcugraph/pagerank.pyx +++ b/python/pylibcugraph/pylibcugraph/pagerank.pyx @@ -14,11 +14,8 @@ # Have cython use python 3 syntax # cython: language_level = 3 -from libc.stdint cimport uintptr_t - from pylibcugraph._cugraph_c.resource_handle cimport ( bool_t, - data_type_id_t, cugraph_resource_handle_t, ) from pylibcugraph._cugraph_c.error cimport ( @@ -27,7 +24,6 @@ from pylibcugraph._cugraph_c.error cimport ( ) from pylibcugraph._cugraph_c.array cimport ( cugraph_type_erased_device_array_view_t, - cugraph_type_erased_device_array_view_create, cugraph_type_erased_device_array_view_free ) from pylibcugraph._cugraph_c.graph cimport ( @@ -49,9 +45,7 @@ from pylibcugraph.graphs cimport ( ) from pylibcugraph.utils cimport ( assert_success, - assert_CAI_type, copy_to_cupy_array, - get_c_type_from_numpy_cupy_type, create_cugraph_type_erased_device_array_view_from_py_obj, ) from pylibcugraph.exceptions import FailedToConvergeError diff --git a/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx b/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx index 4dd6506286c..79ef80be549 100644 --- a/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx +++ b/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx @@ -14,11 +14,8 @@ # Have cython use python 3 syntax # cython: language_level = 3 -from libc.stdint cimport uintptr_t - from pylibcugraph._cugraph_c.resource_handle cimport ( bool_t, - data_type_id_t, cugraph_resource_handle_t, ) from pylibcugraph._cugraph_c.error cimport ( @@ -27,7 +24,6 @@ from pylibcugraph._cugraph_c.error cimport ( ) from pylibcugraph._cugraph_c.array cimport ( cugraph_type_erased_device_array_view_t, - cugraph_type_erased_device_array_view_create, cugraph_type_erased_device_array_view_free ) from pylibcugraph._cugraph_c.graph cimport ( @@ -49,9 +45,7 @@ from pylibcugraph.graphs cimport ( ) from pylibcugraph.utils cimport ( assert_success, - assert_CAI_type, copy_to_cupy_array, - get_c_type_from_numpy_cupy_type, create_cugraph_type_erased_device_array_view_from_py_obj, ) from pylibcugraph.exceptions import FailedToConvergeError diff --git a/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx b/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx index 78fbd40fd32..6defb4c6b43 100644 --- a/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx +++ b/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx @@ -39,7 +39,7 @@ from pylibcugraph.resource_handle cimport ( from pylibcugraph.utils cimport ( assert_success, assert_CAI_type, - get_c_type_from_numpy_cupy_type, + get_c_type_from_numpy_type, ) from pylibcugraph._cugraph_c.array cimport ( cugraph_type_erased_device_array_view_t, @@ -111,13 +111,13 @@ def create_sampling_result(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_srcs_ptr, len(device_sources), - get_c_type_from_numpy_cupy_type(device_sources.dtype)) + get_c_type_from_numpy_type(device_sources.dtype)) ) cdef cugraph_type_erased_device_array_view_t* c_dsts_view_ptr = ( cugraph_type_erased_device_array_view_create( cai_dsts_ptr, len(device_destinations), - get_c_type_from_numpy_cupy_type(device_destinations.dtype)) + get_c_type_from_numpy_type(device_destinations.dtype)) ) cdef cugraph_type_erased_device_array_view_t* c_weight_ptr = NULL if device_weights is not None: @@ -125,7 +125,7 @@ def create_sampling_result(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_weights_ptr, len(device_weights), - get_c_type_from_numpy_cupy_type(device_weights.dtype) + get_c_type_from_numpy_type(device_weights.dtype) ) ) cdef cugraph_type_erased_device_array_view_t* c_edge_id_ptr = NULL @@ -134,7 +134,7 @@ def create_sampling_result(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_edge_ids_ptr, len(device_edge_id), - get_c_type_from_numpy_cupy_type(device_edge_id.dtype) + get_c_type_from_numpy_type(device_edge_id.dtype) ) ) cdef cugraph_type_erased_device_array_view_t* c_edge_type_ptr = NULL @@ -143,7 +143,7 @@ def create_sampling_result(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_edge_types_ptr, len(device_edge_type), - get_c_type_from_numpy_cupy_type(device_edge_type.dtype) + get_c_type_from_numpy_type(device_edge_type.dtype) ) ) @@ -153,7 +153,7 @@ def create_sampling_result(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_hop_ptr, len(device_hop), - get_c_type_from_numpy_cupy_type(device_hop.dtype) + get_c_type_from_numpy_type(device_hop.dtype) ) ) @@ -163,7 +163,7 @@ def create_sampling_result(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_batch_id_ptr, len(device_batch_label), - get_c_type_from_numpy_cupy_type(device_batch_label.dtype) + get_c_type_from_numpy_type(device_batch_label.dtype) ) ) diff --git a/python/pylibcugraph/pylibcugraph/triangle_count.pyx b/python/pylibcugraph/pylibcugraph/triangle_count.pyx index b6dc0f41fa6..fd86181b581 100644 --- a/python/pylibcugraph/pylibcugraph/triangle_count.pyx +++ b/python/pylibcugraph/pylibcugraph/triangle_count.pyx @@ -18,7 +18,6 @@ from libc.stdint cimport uintptr_t from pylibcugraph._cugraph_c.resource_handle cimport ( bool_t, - data_type_id_t, cugraph_resource_handle_t, ) from pylibcugraph._cugraph_c.error cimport ( @@ -50,7 +49,7 @@ from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, assert_CAI_type, - get_c_type_from_numpy_cupy_type, + get_c_type_from_numpy_type, ) @@ -109,7 +108,7 @@ def triangle_count(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_start_ptr, len(start_list), - get_c_type_from_numpy_cupy_type(start_list.dtype)) + get_c_type_from_numpy_type(start_list.dtype)) else: start_ptr = NULL diff --git a/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx b/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx index b2e7e1ebefc..3989e45d48f 100644 --- a/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx +++ b/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx @@ -25,7 +25,6 @@ from pylibcugraph._cugraph_c.error cimport ( ) from pylibcugraph._cugraph_c.array cimport ( cugraph_type_erased_device_array_view_t, - cugraph_type_erased_device_array_view_create, cugraph_type_erased_device_array_view_free, ) from pylibcugraph._cugraph_c.graph_functions cimport ( @@ -46,9 +45,7 @@ from pylibcugraph.graphs cimport ( ) from pylibcugraph.utils cimport ( assert_success, - assert_CAI_type, copy_to_cupy_array, - get_c_type_from_numpy_cupy_type, create_cugraph_type_erased_device_array_view_from_py_obj ) diff --git a/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx b/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx index c9e5006b65a..d4fc5daf055 100644 --- a/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx +++ b/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx @@ -18,7 +18,6 @@ from libc.stdint cimport uintptr_t from pylibcugraph._cugraph_c.resource_handle cimport ( bool_t, - data_type_id_t, cugraph_resource_handle_t, ) from pylibcugraph._cugraph_c.error cimport ( @@ -38,10 +37,6 @@ from pylibcugraph._cugraph_c.graph cimport ( ) from pylibcugraph._cugraph_c.algorithms cimport ( cugraph_sample_result_t, - cugraph_sample_result_get_sources, - cugraph_sample_result_get_destinations, - cugraph_sample_result_get_index, - cugraph_sample_result_free, ) from pylibcugraph._cugraph_c.sampling_algorithms cimport ( cugraph_uniform_neighbor_sample_with_edge_properties, @@ -51,14 +46,12 @@ from pylibcugraph.resource_handle cimport ( ) from pylibcugraph.graphs cimport ( _GPUGraph, - MGGraph, ) from pylibcugraph.utils cimport ( assert_success, - copy_to_cupy_array, assert_CAI_type, assert_AI_type, - get_c_type_from_numpy_cupy_type, + get_c_type_from_numpy_type, ) from pylibcugraph.internal_types.sampling_result cimport ( SamplingResult, @@ -172,7 +165,7 @@ def uniform_neighbor_sample(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_start_ptr, len(start_list), - get_c_type_from_numpy_cupy_type(start_list.dtype)) + get_c_type_from_numpy_type(start_list.dtype)) cdef cugraph_type_erased_device_array_view_t* batch_id_ptr = NULL if batch_id_list is not None: @@ -180,7 +173,7 @@ def uniform_neighbor_sample(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_batch_id_ptr, len(batch_id_list), - get_c_type_from_numpy_cupy_type(batch_id_list.dtype) + get_c_type_from_numpy_type(batch_id_list.dtype) ) cdef cugraph_type_erased_device_array_view_t* label_list_ptr = NULL @@ -189,7 +182,7 @@ def uniform_neighbor_sample(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_label_list_ptr, len(label_list), - get_c_type_from_numpy_cupy_type(label_list.dtype) + get_c_type_from_numpy_type(label_list.dtype) ) cdef cugraph_type_erased_device_array_view_t* label_to_output_comm_rank_ptr = NULL @@ -198,14 +191,14 @@ def uniform_neighbor_sample(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_label_to_output_comm_rank_ptr, len(label_to_output_comm_rank), - get_c_type_from_numpy_cupy_type(label_to_output_comm_rank.dtype) + get_c_type_from_numpy_type(label_to_output_comm_rank.dtype) ) cdef cugraph_type_erased_host_array_view_t* fan_out_ptr = \ cugraph_type_erased_host_array_view_create( ai_fan_out_ptr, len(h_fan_out), - get_c_type_from_numpy_cupy_type(h_fan_out.dtype)) + get_c_type_from_numpy_type(h_fan_out.dtype)) cg_rng_state = CuGraphRandomState(resource_handle, random_state) diff --git a/python/pylibcugraph/pylibcugraph/uniform_random_walks.pyx b/python/pylibcugraph/pylibcugraph/uniform_random_walks.pyx index c19dd5a5d4c..4a2b8a70189 100644 --- a/python/pylibcugraph/pylibcugraph/uniform_random_walks.pyx +++ b/python/pylibcugraph/pylibcugraph/uniform_random_walks.pyx @@ -17,8 +17,6 @@ from libc.stdint cimport uintptr_t from pylibcugraph._cugraph_c.resource_handle cimport ( - bool_t, - data_type_id_t, cugraph_resource_handle_t, ) from pylibcugraph._cugraph_c.error cimport ( @@ -29,9 +27,6 @@ from pylibcugraph._cugraph_c.array cimport ( cugraph_type_erased_device_array_view_t, cugraph_type_erased_device_array_view_create, cugraph_type_erased_device_array_view_free, - cugraph_type_erased_host_array_view_t, - cugraph_type_erased_host_array_view_create, - cugraph_type_erased_host_array_view_free, ) from pylibcugraph._cugraph_c.graph cimport ( cugraph_graph_t, @@ -41,7 +36,6 @@ from pylibcugraph._cugraph_c.algorithms cimport ( cugraph_random_walk_result_t, cugraph_random_walk_result_get_paths, cugraph_random_walk_result_get_weights, - cugraph_random_walk_result_get_path_sizes, cugraph_random_walk_result_get_max_path_length, cugraph_random_walk_result_free, ) @@ -50,14 +44,12 @@ from pylibcugraph.resource_handle cimport ( ) from pylibcugraph.graphs cimport ( _GPUGraph, - MGGraph, ) from pylibcugraph.utils cimport ( assert_success, copy_to_cupy_array, assert_CAI_type, - assert_AI_type, - get_c_type_from_numpy_cupy_type, + get_c_type_from_numpy_type, ) @@ -108,7 +100,7 @@ def uniform_random_walks(ResourceHandle resource_handle, cugraph_type_erased_device_array_view_create( cai_start_ptr, len(start_vertices), - get_c_type_from_numpy_cupy_type(start_vertices.dtype)) + get_c_type_from_numpy_type(start_vertices.dtype)) error_code = cugraph_uniform_random_walks( c_resource_handle_ptr, diff --git a/python/pylibcugraph/pylibcugraph/utils.pxd b/python/pylibcugraph/pylibcugraph/utils.pxd index e3ec2dcc8f4..7fc140e9aed 100644 --- a/python/pylibcugraph/pylibcugraph/utils.pxd +++ b/python/pylibcugraph/pylibcugraph/utils.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023, NVIDIA CORPORATION. +# Copyright (c) 2022, 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 @@ -37,7 +37,7 @@ cdef assert_AI_type(obj, var_name, allow_None=*) cdef get_numpy_type_from_c_type(data_type_id_t c_type) -cdef get_c_type_from_numpy_cupy_type(numpy_type) +cdef get_c_type_from_numpy_type(numpy_type) cdef get_c_weight_type_from_numpy_edge_ids_type(numpy_type) diff --git a/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx b/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx index dcb2abc61b4..7cc0d8ab4c1 100644 --- a/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx +++ b/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx @@ -14,12 +14,10 @@ # Have cython use python 3 syntax # cython: language_level = 3 -from libc.stdint cimport uintptr_t from pylibcugraph import GraphProperties, SGGraph from pylibcugraph._cugraph_c.resource_handle cimport ( bool_t, - data_type_id_t, cugraph_resource_handle_t, ) from pylibcugraph._cugraph_c.error cimport ( @@ -28,7 +26,6 @@ from pylibcugraph._cugraph_c.error cimport ( ) from pylibcugraph._cugraph_c.array cimport ( cugraph_type_erased_device_array_view_t, - cugraph_type_erased_device_array_view_create, cugraph_type_erased_device_array_view_copy, ) from pylibcugraph._cugraph_c.graph cimport ( @@ -51,7 +48,6 @@ from pylibcugraph.utils cimport ( assert_success, assert_CAI_type, copy_to_cupy_array, - get_c_type_from_numpy_cupy_type, create_cugraph_type_erased_device_array_view_from_py_obj, ) From 426db2eeae64b3db238fe924c8019f6c2b3c748b Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Wed, 12 Jul 2023 05:56:51 -0700 Subject: [PATCH 55/62] add support for string in 'dtype' --- python/cugraph/cugraph/generators/rmat.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index b3cb1baec00..359f987e9e5 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -83,7 +83,8 @@ def _ensure_args_rmat( "'maximum_weight' and 'minimum_weight' must not be 'None' " "if 'include_edge_weights' is True" ) - if dtype not in [np.float32, np.float64, cp.float32, cp.float64]: + if dtype not in [ + np.float32, np.float64, cp.float32, cp.float64, "float32", "float64"]: raise ValueError( "dtype must be either numpy or cupy 'float32' or 'float64' if " "'include_edge_weights' is True." @@ -478,7 +479,7 @@ def rmat( Maximum weight value to generate if 'include_edge_weights' is True otherwise, this parameter is ignored. - dtype : numpy.float32, numpy.float64, cupy.float32, cupy.float64 + dtype : numpy.float32, numpy.float64, cupy.float32, cupy.float64, "float32", "float64" The type of weight to generate which is ignored unless include_weights is true. @@ -686,7 +687,7 @@ def multi_rmat( Maximum edge type to generate if 'include_edge_types' is True otherwise, this paramter is ignored. - dtype : numpy.float32, numpy.float64, cupy.float32, cupy.float64 + dtype : numpy.float32, numpy.float64, cupy.float32, cupy.float64, "float32", "float64" The type of weight to generate which is ignored unless include_weights is true. From 8e9bcbc580bf23f38fa4ca247137ee082ee61303 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Wed, 12 Jul 2023 06:02:51 -0700 Subject: [PATCH 56/62] update tests --- python/cugraph/cugraph/tests/generators/test_rmat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/cugraph/cugraph/tests/generators/test_rmat.py b/python/cugraph/cugraph/tests/generators/test_rmat.py index 6baf8d48179..514e2f5b839 100644 --- a/python/cugraph/cugraph/tests/generators/test_rmat.py +++ b/python/cugraph/cugraph/tests/generators/test_rmat.py @@ -39,8 +39,7 @@ _include_edge_weights_test_ids = [ f"include_edge_weights={x}" for x in _include_edge_weights ] -_dtype = [None, "FLOAT32", "FLOAT64", "INT32"] -_dtype = [np.float32, cp.float32, None, "FLOAT64"] +_dtype = [np.float32, cp.float32, None, "FLOAT64", "float32"] _dtype_test_ids = [f"_dtype={x}" for x in _dtype] _min_max_weight_values = [[None, None], [0, 1], [2, 5]] _min_max_weight_values_test_ids = [ @@ -129,7 +128,8 @@ def test_rmat_edge_weights( if ( minimum_weight is None or maximum_weight is None - or dtype not in [np.float32, np.float64, cp.float32, cp.float64] + or dtype not in [ + np.float32, np.float64, cp.float32, cp.float64, "float32", "float64"] ): with pytest.raises(ValueError): _call_rmat( From c1f1fc23c827f36ef7573b4eb740b36dc14323f9 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Wed, 12 Jul 2023 06:16:09 -0700 Subject: [PATCH 57/62] fix style --- python/cugraph/cugraph/generators/rmat.py | 14 +++++++++++--- .../cugraph/cugraph/tests/generators/test_rmat.py | 11 +++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/python/cugraph/cugraph/generators/rmat.py b/python/cugraph/cugraph/generators/rmat.py index 359f987e9e5..7a37e9bdaf2 100644 --- a/python/cugraph/cugraph/generators/rmat.py +++ b/python/cugraph/cugraph/generators/rmat.py @@ -84,7 +84,13 @@ def _ensure_args_rmat( "if 'include_edge_weights' is True" ) if dtype not in [ - np.float32, np.float64, cp.float32, cp.float64, "float32", "float64"]: + np.float32, + np.float64, + cp.float32, + cp.float64, + "float32", + "float64", + ]: raise ValueError( "dtype must be either numpy or cupy 'float32' or 'float64' if " "'include_edge_weights' is True." @@ -479,7 +485,8 @@ def rmat( Maximum weight value to generate if 'include_edge_weights' is True otherwise, this parameter is ignored. - dtype : numpy.float32, numpy.float64, cupy.float32, cupy.float64, "float32", "float64" + dtype : numpy.float32, numpy.float64, cupy.float32, cupy.float64, + "float32", "float64" The type of weight to generate which is ignored unless include_weights is true. @@ -687,7 +694,8 @@ def multi_rmat( Maximum edge type to generate if 'include_edge_types' is True otherwise, this paramter is ignored. - dtype : numpy.float32, numpy.float64, cupy.float32, cupy.float64, "float32", "float64" + dtype : numpy.float32, numpy.float64, cupy.float32, cupy.float64, + "float32", "float64" The type of weight to generate which is ignored unless include_weights is true. diff --git a/python/cugraph/cugraph/tests/generators/test_rmat.py b/python/cugraph/cugraph/tests/generators/test_rmat.py index 514e2f5b839..876e9727b37 100644 --- a/python/cugraph/cugraph/tests/generators/test_rmat.py +++ b/python/cugraph/cugraph/tests/generators/test_rmat.py @@ -128,8 +128,15 @@ def test_rmat_edge_weights( if ( minimum_weight is None or maximum_weight is None - or dtype not in [ - np.float32, np.float64, cp.float32, cp.float64, "float32", "float64"] + or dtype + not in [ + np.float32, + np.float64, + cp.float32, + cp.float64, + "float32", + "float64", + ] ): with pytest.raises(ValueError): _call_rmat( From 4495f9f5461fb6d89d43629dc266b1265a8e1bfc Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Wed, 12 Jul 2023 06:22:47 -0700 Subject: [PATCH 58/62] remove unused import --- python/pylibcugraph/pylibcugraph/bfs.pyx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/python/pylibcugraph/pylibcugraph/bfs.pyx b/python/pylibcugraph/pylibcugraph/bfs.pyx index 1b0a41e82f7..8687e1ea16b 100644 --- a/python/pylibcugraph/pylibcugraph/bfs.pyx +++ b/python/pylibcugraph/pylibcugraph/bfs.pyx @@ -28,15 +28,11 @@ from pylibcugraph._cugraph_c.algorithms cimport ( cugraph_paths_result_free, ) from pylibcugraph._cugraph_c.array cimport ( - cugraph_type_erased_device_array_view, - cugraph_type_erased_device_array_t, cugraph_type_erased_device_array_view_t, cugraph_type_erased_device_array_view_create, - cugraph_type_erased_device_array_view_free, ) from pylibcugraph._cugraph_c.resource_handle cimport ( bool_t, - data_type_id_t, cugraph_resource_handle_t, ) from pylibcugraph._cugraph_c.error cimport ( From 8c000d0fb52d88d11075aba3d9c3b0cc4597d8db Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Wed, 12 Jul 2023 06:23:26 -0700 Subject: [PATCH 59/62] update copyright --- python/pylibcugraph/pylibcugraph/bfs.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pylibcugraph/pylibcugraph/bfs.pyx b/python/pylibcugraph/pylibcugraph/bfs.pyx index 8687e1ea16b..3034dcc8cb1 100644 --- a/python/pylibcugraph/pylibcugraph/bfs.pyx +++ b/python/pylibcugraph/pylibcugraph/bfs.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-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 From 4ebaf9b26e7ae0ebf3a655a45865c3986e6a7648 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 24 Jul 2023 02:09:32 -0700 Subject: [PATCH 60/62] clean up code --- .../pylibcugraph/tests/test_rmat.py | 38 ++++--------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/python/pylibcugraph/pylibcugraph/tests/test_rmat.py b/python/pylibcugraph/pylibcugraph/tests/test_rmat.py index 61970fc8e9a..d091da22d54 100644 --- a/python/pylibcugraph/pylibcugraph/tests/test_rmat.py +++ b/python/pylibcugraph/pylibcugraph/tests/test_rmat.py @@ -32,36 +32,6 @@ # ============================================================================= -def check_edges(result, srcs, dsts, weights, num_verts, num_edges, num_seeds): - result_srcs, result_dsts, result_indices = result - - h_src_arr = srcs - h_dst_arr = dsts - h_wgt_arr = weights - - if isinstance(h_src_arr, cp.ndarray): - h_src_arr = h_src_arr.get() - if isinstance(h_dst_arr, cp.ndarray): - h_dst_arr = h_dst_arr.get() - if isinstance(h_wgt_arr, cp.ndarray): - h_wgt_arr = h_wgt_arr.get() - - h_result_srcs = result_srcs.get() - h_result_dsts = result_dsts.get() - h_result_indices = result_indices.get() - - # Following the C validation, we will check that all edges are part of the - # graph - M = np.zeros((num_verts, num_verts), dtype=np.float32) - - # Construct the adjacency matrix - for idx in range(num_edges): - M[h_dst_arr[idx]][h_src_arr[idx]] = h_wgt_arr[idx] - - for edge in range(len(h_result_indices)): - assert M[h_result_dsts[edge]][h_result_srcs[edge]] == h_result_indices[edge] - - def check_results( result, scale, num_edges, include_edge_ids, include_edge_weights, include_edge_types ): @@ -75,6 +45,10 @@ def check_results( if include_edge_types: assert h_types_arr is not None + vertices = cp.union1d(h_src_arr, h_dst_arr) + assert len(h_src_arr) == len(h_dst_arr) == num_edges + assert len(vertices) <= 2**scale + # TODO: Coverage for the MG implementation @pytest.mark.parametrize("scale", [2, 4, 8]) @@ -124,3 +98,7 @@ def test_rmat( include_edge_weights, include_edge_types, ) + + +def test_rmat_invalid_dtype(): + From af58fa6306564212ea71a4e0de9cdb949db38b5a Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 24 Jul 2023 02:11:48 -0700 Subject: [PATCH 61/62] fix style --- python/pylibcugraph/pylibcugraph/tests/test_rmat.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/python/pylibcugraph/pylibcugraph/tests/test_rmat.py b/python/pylibcugraph/pylibcugraph/tests/test_rmat.py index d091da22d54..831a603c463 100644 --- a/python/pylibcugraph/pylibcugraph/tests/test_rmat.py +++ b/python/pylibcugraph/pylibcugraph/tests/test_rmat.py @@ -98,7 +98,3 @@ def test_rmat( include_edge_weights, include_edge_types, ) - - -def test_rmat_invalid_dtype(): - From e374160729593e247061d2ca7d2b4f72f8a93ba5 Mon Sep 17 00:00:00 2001 From: jnke2016 Date: Mon, 24 Jul 2023 02:12:46 -0700 Subject: [PATCH 62/62] remove unused import --- python/pylibcugraph/pylibcugraph/tests/test_rmat.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/pylibcugraph/pylibcugraph/tests/test_rmat.py b/python/pylibcugraph/pylibcugraph/tests/test_rmat.py index 831a603c463..b57cb12aa28 100644 --- a/python/pylibcugraph/pylibcugraph/tests/test_rmat.py +++ b/python/pylibcugraph/pylibcugraph/tests/test_rmat.py @@ -14,7 +14,6 @@ import pytest import cupy as cp -import numpy as np from pylibcugraph import ( ResourceHandle,