Skip to content

Commit

Permalink
Also add is_incomplete and is_different
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknw committed Jan 2, 2024
1 parent b051bae commit 8ed2e17
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 14 deletions.
14 changes: 12 additions & 2 deletions python/nx-cugraph/nx_cugraph/algorithms/centrality/betweenness.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
__all__ = ["betweenness_centrality", "edge_betweenness_centrality"]


@networkx_algorithm(plc="betweenness_centrality", version_added="23.10")
@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
):
Expand Down Expand Up @@ -46,7 +51,12 @@ def _(G, k=None, normalized=True, weight=None, endpoints=False, seed=None):
return weight is None


@networkx_algorithm(plc="edge_betweenness_centrality", version_added="23.10")
@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."""
if weight is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@

@not_implemented_for("multigraph")
@networkx_algorithm(
extra_params=_dtype_param, plc="eigenvector_centrality", version_added="23.12"
is_incomplete=True, # nstart not supported
extra_params=_dtype_param,
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
5 changes: 4 additions & 1 deletion python/nx-cugraph/nx_cugraph/algorithms/centrality/katz.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@

@not_implemented_for("multigraph")
@networkx_algorithm(
extra_params=_dtype_param, plc="katz_centrality", version_added="23.12"
is_incomplete=True, # nstart and normalized=False not supported
extra_params=_dtype_param,
plc="katz_centrality",
version_added="23.12",
)
def katz_centrality(
G,
Expand Down
2 changes: 2 additions & 0 deletions python/nx-cugraph/nx_cugraph/algorithms/community/louvain.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

@not_implemented_for("directed")
@networkx_algorithm(
is_incomplete=True, # seed not supported; self-loops not supported
is_different=True, # RNG different
extra_params={
"max_level : int, optional": (
"Upper limit of the number of macro-iterations (max: 500)."
Expand Down
2 changes: 1 addition & 1 deletion python/nx-cugraph/nx_cugraph/algorithms/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

@not_implemented_for("directed")
@not_implemented_for("multigraph")
@networkx_algorithm(plc="k_truss_subgraph", version_added="23.12")
@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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@


@networkx_algorithm(
is_incomplete=True, # dangling not supported
extra_params=_dtype_param,
plc={"pagerank", "personalized_pagerank"},
version_added="23.12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _bfs(G, source, *, depth_limit=None, reverse=False):
return distances[mask], predecessors[mask], node_ids[mask]


@networkx_algorithm(plc="bfs", version_added="24.02")
@networkx_algorithm(is_incomplete=True, plc="bfs", version_added="24.02")
def generic_bfs_edges(G, source, neighbors=None, depth_limit=None, sort_neighbors=None):
"""`neighbors` and `sort_neighbors` parameters are not yet supported."""
return bfs_edges(source, depth_limit=depth_limit)
Expand All @@ -68,7 +68,7 @@ def _(G, source, neighbors=None, depth_limit=None, sort_neighbors=None):
return neighbors is None and sort_neighbors is None


@networkx_algorithm(plc="bfs", version_added="24.02")
@networkx_algorithm(is_incomplete=True, plc="bfs", version_added="24.02")
def bfs_edges(G, source, reverse=False, depth_limit=None, sort_neighbors=None):
"""`sort_neighbors` parameter is not yet supported."""
G = _check_G_and_source(G, source)
Expand All @@ -95,7 +95,7 @@ def _(G, source, reverse=False, depth_limit=None, sort_neighbors=None):
return sort_neighbors is None


@networkx_algorithm(plc="bfs", version_added="24.02")
@networkx_algorithm(is_incomplete=True, plc="bfs", version_added="24.02")
def bfs_tree(G, source, reverse=False, depth_limit=None, sort_neighbors=None):
"""`sort_neighbors` parameter is not yet supported."""
G = _check_G_and_source(G, source)
Expand Down Expand Up @@ -149,7 +149,7 @@ def _(G, source, reverse=False, depth_limit=None, sort_neighbors=None):
return sort_neighbors is None


@networkx_algorithm(plc="bfs", version_added="24.02")
@networkx_algorithm(is_incomplete=True, plc="bfs", version_added="24.02")
def bfs_successors(G, source, depth_limit=None, sort_neighbors=None):
"""`sort_neighbors` parameter is not yet supported."""
G = _check_G_and_source(G, source)
Expand Down Expand Up @@ -201,7 +201,7 @@ def bfs_layers(G, sources):
return (G._nodearray_to_list(groups[key]) for key in range(len(groups)))


@networkx_algorithm(plc="bfs", version_added="24.02")
@networkx_algorithm(is_incomplete=True, plc="bfs", version_added="24.02")
def bfs_predecessors(G, source, depth_limit=None, sort_neighbors=None):
"""`sort_neighbors` parameter is not yet supported."""
G = _check_G_and_source(G, source)
Expand Down
3 changes: 2 additions & 1 deletion python/nx-cugraph/nx_cugraph/convert_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
]


@networkx_algorithm(version_added="23.12")
# Value columns with string dtype is not supported
@networkx_algorithm(is_incomplete=True, version_added="23.12")
def from_pandas_edgelist(
df,
source="source",
Expand Down
13 changes: 10 additions & 3 deletions python/nx-cugraph/nx_cugraph/scripts/print_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ def get_path_to_name():
}


Info = namedtuple("Info", "networkx_path, dispatch_name, version_added, plc")
Info = namedtuple(
"Info",
"networkx_path, dispatch_name, version_added, plc, is_incomplete, is_different",
)


def get_path_to_info(path_to_name=None, version_added_sep=".", plc_sep="/"):
Expand All @@ -44,14 +47,18 @@ def get_path_to_info(path_to_name=None, version_added_sep=".", plc_sep="/"):
cufunc = getattr(BackendInterface, funcname)
plc = plc_sep.join(sorted(cufunc._plc_names)) if cufunc._plc_names else ""
version_added = cufunc.version_added.replace(".", version_added_sep)
rv[funcpath] = Info(funcpath, funcname, version_added, plc)
is_incomplete = cufunc.is_incomplete
is_different = cufunc.is_different
rv[funcpath] = Info(
funcpath, funcname, version_added, plc, is_incomplete, is_different
)
return rv


def main(path_to_info=None, *, file=sys.stdout):
if path_to_info is None:
path_to_info = get_path_to_info(version_added_sep=".")
lines = ["networkx_path,dispatch_name,version_added,plc"]
lines = ["networkx_path,dispatch_name,version_added,plc,is_incomplete,is_different"]
lines.extend(",".join(info) for info in path_to_info.values())
text = "\n".join(lines)
print(text, file=file)
Expand Down
24 changes: 24 additions & 0 deletions python/nx-cugraph/nx_cugraph/scripts/print_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def get_extra(
version_added=False,
plc=False,
dispatch_name_if_different=False,
incomplete=False,
different=False,
):
extra = []
if networkx_path:
Expand All @@ -58,6 +60,10 @@ def get_extra(
extra.append(v[:2] + "." + v[-2:])
if plc and info.plc:
extra.append(info.plc)
if incomplete and info.is_incomplete:
extra.append("is-incomplete")
if different and info.is_different:
extra.append("is-different")
return extra


Expand All @@ -71,6 +77,8 @@ def create_tree(
version_added=False,
plc=False,
dispatch_name_if_different=False,
incomplete=False,
different=False,
prefix="",
):
if path_to_info is None:
Expand Down Expand Up @@ -106,6 +114,8 @@ def main(
version_added=False,
plc=False,
dispatch_name_if_different=True,
incomplete=False,
different=False,
file=sys.stdout,
):
if path_to_info is None:
Expand All @@ -116,6 +126,8 @@ def main(
"version_added": version_added,
"plc": plc,
"dispatch_name_if_different": dispatch_name_if_different,
"incomplete": incomplete,
"different": different,
}
if by == "networkx_path":
G = create_tree(path_to_info, by="networkx_path", **kwargs)
Expand Down Expand Up @@ -199,6 +211,16 @@ def get_argumentparser(add_help=True):
action="store_true",
help="Show the full networkx path in parentheses",
)
parser.add_argument(
"--incomplete",
action="store_true",
help="Show which functions are incomplete",
)
parser.add_argument(
"--different",
action="store_true",
help="Show which functions are different",
)
return parser


Expand All @@ -212,4 +234,6 @@ def get_argumentparser(add_help=True):
version_added=args.version_added,
plc=args.plc,
dispatch_name_if_different=not args.dispatch_name_always,
incomplete=args.incomplete,
different=args.different,
)
8 changes: 8 additions & 0 deletions python/nx-cugraph/nx_cugraph/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class networkx_algorithm:
extra_doc: str | None
extra_params: dict[str, str] | None
version_added: str
is_incomplete: bool
is_different: bool
_plc_names: set[str] | None

def __new__(
Expand All @@ -53,6 +55,8 @@ def __new__(
nodes_or_number: list[int] | int | None = None,
plc: str | set[str] | None = None,
version_added: str,
is_incomplete: bool = False,
is_different: bool = False,
):
if func is None:
return partial(
Expand All @@ -62,6 +66,8 @@ def __new__(
nodes_or_number=nodes_or_number,
plc=plc,
version_added=version_added,
is_incomplete=is_incomplete,
is_different=is_different,
)
instance = object.__new__(cls)
if nodes_or_number is not None and nx.__version__[:3] > "3.2":
Expand All @@ -87,6 +93,8 @@ def __new__(
else:
raise TypeError(f"plc argument must be str, set, or None; got {type(plc)}")
instance.version_added = version_added
instance.is_incomplete = is_incomplete
instance.is_different = is_different
# The docstring on our function is added to the NetworkX docstring.
instance.extra_doc = (
dedent(func.__doc__.lstrip("\n").rstrip()) if func.__doc__ else None
Expand Down

0 comments on commit 8ed2e17

Please sign in to comment.