Note

This is the documentation for the current state of the development branch of Qiskit Experiments. The documentation or APIs here can change prior to being released.

IQPlotter

class IQPlotter(drawer)[source]

A plotter class to plot IQ data.

IQPlotter plots results from experiments which used measurement-level 1, i.e. IQ data. This class also supports plotting predictions from a discriminator (subclass of BaseDiscriminator), which is used to classify IQ results into labels. The discriminator labels are matched with the series names to generate an image of the predictions. Points that are misclassified by the discriminator are flagged in the figure (see the flag_misclassified option). A canonical application of IQPlotter is for classification of single-qubit readout for different prepared states.

Example

# Create plotter
plotter = IQPlotter(MplDrawer())

# Iterate over results, one per prepared state. Add points and centroid to
# plotter and set label for prepared states as |n> where n is the
# prepared-state number.
series_params = {}
for res in results:
    # Get IQ points from result memory.
    points = res.memory

    # Compute centroid as mean of all points.
    centroid = np.mean(points, axis=1)

    # Get ``prep``, which is part of the result metadata.
    prep = res.prep

    # Create label as a ket instead of just a state number (i.e., prep).
    series_params[prep] = {
        "label":f"|{prep}>",
    }

    plotter.set_series_data(prep, points=points, centroid=centroid)
plotter.set_figure_options(series_params=series_params)
...
# Optional: Add trained discriminator.
discrim = MyIQDiscriminator()
# Discriminator labels are the same as series names.
discrim.fit(train_data, train_labels)
plotter.set_supplementary_data(discriminator=discrim)
...
# Plot figure.
fig = plotter.figure()

Options

The following can be set using set_options().

Options
  • Defined in the class IQPlotter:

    • plot_discriminator (bool)

      Default value: True
      Whether to plot an image showing the predictions of the discriminator entry in supplementary_data. If True, the “discriminator” supplementary data entry must be set.
    • discriminator_multiplier (float)

      Default value: 1.1
      The multiplier to use when computing the extent of the discriminator plot. The range of the series data is taken as the base value and multiplied by discriminator_extent_multiplier to compute the extent of the discriminator predictions. Defaults to 1.1.
    • discriminator_aspect_ratio (float)

      Default value: 1.0
      The aspect ratio of the extent of the discriminator predictions, being width/height. Defaults to 1 for a square region.
    • discriminator_max_resolution (int)

      Default value: 1024
      The number of pixels to use for the largest edge of the discriminator extent, used when sampling the discriminator to create the prediction image. Defaults to 1024.
    • discriminator_alpha (float)

      Default value: 0.2
      The transparency of the discriminator prediction image. Defaults to 0.2 (i.e., 20%).
    • discriminator_extent (Optional[ExtentTuple])

      Default value: None
      An optional tuple defining the extent of the image created by sampling from the discriminator. If None, the extent tuple is computed using discriminator_multiplier, discriminator_aspect_ratio, and the series-data points and centroid. Defaults to None.
    • flag_misclassified (bool)

      Default value: True
      Whether to mark misclassified IQ values from all points series data, based on whether their series name is not the same as the prediction from the discriminator provided as supplementary data. If discriminator is not provided, flag_misclassified has no effect. Defaults to True.
    • misclassified_symbol (str)

      Default value: "x"
      Symbol for misclassified points, as a drawer-compatible string. Defaults to “x”.
    • misclassified_color (str | tuple)

      Default value: "r"
      Color for misclassified points, as a drawer-compatible string or RGB tuple. Defaults to “r”.
  • Defined in the class BasePlotter:

    • axis (Any)

      Default value: None
      Arbitrary object that can be used as a drawing canvas.
    • subplots (Tuple[int, int])

      Default value: (1, 1)
      Number of rows and columns when the experimental result is drawn in the multiple windows.
    • style (PlotStyle)

      Default value: {}
      The style definition to use when plotting. This overwrites figure option custom_style set in drawer. The default is an empty style object, and such the default drawer plotting style will be used.

Figure options

The following can be set using set_figure_options().

Options
  • Defined in the class BasePlotter:

    • xlabel (Union[str, List[str]])

      Default value: "In-Phase"
      X-axis label string of the output figure. If there are multiple columns in the canvas, this could be a list of labels.
    • ylabel (Union[str, List[str]])

      Default value: "Quadrature"
      Y-axis label string of the output figure. If there are multiple rows in the canvas, this could be a list of labels.
    • xlim (Tuple[float, float])

      Default value: None
      Min and max value of the horizontal axis. If not provided, it is automatically scaled based on the input data points.
    • ylim (Tuple[float, float])

      Default value: None
      Min and max value of the vertical axis. If not provided, it is automatically scaled based on the input data points.
    • xval_unit (str)

      Default value: "arb."
      Unit of x values. No scaling prefix is needed here as this is controlled by xval_unit_scale.
    • yval_unit (str)

      Default value: "arb."
      Unit of y values. See xval_unit for details.
    • xval_unit_scale (bool)

      Default value: False
      Whether to add an SI unit prefix to xval_unit if needed. For example, when the x values represent time and xval_unit="s", xval_unit_scale=True adds an SI unit prefix to "s" based on X values of plotted data. In the output figure, the prefix is automatically selected based on the maximum value in this axis. If your x values are in [1e-3, 1e-4], they are displayed as [1 ms, 10 ms]. By default, this option is set to True. If False is provided, the axis numbers will be displayed in the scientific notation.
    • yval_unit_scale (bool)

      Default value: False
      Whether to add an SI unit prefix to yval_unit if needed. See xval_unit_scale for details.
    • figure_title (str)

      Default value: None
      Title of the figure. Defaults to None, i.e. nothing is shown.
    • series_params (Dict[SeriesName, Dict[str, Any]])

      Default value: {}
      A dictionary of plot parameters for each series. This is keyed on the name for each series. Sub-dictionary is expected to have following three configurations, “canvas”, “color”, and “symbol”; “canvas” is the integer index of axis (when multi-canvas plot is set), “color” is the color of the curve, and “symbol” is the marker Style of the curve for scatter plots.

Initialization

Create a new plotter instance.

Parameters:

drawer (BaseDrawer) – The drawer to use when creating the figure.

Attributes

IQPlotter.figure_options

Figure options for the plotter and its drawer.

IQPlotter.options

Options for the plotter.

IQPlotter.series

Series names that have been added to this plotter.

IQPlotter.series_data

Data for series being plotted.

IQPlotter.supplementary_data

Additional data for the figure being plotted, that isn't associated with a series.

Methods

IQPlotter.clear_series_data([series_name])

Clear series data for this plotter.

IQPlotter.clear_supplementary_data()

Clears supplementary data.

IQPlotter.config()

Return the config dictionary for this drawing.

IQPlotter.data_exists_for(series_name, data_keys)

Returns whether the given data keys exist for the given series.

IQPlotter.data_for(series_name, data_keys)

Returns data associated with the given series.

IQPlotter.data_keys_for(series_name)

Returns a list of data keys for the given series.

IQPlotter.expected_series_data_keys()

Returns the expected series data keys supported by this plotter.

IQPlotter.expected_supplementary_data_keys()

Returns the expected figures data keys supported by this plotter.

IQPlotter.figure()

Generates and returns a figure for the already provided series and supplementary data.

IQPlotter.set_figure_options(**fields)

Set the figure options.

IQPlotter.set_options(**fields)

Set the plotter options.

IQPlotter.set_series_data(series_name, ...)

Sets data for the given series.

IQPlotter.set_supplementary_data(**data_kwargs)

Sets supplementary data for the plotter.