From 3b1092f4e7b800412128a6a885c7f35fcdd9bf53 Mon Sep 17 00:00:00 2001 From: BradReesWork Date: Tue, 10 Jan 2023 12:54:29 -0500 Subject: [PATCH 01/17] Drop DiGraph --- python/cugraph/cugraph/__init__.py | 3 -- .../cugraph/community/subgraph_extraction.py | 5 ++- .../cugraph/components/connectivity.py | 12 +++--- python/cugraph/cugraph/sampling/node2vec.py | 2 +- python/cugraph/cugraph/structure/__init__.py | 3 -- .../cugraph/structure/convert_matrix.py | 16 +------ .../cugraph/structure/graph_classes.py | 43 ------------------- .../simpleDistributedGraph.py | 6 +-- python/cugraph/cugraph/testing/utils.py | 6 +-- .../cugraph/tests/test_balanced_cut.py | 42 +++++++++--------- python/cugraph/cugraph/tests/test_bfs.py | 2 +- .../cugraph/tests/test_connectivity.py | 4 +- .../cugraph/tests/test_convert_matrix.py | 19 +++++--- python/cugraph/cugraph/tests/test_graph.py | 5 ++- .../cugraph/cugraph/tests/test_multigraph.py | 2 +- .../cugraph/cugraph/tests/test_nx_convert.py | 4 +- .../cugraph/tests/test_random_walks.py | 4 +- python/cugraph/cugraph/tests/test_sssp.py | 2 +- .../cugraph/tests/test_subgraph_extraction.py | 11 ++--- python/cugraph/cugraph/traversal/bfs.py | 6 +-- python/cugraph/cugraph/traversal/ms_bfs.py | 8 ++-- python/cugraph/cugraph/traversal/sssp.py | 6 +-- python/cugraph/cugraph/utilities/utils.py | 7 ++- 23 files changed, 76 insertions(+), 142 deletions(-) diff --git a/python/cugraph/cugraph/__init__.py b/python/cugraph/cugraph/__init__.py index 00c36a950b3..55b06f0709f 100644 --- a/python/cugraph/cugraph/__init__.py +++ b/python/cugraph/cugraph/__init__.py @@ -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..7182ba90c57 100644 --- a/python/cugraph/cugraph/community/subgraph_extraction.py +++ b/python/cugraph/cugraph/community/subgraph_extraction.py @@ -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..dc6bc3e606d 100644 --- a/python/cugraph/cugraph/components/connectivity.py +++ b/python/cugraph/cugraph/components/connectivity.py @@ -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): @@ -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(ditected=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..eefedaf48b6 100644 --- a/python/cugraph/cugraph/sampling/node2vec.py +++ b/python/cugraph/cugraph/sampling/node2vec.py @@ -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..937ca622a12 100644 --- a/python/cugraph/cugraph/structure/__init__.py +++ b/python/cugraph/cugraph/structure/__init__.py @@ -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..d98e326a443 100644 --- a/python/cugraph/cugraph/structure/convert_matrix.py +++ b/python/cugraph/cugraph/structure/convert_matrix.py @@ -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..b99afe37a72 100644 --- a/python/cugraph/cugraph/structure/graph_classes.py +++ b/python/cugraph/cugraph/structure/graph_classes.py @@ -688,15 +688,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 +705,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 +901,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..cea66ebf233 100644 --- a/python/cugraph/cugraph/structure/graph_implementation/simpleDistributedGraph.py +++ b/python/cugraph/cugraph/structure/graph_implementation/simpleDistributedGraph.py @@ -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..5432a4b1bb7 100644 --- a/python/cugraph/cugraph/testing/utils.py +++ b/python/cugraph/cugraph/testing/utils.py @@ -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..1595de2dff9 100644 --- a/python/cugraph/cugraph/tests/test_balanced_cut.py +++ b/python/cugraph/cugraph/tests/test_balanced_cut.py @@ -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,26 +97,24 @@ def test_edge_cut_clustering_with_edgevals(graph_file, partitions): assert cu_score < rand_score -# Test to ensure DiGraph objs are not accepted +# Test to ensure Directed 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) +#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.Graph(directed=True) +# 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) diff --git a/python/cugraph/cugraph/tests/test_bfs.py b/python/cugraph/cugraph/tests/test_bfs.py index 679876fa57b..d7b77874d9c 100644 --- a/python/cugraph/cugraph/tests/test_bfs.py +++ b/python/cugraph/cugraph/tests/test_bfs.py @@ -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..a219d28fb8a 100644 --- a/python/cugraph/cugraph/tests/test_connectivity.py +++ b/python/cugraph/cugraph/tests/test_connectivity.py @@ -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..7bfeff706a0 100644 --- a/python/cugraph/cugraph/tests/test_convert_matrix.py +++ b/python/cugraph/cugraph/tests/test_convert_matrix.py @@ -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,14 @@ 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 +113,8 @@ 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 +132,8 @@ 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 +188,12 @@ 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..57e219f03cb 100644 --- a/python/cugraph/cugraph/tests/test_graph.py +++ b/python/cugraph/cugraph/tests/test_graph.py @@ -397,7 +397,8 @@ 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 +684,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_multigraph.py b/python/cugraph/cugraph/tests/test_multigraph.py index c67454181c1..c3387294038 100644 --- a/python/cugraph/cugraph/tests/test_multigraph.py +++ b/python/cugraph/cugraph/tests/test_multigraph.py @@ -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..5cc11effe45 100644 --- a/python/cugraph/cugraph/tests/test_nx_convert.py +++ b/python/cugraph/cugraph/tests/test_nx_convert.py @@ -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..39a1a23a48f 100644 --- a/python/cugraph/cugraph/tests/test_random_walks.py +++ b/python/cugraph/cugraph/tests/test_random_walks.py @@ -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..a65db15f74e 100644 --- a/python/cugraph/cugraph/tests/test_sssp.py +++ b/python/cugraph/cugraph/tests/test_sssp.py @@ -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..5d53081f4dd 100644 --- a/python/cugraph/cugraph/tests/test_subgraph_extraction.py +++ b/python/cugraph/cugraph/tests/test_subgraph_extraction.py @@ -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..9f6bc9ed1e6 100644 --- a/python/cugraph/cugraph/traversal/bfs.py +++ b/python/cugraph/cugraph/traversal/bfs.py @@ -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 in [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 in [Graph]: return df elif is_nx_graph_type(input_type): diff --git a/python/cugraph/cugraph/traversal/ms_bfs.py b/python/cugraph/cugraph/traversal/ms_bfs.py index cce4546c8b5..b348a0fdc06 100644 --- a/python/cugraph/cugraph/traversal/ms_bfs.py +++ b/python/cugraph/cugraph/traversal/ms_bfs.py @@ -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..91b529eeaf7 100644 --- a/python/cugraph/cugraph/traversal/sssp.py +++ b/python/cugraph/cugraph/traversal/sssp.py @@ -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 in [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..5e4ebfd3e21 100644 --- a/python/cugraph/cugraph/utilities/utils.py +++ b/python/cugraph/cugraph/utilities/utils.py @@ -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): From ba2f390277f70529db3e1b01132a54d5da97066b Mon Sep 17 00:00:00 2001 From: BradReesWork Date: Tue, 10 Jan 2023 13:26:08 -0500 Subject: [PATCH 02/17] fix dlpack DeprecationWarning --- python/cugraph/cugraph/components/connectivity.py | 2 +- python/cugraph/cugraph/tests/test_louvain.py | 4 ++-- python/cugraph/cugraph/traversal/bfs.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/python/cugraph/cugraph/components/connectivity.py b/python/cugraph/cugraph/components/connectivity.py index dc6bc3e606d..7f4046d4b7f 100644 --- a/python/cugraph/cugraph/components/connectivity.py +++ b/python/cugraph/cugraph/components/connectivity.py @@ -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) diff --git a/python/cugraph/cugraph/tests/test_louvain.py b/python/cugraph/cugraph/tests/test_louvain.py index cbd243e888d..8a8a1b741cf 100644 --- a/python/cugraph/cugraph/tests/test_louvain.py +++ b/python/cugraph/cugraph/tests/test_louvain.py @@ -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/traversal/bfs.py b/python/cugraph/cugraph/traversal/bfs.py index 9f6bc9ed1e6..4271f052850 100644 --- a/python/cugraph/cugraph/traversal/bfs.py +++ b/python/cugraph/cugraph/traversal/bfs.py @@ -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() From c9d61559484bed17267c76e15d465c3a92aafc46 Mon Sep 17 00:00:00 2001 From: BradReesWork Date: Tue, 10 Jan 2023 13:58:27 -0500 Subject: [PATCH 03/17] setting copyright to 2023 --- python/cugraph/cugraph/__init__.py | 2 +- python/cugraph/cugraph/community/subgraph_extraction.py | 2 +- python/cugraph/cugraph/components/connectivity.py | 2 +- python/cugraph/cugraph/sampling/node2vec.py | 2 +- python/cugraph/cugraph/structure/__init__.py | 2 +- python/cugraph/cugraph/structure/convert_matrix.py | 2 +- python/cugraph/cugraph/structure/graph_classes.py | 2 +- .../structure/graph_implementation/simpleDistributedGraph.py | 2 +- python/cugraph/cugraph/testing/utils.py | 2 +- python/cugraph/cugraph/tests/test_balanced_cut.py | 2 +- python/cugraph/cugraph/tests/test_bfs.py | 2 +- python/cugraph/cugraph/tests/test_connectivity.py | 2 +- python/cugraph/cugraph/tests/test_convert_matrix.py | 2 +- python/cugraph/cugraph/tests/test_graph.py | 2 +- python/cugraph/cugraph/tests/test_louvain.py | 2 +- python/cugraph/cugraph/tests/test_multigraph.py | 2 +- python/cugraph/cugraph/tests/test_nx_convert.py | 2 +- python/cugraph/cugraph/tests/test_random_walks.py | 2 +- python/cugraph/cugraph/tests/test_sssp.py | 2 +- python/cugraph/cugraph/tests/test_subgraph_extraction.py | 2 +- python/cugraph/cugraph/traversal/bfs.py | 2 +- python/cugraph/cugraph/traversal/ms_bfs.py | 2 +- python/cugraph/cugraph/traversal/sssp.py | 2 +- python/cugraph/cugraph/utilities/utils.py | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/python/cugraph/cugraph/__init__.py b/python/cugraph/cugraph/__init__.py index 55b06f0709f..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 diff --git a/python/cugraph/cugraph/community/subgraph_extraction.py b/python/cugraph/cugraph/community/subgraph_extraction.py index 7182ba90c57..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 diff --git a/python/cugraph/cugraph/components/connectivity.py b/python/cugraph/cugraph/components/connectivity.py index 7f4046d4b7f..4437a522957 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 diff --git a/python/cugraph/cugraph/sampling/node2vec.py b/python/cugraph/cugraph/sampling/node2vec.py index eefedaf48b6..c0f9e6a3cfc 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) 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/structure/__init__.py b/python/cugraph/cugraph/structure/__init__.py index 937ca622a12..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 diff --git a/python/cugraph/cugraph/structure/convert_matrix.py b/python/cugraph/cugraph/structure/convert_matrix.py index d98e326a443..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 diff --git a/python/cugraph/cugraph/structure/graph_classes.py b/python/cugraph/cugraph/structure/graph_classes.py index b99afe37a72..1f8435ea208 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 diff --git a/python/cugraph/cugraph/structure/graph_implementation/simpleDistributedGraph.py b/python/cugraph/cugraph/structure/graph_implementation/simpleDistributedGraph.py index cea66ebf233..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 diff --git a/python/cugraph/cugraph/testing/utils.py b/python/cugraph/cugraph/testing/utils.py index 5432a4b1bb7..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 diff --git a/python/cugraph/cugraph/tests/test_balanced_cut.py b/python/cugraph/cugraph/tests/test_balanced_cut.py index 1595de2dff9..7387a737db8 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 diff --git a/python/cugraph/cugraph/tests/test_bfs.py b/python/cugraph/cugraph/tests/test_bfs.py index d7b77874d9c..ecbf950c969 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 diff --git a/python/cugraph/cugraph/tests/test_connectivity.py b/python/cugraph/cugraph/tests/test_connectivity.py index a219d28fb8a..f61169bd705 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 diff --git a/python/cugraph/cugraph/tests/test_convert_matrix.py b/python/cugraph/cugraph/tests/test_convert_matrix.py index 7bfeff706a0..49825fe7059 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 diff --git a/python/cugraph/cugraph/tests/test_graph.py b/python/cugraph/cugraph/tests/test_graph.py index 57e219f03cb..711b8144e0a 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 diff --git a/python/cugraph/cugraph/tests/test_louvain.py b/python/cugraph/cugraph/tests/test_louvain.py index 8a8a1b741cf..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 diff --git a/python/cugraph/cugraph/tests/test_multigraph.py b/python/cugraph/cugraph/tests/test_multigraph.py index c3387294038..aec016b050c 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 diff --git a/python/cugraph/cugraph/tests/test_nx_convert.py b/python/cugraph/cugraph/tests/test_nx_convert.py index 5cc11effe45..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 diff --git a/python/cugraph/cugraph/tests/test_random_walks.py b/python/cugraph/cugraph/tests/test_random_walks.py index 39a1a23a48f..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 diff --git a/python/cugraph/cugraph/tests/test_sssp.py b/python/cugraph/cugraph/tests/test_sssp.py index a65db15f74e..5c817bb273e 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 diff --git a/python/cugraph/cugraph/tests/test_subgraph_extraction.py b/python/cugraph/cugraph/tests/test_subgraph_extraction.py index 5d53081f4dd..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 diff --git a/python/cugraph/cugraph/traversal/bfs.py b/python/cugraph/cugraph/traversal/bfs.py index 4271f052850..eac30414f07 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 diff --git a/python/cugraph/cugraph/traversal/ms_bfs.py b/python/cugraph/cugraph/traversal/ms_bfs.py index b348a0fdc06..cb6d1ca0b23 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 diff --git a/python/cugraph/cugraph/traversal/sssp.py b/python/cugraph/cugraph/traversal/sssp.py index 91b529eeaf7..ec03d6a3701 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 diff --git a/python/cugraph/cugraph/utilities/utils.py b/python/cugraph/cugraph/utilities/utils.py index 5e4ebfd3e21..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 From c1d26d318ba48710dd5cd986d540475e56fb2549 Mon Sep 17 00:00:00 2001 From: BradReesWork Date: Tue, 10 Jan 2023 14:06:21 -0500 Subject: [PATCH 04/17] fix flake8 error --- python/cugraph/cugraph/structure/graph_classes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/cugraph/cugraph/structure/graph_classes.py b/python/cugraph/cugraph/structure/graph_classes.py index 1f8435ea208..add1be1f099 100644 --- a/python/cugraph/cugraph/structure/graph_classes.py +++ b/python/cugraph/cugraph/structure/graph_classes.py @@ -19,7 +19,6 @@ ) import cudf import dask_cudf -import warnings from cugraph.utilities.utils import import_optional From e52259c27ff87d057cd4e90c3197aeed8e79868b Mon Sep 17 00:00:00 2001 From: BradReesWork Date: Tue, 10 Jan 2023 14:13:37 -0500 Subject: [PATCH 05/17] remove dead code and flake8 error --- .../cugraph/tests/test_balanced_cut.py | 23 ++----------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/python/cugraph/cugraph/tests/test_balanced_cut.py b/python/cugraph/cugraph/tests/test_balanced_cut.py index 7387a737db8..4b25c09ff0f 100644 --- a/python/cugraph/cugraph/tests/test_balanced_cut.py +++ b/python/cugraph/cugraph/tests/test_balanced_cut.py @@ -27,7 +27,8 @@ def cugraph_call(G, partitions): G, partitions, num_eigen_vects=partitions ) - score = cugraph.analyzeClustering_edge_cut(G, partitions, df, "vertex", "cluster") + score = cugraph.analyzeClustering_edge_cut( + G, partitions, df, "vertex", "cluster") return set(df["vertex"].to_numpy()), score @@ -97,26 +98,6 @@ def test_edge_cut_clustering_with_edgevals(graph_file, partitions): assert cu_score < rand_score -# Test to ensure Directed 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.Graph(directed=True) -# 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): From 8887709bf1b6970ac3efce7b32308884588f5f7a Mon Sep 17 00:00:00 2001 From: BradReesWork Date: Tue, 10 Jan 2023 14:26:14 -0500 Subject: [PATCH 06/17] flake8 issues --- .../cugraph/tests/test_convert_matrix.py | 15 ++++-- python/cugraph/cugraph/tests/test_graph.py | 48 +++++++++++++------ .../cugraph/cugraph/tests/test_multigraph.py | 11 +++-- python/cugraph/cugraph/traversal/ms_bfs.py | 10 ++-- 4 files changed, 57 insertions(+), 27 deletions(-) diff --git a/python/cugraph/cugraph/tests/test_convert_matrix.py b/python/cugraph/cugraph/tests/test_convert_matrix.py index 49825fe7059..c3cfb9d74bd 100644 --- a/python/cugraph/cugraph/tests/test_convert_matrix.py +++ b/python/cugraph/cugraph/tests/test_convert_matrix.py @@ -113,8 +113,10 @@ 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.Graph(directed=True)) + 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) @@ -132,8 +134,10 @@ 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.Graph(directed=True)) + 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,7 +189,8 @@ def test_from_adjlist(graph_file): with pytest.raises(TypeError): G1 = cugraph.from_adjlist(cu_offsets, pd_indices) with pytest.raises(TypeError): - 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=33) G1 = cugraph.from_adjlist( cu_offsets, cu_indices, cu_vals, diff --git a/python/cugraph/cugraph/tests/test_graph.py b/python/cugraph/cugraph/tests/test_graph.py index 711b8144e0a..975eb294e53 100644 --- a/python/cugraph/cugraph/tests/test_graph.py +++ b/python/cugraph/cugraph/tests/test_graph.py @@ -112,7 +112,8 @@ def compare_graphs(nx_graph, cu_graph): if len(edgelist_df.columns) > 2: df0 = cudf.from_pandas(nx.to_pandas_edgelist(nx_graph)) - merge = df.merge(df0, on=["source", "target"], suffixes=("_cugraph", "_nx")) + merge = df.merge( + df0, on=["source", "target"], suffixes=("_cugraph", "_nx")) print("merge = \n", merge) print(merge[merge.weight_cugraph != merge.weight_nx]) if not merge["weight_cugraph"].equals(merge["weight_nx"]): @@ -192,7 +193,9 @@ def test_add_edge_list_to_adj_list(graph_file): def test_add_adj_list_to_edge_list(graph_file): Mnx = utils.read_csv_for_nx(graph_file) N = max(max(Mnx["0"]), max(Mnx["1"])) + 1 - Mcsr = scipy.sparse.csr_matrix((Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) + Mcsr = scipy.sparse.csr_matrix( + (Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N) + ) offsets = cudf.Series(Mcsr.indptr) indices = cudf.Series(Mcsr.indices) @@ -217,7 +220,9 @@ def test_add_adj_list_to_edge_list(graph_file): def test_view_edge_list_from_adj_list(graph_file): Mnx = utils.read_csv_for_nx(graph_file) N = max(max(Mnx["0"]), max(Mnx["1"])) + 1 - Mcsr = scipy.sparse.csr_matrix((Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) + Mcsr = scipy.sparse.csr_matrix( + (Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N) + ) offsets = cudf.Series(Mcsr.indptr) indices = cudf.Series(Mcsr.indices) @@ -240,7 +245,8 @@ def test_delete_edge_list_delete_adj_list(graph_file): df["dst"] = cudf.Series(Mnx["1"]) N = max(max(Mnx["0"]), max(Mnx["1"])) + 1 - Mcsr = scipy.sparse.csr_matrix((Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) + Mcsr = scipy.sparse.csr_matrix( + (Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) offsets = cudf.Series(Mcsr.indptr) indices = cudf.Series(Mcsr.indices) @@ -266,7 +272,8 @@ def test_add_edge_or_adj_list_after_add_edge_or_adj_list(graph_file): df["dst"] = cudf.Series(Mnx["1"]) N = max(max(Mnx["0"]), max(Mnx["1"])) + 1 - Mcsr = scipy.sparse.csr_matrix((Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) + Mcsr = scipy.sparse.csr_matrix(( + Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) offsets = cudf.Series(Mcsr.indptr) indices = cudf.Series(Mcsr.indices) @@ -367,8 +374,10 @@ def test_view_edge_list_for_Graph(graph_file): # Compare nx and cugraph edges when viewing edgelist # assert cu_edge_list.equals(nx_edge_list) - assert (cu_edge_list["src"].to_numpy() == nx_edge_list["src"].to_numpy()).all() - assert (cu_edge_list["dst"].to_numpy() == nx_edge_list["dst"].to_numpy()).all() + assert (cu_edge_list["src"].to_numpy() == + nx_edge_list["src"].to_numpy()).all() + assert (cu_edge_list["dst"].to_numpy() == + nx_edge_list["dst"].to_numpy()).all() # Test @@ -423,7 +432,8 @@ def test_two_hop_neighbors(graph_file): df = G.get_two_hop_neighbors() Mnx = utils.read_csv_for_nx(graph_file) N = max(max(Mnx["0"]), max(Mnx["1"])) + 1 - Mcsr = scipy.sparse.csr_matrix((Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) + Mcsr = scipy.sparse.csr_matrix(( + Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) find_two_paths(df, Mcsr) check_all_two_hops(df, Mcsr) @@ -438,7 +448,8 @@ def test_degree_functionality(graph_file): G = cugraph.Graph(directed=True) G.from_cudf_edgelist(cu_M, source="0", destination="1", edge_attr="2") - Gnx = nx.from_pandas_edgelist(M, source="0", target="1", create_using=nx.DiGraph()) + Gnx = nx.from_pandas_edgelist( + M, source="0", target="1", create_using=nx.DiGraph()) df_in_degree = G.in_degree() df_out_degree = G.out_degree() @@ -474,7 +485,8 @@ def test_degrees_functionality(graph_file): G = cugraph.Graph(directed=True) G.from_cudf_edgelist(cu_M, source="0", destination="1", edge_attr="2") - Gnx = nx.from_pandas_edgelist(M, source="0", target="1", create_using=nx.DiGraph()) + Gnx = nx.from_pandas_edgelist( + M, source="0", target="1", create_using=nx.DiGraph()) df = G.degrees() @@ -506,7 +518,8 @@ def test_number_of_vertices(graph_file): # cugraph add_edge_list G = cugraph.Graph(directed=True) G.from_cudf_edgelist(cu_M, source="0", destination="1") - Gnx = nx.from_pandas_edgelist(M, source="0", target="1", create_using=nx.DiGraph()) + Gnx = nx.from_pandas_edgelist( + M, source="0", target="1", create_using=nx.DiGraph()) assert G.number_of_vertices() == Gnx.number_of_nodes() @@ -522,7 +535,8 @@ def test_to_directed(graph_file): # cugraph add_edge_list G = cugraph.Graph() G.from_cudf_edgelist(cu_M, source="0", destination="1") - Gnx = nx.from_pandas_edgelist(M, source="0", target="1", create_using=nx.Graph()) + Gnx = nx.from_pandas_edgelist( + M, source="0", target="1", create_using=nx.Graph()) DiG = G.to_directed() DiGnx = Gnx.to_directed() @@ -619,7 +633,7 @@ def test_bipartite_api(graph_file): nodes = cudf.concat([cu_M["0"], cu_M["1"]]).unique() # Create set of nodes for partition - set1_exp = cudf.Series(nodes[0 : int(len(nodes) / 2)]) + set1_exp = cudf.Series(nodes[0: int(len(nodes) / 2)]) set2_exp = cudf.Series(set(nodes.values_host) - set(set1_exp.values_host)) G = cugraph.BiPartiteGraph() @@ -648,7 +662,8 @@ def test_neighbors(graph_file): G = cugraph.Graph() G.from_cudf_edgelist(cu_M, source="0", destination="1") - Gnx = nx.from_pandas_edgelist(M, source="0", target="1", create_using=nx.Graph()) + Gnx = nx.from_pandas_edgelist(M, source="0", target="1", + create_using=nx.Graph()) for n in nodes.values_host: cu_neighbors = G.neighbors(n).to_arrow().to_pylist() nx_neighbors = [i for i in Gnx.neighbors(n)] @@ -692,7 +707,10 @@ def test_graph_init_with_multigraph(): @pytest.mark.parametrize("graph_file", utils.DATASETS) def test_create_sg_graph(graph_file): el = utils.read_csv_file(graph_file) - G = cugraph.from_cudf_edgelist(el, source="0", destination="1", edge_attr="2") + G = cugraph.from_cudf_edgelist( + el, source="0", + destination="1", edge_attr="2" + ) # ensure graph exists assert G._plc_graph is not None diff --git a/python/cugraph/cugraph/tests/test_multigraph.py b/python/cugraph/cugraph/tests/test_multigraph.py index aec016b050c..7ca2f92d39d 100644 --- a/python/cugraph/cugraph/tests/test_multigraph.py +++ b/python/cugraph/cugraph/tests/test_multigraph.py @@ -47,14 +47,17 @@ def test_multigraph(graph_file): assert G.number_of_nodes() == Gnx.number_of_nodes() cuedges = cugraph.to_pandas_edgelist(G) cuedges.rename( - columns={"src": "source", "dst": "target", "weights": "weight"}, inplace=True + columns={"src": "source", "dst": "target", "weights": "weight"}, + inplace=True ) cuedges["weight"] = cuedges["weight"].round(decimals=3) nxedges = nx.to_pandas_edgelist(Gnx).astype( dtype={"source": "int32", "target": "int32", "weight": "float32"} ) - cuedges = cuedges.sort_values(by=["source", "target"]).reset_index(drop=True) - nxedges = nxedges.sort_values(by=["source", "target"]).reset_index(drop=True) + cuedges = cuedges.sort_values( + by=["source", "target"]).reset_index(drop=True) + nxedges = nxedges.sort_values( + by=["source", "target"]).reset_index(drop=True) nxedges["weight"] = nxedges["weight"].round(decimals=3) assert nxedges.equals(cuedges[["source", "target", "weight"]]) @@ -84,7 +87,7 @@ def test_Graph_from_MultiGraph(graph_file): edge_attr="weight", create_using=nx.MultiGraph(), ) - Gd = cugraph.Graph(GdM,directed=True) + 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/traversal/ms_bfs.py b/python/cugraph/cugraph/traversal/ms_bfs.py index cb6d1ca0b23..da69a2b2e86 100644 --- a/python/cugraph/cugraph/traversal/ms_bfs.py +++ b/python/cugraph/cugraph/traversal/ms_bfs.py @@ -24,7 +24,7 @@ def _get_feasibility(G, sources, components=None, depth_limit=None): Parameters ---------- - G : cugraph.Graph + G : cugraph.Graph The adjacency list will be computed if not already present. sources : cudf.Series @@ -93,7 +93,9 @@ def _get_feasibility(G, sources, components=None, depth_limit=None): tmp = components["color"].value_counts() n_components = tmp.size if n_sources / n_components > 100: - warnings.warn("High number of seeds per component result in large output.") + warnings.warn( + "High number of seeds per component result in large output." + ) mean_component_sz = tmp.mean() output_sz = mean_component_sz * n_sources * 2 * size_of_e @@ -180,7 +182,9 @@ def concurrent_bfs(Graphs, sources, depth_limit=None, offload=False): # ) -def multi_source_bfs(G, sources, components=None, depth_limit=None, offload=False): +def multi_source_bfs( + G, sources, components=None, depth_limit=None, offload=False + ): """ Find the breadth first traversal from multiple sources in a graph. From 682aba67d4e0daf80712713593084d1a4fb92d5f Mon Sep 17 00:00:00 2001 From: Brad Rees <34135411+BradReesWork@users.noreply.github.com> Date: Tue, 10 Jan 2023 14:29:11 -0500 Subject: [PATCH 07/17] Update python/cugraph/cugraph/components/connectivity.py Co-authored-by: Alex Barghi <105237337+alexbarghi-nv@users.noreply.github.com> --- python/cugraph/cugraph/components/connectivity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cugraph/cugraph/components/connectivity.py b/python/cugraph/cugraph/components/connectivity.py index 4437a522957..394c07e94f1 100644 --- a/python/cugraph/cugraph/components/connectivity.py +++ b/python/cugraph/cugraph/components/connectivity.py @@ -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 Graph(ditected=True) + 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 From 2e741e8a126074b52d5bfd65673e4b22ec708e3d Mon Sep 17 00:00:00 2001 From: Brad Rees <34135411+BradReesWork@users.noreply.github.com> Date: Tue, 10 Jan 2023 14:31:05 -0500 Subject: [PATCH 08/17] Update python/cugraph/cugraph/tests/test_bfs.py Co-authored-by: Alex Barghi <105237337+alexbarghi-nv@users.noreply.github.com> --- python/cugraph/cugraph/tests/test_bfs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cugraph/cugraph/tests/test_bfs.py b/python/cugraph/cugraph/tests/test_bfs.py index ecbf950c969..9cda09de87c 100644 --- a/python/cugraph/cugraph/tests/test_bfs.py +++ b/python/cugraph/cugraph/tests/test_bfs.py @@ -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)): + 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 From 291b5b9f901f34d2553ddd035089a407ad39937c Mon Sep 17 00:00:00 2001 From: Brad Rees <34135411+BradReesWork@users.noreply.github.com> Date: Tue, 10 Jan 2023 14:31:13 -0500 Subject: [PATCH 09/17] Update python/cugraph/cugraph/tests/test_connectivity.py Co-authored-by: Alex Barghi <105237337+alexbarghi-nv@users.noreply.github.com> --- python/cugraph/cugraph/tests/test_connectivity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cugraph/cugraph/tests/test_connectivity.py b/python/cugraph/cugraph/tests/test_connectivity.py index f61169bd705..f403f09cb5a 100644 --- a/python/cugraph/cugraph/tests/test_connectivity.py +++ b/python/cugraph/cugraph/tests/test_connectivity.py @@ -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)): + if not isinstance(cugraph_input_type, cugraph.Graph): input_G_or_matrix = utils.create_obj_from_csv( dataset_path, cugraph_input_type, edgevals=True ) From 4a2afe34dbb51434c0441ac2545e3d054a13ae04 Mon Sep 17 00:00:00 2001 From: Brad Rees <34135411+BradReesWork@users.noreply.github.com> Date: Tue, 10 Jan 2023 14:31:21 -0500 Subject: [PATCH 10/17] Update python/cugraph/cugraph/tests/test_connectivity.py Co-authored-by: Alex Barghi <105237337+alexbarghi-nv@users.noreply.github.com> --- python/cugraph/cugraph/tests/test_connectivity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cugraph/cugraph/tests/test_connectivity.py b/python/cugraph/cugraph/tests/test_connectivity.py index f403f09cb5a..9650f5ee559 100644 --- a/python/cugraph/cugraph/tests/test_connectivity.py +++ b/python/cugraph/cugraph/tests/test_connectivity.py @@ -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)): + if not isinstance(cugraph_input_type, cugraph.Graph): input_G_or_matrix = utils.create_obj_from_csv( dataset_path, cugraph_input_type, edgevals=True ) From dc46b3eff4fe9875109283f4f1bc2f3cff15ace5 Mon Sep 17 00:00:00 2001 From: Brad Rees <34135411+BradReesWork@users.noreply.github.com> Date: Tue, 10 Jan 2023 14:31:53 -0500 Subject: [PATCH 11/17] Update python/cugraph/cugraph/tests/test_sssp.py Co-authored-by: Alex Barghi <105237337+alexbarghi-nv@users.noreply.github.com> --- python/cugraph/cugraph/tests/test_sssp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cugraph/cugraph/tests/test_sssp.py b/python/cugraph/cugraph/tests/test_sssp.py index 5c817bb273e..65f248d16d9 100644 --- a/python/cugraph/cugraph/tests/test_sssp.py +++ b/python/cugraph/cugraph/tests/test_sssp.py @@ -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)): + if not isinstance(cugraph_input_type, cugraph.Graph): input_G_or_matrix = utils.create_obj_from_csv( dataset_path, cugraph_input_type, edgevals=True ) From 2180dd381d063e0519f76047b89ecd55d9fe808b Mon Sep 17 00:00:00 2001 From: Brad Rees <34135411+BradReesWork@users.noreply.github.com> Date: Tue, 10 Jan 2023 14:32:11 -0500 Subject: [PATCH 12/17] Update python/cugraph/cugraph/traversal/bfs.py Co-authored-by: Alex Barghi <105237337+alexbarghi-nv@users.noreply.github.com> --- python/cugraph/cugraph/traversal/bfs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cugraph/cugraph/traversal/bfs.py b/python/cugraph/cugraph/traversal/bfs.py index eac30414f07..e91b9bf3d82 100644 --- a/python/cugraph/cugraph/traversal/bfs.py +++ b/python/cugraph/cugraph/traversal/bfs.py @@ -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]) 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") From 49186c32c405714065223838a0e409d3a8021005 Mon Sep 17 00:00:00 2001 From: Brad Rees <34135411+BradReesWork@users.noreply.github.com> Date: Tue, 10 Jan 2023 14:32:19 -0500 Subject: [PATCH 13/17] Update python/cugraph/cugraph/traversal/bfs.py Co-authored-by: Alex Barghi <105237337+alexbarghi-nv@users.noreply.github.com> --- python/cugraph/cugraph/traversal/bfs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cugraph/cugraph/traversal/bfs.py b/python/cugraph/cugraph/traversal/bfs.py index e91b9bf3d82..96e8eb02a77 100644 --- a/python/cugraph/cugraph/traversal/bfs.py +++ b/python/cugraph/cugraph/traversal/bfs.py @@ -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]: + if input_type is Graph: return df elif is_nx_graph_type(input_type): From c59d32848abb0892b77e69b9c19fb8670d9f2072 Mon Sep 17 00:00:00 2001 From: Brad Rees <34135411+BradReesWork@users.noreply.github.com> Date: Tue, 10 Jan 2023 14:32:26 -0500 Subject: [PATCH 14/17] Update python/cugraph/cugraph/traversal/sssp.py Co-authored-by: Alex Barghi <105237337+alexbarghi-nv@users.noreply.github.com> --- python/cugraph/cugraph/traversal/sssp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cugraph/cugraph/traversal/sssp.py b/python/cugraph/cugraph/traversal/sssp.py index ec03d6a3701..020d5933365 100644 --- a/python/cugraph/cugraph/traversal/sssp.py +++ b/python/cugraph/cugraph/traversal/sssp.py @@ -46,7 +46,7 @@ def _ensure_args( G_type = type(G) # Check for Graph-type inputs - if (G_type in [Graph]) 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: From adda3cb275d3cf27ab1532d656a1d80eee3d3dd1 Mon Sep 17 00:00:00 2001 From: BradReesWork Date: Tue, 10 Jan 2023 14:33:49 -0500 Subject: [PATCH 15/17] copyright fix --- python/cugraph/cugraph/sampling/node2vec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cugraph/cugraph/sampling/node2vec.py b/python/cugraph/cugraph/sampling/node2vec.py index c0f9e6a3cfc..e12eb65483c 100644 --- a/python/cugraph/cugraph/sampling/node2vec.py +++ b/python/cugraph/cugraph/sampling/node2vec.py @@ -1,4 +1,4 @@ -# Copyright (c) 2023, 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 baa5615dbcb382e3eb606d6616bf41babc88694f Mon Sep 17 00:00:00 2001 From: BradReesWork Date: Tue, 10 Jan 2023 14:39:57 -0500 Subject: [PATCH 16/17] fixed extra space in copyright --- python/cugraph/cugraph/sampling/node2vec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cugraph/cugraph/sampling/node2vec.py b/python/cugraph/cugraph/sampling/node2vec.py index e12eb65483c..2f94fa9dceb 100644 --- a/python/cugraph/cugraph/sampling/node2vec.py +++ b/python/cugraph/cugraph/sampling/node2vec.py @@ -1,4 +1,4 @@ -# Copyright (c) 2022- 2023, 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 322c8d44902b258a815b5da5fd83a733eff6c44c Mon Sep 17 00:00:00 2001 From: BradReesWork Date: Tue, 10 Jan 2023 14:59:22 -0500 Subject: [PATCH 17/17] black format --- .../cugraph/tests/test_balanced_cut.py | 3 +- .../cugraph/tests/test_convert_matrix.py | 26 +++++---- python/cugraph/cugraph/tests/test_graph.py | 54 +++++++------------ .../cugraph/cugraph/tests/test_multigraph.py | 9 ++-- python/cugraph/cugraph/traversal/ms_bfs.py | 8 +-- 5 files changed, 37 insertions(+), 63 deletions(-) diff --git a/python/cugraph/cugraph/tests/test_balanced_cut.py b/python/cugraph/cugraph/tests/test_balanced_cut.py index 4b25c09ff0f..9054d485779 100644 --- a/python/cugraph/cugraph/tests/test_balanced_cut.py +++ b/python/cugraph/cugraph/tests/test_balanced_cut.py @@ -27,8 +27,7 @@ def cugraph_call(G, partitions): G, partitions, num_eigen_vects=partitions ) - score = cugraph.analyzeClustering_edge_cut( - G, partitions, df, "vertex", "cluster") + score = cugraph.analyzeClustering_edge_cut(G, partitions, df, "vertex", "cluster") return set(df["vertex"].to_numpy()), score diff --git a/python/cugraph/cugraph/tests/test_convert_matrix.py b/python/cugraph/cugraph/tests/test_convert_matrix.py index c3cfb9d74bd..44a2b9d9598 100644 --- a/python/cugraph/cugraph/tests/test_convert_matrix.py +++ b/python/cugraph/cugraph/tests/test_convert_matrix.py @@ -97,8 +97,11 @@ def test_from_to_numpy(graph_file): ) cuG = cugraph.from_pandas_edgelist( - M, source="0", destination="1", edge_attr="weight", - create_using=cugraph.Graph(directed=True) + M, + source="0", + destination="1", + edge_attr="weight", + create_using=cugraph.Graph(directed=True), ) # convert graphs to numpy array @@ -114,9 +117,8 @@ 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.Graph(directed=True) - ) + nparray_cu, create_using=cugraph.Graph(directed=True) + ) # Assert graphs are same exp_pdf = nx.to_pandas_edgelist(new_nxG) @@ -135,9 +137,8 @@ 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.Graph(directed=True) - ) + npmatrix_cu, create_using=cugraph.Graph(directed=True) + ) # Assert graphs are same exp_pdf = nx.to_pandas_edgelist(new_nxG) @@ -189,16 +190,13 @@ def test_from_adjlist(graph_file): with pytest.raises(TypeError): G1 = cugraph.from_adjlist(cu_offsets, pd_indices) with pytest.raises(TypeError): - 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=33) G1 = cugraph.from_adjlist( - cu_offsets, cu_indices, cu_vals, - create_using=cugraph.Graph(directed=True) + 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.Graph(directed=True) + 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 975eb294e53..c795453d8a0 100644 --- a/python/cugraph/cugraph/tests/test_graph.py +++ b/python/cugraph/cugraph/tests/test_graph.py @@ -112,8 +112,7 @@ def compare_graphs(nx_graph, cu_graph): if len(edgelist_df.columns) > 2: df0 = cudf.from_pandas(nx.to_pandas_edgelist(nx_graph)) - merge = df.merge( - df0, on=["source", "target"], suffixes=("_cugraph", "_nx")) + merge = df.merge(df0, on=["source", "target"], suffixes=("_cugraph", "_nx")) print("merge = \n", merge) print(merge[merge.weight_cugraph != merge.weight_nx]) if not merge["weight_cugraph"].equals(merge["weight_nx"]): @@ -193,9 +192,7 @@ def test_add_edge_list_to_adj_list(graph_file): def test_add_adj_list_to_edge_list(graph_file): Mnx = utils.read_csv_for_nx(graph_file) N = max(max(Mnx["0"]), max(Mnx["1"])) + 1 - Mcsr = scipy.sparse.csr_matrix( - (Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N) - ) + Mcsr = scipy.sparse.csr_matrix((Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) offsets = cudf.Series(Mcsr.indptr) indices = cudf.Series(Mcsr.indices) @@ -220,9 +217,7 @@ def test_add_adj_list_to_edge_list(graph_file): def test_view_edge_list_from_adj_list(graph_file): Mnx = utils.read_csv_for_nx(graph_file) N = max(max(Mnx["0"]), max(Mnx["1"])) + 1 - Mcsr = scipy.sparse.csr_matrix( - (Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N) - ) + Mcsr = scipy.sparse.csr_matrix((Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) offsets = cudf.Series(Mcsr.indptr) indices = cudf.Series(Mcsr.indices) @@ -245,8 +240,7 @@ def test_delete_edge_list_delete_adj_list(graph_file): df["dst"] = cudf.Series(Mnx["1"]) N = max(max(Mnx["0"]), max(Mnx["1"])) + 1 - Mcsr = scipy.sparse.csr_matrix( - (Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) + Mcsr = scipy.sparse.csr_matrix((Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) offsets = cudf.Series(Mcsr.indptr) indices = cudf.Series(Mcsr.indices) @@ -272,8 +266,7 @@ def test_add_edge_or_adj_list_after_add_edge_or_adj_list(graph_file): df["dst"] = cudf.Series(Mnx["1"]) N = max(max(Mnx["0"]), max(Mnx["1"])) + 1 - Mcsr = scipy.sparse.csr_matrix(( - Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) + Mcsr = scipy.sparse.csr_matrix((Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) offsets = cudf.Series(Mcsr.indptr) indices = cudf.Series(Mcsr.indices) @@ -374,10 +367,8 @@ def test_view_edge_list_for_Graph(graph_file): # Compare nx and cugraph edges when viewing edgelist # assert cu_edge_list.equals(nx_edge_list) - assert (cu_edge_list["src"].to_numpy() == - nx_edge_list["src"].to_numpy()).all() - assert (cu_edge_list["dst"].to_numpy() == - nx_edge_list["dst"].to_numpy()).all() + assert (cu_edge_list["src"].to_numpy() == nx_edge_list["src"].to_numpy()).all() + assert (cu_edge_list["dst"].to_numpy() == nx_edge_list["dst"].to_numpy()).all() # Test @@ -406,8 +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.Graph(directed=True) + ddf, + source="source", + destination="target", + create_using=cugraph.Graph(directed=True), ) t1 = time.time() @@ -432,8 +425,7 @@ def test_two_hop_neighbors(graph_file): df = G.get_two_hop_neighbors() Mnx = utils.read_csv_for_nx(graph_file) N = max(max(Mnx["0"]), max(Mnx["1"])) + 1 - Mcsr = scipy.sparse.csr_matrix(( - Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) + Mcsr = scipy.sparse.csr_matrix((Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N)) find_two_paths(df, Mcsr) check_all_two_hops(df, Mcsr) @@ -448,8 +440,7 @@ def test_degree_functionality(graph_file): G = cugraph.Graph(directed=True) G.from_cudf_edgelist(cu_M, source="0", destination="1", edge_attr="2") - Gnx = nx.from_pandas_edgelist( - M, source="0", target="1", create_using=nx.DiGraph()) + Gnx = nx.from_pandas_edgelist(M, source="0", target="1", create_using=nx.DiGraph()) df_in_degree = G.in_degree() df_out_degree = G.out_degree() @@ -485,8 +476,7 @@ def test_degrees_functionality(graph_file): G = cugraph.Graph(directed=True) G.from_cudf_edgelist(cu_M, source="0", destination="1", edge_attr="2") - Gnx = nx.from_pandas_edgelist( - M, source="0", target="1", create_using=nx.DiGraph()) + Gnx = nx.from_pandas_edgelist(M, source="0", target="1", create_using=nx.DiGraph()) df = G.degrees() @@ -518,8 +508,7 @@ def test_number_of_vertices(graph_file): # cugraph add_edge_list G = cugraph.Graph(directed=True) G.from_cudf_edgelist(cu_M, source="0", destination="1") - Gnx = nx.from_pandas_edgelist( - M, source="0", target="1", create_using=nx.DiGraph()) + Gnx = nx.from_pandas_edgelist(M, source="0", target="1", create_using=nx.DiGraph()) assert G.number_of_vertices() == Gnx.number_of_nodes() @@ -535,8 +524,7 @@ def test_to_directed(graph_file): # cugraph add_edge_list G = cugraph.Graph() G.from_cudf_edgelist(cu_M, source="0", destination="1") - Gnx = nx.from_pandas_edgelist( - M, source="0", target="1", create_using=nx.Graph()) + Gnx = nx.from_pandas_edgelist(M, source="0", target="1", create_using=nx.Graph()) DiG = G.to_directed() DiGnx = Gnx.to_directed() @@ -633,7 +621,7 @@ def test_bipartite_api(graph_file): nodes = cudf.concat([cu_M["0"], cu_M["1"]]).unique() # Create set of nodes for partition - set1_exp = cudf.Series(nodes[0: int(len(nodes) / 2)]) + set1_exp = cudf.Series(nodes[0 : int(len(nodes) / 2)]) set2_exp = cudf.Series(set(nodes.values_host) - set(set1_exp.values_host)) G = cugraph.BiPartiteGraph() @@ -662,8 +650,7 @@ def test_neighbors(graph_file): G = cugraph.Graph() G.from_cudf_edgelist(cu_M, source="0", destination="1") - Gnx = nx.from_pandas_edgelist(M, source="0", target="1", - create_using=nx.Graph()) + Gnx = nx.from_pandas_edgelist(M, source="0", target="1", create_using=nx.Graph()) for n in nodes.values_host: cu_neighbors = G.neighbors(n).to_arrow().to_pylist() nx_neighbors = [i for i in Gnx.neighbors(n)] @@ -707,10 +694,7 @@ def test_graph_init_with_multigraph(): @pytest.mark.parametrize("graph_file", utils.DATASETS) def test_create_sg_graph(graph_file): el = utils.read_csv_file(graph_file) - G = cugraph.from_cudf_edgelist( - el, source="0", - destination="1", edge_attr="2" - ) + G = cugraph.from_cudf_edgelist(el, source="0", destination="1", edge_attr="2") # ensure graph exists assert G._plc_graph is not None diff --git a/python/cugraph/cugraph/tests/test_multigraph.py b/python/cugraph/cugraph/tests/test_multigraph.py index 7ca2f92d39d..e6aad439fbd 100644 --- a/python/cugraph/cugraph/tests/test_multigraph.py +++ b/python/cugraph/cugraph/tests/test_multigraph.py @@ -47,17 +47,14 @@ def test_multigraph(graph_file): assert G.number_of_nodes() == Gnx.number_of_nodes() cuedges = cugraph.to_pandas_edgelist(G) cuedges.rename( - columns={"src": "source", "dst": "target", "weights": "weight"}, - inplace=True + columns={"src": "source", "dst": "target", "weights": "weight"}, inplace=True ) cuedges["weight"] = cuedges["weight"].round(decimals=3) nxedges = nx.to_pandas_edgelist(Gnx).astype( dtype={"source": "int32", "target": "int32", "weight": "float32"} ) - cuedges = cuedges.sort_values( - by=["source", "target"]).reset_index(drop=True) - nxedges = nxedges.sort_values( - by=["source", "target"]).reset_index(drop=True) + cuedges = cuedges.sort_values(by=["source", "target"]).reset_index(drop=True) + nxedges = nxedges.sort_values(by=["source", "target"]).reset_index(drop=True) nxedges["weight"] = nxedges["weight"].round(decimals=3) assert nxedges.equals(cuedges[["source", "target", "weight"]]) diff --git a/python/cugraph/cugraph/traversal/ms_bfs.py b/python/cugraph/cugraph/traversal/ms_bfs.py index da69a2b2e86..df624e453ee 100644 --- a/python/cugraph/cugraph/traversal/ms_bfs.py +++ b/python/cugraph/cugraph/traversal/ms_bfs.py @@ -93,9 +93,7 @@ def _get_feasibility(G, sources, components=None, depth_limit=None): tmp = components["color"].value_counts() n_components = tmp.size if n_sources / n_components > 100: - warnings.warn( - "High number of seeds per component result in large output." - ) + warnings.warn("High number of seeds per component result in large output.") mean_component_sz = tmp.mean() output_sz = mean_component_sz * n_sources * 2 * size_of_e @@ -182,9 +180,7 @@ def concurrent_bfs(Graphs, sources, depth_limit=None, offload=False): # ) -def multi_source_bfs( - G, sources, components=None, depth_limit=None, offload=False - ): +def multi_source_bfs(G, sources, components=None, depth_limit=None, offload=False): """ Find the breadth first traversal from multiple sources in a graph.