sf.Result¶
-
class
Result
(result, **kwargs)[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.samples_dict
: Measurement samples from any measurements performed, sorted by measured mode. Not available for remote backends.results.metadata
: Metadata for job results.results.ancillae_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 aResult
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 ofResult.state
will beNone
.Attributes
All measurement samples from ancillary modes used for measurement-based gates.
Metadata for the job results.
Measurement samples.
All measurement samples as a dictionary.
The quantum state object.
-
ancillae_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
Mapping[int, list]
-
metadata
¶ Metadata for the job results.
The metadata is considered to be everything contained in the raw results except for the samples, which is stored under the “output” key.
- Returns
dictionary containing job result metadata
- Return type
Mapping[str, ndarray]
-
samples
¶ Measurement samples.
Returned measurement samples will have shape
(shots, modes)
.- Returns
measurement samples returned from program execution
- Return type
ndarray[ndarray[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.
Note
The samples dictionary may contain samples that are not present in the samples array. In the samples array, each time a mode is measured the prior measured sample on the same mode is replaced. The samples dictionary, on the other hand, keeps _all_ measurements.
- Returns
mode index associated with the list of measurement outcomes
- Return type
Mapping[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 ofResult.state
will beNone
.- Returns
quantum state returned from program execution
- Return type