Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop DiGraph #3126

Merged
merged 19 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions python/cugraph/cugraph/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -30,11 +30,8 @@

from cugraph.structure import (
Graph,
DiGraph,
MultiGraph,
MultiDiGraph,
BiPartiteGraph,
BiPartiteDiGraph,
from_edgelist,
from_cudf_edgelist,
from_pandas_edgelist,
Expand Down
7 changes: 4 additions & 3 deletions python/cugraph/cugraph/community/subgraph_extraction.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -57,14 +57,15 @@ def subgraph(G, vertices):
"""

G, isNx = ensure_cugraph_obj_for_nx(G)
directed = G.is_directed()

if G.renumbered:
if isinstance(vertices, cudf.DataFrame):
vertices = G.lookup_internal_vertex_id(vertices, vertices.columns)
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"
Expand Down
16 changes: 8 additions & 8 deletions python/cugraph/cugraph/components/connectivity.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/cugraph/cugraph/sampling/node2vec.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022, NVIDIA CORPORATION.
# Copyright (c) 2023, NVIDIA CORPORATION.
BradReesWork marked this conversation as resolved.
Show resolved Hide resolved
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions python/cugraph/cugraph/structure/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,11 +13,8 @@

from cugraph.structure.graph_classes import (
Graph,
DiGraph,
MultiGraph,
MultiDiGraph,
BiPartiteGraph,
BiPartiteDiGraph,
)
from cugraph.structure.graph_classes import (
is_weighted,
Expand Down
18 changes: 2 additions & 16 deletions python/cugraph/cugraph/structure/convert_matrix.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
46 changes: 1 addition & 45 deletions python/cugraph/cugraph/structure/graph_classes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021-2022, NVIDIA CORPORATION.
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -19,7 +19,6 @@
)
import cudf
import dask_cudf
import warnings

from cugraph.utilities.utils import import_optional

Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021-2022, NVIDIA CORPORATION.
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -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).

Expand Down
8 changes: 4 additions & 4 deletions python/cugraph/cugraph/testing/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
)

Expand Down
Loading