sf.api.Result

class Result(samples, all_samples=None, is_stateful=True)[source]

Bases: object

Result of a quantum computation.

Represents the results of the execution of a quantum program on a local or remote backend.

The returned Result object provides several useful properties for accessing the results of your program execution:

  • results.state: The quantum state object contains details and methods for manipulation of the final circuit state. Not available for remote backends. See States for more information regarding available state methods.

  • results.samples: Measurement samples from any measurements performed.

Example:

The following example runs an existing Strawberry Fields quantum Program on the Gaussian backend to get a Result object.

Using this Result object, the measurement samples can be returned, as well as quantum state information.

>>> eng = sf.Engine("gaussian")
>>> results = eng.run(prog)
>>> print(results)
Result: 3 subsystems
    state: <GaussianState: num_modes=3, pure=True, hbar=2>
    samples: [[0, 0, 0]]
>>> results.samples
np.array([[0, 0, 0]])
>>> results.state.is_pure()
True

Note

Only local simulators will return a state object. Remote simulators and hardware backends will return measurement samples (Result.samples), but the return value of Result.state will be None.

all_samples

All measurement samples.

samples

Measurement samples.

state

The quantum state object.

all_samples

All measurement samples.

Returns a dictionary which associates each mode (keys) with the list of measurements outcomes (values). For multiple shots or batched execution arrays and tensors are stored.

Returns

mode index associated with the list of

measurement outcomes

Return type

dict[int, list]

samples

Measurement samples.

Returned measurement samples will have shape (shots, modes).

Returns

measurement samples returned from program execution

Return type

array[array[float, int]]

state

The quantum state object.

The quantum state object contains details and methods for manipulation of the final circuit state.

See States for more information regarding available state methods.

Note

Only local simulators will return a state object. Remote simulators and hardware backends will return measurement samples (Result.samples), but the return value of Result.state will be None.

Returns

quantum state returned from program execution

Return type

BaseState