def test_acquire(self):
        """Test converted qobj from Acquire."""
        schedule = Schedule()
        for i in range(self.num_qubits):
            schedule |= Acquire(10,
                                AcquireChannel(i),
                                MemorySlot(i),
                                RegisterSlot(i),
                                kernel=Kernel(name='test_kern',
                                              test_params='test'),
                                discriminator=Discriminator(name='test_disc',
                                                            test_params=1.0))

        qobj = PulseQobjInstruction(
            name='acquire',
            t0=0,
            duration=10,
            qubits=[0, 1],
            memory_slot=[0, 1],
            register_slot=[0, 1],
            kernels=[
                QobjMeasurementOption(name='test_kern',
                                      params={'test_params': 'test'})
            ],
            discriminators=[
                QobjMeasurementOption(name='test_disc',
                                      params={'test_params': 1.0})
            ])
        converted_instruction = self.converter(qobj)

        self.assertEqual(converted_instruction.timeslots, schedule.timeslots)
        self.assertEqual(converted_instruction.instructions[0][-1].duration,
                         10)
        self.assertEqual(
            converted_instruction.instructions[0][-1].kernel.params,
            {'test_params': 'test'})
        self.assertEqual(converted_instruction.instructions[1][-1].channel,
                         AcquireChannel(1))
Ejemplo n.º 2
0
    def test_filter_inst_types(self):
        """Test filtering on instruction types."""
        device = self.two_qubit_device
        lp0 = self.linear(duration=3, slope=0.2, intercept=0.1)
        acquire = Acquire(5)
        sched = Schedule(name='fake_experiment')
        sched = sched.insert(0, lp0(device.drives[0]))
        sched = sched.insert(10, lp0(device.drives[1]))
        sched = sched.insert(30, FrameChange(phase=-1.57)(device.drives[0]))
        sched = sched.insert(60, acquire(device.acquires, device.memoryslots))
        sched = sched.insert(90, lp0(device.drives[0]))

        only_acquires = sched.filter(instruction_types=[AcquireInstruction])
        for _, inst in only_acquires.instructions:
            self.assertIsInstance(inst, AcquireInstruction)
        only_pulse_and_fc = sched.filter(
            instruction_types=[PulseInstruction, FrameChangeInstruction])
        for _, inst in only_pulse_and_fc.instructions:
            self.assertIsInstance(inst,
                                  (PulseInstruction, FrameChangeInstruction))
        self.assertEqual(len(only_pulse_and_fc.instructions), 4)
        only_fc = sched.filter(instruction_types={FrameChangeInstruction})
        self.assertEqual(len(only_fc.instructions), 1)
Ejemplo n.º 3
0
    def test_filter_inst_types(self):
        """Test filtering on instruction types."""
        lp0 = self.linear(duration=3, slope=0.2, intercept=0.1)
        acquire = Acquire(5)
        sched = Schedule(name='fake_experiment')
        sched = sched.insert(0, lp0(self.config.drive(0)))
        sched = sched.insert(10, lp0(self.config.drive(1)))
        sched = sched.insert(30, ShiftPhase(-1.57, self.config.drive(0)))
        for i in range(2):
            sched = sched.insert(
                60, acquire(self.config.acquire(i), MemorySlot(i)))
        sched = sched.insert(90, lp0(self.config.drive(0)))

        # test on Acquire
        only_acquire, no_acquire = \
            self._filter_and_test_consistency(sched, instruction_types=[AcquireInstruction])
        for _, inst in only_acquire.instructions:
            self.assertIsInstance(inst, AcquireInstruction)
        for _, inst in no_acquire.instructions:
            self.assertFalse(isinstance(inst, AcquireInstruction))

        # test two instruction types
        only_pulse_and_fc, no_pulse_and_fc = \
            self._filter_and_test_consistency(sched, instruction_types=[PulseInstruction,
                                                                        ShiftPhase])
        for _, inst in only_pulse_and_fc.instructions:
            self.assertIsInstance(inst, (PulseInstruction, ShiftPhase))
        for _, inst in no_pulse_and_fc.instructions:
            self.assertFalse(isinstance(inst, (PulseInstruction, ShiftPhase)))
        self.assertEqual(len(only_pulse_and_fc.instructions), 4)
        self.assertEqual(len(no_pulse_and_fc.instructions), 2)

        # 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), 5)
Ejemplo n.º 4
0
    def test_buffering(self):
        """Test channel buffering."""
        buffer_chan = DriveChannel(0, buffer=5)
        measure_chan = MeasureChannel(0, buffer=10)
        acquire_chan = AcquireChannel(0, buffer=10)
        memory_slot = MemorySlot(0)
        gp0 = pulse_lib.gaussian(duration=10, amp=0.7, sigma=3)
        fc_pi_2 = FrameChange(phase=1.57)

        # no initial buffer
        sched = Schedule()
        sched += gp0(buffer_chan)

        self.assertEqual(sched.duration, 10)

        # this pulse should be buffered
        sched += gp0(buffer_chan)

        self.assertEqual(sched.duration, 25)

        # should not be buffered as framechange
        sched += fc_pi_2(buffer_chan)

        self.assertEqual(sched.duration, 25)

        # use buffer with insert
        sched = sched.insert(sched.duration, gp0(buffer_chan), buffer=True)

        self.assertEqual(sched.duration, 40)

        sched = Schedule()

        sched = gp0(measure_chan) + Acquire(duration=10)(acquire_chan,
                                                         memory_slot)

        self.assertEqual(sched.duration, 10)
Ejemplo n.º 5
0
    def test_filter_multiple(self):
        """Test filter composition."""
        device = self.two_qubit_device
        lp0 = self.linear(duration=3, slope=0.2, intercept=0.1)
        acquire = Acquire(5)
        sched = Schedule(name='fake_experiment')
        sched = sched.insert(0, lp0(device.q[0].drive))
        sched = sched.insert(10, lp0(device.q[1].drive))
        sched = sched.insert(30, FrameChange(phase=-1.57)(device.q[0].drive))
        sched = sched.insert(60, acquire(device.q, device.mem))
        sched = sched.insert(90, lp0(device.q[0].drive))

        filtered = sched.filter(channels={0}, instruction_types=[PulseInstruction],
                                time_ranges=[(25, 100)])
        for time, inst in filtered.instructions:
            self.assertIsInstance(inst, PulseInstruction)
            self.assertTrue(any([chan.index == 0 for chan in inst.channels]))
            self.assertTrue(25 <= time <= 100)

        filtered_b = sched.filter(instruction_types=[PulseInstruction, FrameChangeInstruction],
                                  time_ranges=[(25, 100), (0, 30)])
        for time, inst in filtered_b.instructions:
            self.assertIsInstance(inst, (FrameChangeInstruction, PulseInstruction))
        self.assertTrue(len(filtered_b.instructions), 4)
Ejemplo n.º 6
0
    def test_filter_multiple(self):
        """Test filter composition."""
        lp0 = self.linear(duration=3, slope=0.2, intercept=0.1)
        acquire = Acquire(5)
        sched = Schedule(name='fake_experiment')
        sched = sched.insert(0, lp0(self.config.drive(0)))
        sched = sched.insert(10, lp0(self.config.drive(1)))
        sched = sched.insert(30, FrameChange(phase=-1.57)(self.config.drive(0)))
        sched = sched.insert(60, acquire([self.config.acquire(i) for i in range(2)],
                                         [MemorySlot(i) for i in range(2)]))
        sched = sched.insert(90, lp0(self.config.drive(0)))

        # split instructions with filters on channel 0, of type PulseInstruction,
        # occurring in the time interval (25, 100)
        filtered, excluded = self._filter_and_test_consistency(sched,
                                                               channels={self.config.drive(0)},
                                                               instruction_types=[PulseInstruction],
                                                               time_ranges=[(25, 100)])
        for time, inst in filtered.instructions:
            self.assertIsInstance(inst, PulseInstruction)
            self.assertTrue(all([chan.index == 0 for chan in inst.channels]))
            self.assertTrue(25 <= time <= 100)
        self.assertEqual(len(excluded.instructions), 4)
        self.assertTrue(excluded.instructions[0][1].channels[0] == DriveChannel(0))
        self.assertTrue(excluded.instructions[2][0] == 30)

        # split based on PulseInstructions in the specified intervals
        filtered, excluded = self._filter_and_test_consistency(sched,
                                                               instruction_types=[PulseInstruction],
                                                               time_ranges=[(25, 100), (0, 11)])
        self.assertTrue(len(excluded.instructions), 3)
        for time, inst in filtered.instructions:
            self.assertIsInstance(inst, (FrameChangeInstruction, PulseInstruction))
        self.assertTrue(len(filtered.instructions), 4)
        # make sure the PulseInstruction not in the intervals is maintained
        self.assertIsInstance(excluded.instructions[0][1], PulseInstruction)
Ejemplo n.º 7
0
    def test_can_create_valid_schedule(self):
        """Test valid schedule creation without error."""
        device = self.two_qubit_device

        # pylint: disable=invalid-name
        @functional_pulse
        def gaussian(duration, amp, t0, sig):
            x = np.linspace(0, duration - 1, duration)
            return amp * np.exp(-(x - t0)**2 / sig**2)

        gp0 = gaussian(duration=20, amp=0.7, t0=9.5, sig=3)
        gp1 = gaussian(duration=20, amp=0.5, t0=9.5, sig=3)

        fc_pi_2 = FrameChange(phase=1.57)
        acquire = Acquire(10)
        sched = Schedule()
        sched = sched.append(gp0(device.q[0].drive))
        sched = sched.insert(
            0,
            PersistentValue(value=0.2 + 0.4j)(device.q[0].control))
        sched = sched.insert(60, FrameChange(phase=-1.57)(device.q[0].drive))
        sched = sched.insert(30, gp1(device.q[1].drive))
        sched = sched.insert(60, gp0(device.q[0].control))
        sched = sched.insert(80, Snapshot("label", "snap_type"))
        sched = sched.insert(90, fc_pi_2(device.q[0].drive))
        sched = sched.insert(90,
                             acquire(device.q[1], device.mem[1], device.c[1]))
        self.assertEqual(0, sched.start_time)
        self.assertEqual(100, sched.stop_time)
        self.assertEqual(100, sched.duration)
        new_sched = Schedule()
        new_sched = new_sched.append(sched)
        new_sched = new_sched.append(sched)
        self.assertEqual(0, new_sched.start_time)
        self.assertEqual(200, new_sched.stop_time)
        self.assertEqual(200, new_sched.duration)
Ejemplo n.º 8
0
        def my_test_make_schedule(acquire: int, memoryslot: int, shift: int):
            op = Acquire(acquire)
            sched1 = op(AcquireChannel(0), MemorySlot(memoryslot))
            sched2 = op(AcquireChannel(1), MemorySlot(memoryslot)).shift(shift)

            return Schedule(sched1, sched2)
Ejemplo n.º 9
0
    def test_multiple_channels_out_of_order(self):
        """Test that schedule with multiple channels equal when out of order."""
        instructions = [(0, FrameChange(0)(DriveChannel(1))),
                        (1, Acquire(10)(AcquireChannel(0), MemorySlot(1)))]

        self.assertEqual(Schedule(*instructions), Schedule(*reversed(instructions)))