Networks¶
Network Utils¶
Header: fiction/networks/network_utils.hpp
-
template<typename Ntk>
struct edge¶ Representation of an edge between two network nodes.
- Template Parameters:
Ntk –
mockturtlenetwork type.
-
template<typename Ntk, typename Fn>
void fiction::networks::foreach_edge(const Ntk &ntk, Fn &&fn)¶ Applies a function to all edges in a
mockturtlenetwork.- Template Parameters:
Ntk –
mockturtlenetwork 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
mockturtlenetwork.- Template Parameters:
Ntk –
mockturtlenetwork type.Fn – Unary function type that takes a
mockturtle::edge<Ntk>object as parameter.
- Parameters:
ntk – Network to iterate over.
n – Node of
ntkwhose outgoing edges are to be considered.fn – Function object to apply to each outgoing edge of
ninntk.
-
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
mockturtlenetwork.- Template Parameters:
Ntk –
mockturtlenetwork type.Fn – Unary function type that takes a
mockturtle::edge<Ntk>object as parameter.
- Parameters:
ntk – Network to iterate over.
n – Node of
ntkwhose incoming edges are to be considered.fn – Function object to apply to each incoming edge of
ninntk.
-
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 –
mockturtlenetwork 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
ninntk.
-
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 –
mockturtlenetwork type.
-
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 –
mockturtlenetwork 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
ninntk.
-
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 –
mockturtlenetwork 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
ninntk.
-
class high_degree_fanin_exception : public std::invalid_argument¶
Exception class that can be thrown if some network exceeds a legal number of fanins.
-
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 –
mockturtlenetwork type.- Parameters:
ntk – Network to check.
threshold – Maximum number of legal fanins.
- Returns:
trueiff any node inntkexceedsthresholdfanins.
-
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 –
mockturtlenetwork type.
-
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 –
mockturtlenetwork 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)inntk.
-
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 –
mockturtlenetwork type.- Parameters:
ntk – Network to check in.
n – Node to check.
- Returns:
trueiff any ofn’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:
n – Node whose paths are desired.
- Returns:
A vector of all possible edge paths leading from terminals to
v.
-
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_viewbut starting from the primary outputs instead of the primary inputs. An implementation along the lines ofinv_depth_viewwould be a lot more sophisticated and desirable, but this quick hack does the job well so far. If anyone wants to build aninv_depth_view, please be my guest.- Template Parameters:
Ntk –
mockturtlenetwork 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 wheren’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 –
mockturtlenetwork type.- Returns:
trueiff any node inntkexceedsthresholdfanins.
Name Utils¶
Header: fiction/networks/name_utils.hpp
-
template<typename NtkOrLyt>
std::string fiction::networks::get_name(const NtkOrLyt &ntk_or_lyt)¶ Helper function to conveniently fetch the name from a layout or network as they use different function names for the same purpose.
- Template Parameters:
NtkOrLyt – Network or layout type.
- Parameters:
ntk_or_lyt – Network or layout object.
- Returns:
Name of given network or layout.
-
template<typename NtkOrLyt>
void fiction::networks::set_name(NtkOrLyt &ntk_or_lyt, const std::string_view &name)¶ Helper function to conveniently assign a name to a layout or network as they use different function names for the same purpose.
- Template Parameters:
NtkOrLyt – Network or layout type.
- Parameters:
ntk_or_lyt – Network or layout object.
name – Name to assign to given network or layout.
-
template<typename NtkOrLytSrc, typename NtkOrLytDest>
void fiction::networks::restore_network_name(const NtkOrLytSrc &ntk_or_lyt_src, NtkOrLytDest &ntk_or_lyt_dest)¶ Helper function to conveniently assign the name of a source network or layout to a target network or layout as they use different function names for the same purpose. This function comes in handy when networks are translated or layouts are being created from networks that are supposed to have the same name.
- Template Parameters:
NtkOrLytSrc – Source network or layout type.
NtkOrLytDest – Target network or layout type.
- Parameters:
ntk_or_lyt_src – Source network or layout whose name is to be assigned to
ntk_or_lyt_dest.ntk_or_lyt_dest – Target network or layout that is to be assigned
ntk_or_lyt_src’s name.
-
template<typename NtkSrc, typename NtkDest>
void fiction::networks::restore_input_names(const NtkSrc &ntk_src, NtkDest &ntk_dest)¶ Assigns input names from one network to another. Matching inputs are identified by their index.
- Template Parameters:
NtkSrc – Source network type.
NtkDest – Target network or gate-level layout type.
- Parameters:
ntk_src – Source logic network whose input names are to be transferred to
ntk_dest.ntk_dest – Target logic network whose inputs are to be assigned
ntk_src’s names.
-
template<typename NtkSrc, typename NtkDest>
void fiction::networks::restore_output_names(const NtkSrc &ntk_src, NtkDest &ntk_dest)¶ Assigns output names from one network to another. Matching outputs are identified by their order.
- Template Parameters:
NtkSrc – Source network type.
NtkDest – Target network or gate-level layout type.
- Parameters:
ntk_src – Source logic network whose output names are to be transferred to
ntk_dest.ntk_dest – Target logic network whose outputs are to be assigned
ntk_src’s names.
-
template<typename NtkSrc, typename NtkDest, typename Signal>
void fiction::networks::restore_signal_names(const NtkSrc &ntk_src, NtkDest &ntk_dest, const mockturtle::node_map<Signal, NtkSrc> &old2new)¶ Transfers signal names from a logic network to a network or placed layout using a
mockturtle::node_map. Skips absent native target endpoints. Complemented signal names transfer when used by gates or POs.- Template Parameters:
NtkSrc – Source logic network type.
NtkDest – Target network or gate-level layout type.
Signal – Target signal or layout output port type.
- Parameters:
ntk_src – Source logic network whose signal names are to be transferred to
ntk_dest.ntk_dest – Target logic network whose signal names are to be assigned
ntk_src’s names.old2new – Mapping of signals from
ntk_srctontk_dest.
-
template<typename NtkSrc, typename NtkDest, uint16_t fanout_size = 2>
void fiction::networks::restore_signal_names(const NtkSrc &ntk_src, NtkDest &ntk_dest, const mockturtle::node_map<physical_design::branching_signal_container<NtkSrc, fanout_size>, NtkSrc> &old2new)¶ Same as the other restore_signal_names function but this overload uses a
mockturtle::node_mapwith a branching_signal_container that is specifically used for networks or layouts that allow branches to be distinct, e.g., by their position on the layout.- Template Parameters:
NtkSrc – Source logic network type.
NtkDest – Target network or gate-level layout type.
fanout_size – Maximum fanout size in the network.
- Parameters:
ntk_src – Source logic network whose signal names are to be transferred to
ntk_dest.ntk_dest – Target logic network whose signal names are to be assigned
ntk_src’s names.old2new – Mapping of signals from
ntk_srctontk_destusing a branching_signal_container.
-
template<typename NtkSrc, typename NtkDest>
void fiction::networks::restore_names(const NtkSrc &ntk_src, NtkDest &ntk_dest)¶ Transfers all input and output names as well as the network/layout name from one network to another. This function calls
restore_network_name,restore_input_names, andrestore_output_names.- Template Parameters:
NtkSrc – Source network type.
NtkDest – Target network or gate-level layout type.
- Parameters:
ntk_src – Source logic network whose I/O names are to be transferred to
ntk_dest.ntk_dest – Target logic network whose I/O names are to be assigned
ntk_src’s names.
-
template<typename NtkSrc, typename NtkDest, typename T>
void fiction::networks::restore_names(const NtkSrc &ntk_src, NtkDest &ntk_dest, mockturtle::node_map<T, NtkSrc> &old2new)¶ Transfers all signal and output names as well as the network/layout name from one network to another. This function calls
restore_network_name,restore_signal_names, andrestore_output_names.- Template Parameters:
NtkSrc – Source network type.
NtkDest – Target network or gate-level layout type.
T – Mapping type to identify signals by. Currently,
mockturtle::signal<NtkDest>andbranching_signal_container<NtkSrc, fanout_size>are supported.
- Parameters:
ntk_src – Source logic network whose signal names are to be transferred to
ntk_dest.ntk_dest – Target logic network whose signal names are to be assigned
ntk_src’s names.old2new – Mapping of signals from
ntk_srctontk_destusing a signal identifier.
- get_name(ntk_or_lyt: cartesian_gate_layout) str¶
- get_name(ntk_or_lyt: mnt.pyfiction.layouts.shifted_cartesian_gate_layout) str
- get_name(ntk_or_lyt: hexagonal_gate_layout) str
- get_name(ntk_or_lyt: qca_layout) str
- get_name(ntk_or_lyt: mol_qca_layout) str
- get_name(ntk_or_lyt: inml_layout) str
- get_name(ntk_or_lyt: fiction::sidb::layout) str
- get_name(ntk_or_lyt: technology_network) str
- get_name(ntk_or_lyt: mnt.pyfiction.networks.aig_network) str
- get_name(ntk_or_lyt: mnt.pyfiction.networks.xag_network) str
- get_name(ntk_or_lyt: mnt.pyfiction.networks.mig_network) str
Helper function to conveniently fetch the name from a layout or network as they use different function names for the same purpose.
- Parameters:
ntk_or_lyt – Network or layout object.
- Template Args:
NtkOrLyt – Network or layout type.
- Returns:
Name of given network or layout.
- set_name(ntk_or_lyt: cartesian_gate_layout, name: str) None¶
- set_name(ntk_or_lyt: mnt.pyfiction.layouts.shifted_cartesian_gate_layout, name: str) None
- set_name(ntk_or_lyt: hexagonal_gate_layout, name: str) None
- set_name(ntk_or_lyt: qca_layout, name: str) None
- set_name(ntk_or_lyt: mol_qca_layout, name: str) None
- set_name(ntk_or_lyt: inml_layout, name: str) None
- set_name(ntk_or_lyt: fiction::sidb::layout, name: str) None
- set_name(ntk_or_lyt: technology_network, name: str) None
- set_name(ntk_or_lyt: mnt.pyfiction.networks.aig_network, name: str) None
- set_name(ntk_or_lyt: mnt.pyfiction.networks.xag_network, name: str) None
- set_name(ntk_or_lyt: mnt.pyfiction.networks.mig_network, name: str) None
Helper function to conveniently assign a name to a layout or network as they use different function names for the same purpose.
- Parameters:
ntk_or_lyt – Network or layout object.
name – Name to assign to given network or layout.
- Template Args:
NtkOrLyt – Network or layout type.