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_set_phase(self): """Test converted qobj from SetPhase.""" qobj = PulseQobjInstruction(name='setp', ch='m0', t0=0, phase=3.14) converted_instruction = self.converter(qobj) instruction = SetPhase(3.14, MeasureChannel(0)) self.assertEqual(converted_instruction.start_time, 0) self.assertEqual(converted_instruction.duration, 0) self.assertEqual(converted_instruction.instructions[0][-1], instruction)
def test_set_phase(self): """Test converted qobj from ShiftPhase.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) instruction = SetPhase(3.14, DriveChannel(0)) valid_qobj = PulseQobjInstruction(name='setp', ch='d0', t0=0, phase=3.14) self.assertEqual(converter(0, instruction), valid_qobj)
def test_parameterized_set_phase(self): """Test converted qobj from SetPhase, with parameterized phase.""" qobj = PulseQobjInstruction(name='setp', ch='m0', t0=0, phase='p/2') converted_instruction = self.converter(qobj) self.assertIsInstance(converted_instruction, ParameterizedSchedule) evaluated_instruction = converted_instruction.bind_parameters(3.14) instruction = SetPhase(3.14 / 2, MeasureChannel(0)) self.assertEqual(evaluated_instruction.start_time, 0) self.assertEqual(evaluated_instruction.duration, 0) self.assertEqual(evaluated_instruction.instructions[0][-1], instruction)
def test_parameterized_set_phase(self): """Test converted qobj from SetPhase, with parameterized phase.""" qobj = PulseQobjInstruction(name="setp", ch="m0", t0=0, phase="p/2") converted_instruction = self.converter(qobj) self.assertIsInstance(converted_instruction, Schedule) bind_dict = {converted_instruction.get_parameters("p")[0]: 3.14} evaluated_instruction = converted_instruction.assign_parameters( bind_dict) instruction = SetPhase(3.14 / 2, MeasureChannel(0)) self.assertEqual(evaluated_instruction.start_time, 0) self.assertEqual(evaluated_instruction.duration, 0) self.assertEqual(evaluated_instruction.instructions[0][-1], instruction)