-
Notifications
You must be signed in to change notification settings - Fork 131
Add IQ plotter class #948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IQ plotter class #948
Conversation
Add discriminator_alpha option to set discriminator prediction transparency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. A few small comments.
I like the suggestions in #948 (comment) I think we could also do this in a follow-up PR (this would allow #936 to move forward in parallel to adding the suggested plotting functionality) since this plotting functionality requires a bit more code. From the user's perspective it should be easy to control through options. E.g.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks.
Summary
The recent addition of the visualization module for Qiskit Experiments introduced plotters to the code-base (#902). This PR adds a new plotter subclass for plotting IQ data, typically acquired from experiments with level-1 results or during state-discrimination training (#936).
Details and comments
This PR adds a new
IQPlotter
class to plot IQ data for multiple prepared states and a discriminator which classifies the IQ points into state labels. The plotter takes in points and centroid data for different prepared states and creates a scatter plot with their values. Modifications were made toBaseDrawer
andMplDrawer
to add functionality to draw an image on a canvas, (i.e., equivalent toplt.imshow
).Usage of
IQPlotter
.Below you can see a figure generated using
IQPlotter
for mock qutrit readout. The code used to generate this figure is given at the end of the PR description. The plotting class supports plotting individual points and centroids for multiple states, where states are different series. It also supports plotting the predictions of a trained discriminator over a region of the IQ space. This is done by sampling the discriminatorspredict()
method for different IQ positions. The discriminator is passed as supplementary data to the plotter.New
BaseDrawer.image()
method.To allow plotters to draw images onto a canvas,
BaseDrawer
andMplDrawer
had to be updated with new functionality.BaseDrawer.image()
takes in a two-dimensional NumPy array of numerical values or strings, or a three-dimensional NumPy array of RGB/RGBA data. If two-dimensional numerical data is provided, the drawer will assign colours to the values based on thecmap
parameter.image()
also supports plotting images of classification labels, where the values indata
are series names (str). Settingcmap_use_series_colors=True
will tell the drawer to use the series colours (from other graphics already drawn on the canvas) as the colours for the image. This is used byIQPlotter
to plot a discriminators predictions and match the colours to IQ points and centroids.image()
also has anextent
parameter which defines the region for the image in the units of the X and Y axes.IQPlotter
uses a helper classDataExtentCalculator
to assist with precomputing the extent of the plotting data, so that the discriminator can be sampled to generate the prediction image.Example code to generate the example figure.