SamplingResult

class lightworks.sdk.results.SamplingResult(results: dict[State, int], input: State, **kwargs: Any)

Stores results data from a sampling experiment in the emulator. There is then a range of options for displaying the data, or alternatively the data can be accessed directly using the [] operator on the class to select which output is required.

Parameters:
  • results (dict | np.ndarray) – The results which are to be stored.

  • input (State) – The input state used in the sampling experiment.

display_as_dataframe(threshold: float = 1e-12) DataFrame

Function to display the results of a given simulation in a dataframe format. Either the probability amplitudes of the state, or the actual probabilities can be displayed.

Parameters:
  • threshold (float, optional) – Threshold to control at which point value are rounded to zero. If looking for very small amplitudes this may need to be lowered.

  • conv_to_probability (bool, optional) – In the case that the result is a probability amplitude, setting this to True will convert it into a probability. If it is not a probability amplitude then this setting will have no effect.

Returns:

A dataframe with the results and input and output

states as labels.

Return type:

pd.Dataframe

property input: State

The input state used in the sampling experiment.

map(mapping: Callable[[State, Any], State], *args: Any, **kwargs: Any) SamplingResult

Performs a generic remapping of states based on a provided function.

property outputs: list[State]

All outputs measured in the sampling experiment.

plot(show: bool = True, state_labels: dict[State, str | State] | None = None) tuple[Figure, Axes] | None

Create a plot of the data contained in the result. This will either take the form of a heatmap or bar chart, depending on the nature of the data contained in the Result object.

Parameters:
  • show (bool, optional) – Can be used to automatically show the created plot with show instead of returning the figure and axes.

  • state_labels (dict, optional) – Provided a dictionary which can be used to specify alternate labels for each of the states when plotting. The keys of this dictionary should be States and the values should be strings or States.

print_outputs() None

Print the output results for each input into the system. This is compatible with all possible result types.