Esempio n. 1
0
    def test_can_create_valid_schedule_with_syntax_sugar(self):
        """Test that in place operations on schedule are still immutable
        and return equivalent schedules."""
        gp0 = library.gaussian(duration=20, amp=0.7, sigma=3)
        gp1 = library.gaussian(duration=20, amp=0.5, sigma=3)

        sched = Schedule()
        sched += Play(gp0, self.config.drive(0))
        sched |= ShiftPhase(-1.57, self.config.drive(0)) << 60
        sched |= Play(gp1, self.config.drive(0)) << 30
        sched |= Play(gp0, self.config.control(qubits=[0, 1])[0]) << 60
        sched |= Snapshot("label", "snap_type") << 60
        sched |= ShiftPhase(1.57, self.config.drive(0)) << 90
        sched |= Acquire(10, self.config.acquire(0), MemorySlot(0)) << 90
        sched += sched
Esempio n. 2
0
    def test_multiple_channels_out_of_order(self):
        """Test that schedule with multiple channels equal when out of order."""
        instructions = [(0, ShiftPhase(0, DriveChannel(1))),
                        (1, Acquire(10, AcquireChannel(0), MemorySlot(1)))]

        self.assertEqual(Schedule(*instructions),
                         Schedule(*reversed(instructions)))
Esempio n. 3
0
    def test_custom_filters(self):
        """Test custom filters."""
        lp0 = self.linear(duration=3, slope=0.2, intercept=0.1)
        sched = Schedule(name='fake_experiment')
        sched = sched.insert(0, Play(lp0, self.config.drive(0)))
        sched = sched.insert(10, Play(lp0, self.config.drive(1)))
        sched = sched.insert(30, ShiftPhase(-1.57, self.config.drive(0)))

        filtered, excluded = self._filter_and_test_consistency(
            sched, lambda x: True)
        for i in filtered.instructions:
            self.assertTrue(i in sched.instructions)
        for i in excluded.instructions:
            self.assertFalse(i in sched.instructions)

        filtered, excluded = self._filter_and_test_consistency(
            sched, lambda x: False)
        self.assertEqual(len(filtered.instructions), 0)
        self.assertEqual(len(excluded.instructions), 3)

        filtered, excluded = self._filter_and_test_consistency(
            sched, lambda x: x[0] < 30)
        self.assertEqual(len(filtered.instructions), 2)
        self.assertEqual(len(excluded.instructions), 1)

        # multiple custom filters
        filtered, excluded = self._filter_and_test_consistency(
            sched, lambda x: x[0] > 0, lambda x: x[0] < 30)
        self.assertEqual(len(filtered.instructions), 1)
        self.assertEqual(len(excluded.instructions), 2)
    def test_filter_inst_types(self):
        """Test filtering on instruction types."""
        lp0 = self.linear(duration=3, slope=0.2, intercept=0.1)
        sched = Schedule(name="fake_experiment")
        sched = sched.insert(0, Play(lp0, self.config.drive(0)))
        sched = sched.insert(10, Play(lp0, self.config.drive(1)))
        sched = sched.insert(30, ShiftPhase(-1.57, self.config.drive(0)))
        sched = sched.insert(40, SetFrequency(8.0, self.config.drive(0)))
        sched = sched.insert(50, ShiftFrequency(4.0e6, self.config.drive(0)))
        sched = sched.insert(55, SetPhase(3.14, self.config.drive(0)))
        for i in range(2):
            sched = sched.insert(
                60, Acquire(5, self.config.acquire(i), MemorySlot(i)))
        sched = sched.insert(90, Play(lp0, self.config.drive(0)))

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

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

        # 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), 8)

        # test on SetPhase
        only_setp, no_setp = self._filter_and_test_consistency(
            sched, instruction_types={SetPhase})
        self.assertEqual(len(only_setp.instructions), 1)
        self.assertEqual(len(no_setp.instructions), 8)

        # test on SetFrequency
        only_setf, no_setf = self._filter_and_test_consistency(
            sched, instruction_types=[SetFrequency])
        for _, inst in only_setf.instructions:
            self.assertTrue(isinstance(inst, SetFrequency))
        self.assertEqual(len(only_setf.instructions), 1)
        self.assertEqual(len(no_setf.instructions), 8)

        # test on ShiftFrequency
        only_shiftf, no_shiftf = self._filter_and_test_consistency(
            sched, instruction_types=[ShiftFrequency])
        for _, inst in only_shiftf.instructions:
            self.assertTrue(isinstance(inst, ShiftFrequency))
        self.assertEqual(len(only_shiftf.instructions), 1)
        self.assertEqual(len(no_shiftf.instructions), 8)
Esempio n. 5
0
    def test_single_channel_out_of_order(self):
        """Test that schedule with single channel equal when out of order."""
        instructions = [(0, ShiftPhase(0, DriveChannel(0))),
                        (15, Play(SamplePulse(np.ones(10)), DriveChannel(0))),
                        (5, Play(SamplePulse(np.ones(10)), DriveChannel(0)))]

        self.assertEqual(Schedule(*instructions), Schedule(*reversed(instructions)))
Esempio n. 6
0
def pulsemaker_to_qiskit(instructions):
    '''Translate pulsemaker to qiskit-schedule format'''

    try:
        from qiskit import pulse
        from qiskit.pulse import Schedule, Play, DriveChannel, ControlChannel, Waveform, ShiftPhase, SetFrequency
    except ImportError:
        return Schedule()

    schedule = Schedule()
    for c, data in instructions.items():
        channel_type = c[0]
        channel_index = int(c[1:])
        if channel_type == 'd':
            channel = DriveChannel(channel_index)
        elif channel_type == 'u':
            channel = ControlChannel(channel_index)

        current_sample_count = 0
        for type, payload in data:
            if type == InstructionType.PULSE:
                sample_count = len(payload)
                if sample_count == 1:
                    continue
                schedule |= Play(Waveform(payload),
                                 channel).shift(current_sample_count)
                current_sample_count += sample_count
            elif type == InstructionType.PHASE:
                schedule |= ShiftPhase(payload,
                                       channel).shift(current_sample_count)
            elif type == InstructionType.FREQ:
                schedule |= SetFrequency(payload,
                                         channel).shift(current_sample_count)

    return schedule
Esempio n. 7
0
    def test_name_inherited(self):
        """Test that schedule keeps name if an instruction is added."""
        gp0 = pulse_lib.gaussian(duration=100,
                                 amp=0.7,
                                 sigma=3,
                                 name='pulse_name')
        with self.assertWarns(DeprecationWarning):
            pv0 = PersistentValue(0.1)
        snapshot = Snapshot('snapshot_label', 'state')

        sched1 = Schedule(name='test_name')
        sched2 = Schedule(name=None)
        sched3 = sched1 | sched2
        self.assertEqual(sched3.name, 'test_name')

        sched_acq = Acquire(
            10, self.config.acquire(1), MemorySlot(1),
            name='acq_name') | sched1
        self.assertEqual(sched_acq.name, 'acq_name')

        sched_pulse = Play(gp0, self.config.drive(0)) | sched1
        self.assertEqual(sched_pulse.name, 'pulse_name')

        with self.assertWarns(DeprecationWarning):
            sched_pv = pv0(self.config.drive(0), name='pv_name') | sched1
        self.assertEqual(sched_pv.name, 'pv_name')

        sched_fc = ShiftPhase(0.1, self.config.drive(0),
                              name='fc_name') | sched1
        self.assertEqual(sched_fc.name, 'fc_name')

        sched_snapshot = snapshot | sched1
        self.assertEqual(sched_snapshot.name, 'snapshot_label')
Esempio n. 8
0
    def test_default(self):
        """Test basic ShiftPhase."""
        shift_phase = ShiftPhase(1.57, DriveChannel(0))

        self.assertEqual(shift_phase.phase, 1.57)
        self.assertEqual(shift_phase.duration, 0)
        self.assertTrue(shift_phase.name.startswith('shiftphase'))
    def test_name_inherited(self):
        """Test that schedule keeps name if an instruction is added."""
        gp0 = library.gaussian(duration=100,
                               amp=0.7,
                               sigma=3,
                               name="pulse_name")
        snapshot = Snapshot("snapshot_label", "state")

        sched1 = Schedule(name="test_name")
        sched2 = Schedule(name=None)
        sched3 = sched1 | sched2
        self.assertEqual(sched3.name, "test_name")

        sched_acq = Acquire(
            10, self.config.acquire(1), MemorySlot(1),
            name="acq_name") | sched1
        self.assertEqual(sched_acq.name, "acq_name")

        sched_pulse = Play(gp0, self.config.drive(0)) | sched1
        self.assertEqual(sched_pulse.name, "pulse_name")

        sched_fc = ShiftPhase(0.1, self.config.drive(0),
                              name="fc_name") | sched1
        self.assertEqual(sched_fc.name, "fc_name")

        sched_snapshot = snapshot | sched1
        self.assertEqual(sched_snapshot.name, "snapshot_label")
Esempio n. 10
0
    def test_pulse_to_signals(self):
        """Generic test."""

        sched = Schedule(name="Schedule")
        sched += Play(Drag(duration=20, amp=0.5, sigma=4, beta=0.5),
                      DriveChannel(0))
        sched += ShiftPhase(1.0, DriveChannel(0))
        sched += Play(Drag(duration=20, amp=0.5, sigma=4, beta=0.5),
                      DriveChannel(0))
        sched += ShiftFrequency(0.5, DriveChannel(0))
        sched += Play(
            GaussianSquare(duration=200, amp=0.3, sigma=4, width=150),
            DriveChannel(0))

        test_gaussian = GaussianSquare(duration=200,
                                       amp=0.3,
                                       sigma=4,
                                       width=150)
        sched = sched.insert(0, Play(test_gaussian, DriveChannel(1)))

        converter = InstructionToSignals(dt=1, carriers=None)

        signals = converter.get_signals(sched)

        self.assertEqual(len(signals), 2)
        self.assertTrue(isinstance(signals[0], PiecewiseConstant))
        self.assertTrue(isinstance(signals[0], PiecewiseConstant))

        samples = test_gaussian.get_waveform().samples
        self.assertTrue(
            np.allclose(signals[1].samples[0:len(samples)], samples))
    def _1Q_frame_change_schedule(self, phi, fc_phi, total_samples, dur_drive1,
                                  dur_drive2):
        """Creates schedule for frame change test. Does a pulse w/ phase phi of duration dur_drive1,
        then frame change of phase fc_phi, then another pulse of phase phi of duration dur_drive2.
        The different durations for the pulses allow manipulation of rotation angles on Bloch sphere

        Args:
            phi (float): drive phase (phi in Hamiltonian)
            fc_phi (float): phase for frame change
            total_samples (int): length of pulses
            dur_drive1 (int): duration of first pulse
            dur_drive2 (int): duration of second pulse

        Returns:
            schedule (pulse schedule): schedule for frame change test
        """
        phase = np.exp(1j * phi)
        drive_pulse_1 = SamplePulse(phase * np.ones(dur_drive1),
                                    name='drive_pulse_1')
        drive_pulse_2 = SamplePulse(phase * np.ones(dur_drive2),
                                    name='drive_pulse_2')

        # add commands to schedule
        schedule = Schedule(name='fc_schedule')
        schedule |= Play(drive_pulse_1, DriveChannel(0))
        schedule += ShiftPhase(fc_phi, DriveChannel(0))
        schedule += Play(drive_pulse_2, DriveChannel(0))
        schedule |= Acquire(total_samples, AcquireChannel(0),
                            MemorySlot(0)) << schedule.duration

        return schedule
Esempio n. 12
0
    def test_filter_channels(self):
        """Test filtering over channels."""
        lp0 = self.linear(duration=3, slope=0.2, intercept=0.1)
        sched = Schedule(name='fake_experiment')
        sched = sched.insert(0, Play(lp0, self.config.drive(0)))
        sched = sched.insert(10, Play(lp0, self.config.drive(1)))
        sched = sched.insert(30, ShiftPhase(-1.57, self.config.drive(0)))
        sched = sched.insert(60, Acquire(5, AcquireChannel(0), MemorySlot(0)))
        sched = sched.insert(60, Acquire(5, AcquireChannel(1), MemorySlot(1)))
        sched = sched.insert(90, Play(lp0, self.config.drive(0)))

        # split instructions for those on AcquireChannel(1) and those not
        filtered, excluded = self._filter_and_test_consistency(
            sched, channels=[AcquireChannel(1)])
        self.assertEqual(len(filtered.instructions), 1)
        self.assertEqual(len(excluded.instructions), 5)

        # Split schedule into the part with channels on 1 and into a part without
        channels = [AcquireChannel(1), DriveChannel(1)]
        filtered, excluded = self._filter_and_test_consistency(
            sched, channels=channels)
        for _, inst in filtered.instructions:
            self.assertTrue(any([chan in channels for chan in inst.channels]))

        for _, inst in excluded.instructions:
            self.assertFalse(any([chan in channels for chan in inst.channels]))
Esempio n. 13
0
    def test_timeslots(self):
        """Test schedule.timeslots."""
        reference_sched = Schedule()
        reference_sched = reference_sched.insert(10,
                                                 Delay(10, DriveChannel(0)))
        reference_sched = reference_sched.insert(10,
                                                 Delay(50, DriveChannel(1)))
        reference_sched = reference_sched.insert(
            10, ShiftPhase(0.1, DriveChannel(0)))

        reference_sched = reference_sched.insert(
            100, ShiftPhase(0.1, DriveChannel(1)))

        self.assertEqual(reference_sched.timeslots[DriveChannel(0)],
                         [(10, 10), (10, 20)])
        self.assertEqual(reference_sched.timeslots[DriveChannel(1)],
                         [(10, 60), (100, 100)])
Esempio n. 14
0
    def test_ch_duration(self):
        """Test schedule.ch_duration."""
        reference_sched = Schedule()
        reference_sched = reference_sched.insert(
            10, Delay(10, DriveChannel(0)))
        reference_sched = reference_sched.insert(
            10, Delay(50, DriveChannel(1)))
        reference_sched = reference_sched.insert(
            10, ShiftPhase(0.1, DriveChannel(0)))

        reference_sched = reference_sched.insert(
            100, ShiftPhase(0.1, DriveChannel(1)))

        self.assertEqual(reference_sched.ch_duration(DriveChannel(0)), 20)
        self.assertEqual(reference_sched.ch_duration(DriveChannel(1)), 100)
        self.assertEqual(reference_sched.ch_duration(*reference_sched.channels),
                         reference_sched.duration)
Esempio n. 15
0
    def test_can_create_valid_schedule_with_syntax_sugar(self):
        """Test that in place operations on schedule are still immutable
           and return equivalent schedules."""
        gp0 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3)
        gp1 = pulse_lib.gaussian(duration=20, amp=0.5, sigma=3)

        sched = Schedule()
        sched += Play(gp0, self.config.drive(0))
        with self.assertWarns(DeprecationWarning):
            sched |= PersistentValue(value=0.2 + 0.4j)(self.config.control(
                [0, 1])[0])
        sched |= ShiftPhase(-1.57, self.config.drive(0)) << 60
        sched |= Play(gp1, self.config.drive(0)) << 30
        sched |= Play(gp0, self.config.control(qubits=[0, 1])[0]) << 60
        sched |= Snapshot("label", "snap_type") << 60
        sched |= ShiftPhase(1.57, self.config.drive(0)) << 90
        sched |= Acquire(10, self.config.acquire(0), MemorySlot(0)) << 90
        sched += sched
Esempio n. 16
0
    def test_can_create_valid_schedule_with_syntax_sugar(self):
        """Test that in place operations on schedule are still immutable
           and return equivalent schedules."""
        gp0 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3)
        gp1 = pulse_lib.gaussian(duration=20, amp=0.5, sigma=3)
        acquire = Acquire(10)

        sched = Schedule()
        sched += gp0(self.config.drive(0))
        sched |= PersistentValue(value=0.2 + 0.4j)(self.config.control(0))
        sched |= ShiftPhase(-1.57, self.config.drive(0)) << 60
        sched |= gp1(self.config.drive(0)) << 30
        sched |= gp0(self.config.control(0)) << 60
        sched |= Snapshot("label", "snap_type") << 60
        sched |= ShiftPhase(1.57, self.config.drive(0)) << 90
        sched |= acquire(self.config.acquire(0), MemorySlot(0),
                         RegisterSlot(0)) << 90
        sched += sched
Esempio n. 17
0
    def test_filter_intervals(self):
        """Test filtering on intervals."""
        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)))

        # split schedule into instructions occurring in (0,13), and those outside
        filtered, excluded = self._filter_and_test_consistency(
            sched, time_ranges=((0, 13), ))
        for start_time, inst in filtered.instructions:
            self.assertTrue((start_time >= 0)
                            and (start_time + inst.stop_time <= 13))
        for start_time, inst in excluded.instructions:
            self.assertFalse((start_time >= 0)
                             and (start_time + inst.stop_time <= 13))
        self.assertEqual(len(filtered.instructions), 2)
        self.assertEqual(len(excluded.instructions), 4)

        # split into schedule occurring in and outside of interval (59,65)
        filtered, excluded = self._filter_and_test_consistency(sched,
                                                               time_ranges=[
                                                                   (59, 65)
                                                               ])
        self.assertEqual(len(filtered.instructions), 2)
        self.assertEqual(filtered.instructions[0][0], 60)
        self.assertIsInstance(filtered.instructions[0][1], Acquire)
        self.assertEqual(len(excluded.instructions), 4)
        self.assertEqual(excluded.instructions[3][0], 90)
        self.assertIsInstance(excluded.instructions[3][1], Play)

        # split instructions based on the interval
        # (none should be, though they have some overlap with some of the instructions)
        filtered, excluded = \
            self._filter_and_test_consistency(sched, time_ranges=[(0, 2), (8, 11), (61, 70)])
        self.assertEqual(len(filtered.instructions), 0)
        self.assertEqual(len(excluded.instructions), 6)

        # split instructions from multiple non-overlapping intervals, specified
        # as time ranges
        filtered, excluded = \
            self._filter_and_test_consistency(sched, time_ranges=[(10, 15), (63, 93)])
        self.assertEqual(len(filtered.instructions), 2)
        self.assertEqual(len(excluded.instructions), 4)

        # split instructions from non-overlapping intervals, specified as Intervals
        filtered, excluded = \
            self._filter_and_test_consistency(sched, intervals=[Interval(10, 15), Interval(63, 93)])
        self.assertEqual(len(filtered.instructions), 2)
        self.assertEqual(len(excluded.instructions), 4)
    def test_check_user_cals(self):
        """Test if schedules provided by user is distinguishable."""
        instmap = FakeOpenPulse2Q().defaults().instruction_schedule_map

        test_u1 = Schedule()
        test_u1 += ShiftPhase(Parameter("P0"), DriveChannel(0))

        instmap.add("u1", (0, ), test_u1, arguments=["P0"])
        publisher = instmap.get("u1", (0, ), P0=0).metadata["publisher"]

        self.assertEqual(publisher, CalibrationPublisher.QISKIT)
    def test_get_schedule_with_unbound_parameter(self):
        """Test get schedule with partial binding."""
        param1 = Parameter("param1")
        param2 = Parameter("param2")

        target_sched = Schedule()
        target_sched.insert(0, ShiftPhase(param1, DriveChannel(0)), inplace=True)
        target_sched.insert(10, ShiftPhase(param2, DriveChannel(0)), inplace=True)

        inst_map = InstructionScheduleMap()
        inst_map.add("target_sched", (0,), target_sched)

        ref_sched = Schedule()
        ref_sched.insert(0, ShiftPhase(param1, DriveChannel(0)), inplace=True)
        ref_sched.insert(10, ShiftPhase(1.23, DriveChannel(0)), inplace=True)

        test_sched = inst_map.get("target_sched", (0,), param2=1.23)

        for test_inst, ref_inst in zip(test_sched.instructions, ref_sched.instructions):
            self.assertEqual(test_inst[0], ref_inst[0])
            self.assertAlmostEqual(test_inst[1], ref_inst[1])
    def test_binding_unassigned_parameters(self):
        """Test getting schedule with unassigned parameter binding."""
        param = Parameter("param")

        target_sched = Schedule()
        target_sched.insert(0, ShiftPhase(param, DriveChannel(0)), inplace=True)

        inst_map = InstructionScheduleMap()
        inst_map.add("target_sched", (0,), target_sched)

        with self.assertRaises(PulseError):
            inst_map.get("target_sched", (0,), P0=0)
    def test_binding_too_many_parameters(self):
        """Test getting schedule with too many parameter binding."""
        param = Parameter('param')

        target_sched = Schedule()
        target_sched.insert(0, ShiftPhase(param, DriveChannel(0)), inplace=True)

        inst_map = InstructionScheduleMap()
        inst_map.add('target_sched', (0,), target_sched)

        with self.assertRaises(PulseError):
            inst_map.get('target_sched', (0,), 0, 1, 2, 3)
    def test_schedule_with_non_alphanumeric_ordering(self):
        """Test adding and getting schedule with non obvious parameter ordering."""
        theta = Parameter("theta")
        phi = Parameter("phi")
        lamb = Parameter("lambda")

        target_sched = Schedule()
        target_sched.insert(0, ShiftPhase(theta, DriveChannel(0)), inplace=True)
        target_sched.insert(10, ShiftPhase(phi, DriveChannel(0)), inplace=True)
        target_sched.insert(20, ShiftPhase(lamb, DriveChannel(0)), inplace=True)

        inst_map = InstructionScheduleMap()
        inst_map.add("target_sched", (0,), target_sched, arguments=["theta", "phi", "lambda"])

        ref_sched = Schedule()
        ref_sched.insert(0, ShiftPhase(0, DriveChannel(0)), inplace=True)
        ref_sched.insert(10, ShiftPhase(1, DriveChannel(0)), inplace=True)
        ref_sched.insert(20, ShiftPhase(2, DriveChannel(0)), inplace=True)

        # if parameter is alphanumerical ordering this maps to
        # theta -> 2
        # phi -> 1
        # lamb -> 0
        # however non alphanumerical ordering is specified in add method thus mapping should be
        # theta -> 0
        # phi -> 1
        # lamb -> 2
        test_sched = inst_map.get("target_sched", (0,), 0, 1, 2)

        for test_inst, ref_inst in zip(test_sched.instructions, ref_sched.instructions):
            self.assertEqual(test_inst[0], ref_inst[0])
            self.assertEqual(test_inst[1], ref_inst[1])
Esempio n. 23
0
    def test_schedule_with_multiple_parameters_under_same_name(self):
        """Test getting schedule with parameters that have the same name."""
        param1 = Parameter('param')
        param2 = Parameter('param')
        param3 = Parameter('param')

        target_sched = Schedule()
        target_sched.insert(0,
                            ShiftPhase(param1, DriveChannel(0)),
                            inplace=True)
        target_sched.insert(10,
                            ShiftPhase(param2, DriveChannel(0)),
                            inplace=True)
        target_sched.insert(20,
                            ShiftPhase(param3, DriveChannel(0)),
                            inplace=True)

        inst_map = InstructionScheduleMap()
        inst_map.add('target_sched', (0, ), target_sched)

        ref_sched = Schedule()
        ref_sched.insert(0, ShiftPhase(1.23, DriveChannel(0)), inplace=True)
        ref_sched.insert(10, ShiftPhase(1.23, DriveChannel(0)), inplace=True)
        ref_sched.insert(20, ShiftPhase(1.23, DriveChannel(0)), inplace=True)

        test_sched = inst_map.get('target_sched', (0, ), param=1.23)

        for test_inst, ref_inst in zip(test_sched.instructions,
                                       ref_sched.instructions):
            self.assertEqual(test_inst[0], ref_inst[0])
            self.assertAlmostEqual(test_inst[1], ref_inst[1])
Esempio n. 24
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, 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)))

        # 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), 5)
        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, (ShiftPhase, PulseInstruction))
        self.assertTrue(len(filtered.instructions), 4)
        # make sure the PulseInstruction not in the intervals is maintained
        self.assertIsInstance(excluded.instructions[0][1], PulseInstruction)

        # split based on AcquireInstruction in the specified intervals
        filtered, excluded = self._filter_and_test_consistency(
            sched,
            instruction_types=[AcquireInstruction],
            time_ranges=[(25, 100)])
        self.assertTrue(len(excluded.instructions), 4)
        for _, inst in filtered.instructions:
            self.assertIsInstance(inst, AcquireInstruction)
        self.assertTrue(len(filtered.instructions), 2)
Esempio n. 25
0
    def test_shift_phase_to_signals(self):
        """Test that a shift phase gives negative envelope."""

        gaussian = Gaussian(duration=20, amp=0.5, sigma=4)

        sched = Schedule(name="Schedule")
        sched += ShiftPhase(np.pi, DriveChannel(0))
        sched += Play(gaussian, DriveChannel(0))

        converter = InstructionToSignals(dt=1, carriers=None)
        signals = converter.get_signals(sched)

        self.assertTrue(signals[0].samples[10] < 0)
        self.assertTrue(gaussian.get_waveform().samples[10] > 0)
Esempio n. 26
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)))
        sched = sched.insert(40, SetFrequency(8.0, 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=[Acquire])
        for _, inst in only_acquire.instructions:
            self.assertIsInstance(inst, Acquire)
        for _, inst in no_acquire.instructions:
            self.assertFalse(isinstance(inst, Acquire))

        # 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), 3)

        # 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), 6)

        # test on SetFrequency
        only_sf, no_sf = \
            self._filter_and_test_consistency(sched,
                                              instruction_types=[SetFrequency])
        for _, inst in only_sf.instructions:
            self.assertTrue(isinstance(inst, SetFrequency))
        self.assertEqual(len(only_sf.instructions), 1)
        self.assertEqual(len(no_sf.instructions), 6)
Esempio n. 27
0
    def test_empty_filters(self):
        """Test behavior on empty filters."""
        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)))

        # empty channels
        filtered, excluded = self._filter_and_test_consistency(sched,
                                                               channels=[])
        self.assertTrue(len(filtered.instructions) == 0)
        self.assertTrue(len(excluded.instructions) == 6)

        # empty instruction_types
        filtered, excluded = self._filter_and_test_consistency(
            sched, instruction_types=[])
        self.assertTrue(len(filtered.instructions) == 0)
        self.assertTrue(len(excluded.instructions) == 6)

        # empty time_ranges
        filtered, excluded = self._filter_and_test_consistency(sched,
                                                               time_ranges=[])
        self.assertTrue(len(filtered.instructions) == 0)
        self.assertTrue(len(excluded.instructions) == 6)

        # empty intervals
        filtered, excluded = self._filter_and_test_consistency(sched,
                                                               intervals=[])
        self.assertTrue(len(filtered.instructions) == 0)
        self.assertTrue(len(excluded.instructions) == 6)

        # empty channels with other non-empty filters
        filtered, excluded = self._filter_and_test_consistency(
            sched, channels=[], instruction_types=[PulseInstruction])
        self.assertTrue(len(filtered.instructions) == 0)
        self.assertTrue(len(excluded.instructions) == 6)
Esempio n. 28
0
 def test_different_time_not_equal(self):
     """Test that not equal if instruction at different time."""
     self.assertNotEqual(Schedule((0, ShiftPhase(0, DriveChannel(1)))),
                         Schedule((1, ShiftPhase(0, DriveChannel(1)))))
Esempio n. 29
0
    def test_same_time_equal(self):
        """Test equal if instruction at same time."""

        self.assertEqual(Schedule((0, ShiftPhase(0, DriveChannel(1)))),
                         Schedule((0, ShiftPhase(0, DriveChannel(1)))))
Esempio n. 30
0
 def test_different_channels(self):
     """Test equality is False if different channels."""
     self.assertNotEqual(Schedule(ShiftPhase(0, DriveChannel(0))),
                         Schedule(ShiftPhase(0, DriveChannel(1))))