def test_schedule_matplotlib_drawer(self):
     filename = self._get_resource_path(
         'current_schedule_matplotlib_ref.png')
     schedule = self.sample_schedule()
     pulse_drawer(schedule, filename=filename)
     self.assertImagesAreEqual(filename, self.schedule_matplotlib_reference)
     os.remove(filename)
예제 #2
0
 def test_truncate_acquisition(self):
     sched = Schedule(name='test_schedule')
     sched = sched.insert(0, Acquire(30, AcquireChannel(1),
                                     MemorySlot(1),
                                     RegisterSlot(1)))
     # Check ValueError is not thrown
     pulse_drawer(sched, plot_range=(0, 15))
 def test_truncated_schedule_matplotlib_drawer(self):
     filename = self._get_resource_path(
         'current_truncated_schedule_matplotlib_ref.png')
     schedule = self.sample_schedule()
     pulse_drawer(schedule, plot_range=(150, 300), filename=filename)
     self.assertImagesAreEqual(filename, self.trunc_sched_mpl_reference)
     os.remove(filename)
 def test_instruction_matplotlib_drawer(self):
     filename = self._get_resource_path(
         'current_instruction_matplotlib_ref.png')
     pulse_instruction = self.sample_instruction()
     pulse_drawer(pulse_instruction, filename=filename)
     self.assertImagesAreEqual(filename, self.instr_matplotlib_reference)
     os.remove(filename)
예제 #5
0
 def test_parametric_pulse_schedule(self):
     """Test that parametric instructions/schedules can be drawn."""
     filename = self._get_resource_path('current_parametric_matplotlib_ref.png')
     schedule = Schedule(name='test_parametric')
     schedule += Play(library.Gaussian(duration=25, sigma=4, amp=0.5j), DriveChannel(0))
     pulse_drawer(schedule, filename=filename)
     self.assertImagesAreEqual(filename, self.parametric_matplotlib_reference)
     os.remove(filename)
 def test_play(self):
     """Test that Play instructions can be drawn. The output should be the same as the
     parametric_pulse_schedule test.
     """
     filename = self._get_resource_path('current_play_matplotlib_ref.png')
     schedule = Schedule(name='test_parametric')
     schedule += Play(pulse_lib.Gaussian(duration=25, sigma=4, amp=0.5j), DriveChannel(0))
     pulse_drawer(schedule, filename=filename)
     self.assertImagesAreEqual(filename, self.parametric_matplotlib_reference)
     os.remove(filename)
예제 #7
0
 def test_schedule_drawer_show_framechange(self):
     filename = self._get_resource_path('current_show_framechange_ref.png')
     gp0 = library.gaussian(duration=20, amp=1.0, sigma=1.0)
     sched = Schedule(name='test_schedule')
     sched = sched.append(Play(gp0, DriveChannel(0)))
     sched = sched.insert(60, ShiftPhase(-1.57, DriveChannel(0)))
     sched = sched.insert(30, ShiftPhase(-1.50, DriveChannel(1)))
     sched = sched.insert(70, ShiftPhase(1.50, DriveChannel(1)))
     pulse_drawer(sched, filename=filename, show_framechange_channels=False)
     self.assertImagesAreEqual(filename, self.schedule_show_framechange_ref)
     os.remove(filename)
 def test_schedule_drawer_show_framechange(self):
     filename = self._get_resource_path('current_show_framechange_ref.png')
     gp0 = pulse_lib.gaussian(duration=20, amp=1.0, sigma=1.0)
     sched = Schedule()
     sched = sched.append(gp0(DriveChannel(0)))
     sched = sched.insert(60, FrameChange(phase=-1.57)(DriveChannel(0)))
     sched = sched.insert(30, FrameChange(phase=-1.50)(DriveChannel(1)))
     sched = sched.insert(70, FrameChange(phase=1.50)(DriveChannel(1)))
     pulse_drawer(sched, filename=filename, show_framechange_channels=False)
     self.assertImagesAreEqual(filename, self.schedule_show_framechange_ref)
     os.remove(filename)
예제 #9
0
    def draw(self, dt: float = 1, style=None,
             filename: Optional[str] = None, interp_method: Optional[Callable] = None,
             scale: Optional[float] = None,
             channel_scales: Optional[Dict[Channel, float]] = None,
             plot_all: bool = False, plot_range: Optional[Tuple[float]] = None,
             interactive: bool = False, table: bool = False, label: bool = False,
             framechange: bool = True, scaling: float = None,
             channels: Optional[List[Channel]] = None,
             show_framechange_channels: bool = True):
        r"""Plot the schedule.

        Args:
            dt: Time interval of samples.
            style (Optional[SchedStyle]): A style sheet to configure plot appearance.
            filename: Name required to save pulse image.
            interp_method: A function for interpolation.
            scale: Relative visual scaling of waveform amplitudes, see Additional Information.
            channel_scales: Channel independent scaling as a dictionary of ``Channel`` object.
            plot_all: Plot empty channels.
            plot_range: A tuple of time range to plot.
            interactive: When set true show the circuit in a new window
                         (this depends on the matplotlib backend being used supporting this).
            table: Draw event table for supported commands.
            label: Label individual instructions.
            framechange: Add framechange indicators.
            scaling: Deprecated, see ``scale``.
            channels: A list of channel names to plot.
            show_framechange_channels: Plot channels with only framechanges.

        Additional Information:
            If you want to manually rescale the waveform amplitude of channels one by one,
            you can set ``channel_scales`` argument instead of ``scale``.
            The ``channel_scales`` should be given as a python dictionary::

                channel_scales = {pulse.DriveChannels(0): 10.0,
                                  pulse.MeasureChannels(0): 5.0}

            When the channel to plot is not included in the ``channel_scales`` dictionary,
            scaling factor of that channel is overwritten by the value of ``scale`` argument.
            In default, waveform amplitude is normalized by the maximum amplitude of the channel.
            The scaling factor is displayed under the channel name alias.

        Returns:
            matplotlib.Figure: A matplotlib figure object of the pulse schedule.
        """
        # pylint: disable=invalid-name, cyclic-import
        if scaling is not None:
            warnings.warn('The parameter "scaling" is being replaced by "scale"',
                          DeprecationWarning, 3)
            scale = scaling

        from qiskit import visualization

        return visualization.pulse_drawer(self, dt=dt, style=style,
                                          filename=filename, interp_method=interp_method,
                                          scale=scale, channel_scales=channel_scales,
                                          plot_all=plot_all, plot_range=plot_range,
                                          interactive=interactive, table=table, label=label,
                                          framechange=framechange, channels=channels,
                                          show_framechange_channels=show_framechange_channels)
예제 #10
0
    def draw(self,
             dt: float = 1,
             style=None,
             filename: Optional[str] = None,
             interp_method: Optional[Callable] = None,
             scale: float = 1,
             interactive: bool = False):
        """Plot the interpolated envelope of pulse.

        Args:
            dt: Time interval of samples.
            style (Optional[PulseStyle]): A style sheet to configure plot appearance.
            filename: Name required to save pulse image.
            interp_method: A function for interpolation.
            scale: Relative visual scaling of waveform amplitudes.
            interactive: When set true show the circuit in a new window.
                         (This depends on the matplotlib backend being used.)

        Returns:
            matplotlib.figure: A matplotlib figure object of the pulse envelope
        """
        # pylint: disable=invalid-name, cyclic-import
        from qiskit import visualization

        return visualization.pulse_drawer(self,
                                          dt=dt,
                                          style=style,
                                          filename=filename,
                                          interp_method=interp_method,
                                          scale=scale,
                                          interactive=interactive)
예제 #11
0
    def draw(self, dt: float = 1,
             style=None,
             filename: Optional[str] = None,
             interp_method: Optional[Callable] = None,
             scale: float = 1, interactive: bool = False,
             scaling: float = None):
        """Plot the interpolated envelope of pulse.

        Args:
            dt: Time interval of samples.
            style (Optional[PulseStyle]): A style sheet to configure plot appearance
            filename: Name required to save pulse image
            interp_method: A function for interpolation
            scale: Relative visual scaling of waveform amplitudes
            interactive: When set true show the circuit in a new window
                (this depends on the matplotlib backend being used supporting this)
            scaling: Deprecated, see `scale`

        Returns:
            matplotlib.figure: A matplotlib figure object of the pulse envelope
        """
        # pylint: disable=invalid-name, cyclic-import
        if scaling is not None:
            warnings.warn(
                'The parameter "scaling" is being replaced by "scale"',
                DeprecationWarning, 3)
            scale = scaling

        from qiskit import visualization

        return visualization.pulse_drawer(self, dt=dt, style=style, filename=filename,
                                          interp_method=interp_method, scale=scale,
                                          interactive=interactive)
예제 #12
0
    def draw(self,
             dt: float = 1,
             style: Optional['SchedStyle'] = None,
             filename: Optional[str] = None,
             interp_method: Optional[Callable] = None,
             scaling: float = 1,
             channels_to_plot: Optional[List[Channel]] = None,
             plot_all: bool = False,
             plot_range: Optional[Tuple[float]] = None,
             interactive: bool = False,
             table: bool = True,
             label: bool = False,
             framechange: bool = True,
             channels: Optional[List[Channel]] = None):
        """Plot the instruction.

        Args:
            dt: Time interval of samples
            style: A style sheet to configure plot appearance
            filename: Name required to save pulse image
            interp_method: A function for interpolation
            scaling: Relative visual scaling of waveform amplitudes
            channels_to_plot: Deprecated, see `channels`
            plot_all: Plot empty channels
            plot_range: A tuple of time range to plot
            interactive: When set true show the circuit in a new window
                (this depends on the matplotlib backend being used supporting this)
            table: Draw event table for supported commands
            label: Label individual instructions
            framechange: Add framechange indicators
            channels: A list of channel names to plot


        Returns:
            matplotlib.figure: A matplotlib figure object of the pulse schedule
        """
        # pylint: disable=invalid-name, cyclic-import

        from qiskit import visualization

        if channels_to_plot:
            warnings.warn(
                'The parameter "channels_to_plot" is being replaced by "channels"',
                DeprecationWarning, 3)
            channels = channels_to_plot

        return visualization.pulse_drawer(self,
                                          dt=dt,
                                          style=style,
                                          filename=filename,
                                          interp_method=interp_method,
                                          scaling=scaling,
                                          plot_all=plot_all,
                                          plot_range=plot_range,
                                          interactive=interactive,
                                          table=table,
                                          label=label,
                                          framechange=framechange,
                                          channels=channels)
예제 #13
0
    def draw(self,
             dt: float = 1,
             style=None,
             filename: str = None,
             interp_method: Callable = None,
             scaling: float = 1,
             channels_to_plot: List[Channel] = None,
             plot_all: bool = False,
             plot_range: Tuple[float] = None,
             interactive: bool = False,
             table: bool = True,
             label: bool = False,
             framechange: bool = True):
        """Plot the instruction.

        Args:
            dt: Time interval of samples
            style (SchedStyle): A style sheet to configure plot appearance
            filename: Name required to save pulse image
            interp_method: A function for interpolation
            scaling (float): Relative visual scaling of waveform amplitudes
            channels_to_plot: A list of channel names to plot
            plot_all: Plot empty channels
            plot_range: A tuple of time range to plot
            interactive: When set true show the circuit in a new window
                (this depends on the matplotlib backend being used supporting this)
            table: Draw event table for supported commands
            label: Label individual instructions
            framechange: Add framechange indicators


        Returns:
            matplotlib.figure: A matplotlib figure object of the pulse schedule.
        """
        # pylint: disable=invalid-name, cyclic-import

        from qiskit import visualization

        return visualization.pulse_drawer(self,
                                          dt=dt,
                                          style=style,
                                          filename=filename,
                                          interp_method=interp_method,
                                          scaling=scaling,
                                          channels_to_plot=channels_to_plot,
                                          plot_all=plot_all,
                                          plot_range=plot_range,
                                          interactive=interactive,
                                          table=table,
                                          label=label,
                                          framechange=framechange)
예제 #14
0
 def test_pulse_matplotlib_drawer(self):
     filename = 'current_pulse_matplotlib_ref.png'
     pulse = self.sample_pulse()
     pulse_drawer(pulse, filename=filename)
     self.assertImagesAreEqual(filename, self.pulse_matplotlib_reference)
     os.remove(filename)