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.
IQPlotterplots results from experiments which used measurement-level 1, i.e. IQ data. This class also supports plotting predictions from a discriminator (subclass ofBaseDiscriminator), 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 theflag_misclassifiedoption). A canonical application ofIQPlotteris 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:TrueWhether to plot an image showing the predictions of thediscriminatorentry insupplementary_data. If True, the “discriminator” supplementary data entry must be set.discriminator_multiplier (float)
Default value:1.1The 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 bydiscriminator_extent_multiplierto compute the extent of the discriminator predictions. Defaults to 1.1.discriminator_aspect_ratio (float)
Default value:1.0The aspect ratio of the extent of the discriminator predictions, beingwidth/height. Defaults to1for a square region.discriminator_max_resolution (int)
Default value:1024The 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.2The transparency of the discriminator prediction image. Defaults to 0.2 (i.e., 20%).discriminator_extent (Optional[ExtentTuple])
Default value:NoneAn optional tuple defining the extent of the image created by sampling from the discriminator. IfNone, the extent tuple is computed usingdiscriminator_multiplier,discriminator_aspect_ratio, and the series-datapointsandcentroid. Defaults toNone.flag_misclassified (bool)
Default value:TrueWhether to mark misclassified IQ values from allpointsseries data, based on whether their series name is not the same as the prediction from the discriminator provided as supplementary data. Ifdiscriminatoris not provided,flag_misclassifiedhas 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:NoneArbitrary 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 indrawer. The default is an empty style object, and such the defaultdrawerplotting 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:NoneMin 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:NoneMin 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 byxval_unit_scale.yval_unit (str)
Default value:"arb."Unit of y values. Seexval_unitfor details.xval_unit_scale (bool)
Default value:FalseWhether to add an SI unit prefix toxval_unitif needed. For example, when the x values represent time andxval_unit="s",xval_unit_scale=Trueadds 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 toTrue. IfFalseis provided, the axis numbers will be displayed in the scientific notation.yval_unit_scale (bool)
Default value:FalseWhether to add an SI unit prefix toyval_unitif needed. Seexval_unit_scalefor details.figure_title (str)
Default value:NoneTitle 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
Figure options for the plotter and its drawer.
Options for the plotter.
Series names that have been added to this plotter.
Data for series being plotted.
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.
Clears supplementary data.
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.
Returns the expected series data keys supported by this plotter.
Returns the expected figures data keys supported by this plotter.
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.