|
| 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 | + |
0 commit comments