diff --git a/_nx_arangodb/VERSION b/_nx_arangodb/VERSION index 1cc5f65..8cfbc90 100644 --- a/_nx_arangodb/VERSION +++ b/_nx_arangodb/VERSION @@ -1 +1 @@ -1.1.0 \ No newline at end of file +1.1.1 \ No newline at end of file diff --git a/nx_arangodb/convert.py b/nx_arangodb/convert.py index 09cfa97..8eda47b 100644 --- a/nx_arangodb/convert.py +++ b/nx_arangodb/convert.py @@ -138,11 +138,11 @@ def _to_nxcg_graph(G: Any, as_directed: bool = False) -> nxcg.Graph: return G if isinstance(G, nxadb.Graph): + logger.debug("converting nx_arangodb graph to nx_cugraph graph") + if not G.graph_exists_in_db: - m = "nx_arangodb.Graph does not exist in ArangoDB. Cannot pull graph." - raise ValueError(m) + return nxcg.convert.from_networkx(G) - logger.debug("converting nx_arangodb graph to nx_cugraph graph") return nxadb_to_nxcg(G, as_directed=as_directed) raise TypeError(f"Expected nx_arangodb.Graph or nxcg.Graph; got {type(G)}") diff --git a/nx_arangodb/interface.py b/nx_arangodb/interface.py index 4704875..c756a32 100644 --- a/nx_arangodb/interface.py +++ b/nx_arangodb/interface.py @@ -62,13 +62,15 @@ def _auto_func(func_name: str, /, *args: Any, **kwargs: Any) -> Any: """ dfunc = _registered_algorithms[func_name] - backend_priority = [] + backend_priority: list[str] = [] if nxadb.convert.GPU_AVAILABLE and nx.config.backends.arangodb.use_gpu: backend_priority.append("cugraph") for backend in backend_priority: - if not dfunc.__wrapped__._should_backend_run(backend, *args, **kwargs): - logger.warning(f"'{func_name}' cannot be run on backend '{backend}'") + if not _should_backend_run(backend, dfunc, *args, **kwargs): + continue + + if not _can_backend_run(backend, dfunc, *args, **kwargs): continue try: @@ -80,7 +82,7 @@ def _auto_func(func_name: str, /, *args: Any, **kwargs: Any) -> Any: ) except NotImplementedError: - logger.warning(f"'{func_name}' not implemented for backend '{backend}'") + logger.debug(f"'{func_name}' not implemented for backend '{backend}'") pass default_backend = "networkx" @@ -88,6 +90,32 @@ def _auto_func(func_name: str, /, *args: Any, **kwargs: Any) -> Any: return _run_with_backend(default_backend, dfunc, args, kwargs) +def _should_backend_run(backend: str, dfunc: Any, *args: Any, **kwargs: Any) -> bool: + """Wrapper around NetworkX's should_backend_run function, because + the signature is different for NetworkX <=3.3 and 3.4: + + - https://github.com/networkx/networkx/blob/networkx-3.3/networkx/utils/backends.py#L821 # noqa: E501 + - https://github.com/networkx/networkx/blob/networkx-3.4.1/networkx/utils/backends.py#L1514 # noqa: E501 + """ + try: + return bool(dfunc.__wrapped__._should_backend_run(backend, *args, **kwargs)) + except TypeError: + return bool(dfunc.__wrapped__._should_backend_run(backend, args, kwargs)) + + +def _can_backend_run(backend: str, dfunc: Any, *args: Any, **kwargs: Any) -> bool: + """Wrapper around NetworkX's _can_backend_run function, because + the signature is different for NetworkX <=3.3 and 3.4: + + - https://github.com/networkx/networkx/blob/networkx-3.3/networkx/utils/backends.py#L810 # noqa: E501 + - https://github.com/networkx/networkx/blob/networkx-3.4.1/networkx/utils/backends.py#L1489 # noqa: E501 + """ + try: + return bool(dfunc.__wrapped__._can_backend_run(backend, *args, **kwargs)) + except TypeError: + return bool(dfunc.__wrapped__._can_backend_run(backend, args, kwargs)) + + def _run_with_backend( backend_name: str, dfunc: NetworkXFunction, diff --git a/pyproject.toml b/pyproject.toml index b804121..35aa776 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ classifiers = [ "Topic :: Software Development :: Libraries :: Python Modules", ] dependencies = [ - "networkx>=3.0,<=3.3", + "networkx>=3.0,<=3.4", "phenolrs~=0.5", "python-arango~=8.1", "adbnx-adapter~=5.0.5"