sf.Result

class Result(result, ancilla_samples=None)[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.

  • results.ancilla_samples: Measurement samples from any ancillary states used for measurement-based gates.

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: shots=1, num_modes=3, contains state=True>
>>> 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.

ancilla_samples

All measurement samples from ancillary modes used for measurement-based gates.

samples

Measurement samples.

samples_dict

All measurement samples as a dictionary.

state

The quantum state object.

ancilla_samples

All measurement samples from ancillary modes used for measurement-based gates.

Returns a dictionary which associates each mode (keys) with the list of measurements outcomes (values) from all the ancilla-assisted gates applied to that mode.

Returns

mode index associated with the list of ancilla 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]]

samples_dict

All measurement samples as a dictionary. Only available on simulators.

Returns a dictionary which associates each mode (keys) with the list of measurements outcomes (values), including modes that are being measured several times. 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]

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