def test_pulse_to_signals(self): """Generic test.""" sched = Schedule(name="Schedule") sched += Play(Drag(duration=20, amp=0.5, sigma=4, beta=0.5), DriveChannel(0)) sched += ShiftPhase(1.0, DriveChannel(0)) sched += Play(Drag(duration=20, amp=0.5, sigma=4, beta=0.5), DriveChannel(0)) sched += ShiftFrequency(0.5, DriveChannel(0)) sched += Play( GaussianSquare(duration=200, amp=0.3, sigma=4, width=150), DriveChannel(0)) test_gaussian = GaussianSquare(duration=200, amp=0.3, sigma=4, width=150) sched = sched.insert(0, Play(test_gaussian, DriveChannel(1))) converter = InstructionToSignals(dt=1, carriers=None) signals = converter.get_signals(sched) self.assertEqual(len(signals), 2) self.assertTrue(isinstance(signals[0], PiecewiseConstant)) self.assertTrue(isinstance(signals[0], PiecewiseConstant)) samples = test_gaussian.get_waveform().samples self.assertTrue( np.allclose(signals[1].samples[0:len(samples)], samples))
def test_filter_inst_types(self): """Test filtering on instruction types.""" lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) sched = Schedule(name="fake_experiment") sched = sched.insert(0, Play(lp0, self.config.drive(0))) sched = sched.insert(10, Play(lp0, self.config.drive(1))) sched = sched.insert(30, ShiftPhase(-1.57, self.config.drive(0))) sched = sched.insert(40, SetFrequency(8.0, self.config.drive(0))) sched = sched.insert(50, ShiftFrequency(4.0e6, self.config.drive(0))) sched = sched.insert(55, SetPhase(3.14, self.config.drive(0))) for i in range(2): sched = sched.insert( 60, Acquire(5, self.config.acquire(i), MemorySlot(i))) sched = sched.insert(90, Play(lp0, self.config.drive(0))) # test on Acquire only_acquire, no_acquire = self._filter_and_test_consistency( sched, instruction_types=[Acquire]) for _, inst in only_acquire.instructions: self.assertIsInstance(inst, Acquire) for _, inst in no_acquire.instructions: self.assertFalse(isinstance(inst, Acquire)) # test two instruction types only_pulse_and_fc, no_pulse_and_fc = self._filter_and_test_consistency( sched, instruction_types=[Play, ShiftPhase]) for _, inst in only_pulse_and_fc.instructions: self.assertIsInstance(inst, (Play, ShiftPhase)) for _, inst in no_pulse_and_fc.instructions: self.assertFalse(isinstance(inst, (Play, ShiftPhase))) self.assertEqual(len(only_pulse_and_fc.instructions), 4) self.assertEqual(len(no_pulse_and_fc.instructions), 5) # test on ShiftPhase only_fc, no_fc = self._filter_and_test_consistency( sched, instruction_types={ShiftPhase}) self.assertEqual(len(only_fc.instructions), 1) self.assertEqual(len(no_fc.instructions), 8) # test on SetPhase only_setp, no_setp = self._filter_and_test_consistency( sched, instruction_types={SetPhase}) self.assertEqual(len(only_setp.instructions), 1) self.assertEqual(len(no_setp.instructions), 8) # test on SetFrequency only_setf, no_setf = self._filter_and_test_consistency( sched, instruction_types=[SetFrequency]) for _, inst in only_setf.instructions: self.assertTrue(isinstance(inst, SetFrequency)) self.assertEqual(len(only_setf.instructions), 1) self.assertEqual(len(no_setf.instructions), 8) # test on ShiftFrequency only_shiftf, no_shiftf = self._filter_and_test_consistency( sched, instruction_types=[ShiftFrequency]) for _, inst in only_shiftf.instructions: self.assertTrue(isinstance(inst, ShiftFrequency)) self.assertEqual(len(only_shiftf.instructions), 1) self.assertEqual(len(no_shiftf.instructions), 8)
def test_shift_frequency(self): """Test that the frequency is properly taken into account.""" sched = Schedule() sched += ShiftFrequency(1.0, DriveChannel(0)) sched += Play(Constant(duration=10, amp=1.0), DriveChannel(0)) converter = InstructionToSignals(dt=0.222, carriers=[5.0]) signals = converter.get_signals(sched) for idx in range(10): self.assertEqual(signals[0].samples[idx], np.exp(2.0j * idx * np.pi * 1.0 * 0.222))