예제 #1
0
    def test_remove_trivial_barriers(self):
        """Test that trivial barriers are properly removed."""
        schedule = pulse.Schedule()
        schedule += directives.RelativeBarrier()
        schedule += directives.RelativeBarrier(pulse.DriveChannel(0))
        schedule += directives.RelativeBarrier(pulse.DriveChannel(0), pulse.DriveChannel(1))
        schedule = transforms.remove_trivial_barriers(schedule)

        reference = pulse.Schedule()
        reference += directives.RelativeBarrier(pulse.DriveChannel(0), pulse.DriveChannel(1))
        self.assertEqual(schedule, reference)
    def test_align_right_with_barrier(self):
        """Test right alignment with a barrier."""
        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.insert(2, instructions.Delay(5, d1), inplace=True)
        sched_grouped += instructions.Delay(7, d0)

        schedule.append(sched_grouped, inplace=True)
        schedule = transforms.remove_directives(
            transforms.align_right(schedule))

        reference = pulse.Schedule()
        # d0
        reference.insert(0, instructions.Delay(3, d0), inplace=True)
        reference.insert(7, instructions.Delay(7, d0), inplace=True)
        # d1
        reference.insert(9, instructions.Delay(5, d1), inplace=True)
        # d2
        reference.insert(3, instructions.Delay(11, d2), inplace=True)

        self.assertEqual(schedule, reference)
    def test_align_sequential_with_barrier(self):
        """Test sequential alignment with a barrier."""
        d0 = pulse.DriveChannel(0)
        d1 = pulse.DriveChannel(1)

        schedule = pulse.Schedule()
        schedule.insert(1, instructions.Delay(3, d0), inplace=True)
        schedule.append(directives.RelativeBarrier(d0, d1), inplace=True)
        schedule.insert(4, instructions.Delay(5, d1), inplace=True)
        schedule.insert(12, instructions.Delay(7, d0), inplace=True)

        schedule = transforms.align_sequential(schedule)

        reference = pulse.Schedule()
        reference.insert(0, instructions.Delay(3, d0), inplace=True)
        reference.insert(3, directives.RelativeBarrier(d0, d1), inplace=True)
        reference.insert(3, instructions.Delay(5, d1), inplace=True)
        reference.insert(8, instructions.Delay(7, d0), inplace=True)

        self.assertEqual(schedule, reference)
예제 #4
0
    def test_barrier_on_qubits(self):
        """Test barrier directive on qubits."""
        with pulse.build(self.backend) as schedule:
            pulse.barrier(0, 1)

        reference = pulse.Schedule()
        reference += directives.RelativeBarrier(pulse.DriveChannel(0),
                                                pulse.DriveChannel(1),
                                                pulse.MeasureChannel(0),
                                                pulse.MeasureChannel(1),
                                                pulse.ControlChannel(0),
                                                pulse.ControlChannel(1),
                                                pulse.AcquireChannel(0),
                                                pulse.AcquireChannel(1))
        self.assertEqual(schedule, reference)