def test_set_parameter_to_complex_schedule(self): """Test get parameters from complicated schedule.""" test_block = deepcopy(self.test_sched) value_dict = { self.amp1_1: 0.1, self.amp1_2: 0.2, self.amp2: 0.3, self.amp3: 0.4, self.dur1: 100, self.dur2: 125, self.dur3: 150, self.ch1: 0, self.ch2: 2, self.ch3: 4, self.phi1: 1.0, self.phi2: 2.0, self.phi3: 3.0, self.meas_dur: 300, self.mem1: 3, self.reg1: 0, self.context_dur: 1000, } visitor = ParameterSetter(param_map=value_dict) assigned = visitor.visit(test_block) # create ref schedule subroutine = pulse.ScheduleBlock(alignment_context=AlignLeft()) subroutine += pulse.ShiftPhase(1.0, pulse.DriveChannel(0)) subroutine += pulse.Play(pulse.Gaussian(100, 0.3, 25), pulse.DriveChannel(0)) sched = pulse.Schedule() sched += pulse.ShiftPhase(3.0, pulse.DriveChannel(4)) ref_obj = pulse.ScheduleBlock(alignment_context=AlignEquispaced(1000), name="long_schedule") ref_obj += subroutine ref_obj += pulse.ShiftPhase(2.0, pulse.DriveChannel(2)) ref_obj += pulse.Play(pulse.Gaussian(125, 0.3, 25), pulse.DriveChannel(2)) ref_obj += pulse.Call(sched) ref_obj += pulse.Play(pulse.Gaussian(150, 0.4, 25), pulse.DriveChannel(4)) ref_obj += pulse.Acquire(300, pulse.AcquireChannel(0), pulse.MemorySlot(3), pulse.RegisterSlot(0)) self.assertEqual(assigned, ref_obj)
def setUp(self): """Just some useful, reusable Parameters, constants, schedules.""" super().setUp() self.amp1_1 = Parameter("amp1_1") self.amp1_2 = Parameter("amp1_2") self.amp2 = Parameter("amp2") self.amp3 = Parameter("amp3") self.dur1 = Parameter("dur1") self.dur2 = Parameter("dur2") self.dur3 = Parameter("dur3") self.parametric_waveform1 = pulse.Gaussian(duration=self.dur1, amp=self.amp1_1 + self.amp1_2, sigma=self.dur1 / 4) self.parametric_waveform2 = pulse.Gaussian(duration=self.dur2, amp=self.amp2, sigma=self.dur2 / 5) self.parametric_waveform3 = pulse.Gaussian(duration=self.dur3, amp=self.amp3, sigma=self.dur3 / 6) self.ch1 = Parameter("ch1") self.ch2 = Parameter("ch2") self.ch3 = Parameter("ch3") self.d1 = pulse.DriveChannel(self.ch1) self.d2 = pulse.DriveChannel(self.ch2) self.d3 = pulse.DriveChannel(self.ch3) self.phi1 = Parameter("phi1") self.phi2 = Parameter("phi2") self.phi3 = Parameter("phi3") self.meas_dur = Parameter("meas_dur") self.mem1 = Parameter("s1") self.reg1 = Parameter("m1") self.context_dur = Parameter("context_dur") # schedule under test subroutine = pulse.ScheduleBlock(alignment_context=AlignLeft()) subroutine += pulse.ShiftPhase(self.phi1, self.d1) subroutine += pulse.Play(self.parametric_waveform1, self.d1) sched = pulse.Schedule() sched += pulse.ShiftPhase(self.phi3, self.d3) long_schedule = pulse.ScheduleBlock(alignment_context=AlignEquispaced( self.context_dur), name="long_schedule") long_schedule += subroutine long_schedule += pulse.ShiftPhase(self.phi2, self.d2) long_schedule += pulse.Play(self.parametric_waveform2, self.d2) long_schedule += pulse.Call(sched) long_schedule += pulse.Play(self.parametric_waveform3, self.d3) long_schedule += pulse.Acquire( self.meas_dur, pulse.AcquireChannel(self.ch1), mem_slot=pulse.MemorySlot(self.mem1), reg_slot=pulse.RegisterSlot(self.reg1), ) self.test_sched = long_schedule