piel.tools.gdsfactory
=====================

.. py:module:: piel.tools.gdsfactory


Submodules
----------

.. toctree::
   :maxdepth: 1

   /autoapi/piel/tools/gdsfactory/netlist/index


Functions
---------

.. autoapisummary::

   piel.tools.gdsfactory.get_input_ports_index
   piel.tools.gdsfactory.get_matched_ports_tuple_index
   piel.tools.gdsfactory.get_netlist
   piel.tools.gdsfactory.get_netlist_recursive


Package Contents
----------------

.. py:function:: get_input_ports_index(ports_index: dict, sorting_algorithm: Literal['prefix'] = 'prefix', prefix: str = 'in') -> tuple

   This function returns the input connection of a component. However, input connection may have different sets of prefixes
   and suffixes. This function implements different sorting algorithms for different connection names. The default
   algorithm is `prefix`, which sorts the connection by their prefix. The Endianness implementation means that the tuple
   order is determined according to the last numerical index order of the port numbering. Returns the indices and
   names of input connection for a component, sorted by a specified algorithm. The default sorting algorithm uses a prefix.

   :param ports_index: A dictionary where keys are port names and values are their indices.
   :type ports_index: dict
   :param sorting_algorithm: The sorting algorithm to use. Defaults to "prefix".
   :type sorting_algorithm: Literal["prefix"], optional
   :param prefix: The prefix to filter and sort connection when using the "prefix" sorting algorithm. Defaults to "in".
   :type prefix: str, optional

   :returns: A tuple where each element is a pair of port index and port name, sorted as specified.
   :rtype: tuple

   .. rubric:: Examples

   >>> raw_ports_index = {
   >>>     "in_o_0": 0,
   >>>     "out_o_0": 1,
   >>>     "out_o_1": 2,
   >>>     "out_o_2": 3,
   >>>     "out_o_3": 4,
   >>>     "in_o_1": 5,
   >>>     "in_o_2": 6,
   >>>     "in_o_3": 7,
   >>> }
   >>> get_input_ports_index(ports_index=raw_ports_index)
   ((0, "in_o_0"), (5, "in_o_1"), (6, "in_o_2"), (7, "in_o_3"))


.. py:function:: get_matched_ports_tuple_index(ports_index: dict, selected_ports_tuple: Optional[tuple] = None, sorting_algorithm: Literal['prefix', 'selected_ports'] = 'prefix', prefix: str = 'in') -> (tuple, tuple)

       This function returns the input connection of a component. However, input connection may have different sets of prefixes
       and suffixes. This function implements different sorting algorithms for different connection names. The default
       algorithm is `prefix`, which sorts the connection by their prefix. The Endianness implementation means that the tuple
       order is determined according to the last numerical index order of the port numbering. Returns just a tuple of
       the index.
   Returns the indices of connection that match specified criteria. The function supports sorting by a prefix or by a selected tuple of connection.

       Args:
           ports_index (dict): A dictionary where keys are port names and values are their indices.
           selected_ports_tuple (tuple, optional): A tuple of selected connection to match. Defaults to None.
           sorting_algorithm (Literal["prefix", "selected_ports"], optional): The sorting algorithm to use. Defaults to "prefix".
           prefix (str, optional): The prefix to filter connection when using the "prefix" sorting algorithm. Defaults to "in".

       Returns:
           tuple[tuple, tuple]:
               - The first tuple contains the indices of the matched connection in the specified order.
               - The second tuple contains the names of the matched connection in the specified order.

       Raises:
           ValueError: If an unsupported sorting algorithm is specified.

       Examples:
           >>> raw_ports_index = {
           >>>     "in_o_0": 0,
           >>>     "out_o_0": 1,
           >>>     "out_o_1": 2,
           >>>     "out_o_2": 3,
           >>>     "out_o_3": 4,
           >>>     "in_o_1": 5,
           >>>     "in_o_2": 6,
           >>>     "in_o_3": 7,
           >>> }
           >>> get_matched_ports_tuple_index(ports_index=raw_ports_index)
           ((0, 5, 6, 7), ("in_o_0", "in_o_1", "in_o_2", "in_o_3"))


.. py:function:: get_netlist(*args, **kwargs)

.. py:function:: get_netlist_recursive(*args, **kwargs)

