Utilities¶
- lightworks.random_unitary(N: int, seed: int | None = None) ndarray[Any, dtype[complex128]] ¶
Generate a random NxN unitary matrix. Seed can be used to produce the same unitary each time the function is called.
- Parameters:
N (int) – The dimension of the random unitary that is to be generated.
seed (int | None, optional) – Specify a random seed to repeatedly produce the same unitary matrix on each function call. Defaults to None, which will produce a random matrix on each call.
- Returns:
The created random unitary matrix.
- Return type:
np.ndarray
- lightworks.random_permutation(N: int, seed: int | None = None) ndarray[Any, dtype[complex128]] ¶
Generate a random NxN permutation. Seed can be used to produce the same unitary each time the function is called.
- Parameters:
N (int) – The dimension of the random permutation that is to be generated.
seed (int | None, optional) – Specify a random seed to repeatedly produce the same unitary matrix on each function call. Defaults to None, which will produce a random matrix on each call.
- Returns:
The created random permutation matrix.
- Return type:
np.ndarray
- class lightworks.convert¶
Contains a range of functions for converting/mapping between quantities.
- static db_loss_to_decimal(loss: float) float ¶
Function to convert from a given dB loss into the equivalent loss value in decimal form. Note this function does not support conversion of gain values.
- Parameters:
loss (float) – The loss value in decibels.
- Returns:
The calculated loss as a decimal.
- Return type:
float
- static decimal_to_db_loss(loss: float) float ¶
Function to convert from a decimal into dB loss. This dB loss will be returned as a positive value.
- Parameters:
loss (float) – The loss value as a decimal, this should be in the range [0,1).
- Returns:
- The calculated dB loss. This is returned as a positive
value.
- Return type:
float
- Raises:
ValueError – Raised in cases where transmission is not in range [0,1).
- static dual_rail_to_qubit(state: State | list[int], allow_invalid: bool = False) State ¶
Converts from a dual-rail encoded Fock state into the qubit encoded equivalent.
- Parameters:
state (State) – The dual-rail state to convert. This state should contain a single photon between pairs of adjacent modes.
allow_invalid (bool) – Controls whether or not invalid values are supported for a qubit. In these cases, the numerical value will be replaced by an X.
- Returns:
The calculated qubit state.
- Return type:
- Raises:
ValueError – Raised when an invalid state is provided for conversion.
- static parity_mapping(state: State, invert: bool = False) State ¶
Apply a parity mapping to a State, in which the state values are converted to either 0 or 1 depending on if the value is odd or even.
- static qubit_to_dual_rail(state: State | list[int] | str) State ¶
Converts from a qubit encoding into a dual-rail encoded state between modes.
- class lightworks.PostSelection(multi_rules: bool = False)¶
Post-selection
- Parameters:
multi_rules (bool, optional) – Controls whether multiple rules can be applied to a single mode.
- add(modes: int | tuple[int, ...], n_photons: int | tuple[int, ...]) None ¶
Adds a post-selection rule across the provided modes, conditioning that the total number of photons across the modes is equal to any of the provided number of photons.
- Parameters:
modes (int, tuple) – The modes across which post-selection should be applied. This can be a singular mode provided as an integer or a range of modes as a tuple.
n_photons (int, tuple) – The valid photon number totals across the modes. This can be a singular integer value or a range of allowable photon numbers.
- property modes: list[int]¶
Returns modes on which rules are currently applied.
- property rules: list[Rule]¶
Returns currently applied post-selection rules.