def sample_schedule(self): """Generate a sample schedule that includes the most common elements of pulse schedules.""" gp0 = library.gaussian(duration=20, amp=1.0, sigma=1.0) gp1 = library.gaussian(duration=20, amp=-1.0, sigma=2.0) gs0 = library.gaussian_square(duration=20, amp=-1.0, sigma=2.0, risefall=3) sched = Schedule(name='test_schedule') sched = sched.append(gp0(DriveChannel(0))) sched = sched.insert(0, Play(library.Constant(duration=60, amp=0.2 + 0.4j), ControlChannel(0))) sched = sched.insert(60, ShiftPhase(-1.57, DriveChannel(0))) sched = sched.insert(60, SetFrequency(8.0, DriveChannel(0))) sched = sched.insert(60, SetPhase(3.14, DriveChannel(0))) sched = sched.insert(70, ShiftFrequency(4.0e6, DriveChannel(0))) sched = sched.insert(30, Play(gp1, DriveChannel(1))) sched = sched.insert(60, Play(gp0, ControlChannel(0))) sched = sched.insert(60, Play(gs0, MeasureChannel(0))) sched = sched.insert(90, ShiftPhase(1.57, DriveChannel(0))) sched = sched.insert(90, Acquire(10, AcquireChannel(1), MemorySlot(1), RegisterSlot(1))) sched = sched.append(Delay(100, DriveChannel(0))) sched = sched + sched sched |= Snapshot("snapshot_1", "snap_type") << 60 sched |= Snapshot("snapshot_2", "snap_type") << 120 return sched
def test_drive_instruction(self): """Test converted qobj from PulseInstruction.""" instruction = Play(self.linear, DriveChannel(0)) qobj = PulseQobjInstruction(name='linear', ch='d0', t0=10) converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.instructions[0][-1], instruction)
def test_drive_instruction(self): """Test converted qobj from Play.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) instruction = Play(Waveform(np.arange(0, 0.01), name='linear'), DriveChannel(0)) valid_qobj = PulseQobjInstruction(name='linear', ch='d0', t0=0) self.assertEqual(converter(0, instruction), valid_qobj)
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)
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_gaussian_pulse_instruction(self): """Test that parametric pulses are correctly converted to PulseQobjInstructions.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) instruction = Play(Gaussian(duration=25, sigma=15, amp=-0.5 + 0.2j), DriveChannel(0)) valid_qobj = PulseQobjInstruction( name='parametric_pulse', pulse_shape='gaussian', ch='d0', t0=0, parameters={'duration': 25, 'sigma': 15, 'amp': -0.5 + 0.2j}) self.assertEqual(converter(0, instruction), valid_qobj)
def test_constant_pulse_instruction(self): """Test that parametric pulses are correctly converted to PulseQobjInstructions.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) instruction = Play(Constant(duration=25, amp=1), ControlChannel(2)) valid_qobj = PulseQobjInstruction( name='parametric_pulse', pulse_shape='constant', ch='u2', t0=20, parameters={'duration': 25, 'amp': 1}) self.assertEqual(converter(20, instruction), valid_qobj)
def test_parametric_pulses(self): """Test converted qobj from ParametricInstruction.""" instruction = Play(Gaussian(duration=25, sigma=15, amp=-0.5 + 0.2j), DriveChannel(0)) qobj = PulseQobjInstruction( name='parametric_pulse', pulse_shape='gaussian', ch='d0', t0=0, parameters={'duration': 25, 'sigma': 15, 'amp': -0.5 + 0.2j}) converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.timeslots, instruction.timeslots) self.assertEqual(converted_instruction.instructions[0][-1], instruction)
def test_gaussian_square_pulse_instruction(self): """Test that parametric pulses are correctly converted to PulseQobjInstructions.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) instruction = Play(GaussianSquare(duration=1500, sigma=15, amp=-0.5 + 0.2j, width=1300), MeasureChannel(1)) valid_qobj = PulseQobjInstruction( name='parametric_pulse', pulse_shape='gaussian_square', ch='m1', t0=10, parameters={'duration': 1500, 'sigma': 15, 'amp': -0.5 + 0.2j, 'width': 1300}) self.assertEqual(converter(10, instruction), valid_qobj)
def test_constant_pulse_instruction(self): """Test that parametric pulses are correctly converted to PulseQobjInstructions.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) instruction = Play(Constant(duration=25, amp=1), ControlChannel(2)) valid_qobj = PulseQobjInstruction( name="parametric_pulse", pulse_shape="constant", ch="u2", t0=20, parameters={ "duration": 25, "amp": 1 }, ) self.assertEqual(converter(20, instruction), valid_qobj)
def test_gaussian_pulse_instruction(self): """Test that parametric pulses are correctly converted to PulseQobjInstructions.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) instruction = Play(Gaussian(duration=25, sigma=15, amp=-0.5 + 0.2j), DriveChannel(0)) valid_qobj = PulseQobjInstruction( name="parametric_pulse", pulse_shape="gaussian", ch="d0", t0=0, parameters={ "duration": 25, "sigma": 15, "amp": -0.5 + 0.2j }, ) self.assertEqual(converter(0, instruction), valid_qobj)
def test_gaussian_square_pulse_instruction(self): """Test that parametric pulses are correctly converted to PulseQobjInstructions.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) instruction = Play( GaussianSquare(duration=1500, sigma=15, amp=-0.5 + 0.2j, width=1300), MeasureChannel(1)) valid_qobj = PulseQobjInstruction( name="parametric_pulse", pulse_shape="gaussian_square", ch="m1", t0=10, parameters={ "duration": 1500, "sigma": 15, "amp": -0.5 + 0.2j, "width": 1300 }, ) self.assertEqual(converter(10, instruction), valid_qobj)
def test_parametric_pulses(self): """Test converted qobj from ParametricInstruction.""" instruction = Play( Gaussian(duration=25, sigma=15, amp=-0.5 + 0.2j, name="pulse1"), DriveChannel(0)) qobj = PulseQobjInstruction( name="parametric_pulse", label="pulse1", pulse_shape="gaussian", ch="d0", t0=0, parameters={ "duration": 25, "sigma": 15, "amp": -0.5 + 0.2j }, ) converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.start_time, 0) self.assertEqual(converted_instruction.duration, 25) self.assertEqual(converted_instruction.instructions[0][-1], instruction) self.assertEqual(converted_instruction.instructions[0][-1].pulse.name, "pulse1")