From fed2e8d143f33439ac93545e98da6f01ecb2df7d Mon Sep 17 00:00:00 2001 From: Joseph Nke Date: Tue, 10 May 2022 15:40:15 -0700 Subject: [PATCH 1/6] update some clustering algos to only support undirected graphs --- .../cugraph/community/ktruss_subgraph.py | 3 +- python/cugraph/cugraph/community/leiden.py | 7 ++-- python/cugraph/cugraph/community/louvain.py | 4 +- .../cugraph/community/triangle_count.py | 6 +-- .../cugraph/cugraph/dask/community/louvain.py | 9 ++--- .../cugraph/tests/mg/test_mg_louvain.py | 34 ++++++++--------- .../cugraph/tests/test_k_truss_subgraph.py | 29 +++++++++++++- python/cugraph/cugraph/tests/test_leiden.py | 38 +++++++++++++++---- python/cugraph/cugraph/tests/test_louvain.py | 24 ++++++++++-- .../cugraph/tests/test_triangle_count.py | 23 ++++++++--- 10 files changed, 127 insertions(+), 50 deletions(-) diff --git a/python/cugraph/cugraph/community/ktruss_subgraph.py b/python/cugraph/cugraph/community/ktruss_subgraph.py index 999a80fef90..4fedd57aee9 100644 --- a/python/cugraph/cugraph/community/ktruss_subgraph.py +++ b/python/cugraph/cugraph/community/ktruss_subgraph.py @@ -134,6 +134,7 @@ def ktruss_subgraph(G, k, use_weights=True): cuGraph graph descriptor with connectivity information. k-Trusses are defined for only undirected graphs as they are defined for undirected triangle in a graph. + The current implementation only supports undirected graphs. k : int The desired k to be used for extracting the k-truss subgraph. @@ -159,7 +160,7 @@ def ktruss_subgraph(G, k, use_weights=True): _ensure_compatible_cuda_version() KTrussSubgraph = Graph() - if type(G) is not Graph: + if G.is_directed(): raise Exception("input graph must be undirected") subgraph_df = ktruss_subgraph_wrapper.ktruss_subgraph(G, k, use_weights) diff --git a/python/cugraph/cugraph/community/leiden.py b/python/cugraph/cugraph/community/leiden.py index 9ffb756167a..1b3f96d7ba0 100644 --- a/python/cugraph/cugraph/community/leiden.py +++ b/python/cugraph/cugraph/community/leiden.py @@ -12,7 +12,6 @@ # limitations under the License. from cugraph.community import leiden_wrapper -from cugraph.structure.graph_classes import Graph from cugraph.utilities import (ensure_cugraph_obj_for_nx, df_score_to_dictionary, ) @@ -34,6 +33,8 @@ def leiden(G, max_iter=100, resolution=1.): G : cugraph.Graph cuGraph graph descriptor of type Graph + The current implementation only supports undirected graphs. + The adjacency list will be computed if not already present. max_iter : integer, optional (default=100) @@ -76,8 +77,8 @@ def leiden(G, max_iter=100, resolution=1.): """ G, isNx = ensure_cugraph_obj_for_nx(G) - if type(G) is not Graph: - raise Exception(f"input graph must be undirected was {type(G)}") + if G.is_directed(): + raise Exception("input graph must be undirected") parts, modularity_score = leiden_wrapper.leiden( G, max_iter, resolution diff --git a/python/cugraph/cugraph/community/louvain.py b/python/cugraph/cugraph/community/louvain.py index a396ba7d65d..509a05c2bad 100644 --- a/python/cugraph/cugraph/community/louvain.py +++ b/python/cugraph/cugraph/community/louvain.py @@ -12,7 +12,6 @@ # limitations under the License. from cugraph.community import louvain_wrapper -from cugraph.structure.graph_classes import Graph from cugraph.utilities import (ensure_cugraph_obj_for_nx, df_score_to_dictionary, ) @@ -35,6 +34,7 @@ def louvain(G, max_iter=100, resolution=1.): The graph descriptor should contain the connectivity information and weights. The adjacency list will be computed if not already present. + The current implementation only supports undirected graphs. max_iter : integer, optional (default=100) This controls the maximum number of levels/iterations of the Louvain @@ -77,7 +77,7 @@ def louvain(G, max_iter=100, resolution=1.): G, isNx = ensure_cugraph_obj_for_nx(G) - if type(G) is not Graph: + if G.is_directed(): raise Exception("input graph must be undirected") parts, modularity_score = louvain_wrapper.louvain( diff --git a/python/cugraph/cugraph/community/triangle_count.py b/python/cugraph/cugraph/community/triangle_count.py index 6d65ca45b27..099911a09cd 100644 --- a/python/cugraph/cugraph/community/triangle_count.py +++ b/python/cugraph/cugraph/community/triangle_count.py @@ -12,7 +12,6 @@ # limitations under the License. from cugraph.community import triangle_count_wrapper -from cugraph.structure.graph_classes import Graph from cugraph.utilities import ensure_cugraph_obj_for_nx @@ -28,7 +27,8 @@ def triangles(G): ---------- G : cugraph.graph or networkx.Graph cuGraph graph descriptor, should contain the connectivity information, - (edge weights are not used in this algorithm) + (edge weights are not used in this algorithm). + The current implementation only supports undirected graphs. Returns ------- @@ -50,7 +50,7 @@ def triangles(G): G, _ = ensure_cugraph_obj_for_nx(G) - if type(G) is not Graph: + if G.is_directed(): raise Exception("input graph must be undirected") result = triangle_count_wrapper.triangles(G) diff --git a/python/cugraph/cugraph/dask/community/louvain.py b/python/cugraph/cugraph/dask/community/louvain.py index 58b4c21168c..d0f313bf5af 100644 --- a/python/cugraph/cugraph/dask/community/louvain.py +++ b/python/cugraph/cugraph/dask/community/louvain.py @@ -69,6 +69,8 @@ def louvain(input_graph, max_iter=100, resolution=1.0): and weights. The adjacency list will be computed if not already present. + The current implementation only supports undirected graphs. + max_iter : integer, optional (default=100) This controls the maximum number of levels/iterations of the Louvain algorithm. When specified the algorithm will terminate after no more @@ -114,11 +116,8 @@ def louvain(input_graph, max_iter=100, resolution=1.0): >>> parts, modularity_score = dcg.louvain(dg) """ - # FIXME: dask methods to populate graphs from edgelists are only present on - # DiGraph classes. Disable the Graph check for now and assume inputs are - # symmetric DiGraphs. - # if type(graph) is not Graph: - # raise Exception("input graph must be undirected") + if input_graph.is_directed(): + raise Exception("input graph must be undirected") client = default_client() # Calling renumbering results in data that is sorted by degree input_graph.compute_renumber_edge_list(transposed=False) diff --git a/python/cugraph/cugraph/tests/mg/test_mg_louvain.py b/python/cugraph/cugraph/tests/mg/test_mg_louvain.py index 43389c0f679..aa59be6214f 100644 --- a/python/cugraph/cugraph/tests/mg/test_mg_louvain.py +++ b/python/cugraph/cugraph/tests/mg/test_mg_louvain.py @@ -17,6 +17,7 @@ import cugraph import dask_cudf from cugraph.tests import utils +from cugraph.tests.utils import RAPIDS_DATASET_ROOT_DIR_PATH # from cugraph.dask.common.mg_utils import is_single_gpu try: @@ -37,19 +38,25 @@ def setFixtureParamNames(*args, **kwargs): pass +# ============================================================================= +# Parameters +# ============================================================================= +DATASETS_ASYMMETRIC = [RAPIDS_DATASET_ROOT_DIR_PATH/"karate-asymmetric.csv"] + + ############################################################################### # Fixtures # @pytest.mark.skipif( # is_single_gpu(), reason="skipping MG testing on Single GPU system" # ) @pytest.fixture(scope="module", - params=utils.DATASETS_UNDIRECTED, + params=DATASETS_ASYMMETRIC, ids=[f"dataset={d.as_posix()}" - for d in utils.DATASETS_UNDIRECTED]) + for d in DATASETS_ASYMMETRIC]) def daskGraphFromDataset(request, dask_client): """ Returns a new dask dataframe created from the dataset file param. - This creates un undirected Graph. + This creates a directed Graph. """ # Since parameterized fixtures do not assign param names to param values, # manually call the helper to do so. @@ -77,7 +84,7 @@ def daskGraphFromDataset(request, dask_client): def uddaskGraphFromDataset(request, dask_client): """ Returns a new dask dataframe created from the dataset file param. - This creates un undirected Graph. + This creates an undirected Graph. """ # Since parameterized fixtures do not assign param names to param # values, manually call the helper to do so. @@ -103,18 +110,11 @@ def uddaskGraphFromDataset(request, dask_client): # @pytest.mark.skipif( # is_single_gpu(), reason="skipping MG testing on Single GPU system" # ) -def test_mg_louvain_with_edgevals(daskGraphFromDataset): - # FIXME: daskGraphFromDataset returns a Directed graph, which Louvain is - # currently accepting. In the future, an MNMG symmeterize will need to - # be called to create a Graph for Louvain. - parts, mod = dcg.louvain(daskGraphFromDataset) - - # FIXME: either call Nx with the same dataset and compare results, or - # hardcode golden results to compare to. - print() - print(parts.compute()) - print(mod) - print() +def test_mg_louvain_with_edgevals_directed_graph(daskGraphFromDataset): + # Directed graphs are not supported by Louvain and an exception should be + # raised + with pytest.raises(Exception): + parts, mod = dcg.louvain(daskGraphFromDataset) ############################################################################### @@ -122,7 +122,7 @@ def test_mg_louvain_with_edgevals(daskGraphFromDataset): # @pytest.mark.skipif( # is_single_gpu(), reason="skipping MG testing on Single GPU system" # ) -def test_mg_udlouvain_with_edgevals(uddaskGraphFromDataset): +def test_mg_louvain_with_edgevals_undirected_graph(uddaskGraphFromDataset): parts, mod = dcg.louvain(uddaskGraphFromDataset) # FIXME: either call Nx with the same dataset and compare results, or diff --git a/python/cugraph/cugraph/tests/test_k_truss_subgraph.py b/python/cugraph/cugraph/tests/test_k_truss_subgraph.py index 1a1f5c66693..38504c40e96 100644 --- a/python/cugraph/cugraph/tests/test_k_truss_subgraph.py +++ b/python/cugraph/cugraph/tests/test_k_truss_subgraph.py @@ -20,6 +20,7 @@ import numpy as np from numba import cuda +from cugraph.tests.utils import RAPIDS_DATASET_ROOT_DIR_PATH # Temporarily suppress warnings till networkX fixes deprecation warnings # (Using or importing the ABCs from 'collections' instead of from @@ -35,6 +36,13 @@ print("Networkx version : {} ".format(nx.__version__)) +# ============================================================================= +# Pytest Setup / Teardown - called for each test function +# ============================================================================= +def setup_function(): + gc.collect() + + # These ground truth files have been created by running the networkx ktruss # function on reference graphs. Currently networkx ktruss has an error such # that nx.k_truss(G,k-2) gives the expected result for running ktruss with @@ -101,7 +109,6 @@ def test_unsupported_cuda_version(): f"{__unsupported_cuda_version} environment.") @pytest.mark.parametrize("graph_file, nx_ground_truth", utils.DATASETS_KTRUSS) def test_ktruss_subgraph_Graph(graph_file, nx_ground_truth): - gc.collect() k = 5 cu_M = utils.read_csv_file(graph_file) @@ -117,7 +124,6 @@ def test_ktruss_subgraph_Graph(graph_file, nx_ground_truth): f"{__unsupported_cuda_version} environment.") @pytest.mark.parametrize("graph_file, nx_ground_truth", utils.DATASETS_KTRUSS) def test_ktruss_subgraph_Graph_nx(graph_file, nx_ground_truth): - gc.collect() k = 5 M = utils.read_csv_for_nx(graph_file, read_weights_in_sp=True) @@ -129,3 +135,22 @@ def test_ktruss_subgraph_Graph_nx(graph_file, nx_ground_truth): k_truss_nx = nx.k_truss(G, k) assert nx.is_isomorphic(k_subgraph, k_truss_nx) + + +@pytest.mark.skipif((__cuda_version == __unsupported_cuda_version), + reason="skipping on unsupported CUDA " + f"{__unsupported_cuda_version} environment.") +def test_ktruss_subgraph_directed_Graph(): + input_data_path = (RAPIDS_DATASET_ROOT_DIR_PATH / + "karate-asymmetric.csv").as_posix() + k = 5 + edgevals = True + cu_M = utils.read_csv_file(input_data_path) + G = cugraph.Graph(directed=True) + if edgevals: + G.from_cudf_edgelist(cu_M, source="0", destination="1", edge_attr="2") + else: + G.from_cudf_edgelist(cu_M, source="0", destination="1") + + with pytest.raises(Exception): + cugraph.k_truss(G, k) diff --git a/python/cugraph/cugraph/tests/test_leiden.py b/python/cugraph/cugraph/tests/test_leiden.py index b6c23dad6f2..141071972d8 100644 --- a/python/cugraph/cugraph/tests/test_leiden.py +++ b/python/cugraph/cugraph/tests/test_leiden.py @@ -19,6 +19,7 @@ import networkx as nx import cugraph from cugraph.tests import utils +from cugraph.tests.utils import RAPIDS_DATASET_ROOT_DIR_PATH # Temporarily suppress warnings till networkX fixes deprecation warnings # (Using or importing the ABCs from 'collections' instead of from @@ -31,7 +32,14 @@ warnings.filterwarnings("ignore", category=DeprecationWarning) -def cugraph_leiden(G, edgevals=False): +# ============================================================================= +# Pytest Setup / Teardown - called for each test function +# ============================================================================= +def setup_function(): + gc.collect() + + +def cugraph_leiden(G): # cugraph Louvain Call t1 = time.time() @@ -42,7 +50,7 @@ def cugraph_leiden(G, edgevals=False): return parts, mod -def cugraph_louvain(G, edgevals=False): +def cugraph_louvain(G): # cugraph Louvain Call t1 = time.time() @@ -55,7 +63,6 @@ def cugraph_louvain(G, edgevals=False): @pytest.mark.parametrize("graph_file", utils.DATASETS) def test_leiden(graph_file): - gc.collect() edgevals = True cu_M = utils.read_csv_file(graph_file) @@ -66,8 +73,8 @@ def test_leiden(graph_file): else: G.from_cudf_edgelist(cu_M, source="0", destination="1") - leiden_parts, leiden_mod = cugraph_leiden(G, edgevals=True) - louvain_parts, louvain_mod = cugraph_louvain(G, edgevals=True) + leiden_parts, leiden_mod = cugraph_leiden(G) + louvain_parts, louvain_mod = cugraph_louvain(G) # Calculating modularity scores for comparison assert leiden_mod >= (0.99 * louvain_mod) @@ -75,7 +82,6 @@ def test_leiden(graph_file): @pytest.mark.parametrize("graph_file", utils.DATASETS) def test_leiden_nx(graph_file): - gc.collect() edgevals = True NM = utils.read_csv_for_nx(graph_file) @@ -89,8 +95,24 @@ def test_leiden_nx(graph_file): NM, create_using=nx.Graph(), source="0", target="1", edge_attr="2" ) - leiden_parts, leiden_mod = cugraph_leiden(G, edgevals=True) - louvain_parts, louvain_mod = cugraph_louvain(G, edgevals=True) + leiden_parts, leiden_mod = cugraph_leiden(G) + louvain_parts, louvain_mod = cugraph_louvain(G) # Calculating modularity scores for comparison assert leiden_mod >= (0.99 * louvain_mod) + + +def test_leiden_directed_graph(): + input_data_path = (RAPIDS_DATASET_ROOT_DIR_PATH / + "karate-asymmetric.csv").as_posix() + + edgevals = True + cu_M = utils.read_csv_file(input_data_path) + G = cugraph.Graph(directed=True) + if edgevals: + G.from_cudf_edgelist(cu_M, source="0", destination="1", edge_attr="2") + else: + G.from_cudf_edgelist(cu_M, source="0", destination="1") + + with pytest.raises(Exception): + parts, mod = cugraph_leiden(G) diff --git a/python/cugraph/cugraph/tests/test_louvain.py b/python/cugraph/cugraph/tests/test_louvain.py index fb9bdd7be80..35c28679d43 100644 --- a/python/cugraph/cugraph/tests/test_louvain.py +++ b/python/cugraph/cugraph/tests/test_louvain.py @@ -18,6 +18,7 @@ import cugraph from cugraph.tests import utils +from cugraph.tests.utils import RAPIDS_DATASET_ROOT_DIR_PATH # Temporarily suppress warnings till networkX fixes deprecation warnings # (Using or importing the ABCs from 'collections' instead of from @@ -41,9 +42,16 @@ print("Networkx version : {} ".format(nx.__version__)) -def cugraph_call(cu_M, edgevals=False): +# ============================================================================= +# Pytest Setup / Teardown - called for each test function +# ============================================================================= +def setup_function(): + gc.collect() + + +def cugraph_call(cu_M, edgevals=False, directed=False): - G = cugraph.Graph() + G = cugraph.Graph(directed=directed) if edgevals: G.from_cudf_edgelist(cu_M, source="0", destination="1", edge_attr="2") else: @@ -75,7 +83,6 @@ def networkx_call(M): @pytest.mark.parametrize("graph_file", utils.DATASETS_UNDIRECTED) def test_louvain_with_edgevals(graph_file): - gc.collect() M = utils.read_csv_for_nx(graph_file) cu_M = utils.read_csv_file(graph_file) @@ -103,7 +110,6 @@ def test_louvain_with_edgevals(graph_file): @pytest.mark.parametrize("graph_file", utils.DATASETS_UNDIRECTED) def test_louvain(graph_file): - gc.collect() M = utils.read_csv_for_nx(graph_file) cu_M = utils.read_csv_file(graph_file) @@ -127,3 +133,13 @@ def test_louvain(graph_file): assert len(cu_parts) == len(nx_parts) assert cu_mod > (0.82 * nx_mod) assert abs(cu_mod - cu_mod_nx) < 0.0001 + + +def test_louvain_directed_graph(): + input_data_path = (RAPIDS_DATASET_ROOT_DIR_PATH / + "karate-asymmetric.csv").as_posix() + + cu_M = utils.read_csv_file(input_data_path) + + with pytest.raises(Exception): + cu_parts, cu_mod = cugraph_call(cu_M, directed=True) diff --git a/python/cugraph/cugraph/tests/test_triangle_count.py b/python/cugraph/cugraph/tests/test_triangle_count.py index 917a4f320a7..328b9e9ecb5 100644 --- a/python/cugraph/cugraph/tests/test_triangle_count.py +++ b/python/cugraph/cugraph/tests/test_triangle_count.py @@ -18,6 +18,7 @@ import cudf import cugraph from cugraph.tests import utils +from cugraph.tests.utils import RAPIDS_DATASET_ROOT_DIR_PATH # Temporarily suppress warnings till networkX fixes deprecation warnings @@ -32,8 +33,15 @@ import networkx as nx -def cugraph_call(M, edgevals=False): - G = cugraph.Graph() +# ============================================================================= +# Pytest Setup / Teardown - called for each test function +# ============================================================================= +def setup_function(): + gc.collect() + + +def cugraph_call(M, edgevals=False, directed=False): + G = cugraph.Graph(directed=directed) cu_M = cudf.DataFrame() cu_M["src"] = cudf.Series(M["0"]) cu_M["dst"] = cudf.Series(M["1"]) @@ -69,7 +77,6 @@ def networkx_call(M): # @pytest.mark.parametrize("graph_file", utils.DATASETS) @pytest.mark.parametrize("graph_file", utils.DATASETS_UNDIRECTED) def test_triangles(graph_file): - gc.collect() M = utils.read_csv_for_nx(graph_file) cu_count = cugraph_call(M) @@ -79,7 +86,6 @@ def test_triangles(graph_file): @pytest.mark.parametrize("graph_file", utils.DATASETS_UNDIRECTED) def test_triangles_edge_vals(graph_file): - gc.collect() M = utils.read_csv_for_nx(graph_file) cu_count = cugraph_call(M, edgevals=True) @@ -89,7 +95,6 @@ def test_triangles_edge_vals(graph_file): @pytest.mark.parametrize("graph_file", utils.DATASETS_UNDIRECTED) def test_triangles_nx(graph_file): - gc.collect() M = utils.read_csv_for_nx(graph_file) G = nx.from_pandas_edgelist( @@ -103,3 +108,11 @@ def test_triangles_nx(graph_file): nx_count += dic[i] assert cu_count == nx_count + + +def test_triangles_directed_graph(): + input_data_path = (RAPIDS_DATASET_ROOT_DIR_PATH / + "karate-asymmetric.csv").as_posix() + M = utils.read_csv_for_nx(input_data_path) + with pytest.raises(Exception): + cugraph_call(M, edgevals=True, directed=True) From 53e4d1cc1d2ac872c2a215d2e25797a39d91eb1d Mon Sep 17 00:00:00 2001 From: Joseph Nke Date: Tue, 10 May 2022 16:10:38 -0700 Subject: [PATCH 2/6] update copyright --- python/cugraph/cugraph/tests/test_leiden.py | 2 +- python/cugraph/cugraph/tests/test_triangle_count.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/cugraph/cugraph/tests/test_leiden.py b/python/cugraph/cugraph/tests/test_leiden.py index 141071972d8..821e8c11ea1 100644 --- a/python/cugraph/cugraph/tests/test_leiden.py +++ b/python/cugraph/cugraph/tests/test_leiden.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-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 diff --git a/python/cugraph/cugraph/tests/test_triangle_count.py b/python/cugraph/cugraph/tests/test_triangle_count.py index 328b9e9ecb5..8e25dd7d177 100644 --- a/python/cugraph/cugraph/tests/test_triangle_count.py +++ b/python/cugraph/cugraph/tests/test_triangle_count.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-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 From bd69c60df4f5692962b9519becf796cc3e61e090 Mon Sep 17 00:00:00 2001 From: Joseph Nke Date: Tue, 10 May 2022 16:15:51 -0700 Subject: [PATCH 3/6] update copyright --- python/cugraph/cugraph/tests/test_k_truss_subgraph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cugraph/cugraph/tests/test_k_truss_subgraph.py b/python/cugraph/cugraph/tests/test_k_truss_subgraph.py index 38504c40e96..0e2b87bf50d 100644 --- a/python/cugraph/cugraph/tests/test_k_truss_subgraph.py +++ b/python/cugraph/cugraph/tests/test_k_truss_subgraph.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021, NVIDIA CORPORATION. +# Copyright (c) 2020-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 From 8c8933548acef91be4cdcf6fb1d789c069939ad0 Mon Sep 17 00:00:00 2001 From: Joseph Nke Date: Tue, 10 May 2022 16:21:17 -0700 Subject: [PATCH 4/6] update copyright --- python/cugraph/cugraph/tests/test_louvain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cugraph/cugraph/tests/test_louvain.py b/python/cugraph/cugraph/tests/test_louvain.py index 35c28679d43..b8e192c1bd0 100644 --- a/python/cugraph/cugraph/tests/test_louvain.py +++ b/python/cugraph/cugraph/tests/test_louvain.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-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 From b6eab15ac8038f3a46704275626454e0a352252b Mon Sep 17 00:00:00 2001 From: Joseph Nke Date: Mon, 16 May 2022 06:47:20 -0700 Subject: [PATCH 5/6] update utils import --- python/cugraph/cugraph/tests/test_k_truss_subgraph.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/cugraph/cugraph/tests/test_k_truss_subgraph.py b/python/cugraph/cugraph/tests/test_k_truss_subgraph.py index 09460b62fd1..0acec11a700 100644 --- a/python/cugraph/cugraph/tests/test_k_truss_subgraph.py +++ b/python/cugraph/cugraph/tests/test_k_truss_subgraph.py @@ -20,7 +20,6 @@ import numpy as np from numba import cuda -from cugraph.tests.utils import RAPIDS_DATASET_ROOT_DIR_PATH # Temporarily suppress warnings till networkX fixes deprecation warnings # (Using or importing the ABCs from 'collections' instead of from @@ -141,7 +140,7 @@ def test_ktruss_subgraph_Graph_nx(graph_file, nx_ground_truth): reason="skipping on unsupported CUDA " f"{__unsupported_cuda_version} environment.") def test_ktruss_subgraph_directed_Graph(): - input_data_path = (RAPIDS_DATASET_ROOT_DIR_PATH / + input_data_path = (utils.RAPIDS_DATASET_ROOT_DIR_PATH / "karate-asymmetric.csv").as_posix() k = 5 edgevals = True From de490ca2877bd12df5be557975b54a84ddbac803 Mon Sep 17 00:00:00 2001 From: Joseph Nke Date: Mon, 16 May 2022 10:46:32 -0700 Subject: [PATCH 6/6] raise a ValueError if the graph is directed --- python/cugraph/cugraph/community/ktruss_subgraph.py | 2 +- python/cugraph/cugraph/community/leiden.py | 2 +- python/cugraph/cugraph/community/louvain.py | 2 +- python/cugraph/cugraph/community/triangle_count.py | 2 +- python/cugraph/cugraph/dask/community/louvain.py | 2 +- python/cugraph/cugraph/tests/mg/test_mg_louvain.py | 4 ++-- python/cugraph/cugraph/tests/test_k_truss_subgraph.py | 2 +- python/cugraph/cugraph/tests/test_leiden.py | 2 +- python/cugraph/cugraph/tests/test_louvain.py | 2 +- python/cugraph/cugraph/tests/test_triangle_count.py | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/python/cugraph/cugraph/community/ktruss_subgraph.py b/python/cugraph/cugraph/community/ktruss_subgraph.py index 4fedd57aee9..203dc0c327e 100644 --- a/python/cugraph/cugraph/community/ktruss_subgraph.py +++ b/python/cugraph/cugraph/community/ktruss_subgraph.py @@ -161,7 +161,7 @@ def ktruss_subgraph(G, k, use_weights=True): KTrussSubgraph = Graph() if G.is_directed(): - raise Exception("input graph must be undirected") + raise ValueError("input graph must be undirected") subgraph_df = ktruss_subgraph_wrapper.ktruss_subgraph(G, k, use_weights) if G.renumbered: diff --git a/python/cugraph/cugraph/community/leiden.py b/python/cugraph/cugraph/community/leiden.py index 1b3f96d7ba0..d10d5700b1a 100644 --- a/python/cugraph/cugraph/community/leiden.py +++ b/python/cugraph/cugraph/community/leiden.py @@ -78,7 +78,7 @@ def leiden(G, max_iter=100, resolution=1.): G, isNx = ensure_cugraph_obj_for_nx(G) if G.is_directed(): - raise Exception("input graph must be undirected") + raise ValueError("input graph must be undirected") parts, modularity_score = leiden_wrapper.leiden( G, max_iter, resolution diff --git a/python/cugraph/cugraph/community/louvain.py b/python/cugraph/cugraph/community/louvain.py index 509a05c2bad..87591f61cbc 100644 --- a/python/cugraph/cugraph/community/louvain.py +++ b/python/cugraph/cugraph/community/louvain.py @@ -78,7 +78,7 @@ def louvain(G, max_iter=100, resolution=1.): G, isNx = ensure_cugraph_obj_for_nx(G) if G.is_directed(): - raise Exception("input graph must be undirected") + raise ValueError("input graph must be undirected") parts, modularity_score = louvain_wrapper.louvain( G, max_iter, resolution diff --git a/python/cugraph/cugraph/community/triangle_count.py b/python/cugraph/cugraph/community/triangle_count.py index 099911a09cd..2916341e86f 100644 --- a/python/cugraph/cugraph/community/triangle_count.py +++ b/python/cugraph/cugraph/community/triangle_count.py @@ -51,7 +51,7 @@ def triangles(G): G, _ = ensure_cugraph_obj_for_nx(G) if G.is_directed(): - raise Exception("input graph must be undirected") + raise ValueError("input graph must be undirected") result = triangle_count_wrapper.triangles(G) diff --git a/python/cugraph/cugraph/dask/community/louvain.py b/python/cugraph/cugraph/dask/community/louvain.py index d0f313bf5af..be6dd907934 100644 --- a/python/cugraph/cugraph/dask/community/louvain.py +++ b/python/cugraph/cugraph/dask/community/louvain.py @@ -117,7 +117,7 @@ def louvain(input_graph, max_iter=100, resolution=1.0): """ if input_graph.is_directed(): - raise Exception("input graph must be undirected") + raise ValueError("input graph must be undirected") client = default_client() # Calling renumbering results in data that is sorted by degree input_graph.compute_renumber_edge_list(transposed=False) diff --git a/python/cugraph/cugraph/tests/mg/test_mg_louvain.py b/python/cugraph/cugraph/tests/mg/test_mg_louvain.py index 20fe3b5b956..72d94d3454e 100644 --- a/python/cugraph/cugraph/tests/mg/test_mg_louvain.py +++ b/python/cugraph/cugraph/tests/mg/test_mg_louvain.py @@ -111,9 +111,9 @@ def uddaskGraphFromDataset(request, dask_client): # is_single_gpu(), reason="skipping MG testing on Single GPU system" # ) def test_mg_louvain_with_edgevals_directed_graph(daskGraphFromDataset): - # Directed graphs are not supported by Louvain and an exception should be + # Directed graphs are not supported by Louvain and a ValueError should be # raised - with pytest.raises(Exception): + with pytest.raises(ValueError): parts, mod = dcg.louvain(daskGraphFromDataset) diff --git a/python/cugraph/cugraph/tests/test_k_truss_subgraph.py b/python/cugraph/cugraph/tests/test_k_truss_subgraph.py index 0acec11a700..4cdba1e62c5 100644 --- a/python/cugraph/cugraph/tests/test_k_truss_subgraph.py +++ b/python/cugraph/cugraph/tests/test_k_truss_subgraph.py @@ -151,5 +151,5 @@ def test_ktruss_subgraph_directed_Graph(): else: G.from_cudf_edgelist(cu_M, source="0", destination="1") - with pytest.raises(Exception): + with pytest.raises(ValueError): cugraph.k_truss(G, k) diff --git a/python/cugraph/cugraph/tests/test_leiden.py b/python/cugraph/cugraph/tests/test_leiden.py index 71674c2f637..950f31ca81c 100644 --- a/python/cugraph/cugraph/tests/test_leiden.py +++ b/python/cugraph/cugraph/tests/test_leiden.py @@ -113,5 +113,5 @@ def test_leiden_directed_graph(): else: G.from_cudf_edgelist(cu_M, source="0", destination="1") - with pytest.raises(Exception): + with pytest.raises(ValueError): parts, mod = cugraph_leiden(G) diff --git a/python/cugraph/cugraph/tests/test_louvain.py b/python/cugraph/cugraph/tests/test_louvain.py index 5ca403c2eb4..f41e8b0ad9c 100644 --- a/python/cugraph/cugraph/tests/test_louvain.py +++ b/python/cugraph/cugraph/tests/test_louvain.py @@ -140,5 +140,5 @@ def test_louvain_directed_graph(): cu_M = utils.read_csv_file(input_data_path) - with pytest.raises(Exception): + with pytest.raises(ValueError): cu_parts, cu_mod = cugraph_call(cu_M, directed=True) diff --git a/python/cugraph/cugraph/tests/test_triangle_count.py b/python/cugraph/cugraph/tests/test_triangle_count.py index 7a13a08d8c5..91802fdf0f6 100644 --- a/python/cugraph/cugraph/tests/test_triangle_count.py +++ b/python/cugraph/cugraph/tests/test_triangle_count.py @@ -113,5 +113,5 @@ def test_triangles_directed_graph(): input_data_path = (utils.RAPIDS_DATASET_ROOT_DIR_PATH / "karate-asymmetric.csv").as_posix() M = utils.read_csv_for_nx(input_data_path) - with pytest.raises(Exception): + with pytest.raises(ValueError): cugraph_call(M, edgevals=True, directed=True)