Skip to content

misc cleanup #54

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

Merged
merged 3 commits into from
Sep 2, 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
23 changes: 9 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# nx-arangodb

<a href="https://colab.research.google.com/github/arangodb/nx-arangodb/blob/main/docs/nx_arangodb.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>


<div style="display: flex; align-items: center; gap: 10px;">
<img src="https://avatars.githubusercontent.com/u/388785?s=200&v=4" alt="NetworkX" style="height: 60px;">
Expand All @@ -12,10 +10,10 @@

<br>

<a href="https://colab.research.google.com/github/arangodb/nx-arangodb/blob/main/docs/nx_arangodb.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/arangodb/nx-arangodb/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/arangodb/nx-arangodb/tree/main)
[![CodeQL](https://github.com/arangodb/nx-arangodb/actions/workflows/analyzee.yaml/badge.svg)](https://github.com/arangodb/nx-arangodb/actions/workflows/analyzee.yaml)
[![Docs](https://github.com/arangodb/nx-arangodb/actions/workflows/docs.yaml/badge.svg)](https://github.com/arangodb/nx-arangodb/actions/workflows/docs.yaml)
[![Last commit](https://img.shields.io/github/last-commit/arangodb/nx-arangodb)](https://github.com/arangodb/nx-arangodb/commits/main)

[![PyPI version badge](https://img.shields.io/pypi/v/nx-arangodb?color=3775A9&style=for-the-badge&logo=pypi&logoColor=FFD43B)](https://pypi.org/project/nx-arangodb/)
[![Python versions badge](https://img.shields.io/badge/3.10%2B-3776AB?style=for-the-badge&logo=python&logoColor=FFD43B&label=Python)](https://pypi.org/project/nx-arangodb/)
Expand All @@ -31,9 +29,7 @@ https://github.com/user-attachments/assets/e5f56574-d3ef-452c-ab21-b47b3d5d5900

## What is this?

This is a [backend to NetworkX](https://networkx.org/documentation/stable/reference/backends.html) that offers [ArangoDB](https://github.com/arangodb/arangodb) as a [Persistence Layer to NetworkX Graphs](https://arangodb.com/introducing-the-arangodb-networkx-persistence-layer/).

`nx-arangodb` allows you to:
This is a [backend to NetworkX](https://networkx.org/documentation/stable/reference/backends.html) that offers [ArangoDB](https://github.com/arangodb/arangodb) as a [Persistence Layer to NetworkX Graphs](https://arangodb.com/introducing-the-arangodb-networkx-persistence-layer/):
1. Persist NetworkX Graphs to ArangoDB.
2. Reload NetworkX Graphs from ArangoDB.
2. Perform CRUD on ArangoDB Graphs via NetworkX.
Expand All @@ -42,11 +38,10 @@ This is a [backend to NetworkX](https://networkx.org/documentation/stable/refere
Benefits of having ArangoDB as a backend to NetworkX include:
1. No need to re-create the graph every time you start a new session.
2. Access to GPU-accelerated graph analytics ([nx-cugraph](https://docs.rapids.ai/api/cugraph/nightly/nx_cugraph/nx_cugraph/)).
2. Access to a database query language ([Arango Query Language](https://arangodb.com/sql-aql-comparison/)).
3. Access to a visual interface for graph exploration ([ArangoDB Web UI](https://docs.arangodb.com/3.11/components/web-interface/graphs/)).
4. Access to cross-collaboration on the same graph ([ArangoDB Cloud](https://dashboard.arangodb.cloud/)).

6. Access to efficient distribution of graph data ([ArangoDB SmartGraphs](https://docs.arangodb.com/3.11/graphs/smartgraphs/)).
3. Access to a database query language ([Arango Query Language](https://arangodb.com/sql-aql-comparison/)).
4. Access to a visual interface for graph exploration ([ArangoDB Web UI](https://docs.arangodb.com/stable/components/web-interface/graphs/)).
5. Access to cross-collaboration on the same graph ([ArangoDB Cloud](https://docs.arangodb.com/stable/get-started/set-up-a-cloud-instance/)).
6. Access to efficient distribution of graph data ([ArangoDB SmartGraphs](https://docs.arangodb.com/stable/graphs/smartgraphs/)).

<p align="center">
<img src="./docs/_static/nxadb.png" style="height: 200px;">
Expand All @@ -55,7 +50,7 @@ Benefits of having ArangoDB as a backend to NetworkX include:

## Does this replace NetworkX?

No. This is a plugin to NetworkX, which means that you can use NetworkX as you normally would, but with the added benefit of persisting your graphs to a database.
Not really. This is a plugin to NetworkX, which means that you can use NetworkX as you normally would, but with the added benefit of persisting your graphs to a database.

```python
import os
Expand Down Expand Up @@ -111,7 +106,7 @@ pip install nx-cugraph-cu12 --extra-index-url https://pypi.nvidia.com
pip install nx-arangodb
```

## What are the easiests ways to set up ArangoDB?
## How can I set up ArangoDB?

**1) Local Instance via Docker**

Expand Down Expand Up @@ -149,7 +144,7 @@ os.environ["DATABASE_NAME"] = credentials["dbName"]
# ...
```

## How does Algorithm Dispatching work?
## How does algorithm dispatching work?

`nx-arangodb` will automatically dispatch algorithm calls to either CPU or GPU based on if `nx-cugraph` is installed. We rely on a rust-based library called [phenolrs](https://github.com/arangoml/phenolrs) to retrieve ArangoDB Graphs as fast as possible.

Expand Down
5 changes: 2 additions & 3 deletions _nx_arangodb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"project": "nx-arangodb",
"package": "nx_arangodb",
"url": "https://github.com/arangodb/nx-arangodb",
"short_summary": "Remote storage backend.",
# "description": "TODO",
"short_summary": "ArangoDB storage backend to NetworkX.",
"description": "Persist, maintain, and reload NetworkX graphs with ArangoDB.",
"functions": {
# BEGIN: functions
"shortest_path",
Expand Down Expand Up @@ -81,7 +81,6 @@ def get_info():
"db_name": None,
"read_parallelism": None,
"read_batch_size": None,
"write_batch_size": None,
"use_gpu": True,
}

Expand Down
2 changes: 1 addition & 1 deletion nx_arangodb/algorithms/shortest_paths/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def shortest_path(
"weight": weight,
}

result = list(G.aql(query, bind_vars=bind_vars))
result = list(G.query(query, bind_vars=bind_vars))

if not result:
raise nx.NodeNotFound(f"Either source {source} or target {target} is not in G")
Expand Down
17 changes: 2 additions & 15 deletions nx_arangodb/classes/dict/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
doc_delete,
doc_insert,
doc_update,
edges_delete,
get_arangodb_graph,
get_node_id,
get_node_type_and_id,
Expand Down Expand Up @@ -303,21 +304,7 @@ def __delitem__(self, key: str) -> None:
if not self.graph.has_vertex(node_id):
raise KeyError(key)

# TODO: wrap in edges_delete() method
remove_statements = "\n".join(
f"REMOVE e IN `{edge_def['edge_collection']}` OPTIONS {{ignoreErrors: true}}" # noqa
for edge_def in self.graph.edge_definitions()
)

query = f"""
FOR v, e IN 1..1 ANY @src_node_id GRAPH @graph_name
{remove_statements}
"""

bind_vars = {"src_node_id": node_id, "graph_name": self.graph.name}

aql(self.db, query, bind_vars)
#####
edges_delete(self.db, self.graph, node_id)

doc_delete(self.db, node_id)

Expand Down
9 changes: 9 additions & 0 deletions nx_arangodb/classes/digraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def __init__(
self.remove_node = self.remove_node_override
self.reverse = self.reverse_override

assert isinstance(self._succ, AdjListOuterDict)
assert isinstance(self._pred, AdjListOuterDict)
self._succ.mirror = self._pred
self._pred.mirror = self._succ
self._succ.traversal_direction = TraversalDirection.OUTBOUND
self._pred.traversal_direction = TraversalDirection.INBOUND

if (
not self.is_multigraph()
and incoming_graph_data is not None
Expand All @@ -78,6 +85,8 @@ def __init__(
#######################

# TODO?
# If we want to continue with "Experimental Views" we need to implement the
# InEdgeView and OutEdgeView classes.
# @cached_property
# def in_edges(self):
# pass
Expand Down
18 changes: 18 additions & 0 deletions nx_arangodb/classes/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,24 @@ def doc_delete(db: StandardDatabase, id: str, **kwargs: Any) -> None:
db.delete_document(id, silent=True, **kwargs)


def edges_delete(
db: StandardDatabase, graph: Graph, src_node_id: str, **kwargs: Any
) -> None:
remove_statements = "\n".join(
f"REMOVE e IN `{edge_def['edge_collection']}` OPTIONS {{ignoreErrors: true}}" # noqa
for edge_def in graph.edge_definitions()
)

query = f"""
FOR v, e IN 1..1 ANY @src_node_id GRAPH @graph_name
{remove_statements}
"""

bind_vars = {"src_node_id": src_node_id, "graph_name": graph.name}

aql(db, query, bind_vars)


def doc_insert(
db: StandardDatabase,
collection: str,
Expand Down
Loading