aigverse.adapters.networkx

AIG to NetworkX adapter.

Module Contents

to_networkx(self: Aig, *, levels: bool = False, fanouts: bool = False, node_tts: bool = False, graph_tts: bool = False, dtype: type[generic] = np.int8) DiGraph[source]

Converts an Aig to a 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. For machine learning tasks, a floating-point type such as float32 or float64 may be more appropriate, as it allows for gradient-based optimization.

Returns:

A 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], 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, optional): The node’s truth table.

  • type (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.

Edge Attributes:
  • type (ndarray): A one-hot encoded vector representing the edge

    type ([regular, inverted]). The data type is determined by the dtype argument, defaulting to int8.

  • name (str, optional): Signal name or primary output name for edges to synthetic

    PO nodes (only for NamedAig).