diff --git a/python/nx-cugraph/_nx_cugraph/__init__.py b/python/nx-cugraph/_nx_cugraph/__init__.py index a57c43944d4..64614fa3949 100644 --- a/python/nx-cugraph/_nx_cugraph/__init__.py +++ b/python/nx-cugraph/_nx_cugraph/__init__.py @@ -164,7 +164,6 @@ }, "louvain_communities": { "dtype : dtype or None, optional": "The data type (np.float32, np.float64, or None) to use for the edge weights in the algorithm. If None, then dtype is determined by the edge values.", - "max_level : int, optional": "Upper limit of the number of macro-iterations (max: 500).", }, "pagerank": { "dtype : dtype or None, optional": "The data type (np.float32, np.float64, or None) to use for the edge weights in the algorithm. If None, then dtype is determined by the edge values.", diff --git a/python/nx-cugraph/nx_cugraph/algorithms/community/louvain.py b/python/nx-cugraph/nx_cugraph/algorithms/community/louvain.py index f58f1000fc4..f7638f47aad 100644 --- a/python/nx-cugraph/nx_cugraph/algorithms/community/louvain.py +++ b/python/nx-cugraph/nx_cugraph/algorithms/community/louvain.py @@ -12,6 +12,7 @@ # limitations under the License. import warnings +import networkx as nx import pylibcugraph as plc from nx_cugraph.convert import _to_undirected_graph @@ -25,13 +26,21 @@ __all__ = ["louvain_communities"] +# max_level argument was added to NetworkX 3.3 +if nx.__version__[:3] <= "3.2": + _max_level_param = { + "max_level : int, optional": ( + "Upper limit of the number of macro-iterations (max: 500)." + ) + } +else: + _max_level_param = {} + @not_implemented_for("directed") @networkx_algorithm( extra_params={ - "max_level : int, optional": ( - "Upper limit of the number of macro-iterations (max: 500)." - ), + **_max_level_param, **_dtype_param, }, is_incomplete=True, # seed not supported; self-loops not supported @@ -44,9 +53,9 @@ def louvain_communities( weight="weight", resolution=1, threshold=0.0000001, + max_level=None, seed=None, *, - max_level=None, dtype=None, ): """`seed` parameter is currently ignored, and self-loops are not yet supported.""" @@ -82,9 +91,9 @@ def _( weight="weight", resolution=1, threshold=0.0000001, + max_level=None, seed=None, *, - max_level=None, dtype=None, ): # NetworkX allows both directed and undirected, but cugraph only allows undirected. diff --git a/python/nx-cugraph/nx_cugraph/interface.py b/python/nx-cugraph/nx_cugraph/interface.py index 46ea5831b0b..3c62fc3628e 100644 --- a/python/nx-cugraph/nx_cugraph/interface.py +++ b/python/nx-cugraph/nx_cugraph/interface.py @@ -257,6 +257,12 @@ def key(testpath): ): different_iteration_order, } ) + elif nxver.minor >= 3: + xfail.update( + { + key("test_louvain.py:test_max_level"): louvain_different, + } + ) too_slow = "Too slow to run" skip = { diff --git a/python/nx-cugraph/nx_cugraph/tests/test_match_api.py b/python/nx-cugraph/nx_cugraph/tests/test_match_api.py index a654ff343ed..595f7819ac1 100644 --- a/python/nx-cugraph/nx_cugraph/tests/test_match_api.py +++ b/python/nx-cugraph/nx_cugraph/tests/test_match_api.py @@ -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 @@ -14,10 +14,13 @@ import inspect import networkx as nx +from packaging.version import parse import nx_cugraph as nxcg from nx_cugraph.utils import networkx_algorithm +nxver = parse(nx.__version__) + def test_match_signature_and_names(): """Simple test to ensure our signatures and basic module layout match networkx.""" @@ -41,6 +44,11 @@ def test_match_signature_and_names(): else: orig_func = dispatchable_func.orig_func + if nxver.major == 3 and nxver.minor <= 2 and name == "louvain_communities": + # The signature of louvain_communities changed in NetworkX 3.3, and + # we updated to match, so we skip this check in older versions. + continue + # Matching signatures? orig_sig = inspect.signature(orig_func) func_sig = inspect.signature(func)