qoqo_strawberry_fields

A Backend to translate qoqo Circuits to Xanadu's StrawberryFields syntax and run them.

Classes

StrawberryFieldsBackend(number_modes[, device])

Qoqo backend executing qoqo objects on StrawberryFields.

class qoqo_strawberry_fields.StrawberryFieldsBackend(number_modes: int, device: str | None = None)[source]

Qoqo backend executing qoqo objects on StrawberryFields.

Initialise the StrawberryFieldsBackend class.

Parameters:
  • number_modes -- The number of modes the backend contains.

  • device -- Optional name of the Strawberry Fields device to use. If none is provided, the default "fock" simulator will be used.

__create_device(shots: int) Engine | RemoteEngine

Creates the device and returns it.

Parameters:

shots -- The number of shots to use for the device.

Returns:

The instanciated device (either an Engine or a RemoteEngine)

Raises:
  • ValueError -- Fock simulator doesn't support shots > 1. Please use the Gaussian simulator instead.

  • ValueError -- 'bosonic' backend isn't allowed for now as it cannot use the MeasureFock operation.

  • ValueError -- Device specified isn't allowed. You can allow it by calling the allow_use_actual_hardware function, but please be aware that this may incur significant monetary charges.

__init__(number_modes: int, device: str | None = None) None[source]

Initialise the StrawberryFieldsBackend class.

Parameters:
  • number_modes -- The number of modes the backend contains.

  • device -- Optional name of the Strawberry Fields device to use. If none is provided, the default "fock" simulator will be used.

__weakref__

list of weak references to the object

_run_circuit(circuit: Circuit) Tuple[Program, Dict[Any, Any]][source]

Simulate a Circuit on a strawberryfields backend.

The default number of shots for the simulation is 100. Any kind of Measurement instruction only works as intended if it is the last instruction in the Circuit. Different measurements on different registers are not supported in strawberryfields.

Parameters:

circuit (Circuit) -- the Circuit to simulate.

Returns:

(sf.Program, {readout})

Raises:

ValueError -- Circuit contains multiple ways to set the number of measurements

allow_use_actual_hardware() None[source]

Allow the use of actual hardware - will cost money.

change_max_circuit_length(length: int) None[source]

Change the maximum circuit length allowed.

Parameters:

length -- new maximum allowed length of circuit

change_max_shots(shots: int) None[source]

Change the maximum number of shots allowed.

Parameters:

shots -- new maximum allowed number of shots

disallow_use_actual_hardware() None[source]

Disallow the use of actual hardware.

run_circuit(circuit: Circuit) Tuple[Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]][source]

Simulate a Circuit on a strawberryfields backend.

The default number of shots for the simulation is 100. Any kind of Measurement instruction only works as intended if it is the last instruction in the Circuit. Currently only one simulation is performed, meaning different measurements on different registers are not supported.

Parameters:

circuit (Circuit) -- the Circuit to simulate.

Returns:

Tuple[Dict[str, List[List[bool]]],

Dict[str, List[List[float]]], Dict[str, List[List[complex]]]]: bit, float and complex registers dictionaries.

run_measurement(measurement: Any) Dict[str, float] | None[source]

Run a circuit with the StrawberryFields backend.

Parameters:

measurement -- The measurement that is run.

Returns:

Optional[Dict[str, float]]

run_measurement_registers(measurement: Any) Tuple[Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]][source]

Run all circuits of a measurement with the StrawberryFields backend.

Parameters:

measurement -- The measurement that is run.

Returns:

Tuple[Dict[str, List[List[bool]]],

Dict[str, List[List[float]]], Dict[str, List[List[complex]]]]