Backend

class lightworks.emulator.Backend(backend: str)

Provide central location for selecting and interacting with different simulation backends.

Parameters:

backend (str) – A string detailing the backend which is to be used.

property backend: str

Returns the name of the currently selected backend.

run(task: Task) Result[Any, Any]
run(task: Batch) list[Result[Any, Any]]

Runs the provided task on the current backend.

Parameters:

task (Task|Batch) – A task or batch to run.

Returns:

A dictionary like results object containing

details of the calculated values from a task. If a batch is run then this will be a list of results in the same order the task were added to the batch.

Return type:

Result|list[Result]

class lightworks.emulator.backends.PermanentBackend

Calculate the permanent for a give unitary matrix and input state. In this case, thewalrus module is used for all permanent calculations.

property compatible_tasks: tuple[str, ...]

Returns backends which are compatible with the backend.

full_probability_distribution(circuit: CompiledPhotonicCircuit, input_state: State) dict[State, float]

Finds the output probability distribution for the provided circuit and input state.

Parameters:
  • circuit (CompiledPhotonicCircuit) – The compiled version of the circuit which is being simulated. This is created by calling the _build method on the target circuit.

  • input_state (State) – The input state to the system.

Returns:

The calculated full probability distribution for the input.

Return type:

dict

property name: str

Returns the name of the backend

probability(unitary: ndarray[Any, dtype[complex128]], input_state: list[int], output_state: list[int]) float

Calculates the probability of a given output state for a provided unitary and input state to the system. Note values should be provided as an array/list.

Parameters:
  • unitary (np.ndarray) – The target unitary matrix which represents the transformation implemented by a circuit.

  • input_state (list) – The input state to the system.

  • output_state (list) – The target output state.

Returns:

The calculated probability of transition between the input

and output.

Return type:

float

probability_amplitude(unitary: ndarray[Any, dtype[complex128]], input_state: list[int], output_state: list[int]) complex

Find the probability amplitude between a given input and output state for the provided unitary. Note values should be provided as an array/list.

Parameters:
  • unitary (np.ndarray) – The target unitary matrix which represents the transformation implemented by a circuit.

  • input_state (list) – The input state to the system.

  • output_state (list) – The target output state.

Returns:

The calculated probability amplitude.

Return type:

complex

class lightworks.emulator.backends.SLOSBackend

Contains calculate function for SLOS method.

calculate(unitary: ndarray[Any, dtype[complex128]], input_state: State) dict[tuple[int, ...], complex]

Performs calculation of full probability distribution given a unitary matrix and input state.

property compatible_tasks: tuple[str, ...]

Returns backends which are compatible with the backend.

full_probability_distribution(circuit: CompiledPhotonicCircuit, input_state: State) dict[State, float]

Finds the output probability distribution for the provided circuit and input state.

Parameters:
  • circuit (CompiledPhotonicCircuit) – The compiled version of the circuit which is being simulated. This is created by calling the _build method on the target circuit.

  • input_state (State) – The input state to the system.

Returns:

The calculated full probability distribution for the input.

Return type:

dict

property name: str

Returns the name of the backend