piel.integration#

Subpackages#

Submodules#

Package Contents#

Functions#

create_gdsfactory_component_from_openlane(...)

This function cretes a gdsfactory layout component that can be included in the network codesign of the device, or that can be used for interconnection codesign.

gdsfactory_netlist_to_spice_netlist(→ hdl21.Module)

This function converts a GDSFactory electrical netlist into a standard SPICE netlist. It follows the same

construct_hdl21_module(→ hdl21.Module)

This function converts a gdsfactory-spice converted netlist using the component models into a SPICE circuit.

convert_connections_to_tuples(connections)

Convert from:

gdsfactory_netlist_with_hdl21_generators(...[, generators])

This function allows us to map the hdl21 models dictionary in a sax-like implementation to the GDSFactory netlist. This allows us to iterate over each instance in the netlist and construct a circuit after this function.]

sax_circuit_permanent(→ tuple)

The permanent of a unitary is used to determine the state probability of combinatorial Gaussian boson samping systems.

unitary_permanent(→ tuple)

The permanent of a unitary is used to determine the state probability of combinatorial Gaussian boson samping systems.

sax_to_ideal_qutip_unitary(sax_input[, input_ports_order])

This function converts the calculated S-parameters into a standard Unitary matrix topology so that the shape and

verify_sax_model_is_unitary(→ bool)

Verify that the model is unitary.

fock_transition_probability_amplitude(...)

This function returns the transition probability amplitude between two Fock states when propagating in between

convert_2d_array_to_string(list_2D)

This function is particularly useful to convert digital data when it is represented as a 2D array into a set of strings.

convert_array_type(array, output_type)

absolute_to_threshold(→ package_array_types)

This function converts the computed optical transmission arrays to single bit digital signals.

Attributes#

array_types

tuple_int_type

package_array_types

create_gdsfactory_component_from_openlane(design_name_v1: str | None = None, design_directory: piel.types.piel_path_types | None = None, run_name: str | None = None, v1: bool = True) gdsfactory.Component[source]#

This function cretes a gdsfactory layout component that can be included in the network codesign of the device, or that can be used for interconnection codesign.

It will look into the latest design run and extract the final OpenLane-generated GDS. You do not have to have run this with OpenLane2 as it just looks at the latest run.

Parameters:
  • design_name_v1 (str) – Design name of the v1 design that can be found within $OPENLANE_ROOT/”<latest>”/designs.

  • design_directory (piel_path_types) – Design directory PATH.

  • run_name (str) – Name of the run to extract the GDS from. If None, it will look at the latest run.

  • v1 (bool) – If True, it will import the design from the OpenLane v1 configuration.

Returns:

GDSFactory component.

Return type:

component(gf.Component)

gdsfactory_netlist_to_spice_netlist(gdsfactory_netlist: dict, generators: dict, **kwargs) hdl21.Module[source]#

This function converts a GDSFactory electrical netlist into a standard SPICE netlist. It follows the same principle as the sax circuit composition.

Each GDSFactory netlist has a set of instances, each with a corresponding model, and each instance with a given set of geometrical settings that can be applied to each particular model. We know the type of SPICE model from the instance model we provides.

We know that the gdsfactory has a set of instances, and we can map unique models via sax through our own composition circuit. Write the SPICE component based on the model into a total circuit representation in string from the reshaped gdsfactory dictionary into our own structure.

Parameters:
  • gdsfactory_netlist – GDSFactory netlist

  • generators – Dictionary of Generators

Returns:

hdl21 module or raw SPICE string

construct_hdl21_module(spice_netlist: dict, **kwargs) hdl21.Module[source]#

This function converts a gdsfactory-spice converted netlist using the component models into a SPICE circuit.

Part of the complexity of this function is the multiport nature of some components and models, and assigning the parameters accordingly into the SPICE function. This is because not every SPICE component will be bi-port, and many will have multi-ports and parameters accordingly. Each model can implement the composition into a SPICE circuit, but they depend on a set of parameters that must be set from the instance. Another aspect is that we may want to assign the component ID according to the type of component. However, we can also assign the ID based on the individual instance in the circuit, which is also a reasonable approximation. However, it could be said, that the ideal implementation would be for each component model provided to return the SPICE instance including connectivity except for the ID.

# TODO implement validators

convert_connections_to_tuples(connections: dict)[source]#

Convert from:

{
'straight_1,e1': 'taper_1,e2',
'straight_1,e2': 'taper_2,e2',
'taper_1,e1': 'via_stack_1,e3',
'taper_2,e1': 'via_stack_2,e1'
}

to:

[(('straight_1', 'e1'), ('taper_1', 'e2')), (('straight_1', 'e2'), ('taper_2', 'e2')), (('taper_1', 'e1'),
('via_stack_1', 'e3')), (('taper_2', 'e1'), ('via_stack_2', 'e1'))]
gdsfactory_netlist_with_hdl21_generators(gdsfactory_netlist: dict, generators=None)[source]#

This function allows us to map the hdl21 models dictionary in a sax-like implementation to the GDSFactory netlist. This allows us to iterate over each instance in the netlist and construct a circuit after this function.]

Example usage:

>>> import gdsfactory as gf
>>> from piel.integration.gdsfactory_hdl21.conversion import gdsfactory_netlist_with_hdl21_generators
>>> from piel.models.physical.electronic import get_default_models
>>> gdsfactory_netlist_with_hdl21_generators(gdsfactory_netlist=gf.components.mzi2x2_2x2_phase_shifter().get_netlist(exclude_port_types="optical"),generators=get_default_models())
Parameters:
  • gdsfactory_netlist – The netlist from GDSFactory to map to the hdl21 models dictionary.

  • generators – The hdl21 models dictionary to map to the GDSFactory netlist.

Returns:

The GDSFactory netlist with the hdl21 models dictionary.

sax_circuit_permanent(sax_input: sax.SType) tuple[source]#

The permanent of a unitary is used to determine the state probability of combinatorial Gaussian boson samping systems.

thewalrus Ryser’s algorithm permananet implementation is described here: https://the-walrus.readthedocs.io/en/latest/gallery/permanent_tutorial.html

# TODO maybe implement subroutine if computation is taking forever.

Parameters:

sax_input (sax.SType) – The sax S-parameter dictionary.

Returns:

The circuit permanent and the time it took to compute it.

Return type:

tuple

unitary_permanent(unitary_matrix: jax.numpy.ndarray) tuple[source]#

The permanent of a unitary is used to determine the state probability of combinatorial Gaussian boson samping systems.

thewalrus Ryser’s algorithm permananet implementation is described here: https://the-walrus.readthedocs.io/en/latest/gallery/permanent_tutorial.html

Note that this function needs to be as optimised as possible, so we need to minimise our computational complexity of our operation.

# TODO implement validation # TODO maybe implement subroutine if computation is taking forever. # TODO why two outputs? Understand this properly later.

Parameters:

unitary_permanent (np.ndarray) – The unitary matrix.

Returns:

The circuit permanent and the time it took to compute it.

Return type:

tuple

sax_to_ideal_qutip_unitary(sax_input: sax.SType, input_ports_order: tuple | None = None)[source]#

This function converts the calculated S-parameters into a standard Unitary matrix topology so that the shape and dimensions of the matrix can be observed.

I think this means we need to transpose the output of the filtered sax SDense matrix to map it to a QuTip matrix. Note that the documentation and formatting of the standard sax mapping to a S-parameter standard notation is already in described in piel/piel/sax/utils.py.

From this stage we can implement a QObj matrix accordingly and perform simulations accordingly. https://qutip.org/docs/latest/guide/qip/qip-basics.html#unitaries

For example, a qutip representation of an s-gate gate would be:

..code-block:

import numpy as np
import qutip
# S-Gate
s_gate_matrix = np.array([[1.,   0], [0., 1.j]])
s_gate = qutip.Qobj(mat, dims=[[2], [2]])

In mathematical notation, this S-gate would be written as:

..math:

S = \begin{bmatrix}
    1 & 0 \\
    0 & i \\
\end{bmatrix}
Parameters:
  • sax_input (sax.SType) – A dictionary of S-parameters in the form of a SDict from sax.

  • input_ports_order (tuple | None) – The order of the input ports. If None, the default order is used.

Returns:

A QuTip QObj representation of the S-parameters in a unitary matrix.

Return type:

qobj_unitary (qutip.Qobj)

verify_sax_model_is_unitary(model: sax.SType, input_ports_order: tuple | None = None) bool[source]#

Verify that the model is unitary.

Parameters:
  • model (dict) – The model to verify.

  • input_ports_order (tuple | None) – The order of the input ports. If None, the default order is used.

Returns:

True if the model is unitary, False otherwise.

Return type:

bool

fock_transition_probability_amplitude(initial_fock_state: qutip.Qobj | jax.numpy.ndarray, final_fock_state: qutip.Qobj | jax.numpy.ndarray, unitary_matrix: jax.numpy.ndarray)[source]#

This function returns the transition probability amplitude between two Fock states when propagating in between the unitary_matrix which represents a quantum state circuit.

Note that based on (TODO cite Jeremy), the initial Fock state corresponds to the columns of the unitary and the final Fock states corresponds to the rows of the unitary.

\[\]

ewcommand{ket}[1]{left|{#1} ight angle}

The subunitary \(U_{f_1}^{f_2}\) is composed from the larger unitary by selecting the rows from the output state Fock state occupation of \(\ket{f_2}\), and columns from the input \(\ket{f_1}\). In our case, we need to select the columns indexes \((0,3)\) and rows indexes \((1,2)\).

If we consider a photon number of more than one for the transition Fock states, then the Permanent needs to be normalised. The probability amplitude for the transition is described as:

\[a(\ket{f_1} o \ket{f_2}) =\]

rac{ ext{per}(U_{f_1}^{f_2})}{sqrt{(j_1! j_2! … j_N!)(j_1^{‘}! j_2^{‘}! … j_N^{‘}!)}}

Args:

initial_fock_state (qutip.Qobj | jnp.ndarray): The initial Fock state. final_fock_state (qutip.Qobj | jnp.ndarray): The final Fock state. unitary_matrix (jnp.ndarray): The unitary matrix that represents the quantum state circuit.

Returns:

float: The transition probability amplitude between the initial and final Fock states.

array_types#
tuple_int_type#
package_array_types#
convert_2d_array_to_string(list_2D: list[list])[source]#

This function is particularly useful to convert digital data when it is represented as a 2D array into a set of strings.

Parameters:

list_2D (list[list]) – A 2D array of binary data.

Returns:

A string of binary data.

Return type:

binary_string (str)

Usage:

list_2D=[[0], [0], [0], [1]] convert_2d_array_to_string(list_2D) >>> “0001”

convert_array_type(array: array_types, output_type: package_array_types)[source]#
absolute_to_threshold(array: array_types, threshold: float = 1e-06, dtype_output: int | float | bool = int, output_array_type: package_array_types = 'jax') package_array_types[source]#

This function converts the computed optical transmission arrays to single bit digital signals. The function takes the absolute value of the array and compares it to a threshold to determine the digital signal.

Parameters:
  • array (array_types) – The optical transmission array of any dimension.

  • dtype_output (int | float | bool, optional) – The output type. Defaults to int.

  • threshold (float, optional) – The threshold to compare the array to. Defaults to 1e-6.

  • output_array_type (array_types, optional) – The output type. Defaults to “jax”.

Returns: