Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump: networkx dep #64

Merged
merged 8 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion nx_arangodb/classes/dict/adj.py
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ def propagate_edge_directed_symmetric(
set_adj_inner_dict_mirror(src_node_id)
set_adj_inner_dict_mirror(dst_node_id)

edge_attr_or_key_dict = set_edge_func( # type: ignore[operator]
edge_attr_or_key_dict = set_edge_func(
src_node_id, dst_node_id, edge_or_edges
)

Expand Down
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
Loading