def test_flatten(self): """Test the flatten transform.""" context_left = transforms.AlignLeft() d0 = pulse.DriveChannel(0) d1 = pulse.DriveChannel(1) schedule = pulse.Schedule() schedule += instructions.Delay(3, d0) grouped = pulse.Schedule() grouped += instructions.Delay(5, d1) grouped += instructions.Delay(7, d0) # include a grouped schedule grouped = schedule + grouped # flatten the schedule inline internal groups flattened = transforms.flatten(grouped) # align all the instructions to the left after flattening flattened = context_left.align(flattened) grouped = context_left.align(grouped) reference = pulse.Schedule() # d0 reference.insert(0, instructions.Delay(3, d0), inplace=True) reference.insert(3, instructions.Delay(7, d0), inplace=True) # d1 reference.insert(0, instructions.Delay(5, d1), inplace=True) self.assertEqual(flattened, reference) self.assertNotEqual(grouped, reference)
def test_align_left_with_barrier(self): """Test left alignment with a barrier.""" context = transforms.AlignLeft() d0 = pulse.DriveChannel(0) d1 = pulse.DriveChannel(1) d2 = pulse.DriveChannel(2) schedule = pulse.Schedule() schedule.insert(1, instructions.Delay(3, d0), inplace=True) schedule.append(directives.RelativeBarrier(d0, d1, d2), inplace=True) schedule.insert(17, instructions.Delay(11, d2), inplace=True) sched_grouped = pulse.Schedule() sched_grouped += instructions.Delay(5, d1) sched_grouped += instructions.Delay(7, d0) schedule.append(sched_grouped, inplace=True) schedule = transforms.remove_directives(context.align(schedule)) reference = pulse.Schedule() # d0 reference.insert(0, instructions.Delay(3, d0), inplace=True) reference.insert(3, instructions.Delay(7, d0), inplace=True) # d1 reference = reference.insert(3, instructions.Delay(5, d1)) # d2 reference = reference.insert(3, instructions.Delay(11, d2)) self.assertEqual(schedule, reference)
def setUp(self): super().setUp() self.backend = FakeOpenPulse2Q() self.test_waveform0 = pulse.Constant(100, 0.1) self.test_waveform1 = pulse.Constant(200, 0.1) self.d0 = pulse.DriveChannel(0) self.d1 = pulse.DriveChannel(1) self.left_context = transforms.AlignLeft() self.right_context = transforms.AlignRight() self.sequential_context = transforms.AlignSequential() self.equispaced_context = transforms.AlignEquispaced(duration=1000) def _align_func(j): return {1: 0.1, 2: 0.25, 3: 0.7, 4: 0.85}.get(j) self.func_context = transforms.AlignFunc(duration=1000, func=_align_func)