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 generate_schedule_blocks(): """Standard QPY testcase for schedule blocks.""" from qiskit.pulse import builder, channels, library from qiskit.utils import optionals # Parameterized schedule test is avoided. # Generated reference and loaded QPY object may induce parameter uuid mismatch. # As workaround, we need test with bounded parameters, however, schedule.parameters # are returned as Set and thus its order is random. # Since schedule parameters are validated, we cannot assign random numbers. # We need to upgrade testing framework. schedule_blocks = [] # Instructions without parameters with builder.build() as block: with builder.align_sequential(): builder.set_frequency(5e9, channels.DriveChannel(0)) builder.shift_frequency(10e6, channels.DriveChannel(1)) builder.set_phase(1.57, channels.DriveChannel(0)) builder.shift_phase(0.1, channels.DriveChannel(1)) builder.barrier(channels.DriveChannel(0), channels.DriveChannel(1)) builder.play(library.Gaussian(160, 0.1, 40), channels.DriveChannel(0)) builder.play(library.GaussianSquare(800, 0.1, 64, 544), channels.ControlChannel(0)) builder.play(library.Drag(160, 0.1, 40, 1.5), channels.DriveChannel(1)) builder.play(library.Constant(800, 0.1), channels.MeasureChannel(0)) builder.acquire(1000, channels.AcquireChannel(0), channels.MemorySlot(0)) schedule_blocks.append(block) # Raw symbolic pulse if optionals.HAS_SYMENGINE: import symengine as sym else: import sympy as sym duration, amp, t = sym.symbols("duration amp t") # pylint: disable=invalid-name expr = amp * sym.sin(2 * sym.pi * t / duration) my_pulse = library.SymbolicPulse( pulse_type="Sinusoidal", duration=100, parameters={"amp": 0.1}, envelope=expr, valid_amp_conditions=sym.Abs(amp) <= 1.0, ) with builder.build() as block: builder.play(my_pulse, channels.DriveChannel(0)) schedule_blocks.append(block) # Raw waveform my_waveform = 0.1 * np.sin(2 * np.pi * np.linspace(0, 1, 100)) with builder.build() as block: builder.play(my_waveform, channels.DriveChannel(0)) schedule_blocks.append(block) return schedule_blocks
def test_play(self): """Test that Play instructions can be drawn. The output should be the same as the parametric_pulse_schedule test. """ filename = 'current_play_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)