Esempio n. 1
0
    def test_single_circuit_delay_calibrations(self):
        """Test that disassembler parses delay instruction back to delay gate."""
        qc = QuantumCircuit(2)
        qc.append(Gate("test", 1, []), [0])
        test_sched = pulse.Delay(64, pulse.DriveChannel(0)) + pulse.Delay(
            160, pulse.DriveChannel(0)
        )

        qc.add_calibration("test", [0], test_sched)

        qobj = assemble(qc, FakeOpenPulse2Q())
        output_circuits, _, _ = disassemble(qobj)

        self.assertEqual(len(qc.calibrations), len(output_circuits[0].calibrations))
        self.assertEqual(qc.calibrations.keys(), output_circuits[0].calibrations.keys())
        self.assertTrue(
            all(
                qc_cal.keys() == out_qc_cal.keys()
                for qc_cal, out_qc_cal in zip(
                    qc.calibrations.values(), output_circuits[0].calibrations.values()
                )
            )
        )
        self.assertEqual(
            qc.calibrations["test"][((0,), ())], output_circuits[0].calibrations["test"][((0,), ())]
        )
    def test_append_an_instruction_to_block_inplace(self):
        """Test append instructions to a non-empty block with inplace."""
        block = pulse.ScheduleBlock()
        block = block.append(pulse.Delay(100, self.d0))

        block.append(pulse.Delay(100, self.d0), inplace=True)

        self.assertEqual(len(block.blocks), 2)
Esempio n. 3
0
    def test_append_an_instruction_to_block(self):
        """Test append instructions to a non-empty block."""
        block = pulse.ScheduleBlock()
        block = block.append(pulse.Delay(100, self.d0))

        block = block.append(pulse.Delay(100, self.d0))

        self.assertEqual(len(block.instructions), 2)
    def test_different_channels(self):
        """Test equality is False if different channels."""
        block1 = pulse.ScheduleBlock()
        block1 += pulse.Delay(10, self.d0)

        block2 = pulse.ScheduleBlock()
        block2 += pulse.Delay(10, self.d1)

        self.assertNotEqual(block1, block2)
    def test_different_transform(self):
        """Test equality is False if different transforms."""
        block1 = pulse.ScheduleBlock(alignment_context=self.left_context)
        block1 += pulse.Delay(10, self.d0)

        block2 = pulse.ScheduleBlock(alignment_context=self.right_context)
        block2 += pulse.Delay(10, self.d0)

        self.assertNotEqual(block1, block2)
Esempio n. 6
0
    def test_padding_until_less(self):
        """Test padding until time that is less than schedule duration."""
        delay = pulse.Delay(10)

        sched = (delay(DriveChannel(0)).shift(10) + delay(DriveChannel(1)))

        ref_sched = (sched | delay(DriveChannel(0))
                     | pulse.Delay(5)(DriveChannel(1)).shift(10))

        self.assertEqual(pad(sched, until=15), ref_sched)
Esempio n. 7
0
    def test_padding_until_greater(self):
        """Test padding until time that is greater than schedule duration."""
        delay = pulse.Delay(10)

        sched = (delay(DriveChannel(0)).shift(10) + delay(DriveChannel(1)))

        ref_sched = (sched | delay(DriveChannel(0))
                     | pulse.Delay(30)(DriveChannel(0)).shift(20)
                     | pulse.Delay(40)(DriveChannel(1)).shift(10))

        self.assertEqual(pad(sched, until=50), ref_sched)
    def test_different_transform_opts(self):
        """Test equality is False if different transform options."""
        context1 = transforms.AlignEquispaced(duration=100)
        context2 = transforms.AlignEquispaced(duration=500)

        block1 = pulse.ScheduleBlock(alignment_context=context1)
        block1 += pulse.Delay(10, self.d0)

        block2 = pulse.ScheduleBlock(alignment_context=context2)
        block2 += pulse.Delay(10, self.d0)

        self.assertNotEqual(block1, block2)
Esempio n. 9
0
    def test_padding_supplied_channels(self):
        """Test padding of only specified channels."""
        delay = pulse.Delay(10)
        double_delay = pulse.Delay(20)

        sched = (delay(DriveChannel(0)).shift(10) + delay(DriveChannel(1)))

        ref_sched = (sched | delay(DriveChannel(0))
                     | double_delay(DriveChannel(2)))

        channels = [DriveChannel(0), DriveChannel(2)]

        self.assertEqual(pad(sched, channels=channels), ref_sched)
    def test_remove_subroutines(self):
        """Test that nested subroutiens are removed."""
        d0 = pulse.DriveChannel(0)

        nested_routine = pulse.Schedule()
        nested_routine.insert(10, pulse.Delay(10, d0), inplace=True)

        subroutine = pulse.Schedule()
        subroutine.insert(0, pulse.Delay(20, d0), inplace=True)
        subroutine.insert(20,
                          pulse.instructions.Call(nested_routine),
                          inplace=True)
        subroutine.insert(50, pulse.Delay(10, d0), inplace=True)

        main_program = pulse.Schedule()
        main_program.insert(0, pulse.Delay(10, d0), inplace=True)
        main_program.insert(30,
                            pulse.instructions.Call(subroutine),
                            inplace=True)

        target = transforms.inline_subroutines(main_program)

        reference = pulse.Schedule()
        reference.insert(0, pulse.Delay(10, d0), inplace=True)
        reference.insert(30, pulse.Delay(20, d0), inplace=True)
        reference.insert(60, pulse.Delay(10, d0), inplace=True)
        reference.insert(80, pulse.Delay(10, d0), inplace=True)

        self.assertEqual(target, reference)
Esempio n. 11
0
    def test_padding_schedule(self):
        """Test padding schedule."""
        delay = pulse.Delay(10)
        double_delay = pulse.Delay(20)

        sched = (delay(pulse.DriveChannel(0)).shift(10) +
                 delay(pulse.DriveChannel(0)).shift(10) +
                 delay(pulse.DriveChannel(1)).shift(10))

        ref_sched = (sched | delay(pulse.DriveChannel(0))
                     | delay(pulse.DriveChannel(0)).shift(20)
                     | delay(pulse.DriveChannel(1))
                     | double_delay(pulse.DriveChannel(1)).shift(20))

        self.assertEqual(pad(sched), ref_sched)
 def test_padding_less_than_sched_duration(self):
     """Test that the until arg is respected even for less than the input schedule duration."""
     delay = 10
     sched = (Delay(delay, DriveChannel(0)) +
              Delay(delay, DriveChannel(0)).shift(20))
     ref_sched = (sched | pulse.Delay(5, DriveChannel(0)).shift(10))
     self.assertEqual(transforms.pad(sched, until=15), ref_sched)
Esempio n. 13
0
    def test_len(self):
        """Test __len__ method"""
        block = pulse.ScheduleBlock()
        self.assertEqual(len(block), 0)

        for j in range(1, 10):
            block = block.append(pulse.Delay(10, self.d0))
            self.assertEqual(len(block), j)
Esempio n. 14
0
    def test_zero_duration_delay(self):
        """Test generating waveforms that contains zero duration delay.

        Zero duration delay should be ignored.
        """
        ch = pulse.DriveChannel(0)

        test_sched = pulse.Schedule()
        test_sched += pulse.Play(pulse.Gaussian(160, 0.1, 40), ch)
        test_sched += pulse.Delay(0, ch)
        test_sched += pulse.Play(pulse.Gaussian(160, 0.1, 40), ch)
        test_sched += pulse.Delay(1, ch)
        test_sched += pulse.Play(pulse.Gaussian(160, 0.1, 40), ch)

        ch_events = events.ChannelEvents.load_program(test_sched, ch)

        self.assertEqual(len(list(ch_events.get_waveforms())), 4)
    def test_delay_duration(self):
        """Test parametrization of delay duration."""
        dur = Parameter('dur')
        ch = pulse.DriveChannel(0)

        test_delay = pulse.Delay(dur, ch)
        test_delay.assign_parameters({dur: 300})

        self.assertEqual(test_delay.duration, 300)
Esempio n. 16
0
    def setUp(self):
        super().setUp()

        self.test_blocks = [
            pulse.Play(self.test_waveform0, self.d0),
            pulse.Play(self.test_waveform1, self.d1),
            pulse.Delay(50, self.d0),
            pulse.Play(self.test_waveform1, self.d0),
        ]
Esempio n. 17
0
    def test_cannot_append_schedule(self):
        """Test schedule cannot be appended. Schedule should be input as Call instruction."""
        block = pulse.ScheduleBlock()

        sched = pulse.Schedule()
        sched += pulse.Delay(10, self.d0)

        with self.assertRaises(PulseError):
            block.append(sched)
Esempio n. 18
0
    def test_padding_schedule_inverse_order(self):
        """Test padding schedule is insensitive to order in which commands were added.

        This test is the same as `test_adding_schedule` but the order by channel
        in which commands were added to the schedule to be padded has been reversed.
        """
        delay = pulse.Delay(10)
        double_delay = pulse.Delay(20)

        sched = (delay(pulse.DriveChannel(1)).shift(10) +
                 delay(pulse.DriveChannel(0)).shift(10) +
                 delay(pulse.DriveChannel(0)).shift(10))

        ref_sched = (sched | delay(pulse.DriveChannel(0))
                     | delay(pulse.DriveChannel(0)).shift(20)
                     | delay(pulse.DriveChannel(1))
                     | double_delay(pulse.DriveChannel(1)).shift(20))

        self.assertEqual(pad(sched), ref_sched)
Esempio n. 19
0
    def test_equispace_alignment(self):
        """Test equispace alignment context."""
        block = pulse.ScheduleBlock(alignment_context=self.equispaced_context)
        for _ in range(4):
            block = block.append(pulse.Play(self.test_waveform0, self.d0))

        ref_sched = pulse.Schedule()
        ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform0,
                                                   self.d0))
        ref_sched = ref_sched.insert(100, pulse.Delay(200, self.d0))
        ref_sched = ref_sched.insert(300,
                                     pulse.Play(self.test_waveform0, self.d0))
        ref_sched = ref_sched.insert(400, pulse.Delay(200, self.d0))
        ref_sched = ref_sched.insert(600,
                                     pulse.Play(self.test_waveform0, self.d0))
        ref_sched = ref_sched.insert(700, pulse.Delay(200, self.d0))
        ref_sched = ref_sched.insert(900,
                                     pulse.Play(self.test_waveform0, self.d0))

        self.assertScheduleEqual(block, ref_sched)
Esempio n. 20
0
    def test_subroutine_not_transformed(self):
        """Test called schedule is not transformed."""
        d0 = pulse.DriveChannel(0)
        d1 = pulse.DriveChannel(1)

        subprogram = pulse.Schedule()
        subprogram.insert(0, pulse.Delay(30, d0), inplace=True)
        subprogram.insert(10, pulse.Delay(10, d1), inplace=True)

        with pulse.build() as target:
            with pulse.align_right():
                pulse.delay(10, d1)
                pulse.call(subprogram)

        reference = pulse.Schedule()
        reference.insert(0, pulse.Delay(10, d1), inplace=True)
        reference.insert(10, pulse.Delay(30, d0), inplace=True)
        reference.insert(20, pulse.Delay(10, d1), inplace=True)

        self.assertScheduleEqual(target, reference)
Esempio n. 21
0
    def test_assemble_with_delay(self):
        """Test that delay instruction is ignored in assembly."""
        backend = FakeOpenPulse2Q()

        orig_schedule = self.schedule
        delay_schedule = orig_schedule + pulse.Delay(10)(self.device.drives[0])

        orig_qobj = assemble(orig_schedule, backend)
        delay_qobj = assemble(delay_schedule, backend)

        self.assertEqual(orig_qobj.experiments[0].to_dict(),
                         delay_qobj.experiments[0].to_dict())
Esempio n. 22
0
    def test_assemble_with_delay(self):
        """Test that delay instruction is ignored in assembly."""
        orig_schedule = self.schedule
        delay_schedule = orig_schedule + pulse.Delay(10, self.backend_config.drive(0))

        orig_qobj = assemble(orig_schedule, self.backend)
        validate_qobj_against_schema(orig_qobj)
        delay_qobj = assemble(delay_schedule, self.backend)
        validate_qobj_against_schema(delay_qobj)

        self.assertEqual(orig_qobj.experiments[0].to_dict(),
                         delay_qobj.experiments[0].to_dict())
Esempio n. 23
0
    def test_replace_instruction_by_block(self):
        """Test replacing instruction with block."""
        sub_block1 = pulse.ScheduleBlock()
        sub_block1 = sub_block1.append(pulse.Delay(50, self.d0))
        sub_block1 = sub_block1.append(pulse.Play(self.test_waveform0,
                                                  self.d0))

        sub_block2 = pulse.ScheduleBlock()
        sub_block2 = sub_block2.append(pulse.Delay(50, self.d0))
        sub_block2 = sub_block2.append(pulse.Play(self.test_waveform1,
                                                  self.d1))

        main_block = pulse.ScheduleBlock()
        main_block = main_block.append(pulse.Delay(50, self.d0))
        main_block = main_block.append(pulse.Play(self.test_waveform0,
                                                  self.d0))
        main_block = main_block.append(pulse.Delay(100, self.d0))
        main_block = main_block.append(sub_block2)
        main_block = main_block.append(pulse.Play(self.test_waveform0,
                                                  self.d1))

        replaced = main_block.replace(pulse.Delay(100, self.d0), sub_block1)

        ref_blocks = [
            pulse.Delay(50, self.d0),
            pulse.Play(self.test_waveform0, self.d0),
            sub_block1,
            sub_block2,
            pulse.Play(self.test_waveform0, self.d1),
        ]

        self.assertListEqual(list(replaced.blocks), ref_blocks)
Esempio n. 24
0
    def test_func_alignment(self):
        """Test func alignment context."""
        block = pulse.ScheduleBlock(alignment_context=self.func_context)
        for _ in range(4):
            block = block.append(pulse.Play(self.test_waveform0, self.d0))

        ref_sched = pulse.Schedule()
        ref_sched = ref_sched.insert(0, pulse.Delay(50, self.d0))
        ref_sched = ref_sched.insert(50,
                                     pulse.Play(self.test_waveform0, self.d0))
        ref_sched = ref_sched.insert(150, pulse.Delay(50, self.d0))
        ref_sched = ref_sched.insert(200,
                                     pulse.Play(self.test_waveform0, self.d0))
        ref_sched = ref_sched.insert(300, pulse.Delay(350, self.d0))
        ref_sched = ref_sched.insert(650,
                                     pulse.Play(self.test_waveform0, self.d0))
        ref_sched = ref_sched.insert(750, pulse.Delay(50, self.d0))
        ref_sched = ref_sched.insert(800,
                                     pulse.Play(self.test_waveform0, self.d0))
        ref_sched = ref_sched.insert(900, pulse.Delay(100, self.d0))

        self.assertScheduleEqual(block, ref_sched)
Esempio n. 25
0
    def test_instruction_out_of_order_complex_not_equal(self):
        """Test complex schedule equality can be correctly evaluated."""
        block1_a = pulse.ScheduleBlock(alignment_context=self.left_context)
        block1_a += pulse.Play(self.test_waveform0, self.d0)
        block1_a += pulse.Play(self.test_waveform1, self.d1)
        block1_a += pulse.Delay(10, self.d0)

        block1_b = pulse.ScheduleBlock(alignment_context=self.left_context)
        block1_b += pulse.Play(self.test_waveform1, self.d1)
        block1_b += pulse.Delay(10, self.d0)
        block1_b += pulse.Play(self.test_waveform0, self.d0)

        block2_a = pulse.ScheduleBlock(alignment_context=self.right_context)
        block2_a += block1_a
        block2_a += block1_b
        block2_a += block1_a

        block2_b = pulse.ScheduleBlock(alignment_context=self.right_context)
        block2_b += block1_a
        block2_b += block1_a
        block2_b += block1_b

        self.assertNotEqual(block2_a, block2_b)
Esempio n. 26
0
    def test_nested_alignment(self):
        """Test nested block scheduling."""
        block_sub = pulse.ScheduleBlock(alignment_context=self.right_context)
        block_sub = block_sub.append(pulse.Play(self.test_waveform0, self.d0))
        block_sub = block_sub.append(pulse.Play(self.test_waveform1, self.d1))

        block_main = pulse.ScheduleBlock(
            alignment_context=self.sequential_context)
        block_main = block_main.append(block_sub)
        block_main = block_main.append(pulse.Delay(10, self.d0))
        block_main = block_main.append(block_sub)

        ref_sched = pulse.Schedule()
        ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform1,
                                                   self.d1))
        ref_sched = ref_sched.insert(100,
                                     pulse.Play(self.test_waveform0, self.d0))
        ref_sched = ref_sched.insert(200, pulse.Delay(10, self.d0))
        ref_sched = ref_sched.insert(210,
                                     pulse.Play(self.test_waveform1, self.d1))
        ref_sched = ref_sched.insert(310,
                                     pulse.Play(self.test_waveform0, self.d0))

        self.assertScheduleEqual(block_main, ref_sched)
Esempio n. 27
0
    def test_assemble_with_delay(self):
        """Test that delay instruction is ignored in assembly."""
        backend = FakeOpenPulse2Q()

        orig_schedule = self.schedule
        with self.assertWarns(DeprecationWarning):
            delay_schedule = orig_schedule + pulse.Delay(10)(
                self.backend_config.drive(0))

        orig_qobj = assemble(orig_schedule, backend)
        validate_qobj_against_schema(orig_qobj)
        delay_qobj = assemble(delay_schedule, backend)
        validate_qobj_against_schema(delay_qobj)

        self.assertEqual(orig_qobj.experiments[0].to_dict(),
                         delay_qobj.experiments[0].to_dict())
Esempio n. 28
0
    def test_replace_parametrized_instruction(self):
        """Test parametrized instruction can updated with parameter table."""
        block = pulse.ScheduleBlock()
        block += pulse.Play(self.test_par_waveform0, self.d0)
        block += pulse.Delay(100, self.d0)
        block += pulse.Play(self.test_waveform0, self.d0)

        replaced = block.replace(pulse.Play(self.test_par_waveform0, self.d0),
                                 pulse.Play(self.test_par_waveform1, self.d0))
        self.assertTrue(replaced.is_parameterized())

        # check assign parameters
        replaced_assigned = replaced.assign_parameters({
            self.dur1: 100,
            self.amp1: 0.1
        })
        self.assertFalse(replaced_assigned.is_parameterized())
Esempio n. 29
0
    def test_replace_inplace(self):
        """Test replacing specific instruction with inplace."""
        block = pulse.ScheduleBlock()
        for inst in self.test_blocks:
            block.append(inst)

        replaced = pulse.Play(pulse.Constant(300, 0.1), self.d1)
        target = pulse.Delay(50, self.d0)

        block.replace(target, replaced, inplace=True)

        ref_sched = pulse.Schedule()
        ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform0,
                                                   self.d0))
        ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform1,
                                                   self.d1))
        ref_sched = ref_sched.insert(200, replaced)
        ref_sched = ref_sched.insert(100,
                                     pulse.Play(self.test_waveform1, self.d0))

        self.assertScheduleEqual(block, ref_sched)
Esempio n. 30
0
    def test_parametrized_context(self):
        """Test parametrize context parameter."""
        duration = circuit.Parameter("dur")
        param_context = transforms.AlignEquispaced(duration=duration)

        block = pulse.ScheduleBlock(alignment_context=param_context)
        block += pulse.Delay(10, self.d0)
        block += pulse.Delay(10, self.d0)
        block += pulse.Delay(10, self.d0)
        block += pulse.Delay(10, self.d0)
        self.assertTrue(block.is_parameterized())
        self.assertFalse(block.is_schedulable())

        block.assign_parameters({duration: 100}, inplace=True)
        self.assertFalse(block.is_parameterized())
        self.assertTrue(block.is_schedulable())

        ref_sched = pulse.Schedule()
        ref_sched = ref_sched.insert(0, pulse.Delay(10, self.d0))
        ref_sched = ref_sched.insert(30, pulse.Delay(10, self.d0))
        ref_sched = ref_sched.insert(60, pulse.Delay(10, self.d0))
        ref_sched = ref_sched.insert(90, pulse.Delay(10, self.d0))

        self.assertScheduleEqual(block, ref_sched)