piel.flows.digital_electro_optic
================================

.. py:module:: piel.flows.digital_electro_optic


Attributes
----------

.. autoapisummary::

   piel.flows.digital_electro_optic.logger


Functions
---------

.. autoapisummary::

   piel.flows.digital_electro_optic.add_truth_table_bit_to_phase_data
   piel.flows.digital_electro_optic.add_truth_table_phase_to_bit_data
   piel.flows.digital_electro_optic.convert_optical_transitions_to_truth_table
   piel.flows.digital_electro_optic.convert_phase_to_bit_iterable
   piel.flows.digital_electro_optic.find_nearest_bit_for_phase
   piel.flows.digital_electro_optic.find_nearest_phase_for_bit
   piel.flows.digital_electro_optic.filter_and_correct_truth_table


Module Contents
---------------

.. py:data:: logger

.. py:function:: add_truth_table_bit_to_phase_data(truth_table: piel.types.TruthTable, bit_phase_map: piel.types.BitPhaseMap, bit_phase_column_name: str = None) -> piel.types.TruthTable

   This function converts the bit column of a dataframe into a phase tuple using the phase_bit_dataframe. The
   phase_bit_dataframe is a dataframe that maps the phase to the bit. The phase_series_name is the name of the
   phase series in the phase_bit_dataframe. The bit_series_name is the name of the bit series in the
   phase_bit_dataframe. The bit_column_name is the name of the bit column in the dataframe. The function returns
   a tuple of phases that correspond to the bit column of the dataframe.

   :param truth_table: The dataframe that contains the bit column.
   :type truth_table: pd.DataFrame
   :param bit_phase_map: The dataframe that maps the phase to the bit.
   :type bit_phase_map: BitPhaseMap
   :param bit_phase_column_name: The name of the bit column in the dataframe.
   :type bit_phase_column_name: str

   :returns: a TruthTable object with the phase columns added.
   :rtype: truth_table (TruthTable)


.. py:function:: add_truth_table_phase_to_bit_data(truth_table: piel.types.TruthTable, bit_phase_map: piel.types.BitPhaseMap, phase_column_name: str = None, rounding_function: Optional[Callable] = None) -> piel.types.TruthTable

   This function converts the phase column of a dataframe into a bit tuple using the phase_bit_dataframe. The
   phase_bit_dataframe is a dataframe that maps the phase to the bit. The phase_series_name is the name of the
   phase series in the phase_bit_dataframe. The bit_series_name is the name of the bit series in the
   phase_bit_dataframe. The phase_column_name is the name of the phase column in the dataframe. The function returns
   a tuple of bits that correspond to the phase column of the dataframe.

   :param truth_table: The dataframe that contains the phase column.
   :type truth_table: pd.DataFrame
   :param bit_phase_map: The dataframe that maps the phase to the bit.
   :type bit_phase_map: BitPhaseMap
   :param rounding_function: The rounding function that is used to round the phase to the nearest
                             phase in the phase_bit_dataframe.
   :type rounding_function: Optional[Callable]

   :returns: A tuple of bits that correspond to the phase column of the dataframe.
   :rtype: tuple


.. py:function:: convert_optical_transitions_to_truth_table(optical_state_transitions: piel.types.OpticalStateTransitionCollection, bit_phase_map=BitPhaseMap, logic: piel.types.TruthTableLogicType = 'implementation') -> piel.types.TruthTable

.. py:function:: convert_phase_to_bit_iterable(phase: piel.types.PhaseMapType, bit_phase_map: piel.types.BitPhaseMap, rounding_function: Optional[Callable] = None) -> tuple

   This function converts a phase array or tuple iterable, into the corresponding mapping of their bitstring
   required within a particular bit-phase mapping. A ``phase_array`` iterable is provided, and each phase is mapped
   to a particular bitstring based on the ``phase_bit_dataframe``. A tuple is composed of strings that represent the
   bitstrings of the phases provided.

   :param phase: Iterable of phases to map to bitstrings.
   :type phase: Iterable
   :param bit_phase_map: Dataframe containing the phase-bits mapping.
   :type bit_phase_map: BitPhaseMap
   :param rounding_function: Rounding function to apply to the target phase.
   :type rounding_function: Callable

   :returns: Tuple of bitstrings corresponding to the phases.
   :rtype: bit_array(tuple)


.. py:function:: find_nearest_bit_for_phase(target_phase: float, bit_phase_map: piel.types.BitPhaseMap, rounding_function: Optional[Callable] = None) -> tuple

   This is a mapping function between a provided target phase that might be more analogous, with the closest
   bit-value in a `bit-phase` ideal relationship. The error between the target phase and the applied phase is
   limited to the discretisation error of the phase mapping.

   :param target_phase: Target phase to map to.
   :type target_phase: float
   :param bit_phase_map: Dataframe containing the phase-bits mapping.
   :type bit_phase_map: pd.DataFrame
   :param rounding_function: Rounding function to apply to the target phase.
   :type rounding_function: Callable

   :returns: Bitstring corresponding to the nearest phase.
   :rtype: bitstring(str)


.. py:function:: find_nearest_phase_for_bit(bits: piel.types.BitsType, phase_map: piel.types.BitPhaseMap) -> piel.types.PhaseMapType

   Maps a bitstring to the nearest phase(s) in a phase-bit mapping dataframe.

   :param bits: Bitstring to map to a phase.
   :type bits: AbstractBitsType
   :param phase_map: Dataframe containing the phase-bits mapping.
   :type phase_map: BitPhaseMap

   :returns: Tuple of phases or an empty tuple if no match is found.
   :rtype: Tuple[str, ...]


.. py:function:: filter_and_correct_truth_table(truth_table_dictionary: dict, input_ports: list, output_ports: list)

   Ensures each unique value of the specified input connection maps to a unique set of values of the output connection.
   If conflicts are found (i.e., the same input maps to different outputs), it retains the first unique mapping.
   It returns a corrected truth table dictionary with only the unique mappings.

   :param input_ports: List of input port names.
   :type input_ports: list of str
   :param output_ports: List of output port names.
   :type output_ports: list of str
   :param truth_table_dictionary: Dictionary containing input and output files. Keys are port names, and values are lists of values.
   :type truth_table_dictionary: dict

   :returns: A corrected truth table dictionary with unique mappings.
   :rtype: dict

   :raises ValueError: If input_ports or output_ports are not found in truth_table_dictionary.


