piel.conversion#

Submodules#

Attributes#

Functions#

absolute_to_threshold(→ piel.types.core.PackageArrayType)

Converts an array of optical transmission values to single-bit digital signals based on a threshold.

convert_2d_array_to_string(→ str)

Converts a 2D array of binary files into a single string of binary values.

convert_array_type(array, output_type)

Converts an array to the specified output type.

convert_to_bits(→ piel.types.digital.BitsType)

Converts an AbstractBitsType to a BitsType (binary string format).

convert_dataframe_to_bits(→ pandas.DataFrame)

Converts specified integer columns in the dataframe to their binary string representations.

read_csv_to_pandas(file_path)

This function returns a Pandas dataframe that contains all the simulation files outputted from the simulation run.

read_vcd_to_json(file_path)

Package Contents#

absolute_to_threshold(array: piel.types.core.ArrayTypes, threshold: float = 1e-06, dtype_output: int | float | bool = int, output_array_type: piel.types.core.PackageArrayType = 'jax') piel.types.core.PackageArrayType[source]#

Converts an array of optical transmission values to single-bit digital signals based on a threshold.

Parameters:
  • array (ArrayTypes) – The input array of any dimension representing optical transmission values.

  • threshold (float, optional) – The threshold value to determine the digital signal. Defaults to 1e-6.

  • dtype_output (int | float | bool, optional) – The desired files type for the output values. Defaults to int.

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

Returns:

The array with values converted to digital signals (0 or 1) based on the threshold and specified output type.

Raises:

ValueError – If the input array is not a numpy or jax array.

Examples

>>> absolute_to_threshold(jnp.array([1e-7, 0.1, 1.0]), threshold=1e-5, output_array_type="numpy")
array([0, 1, 1])
convert_2d_array_to_string(list_2D: list[list]) str[source]#

Converts a 2D array of binary files into a single string of binary values.

Parameters:

list_2D (list[list]) – A 2D array of binary files where each sublist contains a single binary value.

Returns:

A string of binary files.

Return type:

str

Examples

>>> convert_2d_array_to_string([[0], [0], [0], [1]])
'0001'
convert_array_type(array: piel.types.core.ArrayTypes, output_type: piel.types.core.PackageArrayType)[source]#

Converts an array to the specified output type.

Parameters:
  • array (ArrayTypes) – The input array which can be of type numpy.ndarray or jax.ndarray.

  • output_type (PackageArrayType) – The desired output type, which can be “qutip”, “jax”, “numpy”, “list”, “tuple”, or a tuple of integers (TupleIntType).

Returns:

The converted array in the specified output type.

Raises:

ValueError – If the specified output type is not recognized or not supported.

Examples

>>> convert_array_type(np.array([1, 2, 3]), "jax")
DeviceArray([1, 2, 3], dtype=int32)
>>> convert_array_type(jnp.array([1, 2, 3]), "numpy")
array([1, 2, 3])
>>> convert_array_type(np.array([1, 2, 3]), TupleIntType)
(1, 2, 3)
convert_tuple_to_string#
convert_to_bits(bits: piel.types.digital.AbstractBitsType) piel.types.digital.BitsType[source]#

Converts an AbstractBitsType to a BitsType (binary string format).

Parameters:

bits (AbstractBitsType) – The digital bits to convert. Can be a string, bytes, or integer.

Returns:

The converted bits in binary string format (without ‘0b’ prefix).

Return type:

BitsType

Raises:

TypeError – If the input type is not supported.

convert_dataframe_to_bits(dataframe: pandas.DataFrame, ports_list: piel.types.digital.LogicSignalsList) pandas.DataFrame[source]#

Converts specified integer columns in the dataframe to their binary string representations.

Parameters:
  • dataframe (pd.DataFrame) – The simulation files as a Pandas dataframe.

  • ports_list (LogicSignalsList) – List of column names (connection) to convert to binary string format.

Returns:

The dataframe with specified columns converted to binary string format.

Return type:

pd.DataFrame

a2d#
read_csv_to_pandas(file_path: piel.types.PathTypes)[source]#

This function returns a Pandas dataframe that contains all the simulation files outputted from the simulation run.

read_vcd_to_json(file_path: piel.types.PathTypes)[source]#