Skip to content

Commit

Permalink
Branch 22.06 bug fixes + update imports (rapidsai#2261)
Browse files Browse the repository at this point in the history
This PR:

1. Updates reference code in the html documentation to reflect recent changes from 22.02 and 22.04 (closes rapidsai#2248 )
2. Updates the default value of max_depth within node2vec, so that a call without a default max_depth value still yields a result (closes rapidsai#2228)
3. Casts a list of start_vertices to int32 type. (closes rapidsai#2229)
4. Remove experimental from list of imports from within pylibcugraph

Authors:
  - https://github.com/betochimas

Approvers:
  - Brad Rees (https://github.com/BradReesWork)
  - Rick Ratzel (https://github.com/rlratzel)
  - Joseph Nke (https://github.com/jnke2016)

URL: rapidsai#2261
  • Loading branch information
betochimas authored May 20, 2022
1 parent aece453 commit f2e4bfd
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 51 deletions.
2 changes: 1 addition & 1 deletion docs/cugraph/source/api_docs/dask-cugraph.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Example
names=['src', 'dst'],
dtype=['int32', 'int32'])
G = cugraph.DiGraph()
G = cugraph.Graph(directed=True)
G.from_dask_cudf_edgelist(e_list, source='src', destination='dst')
# now run PageRank
Expand Down
35 changes: 18 additions & 17 deletions python/cugraph/cugraph/sampling/node2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from pylibcugraph.experimental import (ResourceHandle,
GraphProperties,
SGGraph,
node2vec as pylibcugraph_node2vec,
)
from pylibcugraph import (ResourceHandle,
GraphProperties,
SGGraph,
node2vec as pylibcugraph_node2vec,
)
from cugraph.utilities import ensure_cugraph_obj_for_nx

import cudf


def node2vec(G,
start_vertices,
max_depth=None,
max_depth=1,
compress_result=True,
p=1.0,
q=1.0):
Expand All @@ -49,8 +49,9 @@ def node2vec(G,
the random walks. In case of multi-column vertices it should be
a cudf.DataFrame. Only supports int32 currently.
max_depth: int
The maximum depth of the random walks
max_depth: int, optional (default=1)
The maximum depth of the random walks. If not specified, the maximum
depth is set to 1.
compress_result: bool, optional (default=True)
If True, coalesced paths are returned with a sizes array with offsets.
Expand Down Expand Up @@ -93,11 +94,11 @@ def node2vec(G,
"""
if (not isinstance(max_depth, int)) or (max_depth < 1):
raise ValueError(f"'max_depth' must be a positive integer, \
got: {max_depth}")
raise ValueError(f"'max_depth' must be a positive integer, "
f"got: {max_depth}")
if (not isinstance(compress_result, bool)):
raise ValueError(f"'compress_result' must be a bool, \
got: {compress_result}")
raise ValueError(f"'compress_result' must be a bool, "
f"got: {compress_result}")
if (not isinstance(p, float)) or (p <= 0.0):
raise ValueError(f"'p' must be a positive float, got: {p}")
if (not isinstance(q, float)) or (q <= 0.0):
Expand All @@ -109,10 +110,10 @@ def node2vec(G,
start_vertices = [start_vertices]

if isinstance(start_vertices, list):
start_vertices = cudf.Series(start_vertices)
start_vertices = cudf.Series(start_vertices, dtype='int32')
if start_vertices.dtype != 'int32':
raise ValueError(f"'start_vertices' must have int32 values, \
got: {start_vertices.dtype}")
raise ValueError(f"'start_vertices' must have int32 values, "
f"got: {start_vertices.dtype}")

if G.renumbered is True:
if isinstance(start_vertices, cudf.DataFrame):
Expand All @@ -126,8 +127,8 @@ def node2vec(G,
weights = G.edgelist.edgelist_df['weights']

if srcs.dtype != 'int32':
raise ValueError(f"Graph vertices must have int32 values, \
got: {srcs.dtype}")
raise ValueError(f"Graph vertices must have int32 values, "
f"got: {srcs.dtype}")

resource_handle = ResourceHandle()
graph_props = GraphProperties(is_multigraph=G.is_multigraph())
Expand Down
2 changes: 1 addition & 1 deletion python/cugraph/cugraph/tests/test_node2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_node2vec_line(graph_file, directed):
@pytest.mark.parametrize(*_get_param_args("graph_file", utils.DATASETS_SMALL))
@pytest.mark.parametrize(*_get_param_args("directed", DIRECTED_GRAPH_OPTIONS))
@pytest.mark.parametrize(*_get_param_args("compress", COMPRESSED))
def test_node2vec_new(
def test_node2vec(
graph_file,
directed,
compress,
Expand Down
6 changes: 3 additions & 3 deletions python/pylibcugraph/pylibcugraph/graphs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ cdef class SGGraph(_GPUGraph):
>>> dsts = cupy.asarray([1, 2, 3], dtype=numpy.int32)
>>> seeds = cupy.asarray([0, 0, 1], dtype=numpy.int32)
>>> weights = cupy.asarray([1.0, 1.0, 1.0], dtype=numpy.float32)
>>> resource_handle = pylibcugraph.experimental.ResourceHandle()
>>> graph_props = pylibcugraph.experimental.GraphProperties(
>>> resource_handle = pylibcugraph.ResourceHandle()
>>> graph_props = pylibcugraph.GraphProperties(
... is_symmetric=False, is_multigraph=False)
>>> G = pylibcugraph.experimental.SGGraph(
>>> G = pylibcugraph.SGGraph(
... resource_handle, graph_props, srcs, dsts, weights,
... store_transposed=False, renumber=False, do_expensive_check=False)
Expand Down
8 changes: 4 additions & 4 deletions python/pylibcugraph/pylibcugraph/node2vec.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ def node2vec(ResourceHandle resource_handle,
>>> dsts = cupy.asarray([1, 2, 3], dtype=numpy.int32)
>>> seeds = cupy.asarray([0, 0, 1], dtype=numpy.int32)
>>> weights = cupy.asarray([1.0, 1.0, 1.0], dtype=numpy.float32)
>>> resource_handle = pylibcugraph.experimental.ResourceHandle()
>>> graph_props = pylibcugraph.experimental.GraphProperties(
>>> resource_handle = pylibcugraph.ResourceHandle()
>>> graph_props = pylibcugraph.GraphProperties(
... is_symmetric=False, is_multigraph=False)
>>> G = pylibcugraph.experimental.SGGraph(
>>> G = pylibcugraph.SGGraph(
... resource_handle, graph_props, srcs, dsts, weights,
... store_transposed=False, renumber=False, do_expensive_check=False)
>>> (paths, weights, sizes) = pylibcugraph.experimental.node2vec(
>>> (paths, weights, sizes) = pylibcugraph.node2vec(
... resource_handle, G, seeds, 3, True, 1.0, 1.0)
"""
Expand Down
8 changes: 4 additions & 4 deletions python/pylibcugraph/pylibcugraph/pagerank.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ def pagerank(ResourceHandle resource_handle,
>>> srcs = cupy.asarray([0, 1, 2], dtype=numpy.int32)
>>> dsts = cupy.asarray([1, 2, 3], dtype=numpy.int32)
>>> weights = cupy.asarray([1.0, 1.0, 1.0], dtype=numpy.float32)
>>> resource_handle = pylibcugraph.experimental.ResourceHandle()
>>> graph_props = pylibcugraph.experimental.GraphProperties(
>>> resource_handle = pylibcugraph.ResourceHandle()
>>> graph_props = pylibcugraph.GraphProperties(
... is_symmetric=False, is_multigraph=False)
>>> G = pylibcugraph.experimental.SGGraph(
>>> G = pylibcugraph.SGGraph(
... resource_handle, graph_props, srcs, dsts, weights,
... store_transposed=True, renumber=False, do_expensive_check=False)
>>> (vertices, pageranks) = pylibcugraph.experimental.pagerank(
>>> (vertices, pageranks) = pylibcugraph.pagerank(
... resource_handle, G, None, alpha=0.85, epsilon=1.0e-6,
... max_iterations=500, has_initial_guess=False,
... do_expensive_check=False)
Expand Down
8 changes: 4 additions & 4 deletions python/pylibcugraph/pylibcugraph/sssp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ def sssp(ResourceHandle resource_handle,
>>> srcs = cupy.asarray([0, 1, 2], dtype=numpy.int32)
>>> dsts = cupy.asarray([1, 2, 3], dtype=numpy.int32)
>>> weights = cupy.asarray([1.0, 1.0, 1.0], dtype=numpy.float32)
>>> resource_handle = pylibcugraph.experimental.ResourceHandle()
>>> graph_props = pylibcugraph.experimental.GraphProperties(
>>> resource_handle = pylibcugraph.ResourceHandle()
>>> graph_props = pylibcugraph.GraphProperties(
... is_symmetric=False, is_multigraph=False)
>>> G = pylibcugraph.experimental.SGGraph(
>>> G = pylibcugraph.SGGraph(
... resource_handle, graph_props, srcs, dsts, weights,
... store_transposed=False, renumber=False, do_expensive_check=False)
>>> (vertices, distances, predecessors) = pylibcugraph.experimental.sssp(
>>> (vertices, distances, predecessors) = pylibcugraph.sssp(
... resource_handle, G, source=1, cutoff=999,
... compute_predecessors=True, do_expensive_check=False)
>>> vertices
Expand Down
8 changes: 4 additions & 4 deletions python/pylibcugraph/pylibcugraph/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ def create_SGGraph(device_srcs,
Creates and returns a SGGraph instance and the corresponding ResourceHandle
using the parameters passed in.
"""
from pylibcugraph.experimental import (SGGraph,
ResourceHandle,
GraphProperties,
)
from pylibcugraph import (SGGraph,
ResourceHandle,
GraphProperties,
)
resource_handle = ResourceHandle()
graph_props = GraphProperties(is_symmetric=False, is_multigraph=False)

Expand Down
10 changes: 5 additions & 5 deletions python/pylibcugraph/pylibcugraph/tests/test_graph_sg.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_graph_properties():


def test_resource_handle():
from pylibcugraph.experimental import ResourceHandle
from pylibcugraph import ResourceHandle
# This type has no attributes and is just defined to pass a struct from C
# back in to C. In the future it may take args to acquire specific
# resources, but for now just make sure nothing crashes.
Expand All @@ -69,10 +69,10 @@ def test_resource_handle():


def test_sg_graph(graph_data):
from pylibcugraph.experimental import (SGGraph,
ResourceHandle,
GraphProperties,
)
from pylibcugraph import (SGGraph,
ResourceHandle,
GraphProperties,
)
# is_valid will only be True if the arrays are expected to produce a valid
# graph. If False, ensure SGGraph() raises the proper exception.
(device_srcs, device_dsts, device_weights, ds_name, is_valid) = graph_data
Expand Down
16 changes: 11 additions & 5 deletions python/pylibcugraph/pylibcugraph/tests/test_katz_centrality.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@
import pytest
import cupy as cp
import numpy as np
from pylibcugraph.experimental import (ResourceHandle,
GraphProperties,
SGGraph,
katz_centrality)
from pylibcugraph.testing import utils
from pylibcugraph import (ResourceHandle,
GraphProperties,
SGGraph,
)
from pylibcugraph.experimental import katz_centrality
from cugraph.testing import utils
import pathlib
import pylibcugraph


datasets = pathlib.Path(pylibcugraph.__path__[0]).parent.parent.parent


# =============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from pylibcugraph import (MGGraph,
ResourceHandle,
GraphProperties,
uniform_neighborhood_sampling,
)
from pylibcugraph.experimental import uniform_neighborhood_sampling


# =============================================================================
Expand Down
2 changes: 1 addition & 1 deletion python/pylibcugraph/pylibcugraph/tests/test_pagerank.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
# auto-transposing in C) or raise the appropriate exception.

def test_pagerank(sg_transposed_graph_objs):
from pylibcugraph.experimental import pagerank
from pylibcugraph import pagerank

(g, resource_handle, ds_name) = sg_transposed_graph_objs
(expected_verts, expected_pageranks) = _test_data[ds_name]
Expand Down
2 changes: 1 addition & 1 deletion python/pylibcugraph/pylibcugraph/tests/test_sssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
# Tests
# =============================================================================
def test_sssp(sg_graph_objs):
from pylibcugraph.experimental import sssp
from pylibcugraph import sssp

(g, resource_handle, ds_name) = sg_graph_objs

Expand Down

0 comments on commit f2e4bfd

Please sign in to comment.