piel.flows.electro_optic
========================

.. py:module:: piel.flows.electro_optic


Attributes
----------

.. autoapisummary::

   piel.flows.electro_optic.logger


Functions
---------

.. autoapisummary::

   piel.flows.electro_optic.compose_phase_address_state
   piel.flows.electro_optic.compose_switch_function_parameter_state
   piel.flows.electro_optic.calculate_switch_unitaries
   piel.flows.electro_optic.calculate_all_transition_probability_amplitudes
   piel.flows.electro_optic.calculate_classical_transition_probability_amplitudes
   piel.flows.electro_optic.construct_unitary_transition_probability_performance
   piel.flows.electro_optic.compose_network_matrix_from_models
   piel.flows.electro_optic.extract_phase_from_fock_state_transitions
   piel.flows.electro_optic.extract_phase_tuple_from_phase_address_state
   piel.flows.electro_optic.format_electro_optic_fock_transition
   piel.flows.electro_optic.generate_s_parameter_circuit_from_photonic_circuit
   piel.flows.electro_optic.get_state_phase_transitions
   piel.flows.electro_optic.get_state_to_phase_map


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

.. py:data:: logger

.. py:function:: compose_phase_address_state(switch_instance_map: dict, switch_phase_permutation_map: dict) -> dict

   This function composes the phase shifter address state for each circuit. This means that we have a dictionary
   that maps the instance address to the phase shifter state. This is then used to compose the function parameter
   state.

   :param switch_instance_map: The dictionary of the switch instances.
   :type switch_instance_map: dict
   :param switch_phase_permutation_map: The dictionary of the switch phase permutations.
   :type switch_phase_permutation_map: dict

   :returns: The dictionary of the phase shifter address state.
   :rtype: phase_shifter_address_state (dict)


.. py:function:: compose_switch_function_parameter_state(switch_phase_address_state: dict) -> dict

   This function composes the combinations of the phase shifter inputs into a form that can be inputted into sax for
   each particular address.

   :param switch_phase_address_state: The dictionary of the switch phase address state.
   :type switch_phase_address_state: dict

   :returns: The dictionary of the phase shifter function parameter state.
   :rtype: phase_shifter_function_parameter_state (dict)


.. py:function:: calculate_switch_unitaries(circuit: piel.types.OpticalTransmissionCircuit, switch_function_parameter_state: dict) -> piel.types.SParameterCollection

   This function calculates the switch unitaries for a given circuit. This means that we iterate over each switch
   function parameter state and we calculate the corresponding unitary matrix.

   :param circuit: The optical transmission circuit.
   :type circuit: OpticalTransmissionCircuit
   :param switch_function_parameter_state: The dictionary of the switch function parameter state.
   :type switch_function_parameter_state: dict

   Returns:



.. py:function:: calculate_all_transition_probability_amplitudes(unitary_matrix: piel.types.ArrayTypes, input_fock_states: list[piel.types.ArrayTypes], output_fock_states: list[piel.types.ArrayTypes]) -> dict[int, piel.types.FockStatePhaseTransition]

   This tells us the transition probabilities between our photon states for a particular implemented unitary.

   :param unitary_matrix: The unitary matrix.
   :type unitary_matrix: jnp.ndarray
   :param input_fock_states: The list of input Fock states.
   :type input_fock_states: list
   :param output_fock_states: The list of output Fock states.
   :type output_fock_states: list

   :returns: The dictionary of the Fock state phase transition type.
   :rtype: dict[int, FockStatePhaseTransition]


.. py:function:: calculate_classical_transition_probability_amplitudes(unitary_matrix: piel.types.ArrayTypes, input_fock_states: list[piel.types.ArrayTypes], target_mode_index: Optional[int] = None, determine_ideal_mode_function: Optional[Callable] = None) -> dict

   This tells us the classical transition probabilities between our photon states for a particular implemented
   s-parameter transformation.

   Note that if no target_mode_index is provided, then the determine_ideal_mode_function will analyse
   the provided files and return the target mode and append the relevant probability files to the files dictionary. It will
   raise an error if no method is implemented.

   :param unitary_matrix: The unitary matrix.
   :type unitary_matrix: jnp.ndarray
   :param input_fock_states: The list of input Fock states.
   :type input_fock_states: list
   :param target_mode_index: The target mode index.
   :type target_mode_index: int
   :param determine_ideal_mode_function: The function that determines the ideal mode.
   :type determine_ideal_mode_function: Callable

   :returns: The dictionary of the circuit transition probability files.
   :rtype: dict


.. py:function:: construct_unitary_transition_probability_performance(unitary_phase_implementations_dictionary: dict, input_fock_states: list, output_fock_states: list) -> dict[int, dict[int, piel.types.FockStatePhaseTransition]]

   This function determines the Fock state probability performance for a given implemented unitary. This means we
   iterate over each circuit, then each implemented unitary, and we determine the probability transformation
   accordingly.

   :param unitary_phase_implementations_dictionary: The dictionary of the unitary phase implementations.
   :type unitary_phase_implementations_dictionary: dict
   :param input_fock_states: The list of input Fock states.
   :type input_fock_states: list
   :param output_fock_states: The list of output Fock states.
   :type output_fock_states: list

   :returns: The dictionary of the implemented unitary probability.
   :rtype: implemented_unitary_probability_dictionary (dict)


.. py:function:: compose_network_matrix_from_models(circuit_component: piel.types.PhotonicCircuitComponent, models: dict, switch_states: list, top_level_instance_prefix: str = 'component_lattice_generic', target_component_prefix: str = 'mzi', netlist_function: Optional[Callable] = None, **kwargs)

   This function composes the network matrix from the measurement dictionary and the switch states. It does this by first
   composing the switch functions, then composing the switch matrix, then composing the network matrix. It returns
   the network matrix and the switch matrix.

   :param circuit_component: The circuit.
   :type circuit_component: gf.Component
   :param models: The measurement dictionary.
   :type models: dict
   :param switch_states: The list of switch states.
   :type switch_states: list
   :param top_level_instance_prefix: The top level instance prefix.
   :type top_level_instance_prefix: str
   :param target_component_prefix: The target component prefix.
   :type target_component_prefix: str
   :param netlist_function: The netlist function.
   :type netlist_function: Optional[Callable]

   :returns: The network matrix.
   :rtype: network_matrix (np.ndarray)


.. py:function:: extract_phase_from_fock_state_transitions(optical_state_transitions: piel.types.OpticalStateTransitionCollection, transition_type: piel.types.PhaseTransitionTypes = 'cross')

   Extracts the phase corresponding to the specified transition type.

   Parameters:
   optical_state_transitions (OpticalStateTransitionCollection): Optical state transitions.
       transition_type (str): Type of transition to extract phase for ('cross' or 'bar').

   :returns: Phase corresponding to the specified transition type.
   :rtype: float


.. py:function:: extract_phase_tuple_from_phase_address_state(phase_address_state: dict)

   Extracts phase values from a dictionary where keys are tuples representing components and values are the phase values.

   :param phase_address_state: The dictionary with tuple keys representing components and their phase values.
   :type phase_address_state: dict

   :returns: A list containing tuples of the phase values.
   :rtype: list of tuples


.. py:function:: format_electro_optic_fock_transition(switch_state_array: piel.types.ArrayTypes, input_fock_state_array: piel.types.ArrayTypes, raw_output_state: piel.types.ArrayTypes, **kwargs) -> piel.types.FockStatePhaseTransition

   Formats the electro-optic state into a standard FockStatePhaseTransition format. This is useful for the
   electro-optic model to ensure that the output state is in the correct format. The output state is a dictionary
   that contains the phase, input fock state, and output fock state. The idea is that this will allow us to
   standardise and compare the output states of the electro-optic model across multiple formats.

   :param switch_state_array: Array of switch states.
   :type switch_state_array: array_types
   :param input_fock_state_array: Array of valid input fock states.
   :type input_fock_state_array: array_types
   :param raw_output_state: Array of raw output state.
   :type raw_output_state: array_types
   :param \*\*kwargs: Additional keyword arguments.

   :returns: Electro-optic state.
   :rtype: electro_optic_state(FockStatePhaseTransition)


.. py:function:: generate_s_parameter_circuit_from_photonic_circuit(circuit: piel.types.PhotonicCircuitComponent, models: Any = None, netlist_function: Optional[Callable] = None) -> tuple[any, any]

   Generates the S-parameters and related information for a given circuit using SAX and custom measurement.

   :param circuit: The circuit for which the S-parameters are to be generated.
   :type circuit: gf.Component
   :param models: The measurement to be used for the S-parameter generation. Defaults to None.
   :type models: sax.ModelFactory, optional
   :param netlist_function: The function to generate the netlist. Defaults to None.
   :type netlist_function: Callable, optional

   :returns: The S-parameters circuit and related information.
   :rtype: tuple[any, any]


.. py:function:: get_state_phase_transitions(circuit_component: piel.types.PhotonicCircuitComponent, models: dict = None, mode_amount: int = None, input_fock_states: list[piel.types.ArrayTypes] | None = None, switch_states: list[piel.types.NumericalTypes] | None = None, determine_ideal_mode_function: Optional[Callable] = None, netlist_function: Optional[Callable] = None, target_mode_index: Optional[int] = None, **kwargs) -> piel.types.OpticalStateTransitionCollection

   The goal of this function is to extract the corresponding phase required to implement a state transition.

   Let's consider a simple MZI 2x2 logic with two transmission states. We want to verify that the electronic function
   switch, effectively switches the optical output between the cross and bar states of the optical transmission function.

   For the corresponding switch model:

   Let's assume a switch model unitary. For a given 2x2 input optical switch "X". In bar state, in dual rail, transforms an optical input:
   ```
   .. raw::

       [[1] ----> [[1]
       [0]]        [0]]

   In cross state, in dual rail, transforms an optical input:

   .. raw::

       [[1] ----> [[0]
       [0]]        [1]]

   However, sometimes it is easier to describe a photonic logic transformation based on these states, rather than inherently
   the numerical phase that is applied. This may be the case, for example, in asymmetric Mach-Zehnder modulators measurement, etc.

   As such, this function will help us extract the corresponding phase for a particular switch transition.

   When the switch function is larger than a single switch, it is necessary to extract the location of the corresponding switches as function parameters.


.. py:function:: get_state_to_phase_map(switch_function: piel.types.OpticalTransmissionCircuit, switch_states: list[piel.types.NumericalTypes] | None = None, input_fock_states: list[piel.types.ArrayTypes] | None = None, target_transition_list: list[dict] | None = None, mode_amount: int | None = None, **kwargs) -> tuple[piel.types.ArrayTypes]

   The goal of this function is to extract the corresponding phase required to implement a state transition.

   Let's consider a simple MZI 2x2 logic with two transmission states. We want to verify that the electronic function
   switch, effectively switches the optical output between the cross and bar states of the optical transmission function.

   For the corresponding switch model:

   Let's assume a switch model unitary. For a given 2x2 input optical switch "X". In bar state, in dual rail, transforms an optical input:
   ```
   .. raw::

       [[1] ----> [[1]
       [0]]        [0]]

   In cross state, in dual rail, transforms an optical input:

   .. raw::

       [[1] ----> [[0]
       [0]]        [1]]

   However, sometimes it is easier to describe a photonic logic transformation based on these states, rather than inherently
   the numerical phase that is applied. This may be the case, for example, in asymmetric Mach-Zehnder modulators measurement, etc.

   As such, this function will help us extract the corresponding phase for a particular switch transition.


