pulse_drawer

pulse_drawer(data, dt=1, style=None, filename=None, interp_method=None, scale=None, channel_scales=None, plot_all=False, plot_range=None, interactive=False, table=False, label=False, framechange=True, channels=None, show_framechange_channels=True)[source]

Plot the interpolated envelope of pulse and schedule.

Parameters
  • data (Union[Waveform, ScheduleComponent]) – Pulse or schedule object to plot.

  • dt (int) – Time interval of samples. Pulses are visualized in the unit of cycle time if not provided.

  • style (Union[PulseStyle, SchedStyle, None]) – A style sheet to configure plot appearance. See qcstyle for more information.

  • filename (Optional[str]) – Name required to save pulse image. The drawer just returns matplot.Figure object if not provided.

  • interp_method (Optional[Callable]) – Interpolation function. Interpolation is disabled in default. See interpolation for more information.

  • scale (Optional[float]) – Scaling of waveform amplitude. Pulses are automatically scaled channel by channel if not provided.

  • channel_scales (Optional[Dict[Channel, float]]) – Dictionary of scale factor for specific channels. Scale of channels not specified here is overwritten by scale.

  • plot_all (bool) – When set True plot empty channels.

  • plot_range (Optional[Tuple[Union[int, float], Union[int, float]]]) – A tuple of time range to plot.

  • interactive (bool) – When set True show the circuit in a new window. This depends on the matplotlib backend being used supporting this.

  • table (bool) – When set True draw event table for supported commands.

  • label (bool) – When set True draw label for individual instructions.

  • framechange (bool) – When set True draw framechange indicators.

  • channels (Optional[List[Channel]]) – A list of channel names to plot. All non-empty channels are shown if not provided.

  • show_framechange_channels (bool) – When set True plot channels with only framechange instructions.

Returns

A matplotlib figure object for the pulse envelope.

Return type

matplotlib.figure.Figure

Example

This example shows how to visualize your pulse schedule. Pulse names are added to the plot, unimportant channels are removed and the time window is truncated to draw out U3 pulse sequence of interest.

import numpy as np
import qiskit
from qiskit import pulse
from qiskit.test.mock.backends.almaden import FakeAlmaden

inst_map = FakeAlmaden().defaults().instruction_schedule_map

sched = pulse.Schedule()
sched += inst_map.get('u3', 0, np.pi, 0, np.pi)
sched += inst_map.get('measure', list(range(20))) << sched.duration

channels = [pulse.DriveChannel(0), pulse.MeasureChannel(0)]
scales = {pulse.DriveChannel(0): 10}

qiskit.visualization.pulse_drawer(sched,
                                  channels=channels,
                                  plot_range=(0, 1000),
                                  label=True,
                                  channel_scales=scales)
../_images/qiskit.visualization.pulse_drawer_0_0.png

You are also able to call visualization module from the instance method:

sched.draw(channels=channels, plot_range=(0, 1000), label=True, channel_scales=scales)

To customize the format of the schedule plot, you can setup your style sheet.

import numpy as np
import qiskit
from qiskit import pulse
from qiskit.test.mock.backends.almaden import FakeAlmaden

inst_map = FakeAlmaden().defaults().instruction_schedule_map

sched = pulse.Schedule()
sched += inst_map.get('u3', 0, np.pi, 0, np.pi)
sched += inst_map.get('measure', list(range(20))) << sched.duration

# setup style sheet
my_style = qiskit.visualization.SchedStyle(
    figsize = (10, 5),
    bg_color='w',
    d_ch_color = ['#32cd32', '#556b2f'])

channels = [pulse.DriveChannel(0), pulse.MeasureChannel(0)]
scales = {pulse.DriveChannel(0): 10}

qiskit.visualization.pulse_drawer(sched, style=my_style,
                                  channels=channels,
                                  plot_range=(0, 1000),
                                  label=True,
                                  channel_scales=scales)
../_images/qiskit.visualization.pulse_drawer_1_0.png
Raises
  • VisualizationError – when invalid data is given

  • ImportError – when matplotlib is not installed