sf.RemoteEngine

class RemoteEngine(target, connection=None, backend_options=None)[source]

Bases: object

A quantum program executor engine that provides a simple interface for running remote jobs in a blocking or non-blocking manner.

Example:

The following examples instantiate an engine with the default settings, and run both blocking and non-blocking jobs.

Run a blocking job:

>>> engine = RemoteEngine("X8_01")
>>> result = engine.run(program, shots=1) # blocking call
>>> result
[[0 1 0 2 1 0 0 0]]

Run a non-blocking job:

>>> job = engine.run_async(program, shots=1)
>>> job.status
"queued"
>>> job.wait()
>>> job.status
"complete"
>>> result = sf.Result(job.result)
>>> result.samples
array([[0 1 0 2 1 0 0 0]])
Parameters
  • target (str) – the target device

  • connection (xcc.Connection, optional) – a connection to the Xanadu Cloud

  • backend_options (Dict[str, Any], optional) – keyword arguments for the backend

DEFAULT_TARGETS

POLLING_INTERVAL_SECONDS

connection

The connection used by the engine.

device_spec

The specification of the target device.

target

The target device used by the engine.

DEFAULT_TARGETS = {'X12': 'X12_01', 'X8': 'X8_01'}
POLLING_INTERVAL_SECONDS = 1
connection

The connection used by the engine. A new xcc.Connection will be created and returned each time this property is accessed if the connection supplied to __init__() was None.

Return type

Connection

Returns

xcc.Connection

device_spec

The specification of the target device.

Returns

the device specification

Return type

DeviceSpec

Raises

requests.exceptions.RequestException – if there was an issue fetching the device specifications from the Xanadu Cloud

target

The target device used by the engine.

Returns

the name of the target

Return type

str

run(program, *[, compile_options, recompile])

Runs a blocking job.

run_async(program, *[, compile_options, …])

Runs a non-blocking remote job.

run(program, *, compile_options=None, recompile=False, **kwargs)[source]

Runs a blocking job.

In the blocking mode, the engine blocks until the job is completed, failed, or cancelled. A job in progress can be cancelled with a keyboard interrupt (ctrl+c).

If the job completes successfully, the result is returned; if the job fails or is cancelled, None is returned.

Parameters
  • program (strawberryfields.Program) – the quantum circuit

  • compile_options (None, Dict[str, Any]) – keyword arguments for Program.compile()

  • recompile (bool) – Specifies if program should be recompiled using compile_options, or if not provided, the default compilation options.

Keyword Arguments

shots (Optional[int]) – The number of shots for which to run the job. If this argument is not provided, the shots are derived from the given program.

Returns

the job result if successful, and None otherwise

Return type

strawberryfields.Result, None

Raises
  • requests.exceptions.RequestException – if there was an issue fetching the device specifications from the Xanadu Cloud

  • FailedJobError – if the remote job fails on the server side (“cancelled” or “failed”)

run_async(program, *, compile_options=None, recompile=False, **kwargs)[source]

Runs a non-blocking remote job.

In the non-blocking mode, a xcc.Job object is returned immediately, and the user can manually refresh the status and check for updated results of the job.

Parameters
  • program (strawberryfields.Program) – the quantum circuit

  • compile_options (None, Dict[str, Any]) – keyword arguments for Program.compile()

  • recompile (bool) – Specifies if program should be recompiled using compile_options, or if not provided, the default compilation options.

Keyword Arguments

shots (Optional[int]) – The number of shots for which to run the job. If this argument is not provided, the shots are derived from the given program.

Returns

the created remote job

Return type

xcc.Job