Network Utilities

Header: fiction/networks/network_utils.hpp

template<typename Ntk>
struct edge

Representation of an edge between two network nodes.

Template Parameters:

Ntk – mockturtle network type.

template<typename Ntk>
using fiction::networks::edge_path = std::vector<mockturtle::edge<Ntk>>

Represents a path in a network as a walk of edges.

template<typename Ntk, typename Fn>
void fiction::networks::foreach_edge(const Ntk &ntk, Fn &&fn)

Applies a function to all edges in a mockturtle network.

Template Parameters:
  • Ntk – mockturtle network type.

  • Fn – Unary function type that takes a mockturtle::edge<Ntk> object as parameter.

Parameters:
  • ntk – Network to iterate over.

  • fn – Function object to apply to each edge in ntk.

template<typename Ntk, typename Fn>
void fiction::networks::foreach_outgoing_edge(const Ntk &ntk, const mockturtle::node<Ntk> &n, Fn &&fn)

Applies a function to all outgoing edges in a mockturtle network.

Template Parameters:
  • Ntk – mockturtle network type.

  • Fn – Unary function type that takes a mockturtle::edge<Ntk> object as parameter.

Parameters:
  • ntk – Network to iterate over.

  • n – Node of ntk whose outgoing edges are to be considered.

  • fn – Function object to apply to each outgoing edge of n in ntk.

template<typename Ntk, typename Fn>
void fiction::networks::foreach_incoming_edge(const Ntk &ntk, const mockturtle::node<Ntk> &n, Fn &&fn)

Applies a function to all incoming edges in a mockturtle network.

Template Parameters:
  • Ntk – mockturtle network type.

  • Fn – Unary function type that takes a mockturtle::edge<Ntk> object as parameter.

Parameters:
  • ntk – Network to iterate over.

  • n – Node of ntk whose incoming edges are to be considered.

  • fn – Function object to apply to each incoming edge of n in ntk.

template<typename Ntk>
std::vector<mockturtle::node<Ntk>> fiction::networks::fanouts(const Ntk &ntk, const mockturtle::node<Ntk> &n) noexcept

Returns a vector of all fanout nodes of some given network node.

Template Parameters:

Ntk – mockturtle network type.

Parameters:
  • ntk – Network in which the fanouts are to be gathered.

  • n – Node whose fanouts are desired.

Returns:

A vector of all outgoing nodes directly adjacent to n in ntk.

template<typename Ntk>
struct fanin_container

Container that stores fanins of a node in a network, including whether one of them is a constant.

Note that this container assumes that each node has a maximum of one constant fanin.

Template Parameters:

Ntk – mockturtle network type.

Public Members

std::vector<mockturtle::node<Ntk>> fanin_nodes = {}

A vector of all fanin nodes except for constants.

std::optional<bool> constant_fanin = {std::nullopt}

Has a value if a fanin node is constant. In that case, it represents the constant value.

template<typename Ntk>
fanin_container<Ntk> fiction::networks::fanins(const Ntk &ntk, const mockturtle::node<Ntk> &n) noexcept

Returns a fanin container filled with all fanin nodes of some given network node.

Note that this function assumes that each node has a maximum of one constant fanin.

Template Parameters:

Ntk – mockturtle network type.

Parameters:
  • ntk – Network in which the fanins are to be gathered.

  • n – Node whose fanins are desired.

Returns:

A container of all incoming nodes directly adjacent to n in ntk.

template<typename Ntk>
uint32_t fiction::networks::num_constant_fanins(const Ntk &ntk, const mockturtle::node<Ntk> &n) noexcept

Computes the number of constant fanin nodes of some network node n.

Template Parameters:

Ntk – mockturtle network type.

Parameters:
  • ntk – Network in which the constant fanins are to be counted.

  • n – Node whose constant fanins are to be counted.

Returns:

Number of constant fanins to n in ntk.

class high_degree_fanin_exception : public std::invalid_argument

Exception class that can be thrown if some network exceeds a legal number of fanins.

Public Functions

inline high_degree_fanin_exception()
template<typename Ntk>
bool fiction::networks::has_high_degree_fanin_nodes(const Ntk &ntk, const uint32_t threshold = 2) noexcept

Checks if a given network exceeds a given fanin threshold in any of its nodes.

Template Parameters:

Ntk – mockturtle network type.

Parameters:
  • ntk – Network to check.

  • threshold – Maximum number of legal fanins.

Returns:

true iff any node in ntk exceeds threshold fanins.

template<typename Ntk>
struct fanin_edge_container

Container that stores fanin edges of a node in a network, including whether one of them is a constant.

Template Parameters:

Ntk – mockturtle network type.

Public Members

std::vector<mockturtle::edge<Ntk>> fanin_edges = {}

A vector of all fanin edges excluding for constants.

template<typename Ntk>
fanin_edge_container<Ntk> fiction::networks::fanin_edges(const Ntk &ntk, const mockturtle::node<Ntk> &n) noexcept

Returns a fanin edge container filled with all fanin edges (fanin, node) of some given network node.

Template Parameters:

Ntk – mockturtle network type.

Parameters:
  • ntk – Network in which the fanin edges are to be gathered.

  • n – Node whose fanins are desired.

Returns:

A container of all incoming edges (fanin, n) in ntk.

template<typename Ntk>
bool fiction::networks::has_incoming_primary_input(const Ntk &ntk, const mockturtle::node<Ntk> &n) noexcept

Checks if a given node in a given network has fanins that are primary inputs.

Template Parameters:

Ntk – mockturtle network type.

Parameters:
  • ntk – Network to check in.

  • n – Node to check.

Returns:

true iff any of n’s fanins are primary inputs.

template<typename Ntk>
std::vector<edge_path<Ntk>> fiction::networks::all_incoming_edge_paths(const Ntk &ntk, const mockturtle::node<Ntk> &n) noexcept

Returns a vector of all possible paths to reach the given node from the primary inputs within the given network.

Each node without predecessors is considered a terminal and a path is defined as a sequence of edges.

Parameters:
  • ntk – Network containing the node.

  • n – Node whose paths are desired.

Returns:

A vector of all possible edge paths leading from terminals to n.

template<typename Ntk>
std::vector<uint32_t> fiction::networks::inverse_levels(const Ntk &ntk) noexcept

A clumsy implementation that returns the inverse level of each node in a given network. Its behavior is similar to mockturtle::depth_view but starting from the primary outputs instead of the primary inputs. An implementation along the lines of inv_depth_view would be a lot more sophisticated and desirable, but this quick hack does the job well so far. If anyone wants to build an inv_depth_view, please be my guest.

Template Parameters:

Ntk – mockturtle network type.

Parameters:

ntk – The network whose inverse levels are desired.

Returns:

A vector of inverse levels for each node where ntk.node_to_index(n) is the position where n’s inverse level is stored.

class high_degree_fanin_exception
has_high_degree_fanin_nodes(ntk: technology_network, threshold: int = 2) → bool

Checks if a given network exceeds a given fanin threshold in any of its nodes.

Parameters:
  • ntk – Network to check.

  • threshold – Maximum number of legal fanins.

Template Args:

Ntk – mockturtle network type.

Returns:

true iff any node in ntk exceeds threshold fanins.