Skip to content

Commit

Permalink
Merge branch 'main' into use-graphs-system-collections
Browse files Browse the repository at this point in the history
  • Loading branch information
aMahanna authored Oct 21, 2024
2 parents 8b90ce2 + 1e7df83 commit aa4621c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion _nx_arangodb/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.1.1
6 changes: 3 additions & 3 deletions nx_arangodb/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}")
Expand Down
36 changes: 32 additions & 4 deletions nx_arangodb/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -80,14 +82,40 @@ 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"
logger.debug(f"'{func_name}' running on default backend '{default_backend}'")
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,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit aa4621c

Please sign in to comment.