Skip to content

Commit

Permalink
Merge branch 'branch-23.12' into docs_c_api
Browse files Browse the repository at this point in the history
  • Loading branch information
nv-rliu authored Nov 1, 2023
2 parents 36ba903 + eb1e515 commit 109684d
Show file tree
Hide file tree
Showing 32 changed files with 2,835 additions and 116 deletions.
2 changes: 1 addition & 1 deletion cpp/src/community/detail/refine_impl.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct leiden_key_aggregated_edge_op_t {
weight_t total_edge_weight{};
weight_t resolution{}; // resolution parameter
weight_t theta{}; // scaling factor
raft::random::DeviceState<raft::random::PCGenerator> device_state{};
raft::random::DeviceState<raft::random::PCGenerator>& device_state;
__device__ auto operator()(
vertex_t src,
vertex_t neighboring_leiden_cluster,
Expand Down
25 changes: 12 additions & 13 deletions cpp/src/prims/detail/nbr_intersection.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ struct update_rx_major_local_degree_t {
size_t local_edge_partition_idx{};

raft::device_span<size_t const> rx_reordered_group_lasts{};
raft::device_span<size_t const> rx_group_firsts{nullptr};
raft::device_span<size_t const> rx_group_firsts{};
raft::device_span<vertex_t const> rx_majors{};

raft::device_span<edge_t> local_degrees_for_rx_majors{};
Expand Down Expand Up @@ -200,7 +200,7 @@ struct update_rx_major_local_nbrs_t {
size_t local_edge_partition_idx{};

raft::device_span<size_t const> rx_reordered_group_lasts{};
raft::device_span<size_t const> rx_group_firsts{nullptr};
raft::device_span<size_t const> rx_group_firsts{};
raft::device_span<vertex_t const> rx_majors{};
raft::device_span<size_t const> local_nbr_offsets_for_rx_majors{};
raft::device_span<vertex_t> local_nbrs_for_rx_majors{};
Expand Down Expand Up @@ -311,10 +311,10 @@ template <typename FirstElementToIdxMap,
bool multi_gpu>
struct pick_min_degree_t {
FirstElementToIdxMap first_element_to_idx_map{};
raft::device_span<edge_t const> first_element_offsets{nullptr};
raft::device_span<edge_t const> first_element_offsets{};

SecondElementToIdxMap second_element_to_idx_map{};
raft::device_span<edge_t const> second_element_offsets{nullptr};
raft::device_span<edge_t const> second_element_offsets{};

edge_partition_device_view_t<vertex_t, edge_t, multi_gpu> edge_partition{};
thrust::optional<edge_partition_edge_property_device_view_t<edge_t, uint32_t const*, bool>>
Expand Down Expand Up @@ -473,12 +473,12 @@ template <typename FirstElementToIdxMap,
struct copy_intersecting_nbrs_and_update_intersection_size_t {
FirstElementToIdxMap first_element_to_idx_map{};
raft::device_span<edge_t const> first_element_offsets{};
raft::device_span<vertex_t const> first_element_indices{nullptr};
raft::device_span<vertex_t const> first_element_indices{};
optional_property_buffer_view_t first_element_edge_property_values{};

SecondElementToIdxMap second_element_to_idx_map{};
raft::device_span<edge_t const> second_element_offsets{};
raft::device_span<vertex_t const> second_element_indices{nullptr};
raft::device_span<vertex_t const> second_element_indices{};
optional_property_buffer_view_t second_element_edge_property_values{};

edge_partition_device_view_t<vertex_t, edge_t, multi_gpu> edge_partition{};
Expand All @@ -487,8 +487,8 @@ struct copy_intersecting_nbrs_and_update_intersection_size_t {
edge_partition_e_mask{};

VertexPairIterator vertex_pair_first;
raft::device_span<size_t const> nbr_intersection_offsets{nullptr};
raft::device_span<vertex_t> nbr_intersection_indices{nullptr};
raft::device_span<size_t const> nbr_intersection_offsets{};
raft::device_span<vertex_t> nbr_intersection_indices{};

optional_property_buffer_mutable_view_t nbr_intersection_e_property_values0{};
optional_property_buffer_mutable_view_t nbr_intersection_e_property_values1{};
Expand All @@ -499,12 +499,11 @@ struct copy_intersecting_nbrs_and_update_intersection_size_t {
using edge_property_value_t = typename edge_partition_e_input_device_view_t::value_type;

auto pair = *(vertex_pair_first + i);

vertex_t const* indices0{nullptr};
vertex_t const* indices0{};
std::conditional_t<!std::is_same_v<edge_property_value_t, thrust::nullopt_t>,
edge_property_value_t const*,
void*>
edge_property_values0{nullptr};
edge_property_values0{};

edge_t local_edge_offset0{0};
edge_t local_degree0{0};
Expand Down Expand Up @@ -548,11 +547,11 @@ struct copy_intersecting_nbrs_and_update_intersection_size_t {
local_degree0 = static_cast<edge_t>(first_element_offsets[idx + 1] - local_edge_offset0);
}

vertex_t const* indices1{nullptr};
vertex_t const* indices1{};
std::conditional_t<!std::is_same_v<edge_property_value_t, thrust::nullopt_t>,
edge_property_value_t const*,
void*>
edge_property_values1{nullptr};
edge_property_values1{};

edge_t local_edge_offset1{0};
edge_t local_degree1{0};
Expand Down
7 changes: 7 additions & 0 deletions python/cugraph-pyg/cugraph_pyg/tests/test_cugraph_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

torch = import_optional("torch")
torch_geometric = import_optional("torch_geometric")
torch_sparse = import_optional("torch_sparse")
trim_to_layer = import_optional("torch_geometric.utils.trim_to_layer")


Expand Down Expand Up @@ -200,6 +201,9 @@ def test_cugraph_loader_from_disk_subset():


@pytest.mark.skipif(isinstance(torch, MissingModule), reason="torch not available")
@pytest.mark.skipif(
isinstance(torch_sparse, MissingModule), reason="torch-sparse not available"
)
def test_cugraph_loader_from_disk_subset_csr():
m = [2, 9, 99, 82, 11, 13]
n = torch.arange(1, 1 + len(m), dtype=torch.int32)
Expand Down Expand Up @@ -332,6 +336,9 @@ def test_cugraph_loader_e2e_coo():


@pytest.mark.skipif(isinstance(torch, MissingModule), reason="torch not available")
@pytest.mark.skipif(
isinstance(torch_sparse, MissingModule), reason="torch-sparse not available"
)
@pytest.mark.parametrize("framework", ["pyg", "cugraph-ops"])
def test_cugraph_loader_e2e_csc(framework):
m = [2, 9, 99, 82, 9, 3, 18, 1, 12]
Expand Down
53 changes: 53 additions & 0 deletions python/nx-cugraph/_nx_cugraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,76 @@
# "description": "TODO",
"functions": {
# BEGIN: functions
"barbell_graph",
"betweenness_centrality",
"bull_graph",
"caveman_graph",
"chvatal_graph",
"circular_ladder_graph",
"complete_bipartite_graph",
"complete_graph",
"complete_multipartite_graph",
"connected_components",
"cubical_graph",
"cycle_graph",
"davis_southern_women_graph",
"degree_centrality",
"desargues_graph",
"diamond_graph",
"dodecahedral_graph",
"edge_betweenness_centrality",
"empty_graph",
"florentine_families_graph",
"from_pandas_edgelist",
"from_scipy_sparse_array",
"frucht_graph",
"heawood_graph",
"house_graph",
"house_x_graph",
"icosahedral_graph",
"in_degree_centrality",
"is_connected",
"is_isolate",
"isolates",
"k_truss",
"karate_club_graph",
"krackhardt_kite_graph",
"ladder_graph",
"les_miserables_graph",
"lollipop_graph",
"louvain_communities",
"moebius_kantor_graph",
"node_connected_component",
"null_graph",
"number_connected_components",
"number_of_isolates",
"number_of_selfloops",
"octahedral_graph",
"out_degree_centrality",
"pappus_graph",
"path_graph",
"petersen_graph",
"sedgewick_maze_graph",
"star_graph",
"tadpole_graph",
"tetrahedral_graph",
"trivial_graph",
"truncated_cube_graph",
"truncated_tetrahedron_graph",
"turan_graph",
"tutte_graph",
"wheel_graph",
# END: functions
},
"extra_docstrings": {
# BEGIN: extra_docstrings
"betweenness_centrality": "`weight` parameter is not yet supported.",
"edge_betweenness_centrality": "`weight` parameter is not yet supported.",
"from_pandas_edgelist": "cudf.DataFrame inputs also supported.",
"k_truss": (
"Currently raises `NotImplementedError` for graphs with more than one connected\n"
"component when k >= 3. We expect to fix this soon."
),
"louvain_communities": "`seed` parameter is currently ignored.",
# END: extra_docstrings
},
Expand Down
8 changes: 4 additions & 4 deletions python/nx-cugraph/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ repos:
- id: pyupgrade
args: [--py39-plus]
- repo: https://github.com/psf/black
rev: 23.10.0
rev: 23.10.1
hooks:
- id: black
# - id: black-jupyter
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.1
rev: v0.1.3
hooks:
- id: ruff
args: [--fix-only, --show-fixes]
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
args: ['--per-file-ignores=_nx_cugraph/__init__.py:E501'] # Why is this necessary?
args: ['--per-file-ignores=_nx_cugraph/__init__.py:E501', '--extend-ignore=SIM105'] # Why is this necessary?
additional_dependencies: &flake8_dependencies
# These versions need updated manually
- flake8==6.1.0
Expand All @@ -77,7 +77,7 @@ repos:
additional_dependencies: [tomli]
files: ^(nx_cugraph|docs)/
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.1
rev: v0.1.3
hooks:
- id: ruff
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
8 changes: 4 additions & 4 deletions python/nx-cugraph/nx_cugraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
from . import convert
from .convert import *

# from . import convert_matrix
# from .convert_matrix import *
from . import convert_matrix
from .convert_matrix import *

# from . import generators
# from .generators import *
from . import generators
from .generators import *

from . import algorithms
from .algorithms import *
Expand Down
4 changes: 3 additions & 1 deletion python/nx-cugraph/nx_cugraph/algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
# 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 centrality, community
from . import bipartite, centrality, community, components
from .bipartite import complete_bipartite_graph
from .centrality import *
from .components import *
from .core import *
from .isolate import *
13 changes: 13 additions & 0 deletions python/nx-cugraph/nx_cugraph/algorithms/bipartite/__init__.py
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 .generators import *
62 changes: 62 additions & 0 deletions python/nx-cugraph/nx_cugraph/algorithms/bipartite/generators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 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 numbers import Integral

import cupy as cp
import networkx as nx
import numpy as np

from nx_cugraph.generators._utils import _create_using_class, _number_and_nodes
from nx_cugraph.utils import index_dtype, networkx_algorithm, nodes_or_number

__all__ = [
"complete_bipartite_graph",
]


@nodes_or_number([0, 1])
@networkx_algorithm
def complete_bipartite_graph(n1, n2, create_using=None):
graph_class, inplace = _create_using_class(create_using)
if graph_class.is_directed():
raise nx.NetworkXError("Directed Graph not supported")
orig_n1, unused_nodes1 = n1
orig_n2, unused_nodes2 = n2
n1, nodes1 = _number_and_nodes(n1)
n2, nodes2 = _number_and_nodes(n2)
all_indices = cp.indices((n1, n2), dtype=index_dtype)
indices0 = all_indices[0].ravel()
indices1 = all_indices[1].ravel() + n1
del all_indices
src_indices = cp.hstack((indices0, indices1))
dst_indices = cp.hstack((indices1, indices0))
bipartite = cp.zeros(n1 + n2, np.int8)
bipartite[n1:] = 1
if isinstance(orig_n1, Integral) and isinstance(orig_n2, Integral):
nodes = None
else:
nodes = list(range(n1)) if nodes1 is None else nodes1
nodes.extend(range(n2) if nodes2 is None else nodes2)
if len(set(nodes)) != len(nodes):
raise nx.NetworkXError("Inputs n1 and n2 must contain distinct nodes")
G = graph_class.from_coo(
n1 + n2,
src_indices,
dst_indices,
node_values={"bipartite": bipartite},
id_to_key=nodes,
name=f"complete_bipartite_graph({orig_n1}, {orig_n2})",
)
if inplace:
return create_using._become(G)
return G
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def louvain_communities(
resolution=resolution,
do_expensive_check=False,
)
groups = _groupby(clusters, vertices)
groups = _groupby(clusters, vertices, groups_are_canonical=True)
rv = [set(G._nodearray_to_list(node_ids)) for node_ids in groups.values()]
# TODO: PLC doesn't handle isolated vertices yet, so this is a temporary fix
isolates = _isolates(G)
Expand Down
13 changes: 13 additions & 0 deletions python/nx-cugraph/nx_cugraph/algorithms/components/__init__.py
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 .connected import *
Loading

0 comments on commit 109684d

Please sign in to comment.