Skip to content

Commit cc897a3

Browse files
committed
doc updates
1 parent 67d4e7e commit cc897a3

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,35 @@ G_nxadb = nxadb.Graph(
204204
assert G_nxadb.number_of_nodes() == G_nx.number_of_nodes()
205205
assert G_nxadb.number_of_edges() == G_nx.number_of_edges()
206206
```
207+
208+
## Direct Conversion Helpers
209+
210+
Use the conversion helpers in `nx_arangodb.convert` to move between ecosystems while preserving directed/multi properties.
211+
212+
```python
213+
import networkx as nx
214+
import nx_arangodb as nxadb
215+
216+
# Start with a NetworkX graph
217+
G_nx = nx.karate_club_graph()
218+
219+
# Convert to nx-arangodb (optionally force directed via as_directed=True)
220+
G_adb = nxadb.convert._to_nxadb_graph(G_nx)
221+
222+
# Convert back to NetworkX
223+
G_nx2 = nxadb.convert._to_nx_graph(G_adb)
224+
225+
# Convert to nx-cugraph (if installed)
226+
try:
227+
G_cg = nxadb.convert._to_nxcg_graph(G_adb)
228+
except NotImplementedError:
229+
# nx-cugraph/CuPy not available in this environment
230+
pass
231+
```
232+
233+
Notes:
234+
- Database-backed graphs: converting `nxadb.Graph` to NetworkX will fetch node and adjacency dictionaries from ArangoDB and build a plain NetworkX graph.
235+
- Local `nxadb.Graph` (not yet persisted) is already NetworkX-compatible and may be returned as-is.
236+
- `as_directed` forces directed variants without changing multiplicity.
237+
- GPU conversions require `nx-cugraph` and CuPy; otherwise `_to_nxcg_graph` raises `NotImplementedError`.
238+
- When converting to `nx-cugraph`, enabling `G_adb.use_nxcg_cache = True` caches the constructed GPU graph for reuse.

doc/convert.rst

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
Conversions between NetworkX, nx-arangodb, and nx-cugraph
2+
=========================================================
3+
4+
This page describes how to convert graphs across ecosystems using
5+
``nx_arangodb.convert`` for interoperability and performance.
6+
7+
Overview
8+
--------
9+
10+
- ``_to_nx_graph``: ``nxadb.Graph`` | ``nx.Graph`` -> ``nx.Graph``
11+
- ``_to_nxadb_graph``: ``nx.Graph`` | ``nxadb.Graph`` -> ``nxadb.Graph``
12+
- ``_to_nxcg_graph``: ``nxadb.Graph`` | ``nxcg.Graph`` -> ``nxcg.Graph``
13+
(requires ``nx-cugraph`` and CuPy)
14+
15+
Behavior notes
16+
--------------
17+
18+
- Database-backed ``nxadb`` graphs: converting to NetworkX pulls node and
19+
adjacency dictionaries from ArangoDB and constructs a plain NetworkX graph.
20+
- Local ``nxadb`` graphs (``graph_exists_in_db`` is ``False``) are already
21+
NetworkX-compatible and may be returned as-is.
22+
- Directed/multi settings are preserved; ``as_directed`` forces directed
23+
variants without changing multiplicity.
24+
- If ``nx-cugraph`` or CuPy is unavailable, GPU conversions are disabled and
25+
``_to_nxcg_graph`` raises ``NotImplementedError``.
26+
27+
Performance and caching
28+
-----------------------
29+
30+
- Database pulls are timed and logged.
31+
- ``nxadb_to_nx`` returns a standard NetworkX graph and does not re-wrap the
32+
custom dict implementations in ``nx_arangodb.classes.dict``.
33+
- ``nxadb_to_nxcg`` can cache the constructed GPU graph when
34+
``G.use_nxcg_cache`` is ``True`` on the ``nxadb.Graph`` instance.
35+
36+
Examples
37+
--------
38+
39+
.. code-block:: python
40+
41+
import networkx as nx
42+
import nx_arangodb as nxadb
43+
44+
# Start with a NetworkX graph
45+
G_nx = nx.karate_club_graph()
46+
47+
# Convert to nx-arangodb (optionally force directed)
48+
G_adb = nxadb.convert._to_nxadb_graph(G_nx, as_directed=False)
49+
50+
# Convert back to NetworkX
51+
G_nx2 = nxadb.convert._to_nx_graph(G_adb)
52+
53+
# Convert to nx-cugraph if available
54+
try:
55+
G_cg = nxadb.convert._to_nxcg_graph(G_adb)
56+
except NotImplementedError:
57+
# nx-cugraph/CuPy not available
58+
pass
59+
60+
API Reference
61+
-------------
62+
63+
.. autofunction:: nx_arangodb.convert._to_nx_graph
64+
65+
.. autofunction:: nx_arangodb.convert._to_nxadb_graph
66+
67+
.. autofunction:: nx_arangodb.convert._to_nxcg_graph
68+
69+
.. autofunction:: nx_arangodb.convert.nx_to_nxadb
70+
71+
.. autofunction:: nx_arangodb.convert.nxadb_to_nx
72+
73+
.. autofunction:: nx_arangodb.convert.nxadb_to_nxcg
74+
75+

doc/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,5 @@ Expect documentation to grow over time:
124124
classes/index
125125
dict/index
126126
algorithms/index
127-
views/index
127+
views/index
128+
convert

0 commit comments

Comments
 (0)