# aigverse.adapters.networkx

AIG to NetworkX adapter.

## Module Contents

### to_networkx(self: [Aig](../../networks/index.html.md#aigverse.networks.Aig), , levels: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, fanouts: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, node_tts: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, graph_tts: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, dtype: [type](../../networks/index.html.md#aigverse.networks.AigRegister.type)[[generic](https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.generic)] = np.int8) → [DiGraph](https://networkx.org/documentation/stable/reference/classes/digraph.html#networkx.DiGraph)

Converts an `Aig` to a [`DiGraph`](https://networkx.org/documentation/stable/reference/classes/digraph.html#networkx.DiGraph).

This function transforms the AIG into a directed graph representation
using the NetworkX library. It allows for the inclusion of various
attributes for the graph, its nodes, and edges, making it suitable
for graph-based machine learning tasks.

Note that the constant-0 node is always included in the graph, as
index 0, even if it is not referenced by any edges.

* **Parameters:**
  * **self** – The AIG object to convert.
  * **levels** – If True, computes and adds level information for each node
    and the total number of levels to the graph, as attributes
    `level` and `levels`, respectively. Defaults to False.
  * **fanouts** – If True, adds the fanout count for each node as an integer
    `fanouts` attribute (`0` for synthetic PO nodes).
    Defaults to False.
  * **node_tts** – If True, computes and adds a truth table for each node
    as a `function` attribute. Defaults to False.
  * **graph_tts** – If True, computes and adds the graph’s overall truth
    table as a `function` attribute to the graph. Defaults to False.
  * **dtype** – The data type for truth tables and all one-hot encodings.
    Defaults to [`int8`](https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.int8). For machine learning tasks, a
    floating-point type such as [`float32`](https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.float32) or
    [`float64`](https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.float64) may be more appropriate, as it allows
    for gradient-based optimization.
* **Returns:**
  A [`DiGraph`](https://networkx.org/documentation/stable/reference/classes/digraph.html#networkx.DiGraph) representing the AIG.

Graph Attributes:
: - type (str): `"AIG"`.
  - num_pis (int): Number of primary inputs.
  - num_pos (int): Number of primary outputs.
  - num_gates (int): Number of AND gates.
  - levels (int, optional): Total number of levels in the AIG.
  - function (list[[`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)], optional): Graph’s truth tables.
  - name (str, optional): Network name (only for `NamedAig`).

Node Attributes:
: - index (int): The node’s identifier.
  - level (int, optional): The level of the node in the AIG.
  - fanouts (int, optional): Fanout count of the node.
    : Included when `fanouts=True`.
  - function ([`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray), optional): The node’s truth table.
  - type ([`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)): A one-hot encoded vector representing
    : the node type (`[const, pi, gate, po]`). The data type is determined
      by the `dtype` argument, defaulting to [`int8`](https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.int8).

Edge Attributes:
: - type ([`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)): A one-hot encoded vector representing the edge
    : type (`[regular, inverted]`). The data type is determined by the
      `dtype` argument, defaulting to [`int8`](https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.int8).
  - name (str, optional): Signal name or primary output name for edges to synthetic
    : PO nodes (only for `NamedAig`).
