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

Removal of remaining DiGraph Python mentions #2049

Merged
merged 11 commits into from
Feb 4, 2022
42 changes: 26 additions & 16 deletions python/cugraph/cugraph/community/spectral_clustering_wrapper.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2021, NVIDIA CORPORATION.
# Copyright (c) 2019-2022, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -39,9 +39,11 @@ def spectralBalancedCutClustering(input_graph,
"""
Call balancedCutClustering_nvgraph
"""
if isinstance(input_graph, cugraph.DiGraph):
raise TypeError("DiGraph objects are not supported")
betochimas marked this conversation as resolved.
Show resolved Hide resolved

if isinstance(input_graph, cugraph.Graph):
if input_graph.is_directed():
raise ValueError("directed graphs are not supported")
else:
raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}")
if not input_graph.adjlist:
input_graph.view_adj_list()

Expand Down Expand Up @@ -110,9 +112,11 @@ def spectralModularityMaximizationClustering(input_graph,
"""
Call spectralModularityMaximization_nvgraph
"""
if isinstance(input_graph, cugraph.DiGraph):
raise TypeError("DiGraph objects are not supported")

if isinstance(input_graph, cugraph.Graph):
if input_graph.is_directed():
raise ValueError("directed graphs are not supported")
else:
raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}")
if not input_graph.adjlist:
input_graph.view_adj_list()

Expand Down Expand Up @@ -172,9 +176,11 @@ def analyzeClustering_modularity(input_graph, n_clusters, clustering):
"""
Call analyzeClustering_modularity_nvgraph
"""
if isinstance(input_graph, cugraph.DiGraph):
raise TypeError("DiGraph objects are not supported")

if isinstance(input_graph, cugraph.Graph):
if input_graph.is_directed():
raise ValueError("directed graphs are not supported")
else:
raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}")
if not input_graph.adjlist:
input_graph.view_adj_list()

Expand Down Expand Up @@ -228,9 +234,11 @@ def analyzeClustering_edge_cut(input_graph, n_clusters, clustering):
"""
Call analyzeClustering_edge_cut_nvgraph
"""
if isinstance(input_graph, cugraph.DiGraph):
raise TypeError("DiGraph objects are not supported")

if isinstance(input_graph, cugraph.Graph):
if input_graph.is_directed():
raise ValueError("directed graphs are not supported")
else:
raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}")
if not input_graph.adjlist:
input_graph.view_adj_list()

Expand Down Expand Up @@ -281,9 +289,11 @@ def analyzeClustering_ratio_cut(input_graph, n_clusters, clustering):
"""
Call analyzeClustering_ratio_cut_nvgraph
"""
if isinstance(input_graph, cugraph.DiGraph):
raise TypeError("DiGraph objects are not supported")

if isinstance(input_graph, cugraph.Graph):
if input_graph.is_directed():
raise ValueError("directed graphs are not supported")
else:
raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}")
if not input_graph.adjlist:
input_graph.view_adj_list()

Expand Down
34 changes: 17 additions & 17 deletions python/cugraph/cugraph/components/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ def weakly_connected_components(G,
For non-Graph-type (eg. sparse matrix) values of G only.
Raises TypeError if used with a Graph object.

If True (default), then convert the input matrix to a cugraph.DiGraph
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
csgraph[j, i].
If True (default), then convert the input matrix to directed
cugraph.Graph 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 csgraph[j, i].

connection : str, optional (default=None)

Expand Down Expand Up @@ -186,7 +186,7 @@ def weakly_connected_components(G,
# FIXME: allow nx_weight_attr to be specified
(G, input_type) = ensure_cugraph_obj(
G, nx_weight_attr="weight",
matrix_graph_type=DiGraph if directed else Graph)
matrix_graph_type=Graph(directed=directed))

df = connectivity_wrapper.weakly_connected_components(G)

Expand Down Expand Up @@ -221,11 +221,11 @@ def strongly_connected_components(G,
For non-Graph-type (eg. sparse matrix) values of G only.
Raises TypeError if used with a Graph object.

If True (default), then convert the input matrix to a cugraph.DiGraph
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
csgraph[j, i].
If True (default), then convert the input matrix to directed
cugraph.Graph 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 csgraph[j, i].

connection : str, optional (default=None)

Expand Down Expand Up @@ -285,7 +285,7 @@ def strongly_connected_components(G,
# FIXME: allow nx_weight_attr to be specified
(G, input_type) = ensure_cugraph_obj(
G, nx_weight_attr="weight",
matrix_graph_type=DiGraph if directed else Graph)
matrix_graph_type=Graph(directed=directed))

df = connectivity_wrapper.strongly_connected_components(G)

Expand Down Expand Up @@ -320,11 +320,11 @@ def connected_components(G,
For non-Graph-type (eg. sparse matrix) values of G only. Raises
TypeError if used with a Graph object.

If True (default), then convert the input matrix to a cugraph.DiGraph
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
csgraph[j, i].
If True (default), then convert the input matrix to directed
cugraph.Graph 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 csgraph[j, i].

connection : str, optional (default='weak')

Expand Down
52 changes: 37 additions & 15 deletions python/cugraph/cugraph/generators/rmat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from cugraph.comms import comms as Comms
import cugraph

_graph_types = [cugraph.Graph, cugraph.MultiGraph]


def _ensure_args_rmat(
scale,
Expand All @@ -35,12 +37,17 @@ def _ensure_args_rmat(
Ensures the args passed in are usable for the rmat() API, raises the
appropriate exception if incorrect, else returns None.
"""
if mg and create_using not in [None, cugraph.DiGraph]:
raise TypeError("Only cugraph.DiGraph and None are supported types "
"for `create_using` for multi-GPU R-MAT")
if create_using not in [None, cugraph.Graph, cugraph.DiGraph]:
raise TypeError("Only cugraph.Graph, cugraph.DiGraph, and None are "
"supported types for 'create_using'")
if create_using is not None:
if isinstance(create_using, cugraph.Graph):
directed = create_using.is_directed()
if mg and not directed:
raise TypeError("Only directed cugraph.Graph and None "
"are supported types for `create_using` "
"and `directed` for multi-GPU R-MAT")
elif create_using not in _graph_types:
raise TypeError("create_using must be a cugraph.Graph "
"(or subclass) type or instance, got: "
f"{type(create_using)}")
if not isinstance(scale, int):
raise TypeError("'scale' must be an int")
if not isinstance(num_edges, int):
Expand All @@ -51,7 +58,7 @@ def _ensure_args_rmat(
if (clip_and_flip not in [True, False]):
raise ValueError("'clip_and_flip' must be a bool")
if (scramble_vertex_ids not in [True, False]):
raise ValueError("'clip_and_flip' must be a bool")
raise ValueError("'scramble_vertex_ids' must be a bool")
if not isinstance(seed, int):
raise TypeError("'seed' must be an int")

Expand Down Expand Up @@ -87,7 +94,7 @@ def _ensure_args_multi_rmat(
if (clip_and_flip not in [True, False]):
raise ValueError("'clip_and_flip' must be a bool")
if (scramble_vertex_ids not in [True, False]):
raise ValueError("'clip_and_flip' must be a bool")
raise ValueError("'scramble_vertex_ids' must be a bool")
if not isinstance(seed, int):
raise TypeError("'seed' must be an int")

Expand All @@ -101,7 +108,7 @@ def _sg_rmat(
seed,
clip_and_flip,
scramble_vertex_ids,
create_using=cugraph.DiGraph
create_using=cugraph.Graph,
):
"""
Calls RMAT on a single GPU and uses the resulting cuDF DataFrame
Expand All @@ -119,7 +126,15 @@ def _sg_rmat(
if create_using is None:
return df

G = create_using()
if isinstance(create_using, cugraph.Graph):
attrs = {"directed": create_using.is_directed()}
G = type(create_using)(**attrs)
elif create_using in _graph_types:
G = create_using()
betochimas marked this conversation as resolved.
Show resolved Hide resolved
else:
raise TypeError("create_using must be a cugraph.Graph "
"(or subclass) type or instance, got: "
f"{type(create_using)}")
G.from_cudf_edgelist(df, source='src', destination='dst', renumber=False)

return G
Expand All @@ -134,7 +149,7 @@ def _mg_rmat(
seed,
clip_and_flip,
scramble_vertex_ids,
create_using=cugraph.DiGraph
create_using=cugraph.Graph
):
"""
Calls RMAT on multiple GPUs and uses the resulting Dask cuDF DataFrame to
Expand Down Expand Up @@ -171,7 +186,15 @@ def _mg_rmat(
if create_using is None:
return ddf

G = create_using()
if isinstance(create_using, cugraph.Graph):
attrs = {"directed": create_using.is_directed()}
G = type(create_using)(**attrs)
elif create_using in _graph_types:
G = create_using()
else:
raise TypeError("create_using must be a cugraph.Graph "
"(or subclass) type or instance, got: "
f"{type(create_using)}")
G.from_dask_cudf_edgelist(ddf, source="src", destination="dst")

return G
Expand Down Expand Up @@ -234,7 +257,7 @@ def rmat(
seed,
clip_and_flip,
scramble_vertex_ids,
create_using=cugraph.DiGraph,
create_using=cugraph.Graph,
mg=False
):
"""
Expand Down Expand Up @@ -277,8 +300,7 @@ def rmat(
edgelist cuDF DataFrame (or dask_cudf DataFrame for MG) is returned
as-is. This is useful for benchmarking Graph construction steps that
require raw data that includes potential self-loops, isolated vertices,
and duplicated edges. Default is cugraph.DiGraph.
NOTE: only the cugraph.DiGraph type is supported for multi-GPU
and duplicated edges. Default is cugraph.Graph.

mg : bool, optional (default=False)
If True, R-MAT generation occurs across multiple GPUs. If False, only a
Expand Down
Loading