diff --git a/python/cugraph/cugraph/__init__.py b/python/cugraph/cugraph/__init__.py index 00c36a950b3..86e8cf4e61c 100644 --- a/python/cugraph/cugraph/__init__.py +++ b/python/cugraph/cugraph/__init__.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -30,11 +30,8 @@ from cugraph.structure import ( Graph, - DiGraph, MultiGraph, - MultiDiGraph, BiPartiteGraph, - BiPartiteDiGraph, from_edgelist, from_cudf_edgelist, from_pandas_edgelist, diff --git a/python/cugraph/cugraph/community/subgraph_extraction.py b/python/cugraph/cugraph/community/subgraph_extraction.py index e83c1623d48..05d61db4132 100644 --- a/python/cugraph/cugraph/community/subgraph_extraction.py +++ b/python/cugraph/cugraph/community/subgraph_extraction.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -12,7 +12,7 @@ # limitations under the License. import cudf - +from cugraph.structure import Graph from cugraph.community import subgraph_extraction_wrapper from cugraph.utilities import ( ensure_cugraph_obj_for_nx, @@ -57,6 +57,7 @@ def subgraph(G, vertices): """ G, isNx = ensure_cugraph_obj_for_nx(G) + directed = G.is_directed() if G.renumbered: if isinstance(vertices, cudf.DataFrame): @@ -64,7 +65,7 @@ def subgraph(G, vertices): else: vertices = G.lookup_internal_vertex_id(vertices) - result_graph = type(G)() + result_graph = Graph(directed=directed) df = subgraph_extraction_wrapper.subgraph(G, vertices) src_names = "src" diff --git a/python/cugraph/cugraph/components/connectivity.py b/python/cugraph/cugraph/components/connectivity.py index a99aaacc6c6..394c07e94f1 100644 --- a/python/cugraph/cugraph/components/connectivity.py +++ b/python/cugraph/cugraph/components/connectivity.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -20,7 +20,7 @@ is_nx_graph_type, cupy_package as cp, ) -from cugraph.structure import Graph, DiGraph +from cugraph.structure import Graph from cugraph.components import connectivity_wrapper import cudf from pylibcugraph import weakly_connected_components as pylibcugraph_wcc @@ -35,7 +35,7 @@ def _ensure_args(api_name, G, directed, connection, return_labels): """ G_type = type(G) # Check for Graph-type inputs and set defaults if unset - if (G_type in [Graph, DiGraph]) or is_nx_graph_type(G_type): + if (G_type in [Graph]) or is_nx_graph_type(G_type): exc_value = "'%s' cannot be specified for a Graph-type input" if directed is not None: raise TypeError(exc_value % "directed") @@ -71,7 +71,7 @@ def _convert_df_to_output_type(df, input_type, return_labels): graph algos in this module, based on input_type. return_labels is only used for return values from cupy/scipy input types. """ - if input_type in [Graph, DiGraph]: + if input_type in [Graph]: return df elif is_nx_graph_type(input_type): @@ -88,7 +88,7 @@ def _convert_df_to_output_type(df, input_type, return_labels): sorted_df = df.sort_values("vertex") if return_labels: if is_cp_matrix_type(input_type): - labels = cp.fromDlpack(sorted_df["labels"].to_dlpack()) + labels = cp.from_dlpack(sorted_df["labels"].to_dlpack()) else: labels = sorted_df["labels"].to_numpy() return (n_components, labels) @@ -121,7 +121,7 @@ def weakly_connected_components(G, directed=None, connection=None, return_labels For non-Graph-type (eg. sparse matrix) values of G only. Raises TypeError if used with a Graph object. - If True, then convert the input matrix to a cugraph.DiGraph + If True, then convert the input matrix to a Graph(directed=True) and only move from point i to point j along paths csgraph[i, j]. If False, then find the shortest path on an undirected graph: the algorithm can progress from point i to j along csgraph[i, j] or @@ -231,7 +231,7 @@ def strongly_connected_components( For non-Graph-type (eg. sparse matrix) values of G only. Raises TypeError if used with a Graph object. - If True, then convert the input matrix to a cugraph.DiGraph + If True, then convert the input matrix to a Graph(directed=True) and only move from point i to point j along paths csgraph[i, j]. If False, then find the shortest path on an undirected graph: the algorithm can progress from point i to j along csgraph[i, j] or @@ -323,7 +323,7 @@ def connected_components(G, directed=None, connection="weak", return_labels=None For non-Graph-type (eg. sparse matrix) values of G only. Raises TypeError if used with a Graph object. - If True, then convert the input matrix to a cugraph.DiGraph + If True, then convert the input matrix to a Graph(directed=True) and only move from point i to point j along paths csgraph[i, j]. If False, then find the shortest path on an undirected graph: the algorithm can progress from point i to j along csgraph[i, j] or diff --git a/python/cugraph/cugraph/sampling/node2vec.py b/python/cugraph/cugraph/sampling/node2vec.py index 5d6e76c05d5..2f94fa9dceb 100644 --- a/python/cugraph/cugraph/sampling/node2vec.py +++ b/python/cugraph/cugraph/sampling/node2vec.py @@ -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 @@ -38,7 +38,7 @@ def node2vec(G, start_vertices, max_depth=1, compress_result=True, p=1.0, q=1.0) Parameters ---------- G : cuGraph.Graph or networkx.Graph - The graph can be either directed (DiGraph) or undirected (Graph). + The graph can be either directed or undirected. Weights in the graph are ignored. start_vertices: int or list or cudf.Series or cudf.DataFrame diff --git a/python/cugraph/cugraph/structure/__init__.py b/python/cugraph/cugraph/structure/__init__.py index 7f6aa23eadc..a3a64432ded 100644 --- a/python/cugraph/cugraph/structure/__init__.py +++ b/python/cugraph/cugraph/structure/__init__.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -13,11 +13,8 @@ from cugraph.structure.graph_classes import ( Graph, - DiGraph, MultiGraph, - MultiDiGraph, BiPartiteGraph, - BiPartiteDiGraph, ) from cugraph.structure.graph_classes import ( is_weighted, diff --git a/python/cugraph/cugraph/structure/convert_matrix.py b/python/cugraph/cugraph/structure/convert_matrix.py index afd26b9d069..1b46f7db970 100644 --- a/python/cugraph/cugraph/structure/convert_matrix.py +++ b/python/cugraph/cugraph/structure/convert_matrix.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -18,7 +18,7 @@ import cudf import dask_cudf -from cugraph.structure.graph_classes import DiGraph, Graph +from cugraph.structure.graph_classes import Graph # optional dependencies used for handling different input types try: @@ -91,8 +91,6 @@ def from_edgelist( elif isinstance(create_using, Graph): attrs = {"directed": create_using.is_directed()} G = type(create_using)(**attrs) - elif isinstance(create_using, DiGraph): - G = type(create_using)() elif type(create_using) is type(Graph): G = create_using() else: @@ -159,8 +157,6 @@ def from_adjlist(offsets, indices, values=None, create_using=Graph): elif isinstance(create_using, Graph): attrs = {"directed": create_using.is_directed()} G = type(create_using)(**attrs) - elif isinstance(create_using, DiGraph): - G = type(create_using)() elif type(create_using) is type(Graph): G = create_using() else: @@ -240,8 +236,6 @@ def from_cudf_edgelist( elif isinstance(create_using, Graph): attrs = {"directed": create_using.is_directed()} G = type(create_using)(**attrs) - elif isinstance(create_using, DiGraph): - G = type(create_using)() elif type(create_using) is type(Graph): G = create_using() else: @@ -327,8 +321,6 @@ def from_pandas_edgelist( elif isinstance(create_using, Graph): attrs = {"directed": create_using.is_directed()} G = type(create_using)(**attrs) - elif isinstance(create_using, DiGraph): - G = type(create_using)() elif type(create_using) is type(Graph): G = create_using() else: @@ -391,8 +383,6 @@ def from_pandas_adjacency(df, create_using=Graph): elif isinstance(create_using, Graph): attrs = {"directed": create_using.is_directed()} G = type(create_using)(**attrs) - elif isinstance(create_using, DiGraph): - G = type(create_using)() elif type(create_using) is type(Graph): G = create_using() else: @@ -438,8 +428,6 @@ def from_numpy_array(A, create_using=Graph): elif isinstance(create_using, Graph): attrs = {"directed": create_using.is_directed()} G = type(create_using)(**attrs) - elif isinstance(create_using, DiGraph): - G = type(create_using)() elif type(create_using) is type(Graph): G = create_using() else: @@ -484,8 +472,6 @@ def from_numpy_matrix(A, create_using=Graph): elif isinstance(create_using, Graph): attrs = {"directed": create_using.is_directed()} G = type(create_using)(**attrs) - elif isinstance(create_using, DiGraph): - G = type(create_using)() elif type(create_using) is type(Graph): G = create_using() else: diff --git a/python/cugraph/cugraph/structure/graph_classes.py b/python/cugraph/cugraph/structure/graph_classes.py index 311ee5a5352..add1be1f099 100644 --- a/python/cugraph/cugraph/structure/graph_classes.py +++ b/python/cugraph/cugraph/structure/graph_classes.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022, NVIDIA CORPORATION. +# Copyright (c) 2021-2023, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -19,7 +19,6 @@ ) import cudf import dask_cudf -import warnings from cugraph.utilities.utils import import_optional @@ -688,15 +687,6 @@ def add_nodes_from(self, nodes): # def properties(): -class DiGraph(Graph): - def __init__(self, m_graph=None): - warnings.warn( - "DiGraph is deprecated, use Graph(directed=True) instead", - DeprecationWarning, - ) - super(DiGraph, self).__init__(m_graph, directed=True) - - class MultiGraph(Graph): """ A Multigraph; a Graph containing more than one edge between vertex pairs. @@ -714,16 +704,6 @@ def is_multigraph(self): return True -class MultiDiGraph(MultiGraph): - def __init__(self): - warnings.warn( - "MultiDiGraph is deprecated,\ - use MultiGraph(directed=True) instead", - DeprecationWarning, - ) - super(MultiDiGraph, self).__init__(directed=True) - - class Tree(Graph): """ A Tree @@ -920,30 +900,6 @@ def is_bipartite(self): return True -class BiPartiteDiGraph(BiPartiteGraph): - """ - A Directed Bipartite Graph - """ - - def __init__(self): - warnings.warn( - "BiPartiteDiGraph is deprecated,\ - use BiPartiteGraph(directed=True) instead", - DeprecationWarning, - ) - super(BiPartiteDiGraph, self).__init__(directed=True) - - -class NPartiteDiGraph(NPartiteGraph): - def __init__(self): - warnings.warn( - "NPartiteDiGraph is deprecated,\ - use NPartiteGraph(directed=True) instead", - DeprecationWarning, - ) - super(NPartiteGraph, self).__init__(directed=True) - - def is_directed(G): """ Returns True if the graph is a directed graph. diff --git a/python/cugraph/cugraph/structure/graph_implementation/simpleDistributedGraph.py b/python/cugraph/cugraph/structure/graph_implementation/simpleDistributedGraph.py index cef40588879..013ef0c8cfc 100644 --- a/python/cugraph/cugraph/structure/graph_implementation/simpleDistributedGraph.py +++ b/python/cugraph/cugraph/structure/graph_implementation/simpleDistributedGraph.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022, NVIDIA CORPORATION. +# Copyright (c) 2021-2023, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -751,15 +751,13 @@ def convert_to_cudf(cp_arrays): return ddf - def to_directed(self, DiG): + def to_directed(self, G): """ Return a directed representation of the graph. - This function sets the type of graph as DiGraph() and returns the - directed view. Returns ------- - G : DiGraph + G : Graph(directed=True) A directed graph with the same nodes, and each edge (u,v,weights) replaced by two directed edges (u,v,weights) and (v,u,weights). diff --git a/python/cugraph/cugraph/testing/utils.py b/python/cugraph/cugraph/testing/utils.py index 443fdcb9092..ce9acbca9b6 100644 --- a/python/cugraph/cugraph/testing/utils.py +++ b/python/cugraph/cugraph/testing/utils.py @@ -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 @@ -168,16 +168,16 @@ def create_obj_from_csv( Return an object based on obj_type populated with the contents of csv_file_name """ - if obj_type in [cugraph.Graph, cugraph.DiGraph]: + if obj_type in [cugraph.Graph]: return generate_cugraph_graph_from_file( csv_file_name, - directed=(obj_type is cugraph.DiGraph), + directed=directed, edgevals=edgevals, ) elif isinstance(obj_type, cugraph.Graph): return generate_cugraph_graph_from_file( csv_file_name, - directed=(obj_type.is_directed()), + directed=directed, edgevals=edgevals, ) diff --git a/python/cugraph/cugraph/tests/test_balanced_cut.py b/python/cugraph/cugraph/tests/test_balanced_cut.py index ef21feb35ad..9054d485779 100644 --- a/python/cugraph/cugraph/tests/test_balanced_cut.py +++ b/python/cugraph/cugraph/tests/test_balanced_cut.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -41,10 +41,10 @@ def random_call(G, partitions): for i in range(num_verts): assignment.append(random.randint(0, partitions - 1)) - assignment_cu = cudf.DataFrame(assignment, columns=["cluster"]) - assignment_cu["vertex"] = assignment_cu.index + assign_cu = cudf.DataFrame(assignment, columns=["cluster"]) + assign_cu["vertex"] = assign_cu.index - score += cugraph.analyzeClustering_edge_cut(G, partitions, assignment_cu) + score += cugraph.analyzeClustering_edge_cut(G, partitions, assign_cu) return set(range(num_verts)), (score / 10.0) @@ -97,28 +97,6 @@ def test_edge_cut_clustering_with_edgevals(graph_file, partitions): assert cu_score < rand_score -# Test to ensure DiGraph objs are not accepted -# Test all combinations of default/managed and pooled/non-pooled allocation - - -def test_digraph_rejected(): - gc.collect() - - df = cudf.DataFrame() - df["src"] = cudf.Series(range(10)) - df["dst"] = cudf.Series(range(10)) - df["val"] = cudf.Series(range(10)) - - with pytest.deprecated_call(): - G = cugraph.DiGraph() - G.from_cudf_edgelist( - df, source="src", destination="dst", edge_attr="val", renumber=False - ) - - with pytest.raises(Exception): - cugraph_call(G, 2) - - @pytest.mark.parametrize("graph_file", DATASETS) @pytest.mark.parametrize("partitions", PARTITIONS) def test_edge_cut_clustering_with_edgevals_nx(graph_file, partitions): diff --git a/python/cugraph/cugraph/tests/test_bfs.py b/python/cugraph/cugraph/tests/test_bfs.py index 679876fa57b..9cda09de87c 100644 --- a/python/cugraph/cugraph/tests/test_bfs.py +++ b/python/cugraph/cugraph/tests/test_bfs.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -405,7 +405,7 @@ def test_bfs(gpubenchmark, dataset_nxresults_startvertex_spc, cugraph_input_type elif cugraph_input_type is nx.Graph: cugraph_input_type = nx.DiGraph - if not isinstance(cugraph_input_type, (cugraph.Graph, cugraph.DiGraph)): + if not isinstance(cugraph_input_type, cugraph.Graph): G_or_matrix = utils.create_obj_from_csv(dataset, cugraph_input_type) else: G_or_matrix = G diff --git a/python/cugraph/cugraph/tests/test_connectivity.py b/python/cugraph/cugraph/tests/test_connectivity.py index 25cbda02094..9650f5ee559 100644 --- a/python/cugraph/cugraph/tests/test_connectivity.py +++ b/python/cugraph/cugraph/tests/test_connectivity.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -306,7 +306,7 @@ def test_weak_cc(gpubenchmark, dataset_nxresults_weak, cugraph_input_type): # cuGraph or nx 'input_type' should have this parameter set to None directed = None - if not isinstance(cugraph_input_type, (cugraph.Graph, cugraph.DiGraph)): + if not isinstance(cugraph_input_type, cugraph.Graph): input_G_or_matrix = utils.create_obj_from_csv( dataset_path, cugraph_input_type, edgevals=True ) @@ -370,7 +370,7 @@ def test_strong_cc(gpubenchmark, dataset_nxresults_strong, cugraph_input_type): api_type, ) = dataset_nxresults_strong - if not isinstance(cugraph_input_type, (cugraph.Graph, cugraph.DiGraph)): + if not isinstance(cugraph_input_type, cugraph.Graph): input_G_or_matrix = utils.create_obj_from_csv( dataset_path, cugraph_input_type, edgevals=True ) diff --git a/python/cugraph/cugraph/tests/test_convert_matrix.py b/python/cugraph/cugraph/tests/test_convert_matrix.py index f4c4360aca8..44a2b9d9598 100644 --- a/python/cugraph/cugraph/tests/test_convert_matrix.py +++ b/python/cugraph/cugraph/tests/test_convert_matrix.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -49,7 +49,7 @@ def test_to_from_pandas(graph_file): nx_pdf = nx_pdf[sorted(nx_pdf.columns)] nx_pdf.sort_index(inplace=True) - # create a cugraph DiGraph and convert to pandas adjacency + # create a cugraph Directed Graph and convert to pandas adjacency cuG = cugraph.from_pandas_edgelist( M, source="0", @@ -91,13 +91,17 @@ def test_from_to_numpy(graph_file): # Read in the graph M = utils.read_csv_for_nx(graph_file, read_weights_in_sp=True) - # create NetworkX and cugraph DiGraph + # create NetworkX and cugraph Directed Graph nxG = nx.from_pandas_edgelist( M, source="0", target="1", edge_attr="weight", create_using=nx.DiGraph ) cuG = cugraph.from_pandas_edgelist( - M, source="0", destination="1", edge_attr="weight", create_using=cugraph.DiGraph + M, + source="0", + destination="1", + edge_attr="weight", + create_using=cugraph.Graph(directed=True), ) # convert graphs to numpy array @@ -112,7 +116,9 @@ def test_from_to_numpy(graph_file): # Create graphs from numpy array new_nxG = nx.from_numpy_array(nparray_nx, create_using=nx.DiGraph) - new_cuG = cugraph.from_numpy_array(nparray_cu, create_using=cugraph.DiGraph) + new_cuG = cugraph.from_numpy_array( + nparray_cu, create_using=cugraph.Graph(directed=True) + ) # Assert graphs are same exp_pdf = nx.to_pandas_edgelist(new_nxG) @@ -130,7 +136,9 @@ def test_from_to_numpy(graph_file): # Create graphs from numpy matrix new_nxG = nx.from_numpy_matrix(npmatrix_nx, create_using=nx.DiGraph) - new_cuG = cugraph.from_numpy_matrix(npmatrix_cu, create_using=cugraph.DiGraph) + new_cuG = cugraph.from_numpy_matrix( + npmatrix_cu, create_using=cugraph.Graph(directed=True) + ) # Assert graphs are same exp_pdf = nx.to_pandas_edgelist(new_nxG) @@ -185,10 +193,10 @@ def test_from_adjlist(graph_file): G1 = cugraph.from_adjlist(cu_offsets, cu_indices, cu_vals, create_using=33) G1 = cugraph.from_adjlist( - cu_offsets, cu_indices, cu_vals, create_using=cugraph.DiGraph + cu_offsets, cu_indices, cu_vals, create_using=cugraph.Graph(directed=True) ) G2 = cugraph.from_adjlist( - pd_offsets, pd_indices, pd_vals, create_using=cugraph.DiGraph + pd_offsets, pd_indices, pd_vals, create_using=cugraph.Graph(directed=True) ) assert G1.AdjList == G2.AdjList diff --git a/python/cugraph/cugraph/tests/test_graph.py b/python/cugraph/cugraph/tests/test_graph.py index 4667b8c9976..c795453d8a0 100644 --- a/python/cugraph/cugraph/tests/test_graph.py +++ b/python/cugraph/cugraph/tests/test_graph.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -397,7 +397,10 @@ def test_consolidation(graph_file): df, source="source", target="target", create_using=nx.DiGraph ) G = cugraph.from_cudf_edgelist( - ddf, source="source", destination="target", create_using=cugraph.DiGraph + ddf, + source="source", + destination="target", + create_using=cugraph.Graph(directed=True), ) t1 = time.time() @@ -683,7 +686,7 @@ def test_graph_init_with_multigraph(): cMG.from_cudf_edgelist(gdf, source="src", destination="dst") cugraph.Graph(m_graph=cMG) - cDiMG = cugraph.MultiDiGraph() # deprecated, but should still work + cDiMG = cugraph.MultiGraph(directed=True) cDiMG.from_cudf_edgelist(gdf, source="src", destination="dst") cugraph.Graph(m_graph=cDiMG) diff --git a/python/cugraph/cugraph/tests/test_louvain.py b/python/cugraph/cugraph/tests/test_louvain.py index cbd243e888d..8717e1bfc97 100644 --- a/python/cugraph/cugraph/tests/test_louvain.py +++ b/python/cugraph/cugraph/tests/test_louvain.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -17,7 +17,7 @@ import pytest import cugraph -import cupy +import cupyx import cudf from cugraph.testing import utils from cugraph.experimental.datasets import DATASETS_UNDIRECTED, karate_asymmetric @@ -116,7 +116,7 @@ def test_louvain_csr_graph(is_weighted): karate = DATASETS_UNDIRECTED[0] df = karate.get_edgelist() - M = cupy.sparse.coo_matrix( + M = cupyx.scipy.sparse.coo_matrix( (df["wgt"].to_cupy(), (df["src"].to_cupy(), df["dst"].to_cupy())) ) M = M.tocsr() diff --git a/python/cugraph/cugraph/tests/test_multigraph.py b/python/cugraph/cugraph/tests/test_multigraph.py index c67454181c1..e6aad439fbd 100644 --- a/python/cugraph/cugraph/tests/test_multigraph.py +++ b/python/cugraph/cugraph/tests/test_multigraph.py @@ -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 @@ -84,7 +84,7 @@ def test_Graph_from_MultiGraph(graph_file): edge_attr="weight", create_using=nx.MultiGraph(), ) - Gd = cugraph.DiGraph(GdM) + Gd = cugraph.Graph(GdM, directed=True) Gnxd = nx.DiGraph(GnxdM) assert Gnxd.number_of_edges() == Gd.number_of_edges() diff --git a/python/cugraph/cugraph/tests/test_nx_convert.py b/python/cugraph/cugraph/tests/test_nx_convert.py index e3340534f10..3d4ef8e6d3e 100644 --- a/python/cugraph/cugraph/tests/test_nx_convert.py +++ b/python/cugraph/cugraph/tests/test_nx_convert.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -81,7 +81,7 @@ def test_networkx_compatibility(graph_file): M, source="0", target="1", edge_attr="weight", create_using=nx.DiGraph() ) - # create a cuGraph DiGraph + # create a cuGraph Directed Graph gdf = cudf.from_pandas(M) gdf = gdf.rename(columns={"weight": "weights"}) cuG = cugraph.from_cudf_edgelist( @@ -89,7 +89,7 @@ def test_networkx_compatibility(graph_file): source="0", destination="1", edge_attr="weights", - create_using=cugraph.DiGraph, + create_using=cugraph.Graph(directed=True), ) _compare_graphs(nxG, cuG) diff --git a/python/cugraph/cugraph/tests/test_random_walks.py b/python/cugraph/cugraph/tests/test_random_walks.py index c951b6a2bc7..00080d312d1 100644 --- a/python/cugraph/cugraph/tests/test_random_walks.py +++ b/python/cugraph/cugraph/tests/test_random_walks.py @@ -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 @@ -43,7 +43,7 @@ def calc_random_walks(graph_file, directed=False, max_depth=None, use_padding=Fa parameters ---------- G : cuGraph.Graph or networkx.Graph - The graph can be either directed (DiGraph) or undirected (Graph). + The graph can be either directed or undirected. Weights in the graph are ignored. Use weight parameter if weights need to be considered (currently not supported) @@ -174,7 +174,7 @@ def test_random_walks( df_G['dst_0'] = df_G['dst'] + 1000 if directed: - G = cugraph.DiGraph() + G = cugraph.Graph(directed=True) else: G = cugraph.Graph() G.from_cudf_edgelist(df_G, source=['src', 'src_0'], diff --git a/python/cugraph/cugraph/tests/test_sssp.py b/python/cugraph/cugraph/tests/test_sssp.py index 1e13116daea..65f248d16d9 100644 --- a/python/cugraph/cugraph/tests/test_sssp.py +++ b/python/cugraph/cugraph/tests/test_sssp.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -223,7 +223,7 @@ def test_sssp(gpubenchmark, dataset_source_nxresults, cugraph_input_type): # Extract the params generated from the fixture (G, dataset_path, source, nx_paths, Gnx) = dataset_source_nxresults - if not isinstance(cugraph_input_type, (cugraph.Graph, cugraph.DiGraph)): + if not isinstance(cugraph_input_type, cugraph.Graph): input_G_or_matrix = utils.create_obj_from_csv( dataset_path, cugraph_input_type, edgevals=True ) diff --git a/python/cugraph/cugraph/tests/test_subgraph_extraction.py b/python/cugraph/cugraph/tests/test_subgraph_extraction.py index fcfd063b61a..bf3137974ef 100644 --- a/python/cugraph/cugraph/tests/test_subgraph_extraction.py +++ b/python/cugraph/cugraph/tests/test_subgraph_extraction.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -40,13 +40,8 @@ def compare_edges(cg, nxg): def cugraph_call(M, verts, directed=True): - # directed is used to create either a Graph or DiGraph so the returned # cugraph can be compared to nx graph of same type. - if directed: - G = cugraph.DiGraph() - else: - G = cugraph.Graph() - cu_M = cudf.DataFrame() + G = cugraph.Graph(directed=directed) cu_M = cudf.from_pandas(M) @@ -75,8 +70,8 @@ def test_subgraph_extraction_DiGraph(graph_file): verts[0] = 0 verts[1] = 1 verts[2] = 17 - cu_sg = cugraph_call(M, verts) - nx_sg = nx_call(M, verts) + cu_sg = cugraph_call(M, verts, True) + nx_sg = nx_call(M, verts, True) assert compare_edges(cu_sg, nx_sg) diff --git a/python/cugraph/cugraph/traversal/bfs.py b/python/cugraph/cugraph/traversal/bfs.py index a5eb463efb8..96e8eb02a77 100644 --- a/python/cugraph/cugraph/traversal/bfs.py +++ b/python/cugraph/cugraph/traversal/bfs.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -17,7 +17,7 @@ from pylibcugraph import ResourceHandle from pylibcugraph import bfs as pylibcugraph_bfs -from cugraph.structure.graph_classes import Graph, DiGraph +from cugraph.structure.graph_classes import Graph from cugraph.utilities import ( ensure_cugraph_obj, is_matrix_type, @@ -43,7 +43,7 @@ def _ensure_args(G, start, i_start, directed): G_type = type(G) # Check for Graph-type inputs - if (G_type in [Graph, DiGraph]) or is_nx_graph_type(G_type): + if G_type is Graph or is_nx_graph_type(G_type): if directed is not None: raise TypeError("'directed' cannot be specified for a " "Graph-type input") @@ -93,7 +93,7 @@ def _convert_df_to_output_type(df, input_type): Given a cudf.DataFrame df, convert it to a new type appropriate for the graph algos in this module, based on input_type. """ - if input_type in [Graph, DiGraph]: + if input_type is Graph: return df elif is_nx_graph_type(input_type): @@ -105,8 +105,8 @@ def _convert_df_to_output_type(df, input_type): # predecessor: cupy.ndarray sorted_df = df.sort_values("vertex") if is_cp_matrix_type(input_type): - distances = cp.fromDlpack(sorted_df["distance"].to_dlpack()) - preds = cp.fromDlpack(sorted_df["predecessor"].to_dlpack()) + distances = cp.from_dlpack(sorted_df["distance"].to_dlpack()) + preds = cp.from_dlpack(sorted_df["predecessor"].to_dlpack()) return (distances, preds) else: distances = sorted_df["distance"].to_numpy() diff --git a/python/cugraph/cugraph/traversal/ms_bfs.py b/python/cugraph/cugraph/traversal/ms_bfs.py index cce4546c8b5..df624e453ee 100644 --- a/python/cugraph/cugraph/traversal/ms_bfs.py +++ b/python/cugraph/cugraph/traversal/ms_bfs.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022, NVIDIA CORPORATION. +# Copyright (c) 2021-2023, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -24,7 +24,7 @@ def _get_feasibility(G, sources, components=None, depth_limit=None): Parameters ---------- - G : cugraph.Graph or cugraph.DiGraph + G : cugraph.Graph The adjacency list will be computed if not already present. sources : cudf.Series @@ -112,7 +112,7 @@ def concurrent_bfs(Graphs, sources, depth_limit=None, offload=False): Parameters ---------- - Graphs : list of cugraph.Graph or cugraph.DiGraph + Graphs : list of cugraph.Graph The adjacency lists will be computed if not already present. sources : list of cudf.Series @@ -152,7 +152,7 @@ def concurrent_bfs(Graphs, sources, depth_limit=None, offload=False): to help us prioritize" ) if not isinstance(Graphs, list): - raise TypeError("Graphs should be a list of cugraph.Graph or cugraph.DiGraph") + raise TypeError("Graphs should be a list of cugraph.Graph") if not isinstance(sources, list): raise TypeError("sources should be a list of cudf.Series") if len(Graphs) != len(sources): @@ -186,7 +186,7 @@ def multi_source_bfs(G, sources, components=None, depth_limit=None, offload=Fals Parameters ---------- - G : cugraph.Graph or cugraph.DiGraph + G : cugraph.Graph The adjacency list will be computed if not already present. sources : cudf.Series diff --git a/python/cugraph/cugraph/traversal/sssp.py b/python/cugraph/cugraph/traversal/sssp.py index 7e04ff7678b..020d5933365 100644 --- a/python/cugraph/cugraph/traversal/sssp.py +++ b/python/cugraph/cugraph/traversal/sssp.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-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 @@ -15,7 +15,7 @@ import warnings import cudf -from cugraph.structure import Graph, DiGraph, MultiGraph, MultiDiGraph +from cugraph.structure import Graph, MultiGraph from cugraph.utilities import ( ensure_cugraph_obj, is_matrix_type, @@ -46,7 +46,7 @@ def _ensure_args( G_type = type(G) # Check for Graph-type inputs - if (G_type in [Graph, DiGraph]) or is_nx_graph_type(G_type): + if G_type is Graph or is_nx_graph_type(G_type): # FIXME: Improve Graph-type checking exc_value = "'%s' cannot be specified for a Graph-type input" if directed is not None: @@ -95,7 +95,7 @@ def _convert_df_to_output_type(df, input_type, return_predecessors): return_predecessors is only used for return values from cupy/scipy input types. """ - if input_type in [Graph, DiGraph, MultiGraph, MultiDiGraph]: + if input_type in [Graph, MultiGraph]: return df elif is_nx_graph_type(input_type): diff --git a/python/cugraph/cugraph/utilities/utils.py b/python/cugraph/cugraph/utilities/utils.py index 1cb15a67851..8cbdf6a8c21 100644 --- a/python/cugraph/cugraph/utilities/utils.py +++ b/python/cugraph/cugraph/utilities/utils.py @@ -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 @@ -257,7 +257,7 @@ def ensure_cugraph_obj(obj, nx_weight_attr=None, matrix_graph_type=None): """ Convert the input obj - if possible - to a cuGraph Graph-type obj (Graph, - DiGraph, etc.) and return a tuple of (cugraph Graph-type obj, original + etc.) and return a tuple of (cugraph Graph-type obj, original input obj type). If matrix_graph_type is specified, it is used as the cugraph Graph-type obj to create when converting from a matrix type. """ @@ -363,10 +363,9 @@ def is_nx_graph_type(g): def is_cugraph_graph_type(g): # FIXME: importing here to avoid circular import - from cugraph.structure import Graph, DiGraph, MultiGraph, MultiDiGraph + from cugraph.structure import Graph, MultiGraph - # FIXME: Remove DiGraph when support is dropped - return g in [Graph, DiGraph, MultiGraph, MultiDiGraph] + return g in [Graph, MultiGraph] def renumber_vertex_pair(input_graph, vertex_pair):