Skip to content

Commit ede0b82

Browse files
authored
misc cleanup (#54)
* misc cleanup * fix: typo * fix: `test_shortest_path`
1 parent df34109 commit ede0b82

File tree

13 files changed

+160
-170
lines changed

13 files changed

+160
-170
lines changed

README.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# nx-arangodb
22

3-
<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>
4-
53

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

1311
<br>
1412

13+
<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>
1514
[![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)
1615
[![CodeQL](https://github.com/arangodb/nx-arangodb/actions/workflows/analyzee.yaml/badge.svg)](https://github.com/arangodb/nx-arangodb/actions/workflows/analyzee.yaml)
1716
[![Docs](https://github.com/arangodb/nx-arangodb/actions/workflows/docs.yaml/badge.svg)](https://github.com/arangodb/nx-arangodb/actions/workflows/docs.yaml)
18-
[![Last commit](https://img.shields.io/github/last-commit/arangodb/nx-arangodb)](https://github.com/arangodb/nx-arangodb/commits/main)
1917

2018
[![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/)
2119
[![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/)
@@ -31,9 +29,7 @@ https://github.com/user-attachments/assets/e5f56574-d3ef-452c-ab21-b47b3d5d5900
3129

3230
## What is this?
3331

34-
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/).
35-
36-
`nx-arangodb` allows you to:
32+
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/):
3733
1. Persist NetworkX Graphs to ArangoDB.
3834
2. Reload NetworkX Graphs from ArangoDB.
3935
2. Perform CRUD on ArangoDB Graphs via NetworkX.
@@ -42,11 +38,10 @@ This is a [backend to NetworkX](https://networkx.org/documentation/stable/refere
4238
Benefits of having ArangoDB as a backend to NetworkX include:
4339
1. No need to re-create the graph every time you start a new session.
4440
2. Access to GPU-accelerated graph analytics ([nx-cugraph](https://docs.rapids.ai/api/cugraph/nightly/nx_cugraph/nx_cugraph/)).
45-
2. Access to a database query language ([Arango Query Language](https://arangodb.com/sql-aql-comparison/)).
46-
3. Access to a visual interface for graph exploration ([ArangoDB Web UI](https://docs.arangodb.com/3.11/components/web-interface/graphs/)).
47-
4. Access to cross-collaboration on the same graph ([ArangoDB Cloud](https://dashboard.arangodb.cloud/)).
48-
49-
6. Access to efficient distribution of graph data ([ArangoDB SmartGraphs](https://docs.arangodb.com/3.11/graphs/smartgraphs/)).
41+
3. Access to a database query language ([Arango Query Language](https://arangodb.com/sql-aql-comparison/)).
42+
4. Access to a visual interface for graph exploration ([ArangoDB Web UI](https://docs.arangodb.com/stable/components/web-interface/graphs/)).
43+
5. Access to cross-collaboration on the same graph ([ArangoDB Cloud](https://docs.arangodb.com/stable/get-started/set-up-a-cloud-instance/)).
44+
6. Access to efficient distribution of graph data ([ArangoDB SmartGraphs](https://docs.arangodb.com/stable/graphs/smartgraphs/)).
5045

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

5651
## Does this replace NetworkX?
5752

58-
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.
53+
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.
5954

6055
```python
6156
import os
@@ -111,7 +106,7 @@ pip install nx-cugraph-cu12 --extra-index-url https://pypi.nvidia.com
111106
pip install nx-arangodb
112107
```
113108

114-
## What are the easiests ways to set up ArangoDB?
109+
## How can I set up ArangoDB?
115110

116111
**1) Local Instance via Docker**
117112

@@ -149,7 +144,7 @@ os.environ["DATABASE_NAME"] = credentials["dbName"]
149144
# ...
150145
```
151146

152-
## How does Algorithm Dispatching work?
147+
## How does algorithm dispatching work?
153148

154149
`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.
155150

_nx_arangodb/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"project": "nx-arangodb",
2727
"package": "nx_arangodb",
2828
"url": "https://github.com/arangodb/nx-arangodb",
29-
"short_summary": "Remote storage backend.",
30-
# "description": "TODO",
29+
"short_summary": "ArangoDB storage backend to NetworkX.",
30+
"description": "Persist, maintain, and reload NetworkX graphs with ArangoDB.",
3131
"functions": {
3232
# BEGIN: functions
3333
"shortest_path",
@@ -81,7 +81,6 @@ def get_info():
8181
"db_name": None,
8282
"read_parallelism": None,
8383
"read_batch_size": None,
84-
"write_batch_size": None,
8584
"use_gpu": True,
8685
}
8786

nx_arangodb/algorithms/shortest_paths/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def shortest_path(
5454
"weight": weight,
5555
}
5656

57-
result = list(G.aql(query, bind_vars=bind_vars))
57+
result = list(G.query(query, bind_vars=bind_vars))
5858

5959
if not result:
6060
raise nx.NodeNotFound(f"Either source {source} or target {target} is not in G")

nx_arangodb/classes/dict/node.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
doc_delete,
2020
doc_insert,
2121
doc_update,
22+
edges_delete,
2223
get_arangodb_graph,
2324
get_node_id,
2425
get_node_type_and_id,
@@ -303,21 +304,7 @@ def __delitem__(self, key: str) -> None:
303304
if not self.graph.has_vertex(node_id):
304305
raise KeyError(key)
305306

306-
# TODO: wrap in edges_delete() method
307-
remove_statements = "\n".join(
308-
f"REMOVE e IN `{edge_def['edge_collection']}` OPTIONS {{ignoreErrors: true}}" # noqa
309-
for edge_def in self.graph.edge_definitions()
310-
)
311-
312-
query = f"""
313-
FOR v, e IN 1..1 ANY @src_node_id GRAPH @graph_name
314-
{remove_statements}
315-
"""
316-
317-
bind_vars = {"src_node_id": node_id, "graph_name": self.graph.name}
318-
319-
aql(self.db, query, bind_vars)
320-
#####
307+
edges_delete(self.db, self.graph, node_id)
321308

322309
doc_delete(self.db, node_id)
323310

nx_arangodb/classes/digraph.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ def __init__(
6666
self.remove_node = self.remove_node_override
6767
self.reverse = self.reverse_override
6868

69+
assert isinstance(self._succ, AdjListOuterDict)
70+
assert isinstance(self._pred, AdjListOuterDict)
71+
self._succ.mirror = self._pred
72+
self._pred.mirror = self._succ
73+
self._succ.traversal_direction = TraversalDirection.OUTBOUND
74+
self._pred.traversal_direction = TraversalDirection.INBOUND
75+
6976
if (
7077
not self.is_multigraph()
7178
and incoming_graph_data is not None
@@ -78,6 +85,8 @@ def __init__(
7885
#######################
7986

8087
# TODO?
88+
# If we want to continue with "Experimental Views" we need to implement the
89+
# InEdgeView and OutEdgeView classes.
8190
# @cached_property
8291
# def in_edges(self):
8392
# pass

nx_arangodb/classes/function.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,24 @@ def doc_delete(db: StandardDatabase, id: str, **kwargs: Any) -> None:
578578
db.delete_document(id, silent=True, **kwargs)
579579

580580

581+
def edges_delete(
582+
db: StandardDatabase, graph: Graph, src_node_id: str, **kwargs: Any
583+
) -> None:
584+
remove_statements = "\n".join(
585+
f"REMOVE e IN `{edge_def['edge_collection']}` OPTIONS {{ignoreErrors: true}}" # noqa
586+
for edge_def in graph.edge_definitions()
587+
)
588+
589+
query = f"""
590+
FOR v, e IN 1..1 ANY @src_node_id GRAPH @graph_name
591+
{remove_statements}
592+
"""
593+
594+
bind_vars = {"src_node_id": src_node_id, "graph_name": graph.name}
595+
596+
aql(db, query, bind_vars)
597+
598+
581599
def doc_insert(
582600
db: StandardDatabase,
583601
collection: str,

0 commit comments

Comments
 (0)