Skip to content

Commit

Permalink
nx-cugraph: indicate which plc algorithms are used and version_added (#…
Browse files Browse the repository at this point in the history
…4069)

Pretty simple PR. I would like for us to use this metadata when creating tables of supported algorithms.

Authors:
  - Erik Welch (https://github.com/eriknw)

Approvers:
  - Rick Ratzel (https://github.com/rlratzel)

URL: #4069
  • Loading branch information
eriknw authored Jan 11, 2024
1 parent b22dd99 commit 88c3884
Show file tree
Hide file tree
Showing 26 changed files with 538 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, 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 @@ -24,7 +24,7 @@
]


@networkx_algorithm(nodes_or_number=[0, 1])
@networkx_algorithm(nodes_or_number=[0, 1], version_added="23.12")
def complete_bipartite_graph(n1, n2, create_using=None):
graph_class, inplace = _create_using_class(create_using)
if graph_class.is_directed():
Expand Down
20 changes: 15 additions & 5 deletions python/nx-cugraph/nx_cugraph/algorithms/centrality/betweenness.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, 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,11 +18,16 @@
__all__ = ["betweenness_centrality", "edge_betweenness_centrality"]


@networkx_algorithm
@networkx_algorithm(
is_incomplete=True, # weight not supported
is_different=True, # RNG with seed is different
plc="betweenness_centrality",
version_added="23.10",
)
def betweenness_centrality(
G, k=None, normalized=True, weight=None, endpoints=False, seed=None
):
"""`weight` parameter is not yet supported."""
"""`weight` parameter is not yet supported, and RNG with seed may be different."""
if weight is not None:
raise NotImplementedError(
"Weighted implementation of betweenness centrality not currently supported"
Expand All @@ -46,9 +51,14 @@ def _(G, k=None, normalized=True, weight=None, endpoints=False, seed=None):
return weight is None


@networkx_algorithm
@networkx_algorithm(
is_incomplete=True, # weight not supported
is_different=True, # RNG with seed is different
plc="edge_betweenness_centrality",
version_added="23.10",
)
def edge_betweenness_centrality(G, k=None, normalized=True, weight=None, seed=None):
"""`weight` parameter is not yet supported."""
"""`weight` parameter is not yet supported, and RNG with seed may be different."""
if weight is not None:
raise NotImplementedError(
"Weighted implementation of betweenness centrality not currently supported"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, 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 @@ -16,7 +16,7 @@
__all__ = ["degree_centrality", "in_degree_centrality", "out_degree_centrality"]


@networkx_algorithm
@networkx_algorithm(version_added="23.12")
def degree_centrality(G):
G = _to_graph(G)
if len(G) <= 1:
Expand All @@ -27,7 +27,7 @@ def degree_centrality(G):


@not_implemented_for("undirected")
@networkx_algorithm
@networkx_algorithm(version_added="23.12")
def in_degree_centrality(G):
G = _to_directed_graph(G)
if len(G) <= 1:
Expand All @@ -38,7 +38,7 @@ def in_degree_centrality(G):


@not_implemented_for("undirected")
@networkx_algorithm
@networkx_algorithm(version_added="23.12")
def out_degree_centrality(G):
G = _to_directed_graph(G)
if len(G) <= 1:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, 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 @@ -26,7 +26,12 @@


@not_implemented_for("multigraph")
@networkx_algorithm(extra_params=_dtype_param)
@networkx_algorithm(
extra_params=_dtype_param,
is_incomplete=True, # nstart not supported
plc="eigenvector_centrality",
version_added="23.12",
)
def eigenvector_centrality(
G, max_iter=100, tol=1.0e-6, nstart=None, weight=None, *, dtype=None
):
Expand Down
9 changes: 7 additions & 2 deletions python/nx-cugraph/nx_cugraph/algorithms/centrality/katz.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, 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 @@ -26,7 +26,12 @@


@not_implemented_for("multigraph")
@networkx_algorithm(extra_params=_dtype_param)
@networkx_algorithm(
extra_params=_dtype_param,
is_incomplete=True, # nstart and normalized=False not supported
plc="katz_centrality",
version_added="23.12",
)
def katz_centrality(
G,
alpha=0.1,
Expand Down
10 changes: 7 additions & 3 deletions python/nx-cugraph/nx_cugraph/algorithms/community/louvain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, 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 @@ -35,7 +35,11 @@
"Upper limit of the number of macro-iterations (max: 500)."
),
**_dtype_param,
}
},
is_incomplete=True, # seed not supported; self-loops not supported
is_different=True, # RNG different
plc="louvain",
version_added="23.10",
)
def louvain_communities(
G,
Expand All @@ -47,7 +51,7 @@ def louvain_communities(
max_level=None,
dtype=None,
):
"""`seed` parameter is currently ignored."""
"""`seed` parameter is currently ignored, and self-loops are not yet supported."""
# NetworkX allows both directed and undirected, but cugraph only allows undirected.
seed = _seed_to_int(seed) # Unused, but ensure it's valid for future compatibility
G = _to_undirected_graph(G, weight)
Expand Down
10 changes: 5 additions & 5 deletions python/nx-cugraph/nx_cugraph/algorithms/components/connected.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, 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,7 +30,7 @@


@not_implemented_for("directed")
@networkx_algorithm
@networkx_algorithm(plc="weakly_connected_components", version_added="23.12")
def number_connected_components(G):
return sum(1 for _ in connected_components(G))
# PREFERRED IMPLEMENTATION, BUT PLC DOES NOT HANDLE ISOLATED VERTICES WELL
Expand All @@ -57,7 +57,7 @@ def _(G):


@not_implemented_for("directed")
@networkx_algorithm
@networkx_algorithm(plc="weakly_connected_components", version_added="23.12")
def connected_components(G):
G = _to_undirected_graph(G)
if G.src_indices.size == 0:
Expand Down Expand Up @@ -86,7 +86,7 @@ def connected_components(G):


@not_implemented_for("directed")
@networkx_algorithm
@networkx_algorithm(plc="weakly_connected_components", version_added="23.12")
def is_connected(G):
G = _to_undirected_graph(G)
if len(G) == 0:
Expand All @@ -110,7 +110,7 @@ def is_connected(G):


@not_implemented_for("directed")
@networkx_algorithm
@networkx_algorithm(plc="weakly_connected_components", version_added="23.12")
def node_connected_component(G, n):
# We could also do plain BFS from n
G = _to_undirected_graph(G)
Expand Down
4 changes: 2 additions & 2 deletions python/nx-cugraph/nx_cugraph/algorithms/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, 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 @@ -27,7 +27,7 @@

@not_implemented_for("directed")
@not_implemented_for("multigraph")
@networkx_algorithm
@networkx_algorithm(is_incomplete=True, plc="k_truss_subgraph", version_added="23.12")
def k_truss(G, k):
"""
Currently raises `NotImplementedError` for graphs with more than one connected
Expand Down
6 changes: 3 additions & 3 deletions python/nx-cugraph/nx_cugraph/algorithms/dag.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, 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 @@ -45,11 +45,11 @@ def _ancestors_and_descendants(G, source, *, is_ancestors):
return G._nodearray_to_set(node_ids[mask])


@networkx_algorithm
@networkx_algorithm(plc="bfs", version_added="24.02")
def descendants(G, source):
return _ancestors_and_descendants(G, source, is_ancestors=False)


@networkx_algorithm
@networkx_algorithm(plc="bfs", version_added="24.02")
def ancestors(G, source):
return _ancestors_and_descendants(G, source, is_ancestors=True)
8 changes: 4 additions & 4 deletions python/nx-cugraph/nx_cugraph/algorithms/isolate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, 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 @@ -25,7 +25,7 @@
__all__ = ["is_isolate", "isolates", "number_of_isolates"]


@networkx_algorithm
@networkx_algorithm(version_added="23.10")
def is_isolate(G, n):
G = _to_graph(G)
index = n if G.key_to_id is None else G.key_to_id[n]
Expand All @@ -51,13 +51,13 @@ def _isolates(G) -> cp.ndarray[IndexValue]:
return cp.nonzero(_mark_isolates(G))[0]


@networkx_algorithm
@networkx_algorithm(version_added="23.10")
def isolates(G):
G = _to_graph(G)
return G._nodeiter_to_iter(iter(_isolates(G).tolist()))


@networkx_algorithm
@networkx_algorithm(version_added="23.10")
def number_of_isolates(G):
G = _to_graph(G)
return _mark_isolates(G).sum().tolist()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, 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 @@ -32,7 +32,9 @@
"The edge attribute to use as the edge weight."
),
**_dtype_param,
}
},
plc="hits",
version_added="23.12",
)
def hits(
G,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, 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 @@ -26,7 +26,12 @@
__all__ = ["pagerank"]


@networkx_algorithm(extra_params=_dtype_param)
@networkx_algorithm(
extra_params=_dtype_param,
is_incomplete=True, # dangling not supported
plc={"pagerank", "personalized_pagerank"},
version_added="23.12",
)
def pagerank(
G,
alpha=0.85,
Expand Down Expand Up @@ -97,7 +102,7 @@ def pagerank(


@pagerank._can_run
def pagerank(
def _(
G,
alpha=0.85,
personalization=None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, 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 @@ -21,12 +21,12 @@
__all__ = ["single_source_shortest_path_length", "single_target_shortest_path_length"]


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


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

Expand Down
Loading

0 comments on commit 88c3884

Please sign in to comment.