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

Forward-merge branch-23.12 to branch-24.02 #4016

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions python/nx-cugraph/_nx_cugraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
"path_graph",
"petersen_graph",
"sedgewick_maze_graph",
"single_source_shortest_path_length",
"single_target_shortest_path_length",
"star_graph",
"tadpole_graph",
"tetrahedral_graph",
Expand Down
3 changes: 2 additions & 1 deletion python/nx-cugraph/nx_cugraph/algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from . import bipartite, centrality, community, components
from . import bipartite, centrality, community, components, shortest_paths
from .bipartite import complete_bipartite_graph
from .centrality import *
from .components import *
from .core import *
from .isolate import *
from .shortest_paths import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .unweighted import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import cupy as cp
import networkx as nx
import numpy as np
import pylibcugraph as plc

from nx_cugraph.convert import _to_graph
from nx_cugraph.utils import index_dtype, networkx_algorithm

__all__ = ["single_source_shortest_path_length", "single_target_shortest_path_length"]


@networkx_algorithm
def single_source_shortest_path_length(G, source, cutoff=None):
return _single_shortest_path_length(G, source, cutoff, "Source")


@networkx_algorithm
def single_target_shortest_path_length(G, target, cutoff=None):
return _single_shortest_path_length(G, target, cutoff, "Target")


def _single_shortest_path_length(G, source, cutoff, kind):
G = _to_graph(G)
if source not in G:
raise nx.NodeNotFound(f"{kind} {source} is not in G")
if G.src_indices.size == 0:
return {source: 0}
if cutoff is None:
cutoff = -1
src_index = source if G.key_to_id is None else G.key_to_id[source]
distances, predecessors, node_ids = plc.bfs(
handle=plc.ResourceHandle(),
graph=G._get_plc_graph(switch_indices=kind == "Target"),
sources=cp.array([src_index], index_dtype),
direction_optimizing=False, # True for undirected only; what's recommended?
depth_limit=cutoff,
compute_predecessors=False,
do_expensive_check=False,
)
mask = distances != np.iinfo(distances.dtype).max
return G._nodearrays_to_dict(node_ids[mask], distances[mask])
9 changes: 7 additions & 2 deletions python/nx-cugraph/nx_cugraph/classes/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ def _get_plc_graph(
edge_dtype: Dtype | None = None,
*,
store_transposed: bool = False,
switch_indices: bool = False,
edge_array: cp.ndarray[EdgeValue] | None = None,
):
if edge_array is not None:
Expand Down Expand Up @@ -613,14 +614,18 @@ def _get_plc_graph(
elif edge_array.dtype not in self._plc_allowed_edge_types:
raise TypeError(edge_array.dtype)
# Should we cache PLC graph?
src_indices = self.src_indices
dst_indices = self.dst_indices
if switch_indices:
src_indices, dst_indices = dst_indices, src_indices
return plc.SGGraph(
resource_handle=plc.ResourceHandle(),
graph_properties=plc.GraphProperties(
is_multigraph=self.is_multigraph(),
is_symmetric=not self.is_directed(),
),
src_or_offset_array=self.src_indices,
dst_or_index_array=self.dst_indices,
src_or_offset_array=src_indices,
dst_or_index_array=dst_indices,
weight_array=edge_array,
store_transposed=store_transposed,
renumber=False,
Expand Down
2 changes: 2 additions & 0 deletions python/nx-cugraph/nx_cugraph/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,11 @@ def key(testpath):
)

too_slow = "Too slow to run"
maybe_oom = "out of memory in CI"
skip = {
key("test_tree_isomorphism.py:test_positive"): too_slow,
key("test_tree_isomorphism.py:test_negative"): too_slow,
key("test_efficiency.py:TestEfficiency.test_using_ego_graph"): maybe_oom,
}

for item in items:
Expand Down
Loading