Skip to content

Commit

Permalink
nx-cugraph: rename plc= to _plc=
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknw committed Jan 22, 2024
1 parent f20219e commit fe848d7
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 53 deletions.
6 changes: 3 additions & 3 deletions python/nx-cugraph/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ repos:
- id: black
# - id: black-jupyter
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
rev: v0.1.14
hooks:
- id: ruff
args: [--fix-only, --show-fixes] # --unsafe-fixes]
Expand All @@ -62,7 +62,7 @@ repos:
additional_dependencies: &flake8_dependencies
# These versions need updated manually
- flake8==7.0.0
- flake8-bugbear==23.12.2
- flake8-bugbear==24.1.17
- flake8-simplify==0.21.0
- repo: https://github.com/asottile/yesqa
rev: v1.5.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.13
rev: v0.1.14
hooks:
- id: ruff
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
2 changes: 1 addition & 1 deletion python/nx-cugraph/nx_cugraph/algorithms/bipartite/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]


@networkx_algorithm(plc="triangle_count", version_added="24.02")
@networkx_algorithm(version_added="24.02", _plc="triangle_count")
def is_bipartite(G):
G = _to_graph(G)
# Counting triangles may not be the fastest way to do this, but it is simple.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
@networkx_algorithm(
is_incomplete=True, # weight not supported
is_different=True, # RNG with seed is different
plc="betweenness_centrality",
version_added="23.10",
_plc="betweenness_centrality",
)
def betweenness_centrality(
G, k=None, normalized=True, weight=None, endpoints=False, seed=None
Expand Down Expand Up @@ -54,8 +54,8 @@ def _(G, k=None, normalized=True, weight=None, endpoints=False, seed=None):
@networkx_algorithm(
is_incomplete=True, # weight not supported
is_different=True, # RNG with seed is different
plc="edge_betweenness_centrality",
version_added="23.10",
_plc="edge_betweenness_centrality",
)
def edge_betweenness_centrality(G, k=None, normalized=True, weight=None, seed=None):
"""`weight` parameter is not yet supported, and RNG with seed may be different."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
@networkx_algorithm(
extra_params=_dtype_param,
is_incomplete=True, # nstart not supported
plc="eigenvector_centrality",
version_added="23.12",
_plc="eigenvector_centrality",
)
def eigenvector_centrality(
G, max_iter=100, tol=1.0e-6, nstart=None, weight=None, *, dtype=None
Expand Down
2 changes: 1 addition & 1 deletion python/nx-cugraph/nx_cugraph/algorithms/centrality/katz.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
@networkx_algorithm(
extra_params=_dtype_param,
is_incomplete=True, # nstart and normalized=False not supported
plc="katz_centrality",
version_added="23.12",
_plc="katz_centrality",
)
def katz_centrality(
G,
Expand Down
16 changes: 12 additions & 4 deletions python/nx-cugraph/nx_cugraph/algorithms/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _triangles(G, nodes, symmetrize=None):


@not_implemented_for("directed")
@networkx_algorithm(plc="triangle_count", version_added="24.02")
@networkx_algorithm(version_added="24.02", _plc="triangle_count")
def triangles(G, nodes=None):
G = _to_undirected_graph(G)
node_ids, triangles, is_single_node = _triangles(G, nodes)
Expand All @@ -57,9 +57,13 @@ def triangles(G, nodes=None):


@not_implemented_for("directed")
@networkx_algorithm(is_incomplete=True, plc="triangle_count", version_added="24.02")
@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="triangle_count")
def clustering(G, nodes=None, weight=None):
"""Directed graphs and `weight` parameter are not yet supported."""
if weight is not None:
raise NotImplementedError(
"Weighted implementation of clustering not currently supported"
)
G = _to_undirected_graph(G)
node_ids, triangles, is_single_node = _triangles(G, nodes)
if len(G) == 0:
Expand All @@ -83,9 +87,13 @@ def _(G, nodes=None, weight=None):


@not_implemented_for("directed")
@networkx_algorithm(is_incomplete=True, plc="triangle_count", version_added="24.02")
@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="triangle_count")
def average_clustering(G, nodes=None, weight=None, count_zeros=True):
"""Directed graphs and `weight` parameter are not yet supported."""
if weight is not None:
raise NotImplementedError(
"Weighted implementation of average_clustering not currently supported"
)
G = _to_undirected_graph(G)
node_ids, triangles, is_single_node = _triangles(G, nodes)
if len(G) == 0:
Expand All @@ -110,7 +118,7 @@ def _(G, nodes=None, weight=None, count_zeros=True):


@not_implemented_for("directed")
@networkx_algorithm(is_incomplete=True, plc="triangle_count", version_added="24.02")
@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="triangle_count")
def transitivity(G):
"""Directed graphs are not yet supported."""
G = _to_undirected_graph(G)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
},
is_incomplete=True, # seed not supported; self-loops not supported
is_different=True, # RNG different
plc="louvain",
version_added="23.10",
_plc="louvain",
)
def louvain_communities(
G,
Expand Down
13 changes: 5 additions & 8 deletions python/nx-cugraph/nx_cugraph/algorithms/components/connected.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


@not_implemented_for("directed")
@networkx_algorithm(plc="weakly_connected_components", version_added="23.12")
@networkx_algorithm(version_added="23.12", _plc="weakly_connected_components")
def number_connected_components(G):
G = _to_undirected_graph(G)
return _number_connected_components(G)
Expand All @@ -50,14 +50,11 @@ def _number_connected_components(G, symmetrize=None):
@number_connected_components._can_run
def _(G):
# NetworkX <= 3.2.1 does not check directedness for us
try:
return not G.is_directed()
except Exception:
return False
return not G.is_directed()


@not_implemented_for("directed")
@networkx_algorithm(plc="weakly_connected_components", version_added="23.12")
@networkx_algorithm(version_added="23.12", _plc="weakly_connected_components")
def connected_components(G):
G = _to_undirected_graph(G)
return _connected_components(G)
Expand All @@ -80,7 +77,7 @@ def _connected_components(G, symmetrize=None):


@not_implemented_for("directed")
@networkx_algorithm(plc="weakly_connected_components", version_added="23.12")
@networkx_algorithm(version_added="23.12", _plc="weakly_connected_components")
def is_connected(G):
G = _to_undirected_graph(G)
return _is_connected(G)
Expand All @@ -106,7 +103,7 @@ def _is_connected(G, symmetrize=None):


@not_implemented_for("directed")
@networkx_algorithm(plc="weakly_connected_components", version_added="23.12")
@networkx_algorithm(version_added="23.12", _plc="weakly_connected_components")
def node_connected_component(G, n):
# We could also do plain BFS from n
G = _to_undirected_graph(G)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _strongly_connected_components(G):


@not_implemented_for("undirected")
@networkx_algorithm(version_added="24.02", plc="strongly_connected_components")
@networkx_algorithm(version_added="24.02", _plc="strongly_connected_components")
def strongly_connected_components(G):
G = _to_directed_graph(G)
if G.src_indices.size == 0:
Expand All @@ -62,7 +62,7 @@ def strongly_connected_components(G):


@not_implemented_for("undirected")
@networkx_algorithm(version_added="24.02", plc="strongly_connected_components")
@networkx_algorithm(version_added="24.02", _plc="strongly_connected_components")
def number_strongly_connected_components(G):
G = _to_directed_graph(G)
if G.src_indices.size == 0:
Expand All @@ -72,7 +72,7 @@ def number_strongly_connected_components(G):


@not_implemented_for("undirected")
@networkx_algorithm(version_added="24.02", plc="strongly_connected_components")
@networkx_algorithm(version_added="24.02", _plc="strongly_connected_components")
def is_strongly_connected(G):
G = _to_directed_graph(G)
if len(G) == 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@


@not_implemented_for("undirected")
@networkx_algorithm(plc="weakly_connected_components", version_added="24.02")
@networkx_algorithm(version_added="24.02", _plc="weakly_connected_components")
def weakly_connected_components(G):
G = _to_directed_graph(G)
return _connected_components(G, symmetrize="union")


@not_implemented_for("undirected")
@networkx_algorithm(plc="weakly_connected_components", version_added="24.02")
@networkx_algorithm(version_added="24.02", _plc="weakly_connected_components")
def number_weakly_connected_components(G):
G = _to_directed_graph(G)
return _number_connected_components(G, symmetrize="union")


@not_implemented_for("undirected")
@networkx_algorithm(plc="weakly_connected_components", version_added="24.02")
@networkx_algorithm(version_added="24.02", _plc="weakly_connected_components")
def is_weakly_connected(G):
G = _to_directed_graph(G)
return _is_connected(G, symmetrize="union")
4 changes: 2 additions & 2 deletions python/nx-cugraph/nx_cugraph/algorithms/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

@not_implemented_for("directed")
@not_implemented_for("multigraph")
@networkx_algorithm(is_incomplete=True, plc="core_number", version_added="24.02")
@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="core_number")
def core_number(G):
"""Directed graphs are not yet supported."""
G = _to_undirected_graph(G)
Expand All @@ -55,7 +55,7 @@ def _(G):

@not_implemented_for("directed")
@not_implemented_for("multigraph")
@networkx_algorithm(is_incomplete=True, plc="k_truss_subgraph", version_added="23.12")
@networkx_algorithm(is_incomplete=True, version_added="23.12", _plc="k_truss_subgraph")
def k_truss(G, k):
"""
Currently raises `NotImplementedError` for graphs with more than one connected
Expand Down
4 changes: 2 additions & 2 deletions python/nx-cugraph/nx_cugraph/algorithms/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def _ancestors_and_descendants(G, source, *, is_ancestors):
return G._nodearray_to_set(node_ids[mask])


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


@networkx_algorithm(plc="bfs", version_added="24.02")
@networkx_algorithm(version_added="24.02", _plc="bfs")
def ancestors(G, source):
return _ancestors_and_descendants(G, source, is_ancestors=True)
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
),
**_dtype_param,
},
plc="hits",
version_added="23.12",
_plc="hits",
)
def hits(
G,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
@networkx_algorithm(
extra_params=_dtype_param,
is_incomplete=True, # dangling not supported
plc={"pagerank", "personalized_pagerank"},
version_added="23.12",
_plc={"pagerank", "personalized_pagerank"},
)
def pagerank(
G,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
__all__ = ["single_source_shortest_path_length", "single_target_shortest_path_length"]


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


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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,17 @@ def _bfs(G, source, *, depth_limit=None, reverse=False):
return distances[mask], predecessors[mask], node_ids[mask]


@networkx_algorithm(is_incomplete=True, plc="bfs", version_added="24.02")
@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="bfs")
def generic_bfs_edges(G, source, neighbors=None, depth_limit=None, sort_neighbors=None):
"""`neighbors` and `sort_neighbors` parameters are not yet supported."""
if neighbors is not None:
raise NotImplementedError(
"neighbors argument in generic_bfs_edges is not currently supported"
)
if sort_neighbors is not None:
raise NotImplementedError(
"sort_neighbors argument in generic_bfs_edges is not currently supported"
)
return bfs_edges(source, depth_limit=depth_limit)


Expand All @@ -68,9 +76,13 @@ def _(G, source, neighbors=None, depth_limit=None, sort_neighbors=None):
return neighbors is None and sort_neighbors is None


@networkx_algorithm(is_incomplete=True, plc="bfs", version_added="24.02")
@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="bfs")
def bfs_edges(G, source, reverse=False, depth_limit=None, sort_neighbors=None):
"""`sort_neighbors` parameter is not yet supported."""
if sort_neighbors is not None:
raise NotImplementedError(
"sort_neighbors argument in bfs_edges is not currently supported"
)
G = _check_G_and_source(G, source)
if depth_limit is not None and depth_limit < 1:
return
Expand All @@ -95,9 +107,13 @@ def _(G, source, reverse=False, depth_limit=None, sort_neighbors=None):
return sort_neighbors is None


@networkx_algorithm(is_incomplete=True, plc="bfs", version_added="24.02")
@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="bfs")
def bfs_tree(G, source, reverse=False, depth_limit=None, sort_neighbors=None):
"""`sort_neighbors` parameter is not yet supported."""
if sort_neighbors is not None:
raise NotImplementedError(
"sort_neighbors argument in bfs_tree is not currently supported"
)
G = _check_G_and_source(G, source)
if depth_limit is not None and depth_limit < 1:
return nxcg.DiGraph.from_coo(
Expand Down Expand Up @@ -149,9 +165,13 @@ def _(G, source, reverse=False, depth_limit=None, sort_neighbors=None):
return sort_neighbors is None


@networkx_algorithm(is_incomplete=True, plc="bfs", version_added="24.02")
@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="bfs")
def bfs_successors(G, source, depth_limit=None, sort_neighbors=None):
"""`sort_neighbors` parameter is not yet supported."""
if sort_neighbors is not None:
raise NotImplementedError(
"sort_neighbors argument in bfs_successors is not currently supported"
)
G = _check_G_and_source(G, source)
if depth_limit is not None and depth_limit < 1:
yield (source, [])
Expand All @@ -173,7 +193,7 @@ def _(G, source, depth_limit=None, sort_neighbors=None):
return sort_neighbors is None


@networkx_algorithm(plc="bfs", version_added="24.02")
@networkx_algorithm(version_added="24.02", _plc="bfs")
def bfs_layers(G, sources):
G = _to_graph(G)
if sources in G:
Expand Down Expand Up @@ -201,9 +221,13 @@ def bfs_layers(G, sources):
return (G._nodearray_to_list(groups[key]) for key in range(len(groups)))


@networkx_algorithm(is_incomplete=True, plc="bfs", version_added="24.02")
@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="bfs")
def bfs_predecessors(G, source, depth_limit=None, sort_neighbors=None):
"""`sort_neighbors` parameter is not yet supported."""
if sort_neighbors is not None:
raise NotImplementedError(
"sort_neighbors argument in bfs_predecessors is not currently supported"
)
G = _check_G_and_source(G, source)
if depth_limit is not None and depth_limit < 1:
return
Expand All @@ -227,7 +251,7 @@ def _(G, source, depth_limit=None, sort_neighbors=None):
return sort_neighbors is None


@networkx_algorithm(plc="bfs", version_added="24.02")
@networkx_algorithm(version_added="24.02", _plc="bfs")
def descendants_at_distance(G, source, distance):
G = _check_G_and_source(G, source)
if distance is None or distance < 0:
Expand Down
Loading

0 comments on commit fe848d7

Please sign in to comment.