示例#1
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]))
    def test_measure_combined(self):
        """
        Test to check for measure on the same qubit which generated another measure schedule.

        The measures on different qubits are combined, but measures on the same qubit
        adds another measure to the schedule.
        """
        q = QuantumRegister(2)
        c = ClassicalRegister(2)
        qc = QuantumCircuit(q, c)
        qc.append(U2Gate(3.14, 1.57), [q[0]])
        qc.cx(q[0], q[1])
        qc.measure(q[0], c[0])
        qc.measure(q[1], c[1])
        qc.measure(q[1], c[1])
        sched = schedule(qc, self.backend, method="as_soon_as_possible")
        expected = Schedule(
            self.inst_map.get('u2', [0], 3.14,
                              1.57), (28, self.inst_map.get('cx', [0, 1])),
            (50, self.inst_map.get('measure', [0, 1])),
            (60, self.inst_map.get(
                'measure', [0, 1]).filter(channels=[MeasureChannel(1)])),
            (60, Acquire(10, AcquireChannel(0), MemorySlot(0))),
            (60, Acquire(10, AcquireChannel(1), MemorySlot(1))))
        self.assertEqual(sched.instructions, expected.instructions)
示例#3
0
        def my_test_make_schedule(acquire: int, memoryslot: int, shift: int):
            sched1 = Acquire(acquire, AcquireChannel(0),
                             MemorySlot(memoryslot))
            sched2 = Acquire(acquire, AcquireChannel(1),
                             MemorySlot(memoryslot)).shift(shift)

            return Schedule(sched1, sched2)
示例#4
0
    def _schedule_2Q_interaction(self,
                                 total_samples,
                                 drive_idx=0,
                                 target_idx=1,
                                 U_idx=1):
        """Creates schedule for testing two qubit interaction. Specifically, do a pi pulse on qub 0
        so it starts in the `1` state (drive channel) and then apply constant pulses to each
        qubit (on control channel 1). This will allow us to test a swap gate.

        Args:
            total_samples (int): length of pulses
        Returns:
            schedule (pulse schedule): schedule for 2q experiment
        """

        # create acquire schedule
        acq_sched = Schedule(name='acq_sched')
        acq_sched |= Acquire(total_samples, AcquireChannel(drive_idx),
                             MemorySlot(drive_idx))
        acq_sched += Acquire(total_samples, AcquireChannel(target_idx),
                             MemorySlot(target_idx))

        # set up const pulse
        const_pulse = SamplePulse(np.ones(total_samples), name='const_pulse')

        # add commands to schedule
        schedule = Schedule(name='2q_schedule')
        schedule |= Play(const_pulse, DriveChannel(drive_idx))
        schedule += Play(const_pulse,
                         ControlChannel(U_idx)) << schedule.duration
        schedule |= acq_sched << schedule.duration

        return schedule
 def test_multiple_measure_in_3Q(self):
     """Test multiple measure, user memslot mapping, 3Q."""
     backend = FakeOpenPulse3Q()
     cmd_def = backend.defaults().build_cmd_def()
     q = QuantumRegister(3)
     c = ClassicalRegister(5)
     qc = QuantumCircuit(q, c)
     qc.measure(q[0], c[2])
     qc.measure(q[0], c[4])
     sched = schedule(qc, backend)
     expected = Schedule(
         cmd_def.get('measure',
                     [0, 1, 2]).filter(channels=[MeasureChannel(0)]),
         Acquire(duration=10)(
             [AcquireChannel(0),
              AcquireChannel(1),
              AcquireChannel(2)],
             [MemorySlot(2), MemorySlot(0),
              MemorySlot(1)]),
         (10, cmd_def.get('measure',
                          [0, 1, 2]).filter(channels=[MeasureChannel(0)])),
         (10, Acquire(duration=10)(
             [AcquireChannel(0),
              AcquireChannel(1),
              AcquireChannel(2)],
             [MemorySlot(4), MemorySlot(0),
              MemorySlot(1)])))
     self.assertEqual(sched.instructions, expected.instructions)
    def test_assemble_with_individual_discriminators(self):
        """Test that assembly works with individual discriminators."""
        disc_one = Discriminator('disc_one', test_params=True)
        disc_two = Discriminator('disc_two', test_params=False)

        schedule = Schedule()
        schedule = schedule.append(
            Acquire(5,
                    AcquireChannel(0),
                    MemorySlot(0),
                    discriminator=disc_one), )
        schedule = schedule.append(
            Acquire(5,
                    AcquireChannel(1),
                    MemorySlot(1),
                    discriminator=disc_two), )

        qobj = assemble(schedule,
                        qubit_lo_freq=self.default_qubit_lo_freq,
                        meas_lo_freq=self.default_meas_lo_freq,
                        meas_map=[[0, 1]])
        validate_qobj_against_schema(qobj)

        qobj_discriminators = qobj.experiments[0].instructions[
            0].discriminators
        self.assertEqual(len(qobj_discriminators), 2)
        self.assertEqual(qobj_discriminators[0].name, 'disc_one')
        self.assertEqual(qobj_discriminators[0].params['test_params'], True)
        self.assertEqual(qobj_discriminators[1].name, 'disc_two')
        self.assertEqual(qobj_discriminators[1].params['test_params'], False)
    def test_single_and_deprecated_acquire_styles(self):
        """Test that acquires are identically combined with Acquires that take a single channel."""
        backend = FakeOpenPulse2Q()
        new_style_schedule = Schedule()
        acq_dur = 1200
        for i in range(5):
            new_style_schedule += Acquire(acq_dur, AcquireChannel(i),
                                          MemorySlot(i))

        deprecated_style_schedule = Schedule()
        for i in range(5):
            deprecated_style_schedule += Acquire(1200, AcquireChannel(i),
                                                 MemorySlot(i))

        # The Qobj IDs will be different
        n_qobj = assemble(new_style_schedule, backend)
        n_qobj.qobj_id = None
        n_qobj.experiments[0].header.name = None
        d_qobj = assemble(deprecated_style_schedule, backend)
        d_qobj.qobj_id = None
        d_qobj.experiments[0].header.name = None
        self.assertEqual(n_qobj, d_qobj)

        assembled_acquire = n_qobj.experiments[0].instructions[0]
        self.assertEqual(assembled_acquire.qubits, [0, 1, 2, 3, 4])
        self.assertEqual(assembled_acquire.memory_slot, [0, 1, 2, 3, 4])
示例#8
0
    def test_multi_acquire(self):
        """Test that an error is raised if multiple acquires occur on the same channel."""
        sched = pulse.Schedule(name='fake_experiment')
        sched = sched.insert(0, Play(self.short_pulse, self.config.drive(0)))
        sched = sched.insert(4,
                             Acquire(5, self.config.acquire(0), MemorySlot(0)))
        sched = sched.insert(10,
                             Acquire(5, self.config.acquire(0), MemorySlot(0)))
        with self.assertRaises(PulseError):
            transforms.align_measures([sched], self.inst_map)

        # Test for measure channel
        sched = pulse.Schedule(name='fake_experiment')
        sched = sched.insert(10, Play(self.short_pulse,
                                      self.config.measure(0)))
        sched = sched.insert(30, Play(self.short_pulse,
                                      self.config.measure(0)))
        with self.assertRaises(PulseError):
            transforms.align_measures([sched], self.inst_map)

        # Test both using inst_map
        sched = pulse.Schedule()
        sched += self.inst_map.get('measure', (0, 1))
        transforms.align_measures([sched], align_time=50)
        sched += self.inst_map.get('measure', (0, 1))
        with self.assertRaises(PulseError):
            transforms.align_measures([sched], align_time=50)
示例#9
0
 def test_align_measures(self):
     """Test that one acquire is delayed to match the time of the later acquire."""
     sched = pulse.Schedule(name='fake_experiment')
     sched = sched.insert(0, Play(self.short_pulse, self.config.drive(0)))
     sched = sched.insert(1,
                          Acquire(5, self.config.acquire(0), MemorySlot(0)))
     sched = sched.insert(10,
                          Acquire(5, self.config.acquire(1), MemorySlot(1)))
     sched = sched.insert(10, Play(self.short_pulse,
                                   self.config.measure(0)))
     sched = sched.insert(10, Play(self.short_pulse,
                                   self.config.measure(1)))
     sched = transforms.align_measures([sched], self.inst_map)[0]
     self.assertEqual(sched.name, 'fake_experiment')
     for time, inst in sched.instructions:
         if isinstance(inst, Acquire):
             self.assertEqual(time, 10)
     sched = transforms.align_measures([sched],
                                       self.inst_map,
                                       align_time=20)[0]
     for time, inst in sched.instructions:
         if isinstance(inst, Acquire):
             self.assertEqual(time, 20)
         if isinstance(inst.channels[0], MeasureChannel):
             self.assertEqual(time, 20)
    def test_align_all(self):
        """Test alignment of all instructions in a schedule."""
        sched0 = pulse.Schedule()
        sched0.insert(0, Play(self.short_pulse, self.config.drive(0)), inplace=True)
        sched0.insert(10, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True)

        sched1 = pulse.Schedule()
        sched1.insert(25, Play(self.short_pulse, self.config.drive(0)), inplace=True)
        sched1.insert(25, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True)

        all_aligned = transforms.align_measures([sched0, sched1], self.inst_map, align_all=True)

        ref1_aligned = pulse.Schedule()
        ref1_aligned.insert(15, Play(self.short_pulse, self.config.drive(0)), inplace=True)
        ref1_aligned.insert(25, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True)

        self.assertEqual(all_aligned[0], ref1_aligned)
        self.assertEqual(all_aligned[1], sched1)

        ref1_not_aligned = pulse.Schedule()
        ref1_not_aligned.insert(0, Play(self.short_pulse, self.config.drive(0)), inplace=True)
        ref1_not_aligned.insert(25, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True)

        all_not_aligned = transforms.align_measures(
            [sched0, sched1],
            self.inst_map,
            align_all=False,
        )
        self.assertEqual(all_not_aligned[0], ref1_not_aligned)
        self.assertEqual(all_not_aligned[1], sched1)
示例#11
0
 def test_measure(self):
     """Test macro - measure."""
     sched = macros.measure(qubits=[0], backend=self.backend)
     expected = Schedule(
         self.inst_map.get('measure',
                           [0, 1]).filter(channels=[MeasureChannel(0)]),
         Acquire(10, AcquireChannel(0), MemorySlot(0)),
         Acquire(10, AcquireChannel(1), MemorySlot(1)))
     self.assertEqual(sched.instructions, expected.instructions)
示例#12
0
 def setUp(self):
     self.backend = FakeOpenPulse2Q()
     self.config = self.backend.configuration()
     self.short_pulse = pulse.Waveform(samples=np.array([0.02739068], dtype=np.complex128),
                                       name='p0')
     sched = pulse.Schedule(name='fake_experiment')
     sched = sched.insert(0, Play(self.short_pulse, self.config.drive(0)))
     sched = sched.insert(5, Acquire(5, self.config.acquire(0), MemorySlot(0)))
     sched = sched.insert(5, Acquire(5, self.config.acquire(1), MemorySlot(1)))
     self.sched = sched
示例#13
0
 def test_measure_sched_with_qubit_mem_slots(self):
     """Test measure with custom qubit_mem_slots."""
     sched = macros.measure(qubits=[0],
                            backend=self.backend,
                            qubit_mem_slots={0: 1})
     expected = Schedule(
         self.inst_map.get('measure', [0, 1]).filter(channels=[MeasureChannel(0)]),
         Acquire(10, AcquireChannel(0), MemorySlot(1)),
         Acquire(10, AcquireChannel(1), MemorySlot(0)))
     self.assertEqual(sched.instructions, expected.instructions)
示例#14
0
    def test_delay_acquire_channel(self):
        """Test Delay on DriveChannel"""

        acquire_ch = self.config.acquire(0)
        # should pass as is an append
        sched = Delay(self.delay_time, acquire_ch) + Acquire(10, acquire_ch, MemorySlot(0))
        self.assertIsInstance(sched, Schedule)
        # should fail due to overlap
        with self.assertRaises(PulseError):
            sched = Delay(self.delay_time, acquire_ch) | Acquire(10, acquire_ch, MemorySlot(0))
            self.assertIsInstance(sched, Schedule)
示例#15
0
    def test_filter_exclude_name(self):
        """Test the name of the schedules after applying filter and exclude functions."""
        sched = Schedule(name='test-schedule')
        sched = sched.insert(10, Acquire(5, AcquireChannel(0), MemorySlot(0)))
        sched = sched.insert(10, Acquire(5, AcquireChannel(1), MemorySlot(1)))
        excluded = sched.exclude(channels=[AcquireChannel(0)])
        filtered = sched.filter(channels=[AcquireChannel(1)])

        # check if the excluded and filtered schedule have the same name as sched
        self.assertEqual(sched.name, filtered.name)
        self.assertEqual(sched.name, excluded.name)
    def test_can_construct_acquire_command_with_default_values(self):
        """Test if an acquire command can be constructed with default discriminator and kernel.
        """
        acq_command_a = Acquire(duration=10)
        acq_command_b = Acquire(duration=10)

        self.assertEqual(acq_command_a.duration, 10)
        self.assertEqual(acq_command_a.discriminator, None)
        self.assertEqual(acq_command_a.kernel, None)
        self.assertTrue(acq_command_a.name.startswith('acq'))
        self.assertNotEqual(acq_command_a.name, acq_command_b.name)
        self.assertEqual(acq_command_b.name,
                         'acq' + str(int(acq_command_a.name[3:]) + 1))
示例#17
0
 def test_measure_sched_with_meas_map(self):
     """Test measure with custom meas_map as list and dict."""
     sched_with_meas_map_list = macros.measure(qubits=[0],
                                               backend=self.backend,
                                               meas_map=[[0, 1]])
     sched_with_meas_map_dict = macros.measure(qubits=[0],
                                               backend=self.backend,
                                               meas_map={0: [0, 1], 1: [0, 1]})
     expected = Schedule(
         self.inst_map.get('measure', [0, 1]).filter(channels=[MeasureChannel(0)]),
         Acquire(10, AcquireChannel(0), MemorySlot(0)),
         Acquire(10, AcquireChannel(1), MemorySlot(1)))
     self.assertEqual(sched_with_meas_map_list.instructions, expected.instructions)
     self.assertEqual(sched_with_meas_map_dict.instructions, expected.instructions)
示例#18
0
 def test_measurement_at_zero(self):
     """Test that acquire at t=0 works."""
     sched1 = pulse.Schedule(name="fake_experiment")
     sched1 = sched1.insert(0, Play(self.short_pulse, self.config.drive(0)))
     sched1 = sched1.insert(0, Acquire(5, self.config.acquire(0), MemorySlot(0)))
     sched2 = pulse.Schedule(name="fake_experiment")
     sched2 = sched2.insert(0, Play(self.short_pulse, self.config.drive(0)))
     sched2 = sched2.insert(0, Acquire(5, self.config.acquire(0), MemorySlot(0)))
     schedules = transforms.align_measures([sched1, sched2], max_calibration_duration=0)
     for time, inst in schedules[0].instructions:
         if isinstance(inst, Acquire):
             self.assertEqual(time, 0)
     for time, inst in schedules[0].instructions:
         if isinstance(inst, Acquire):
             self.assertEqual(time, 0)
示例#19
0
 def test_align_across_schedules(self):
     """Test that acquires are aligned together across multiple schedules."""
     sched1 = pulse.Schedule(name="fake_experiment")
     sched1 = sched1.insert(0, Play(self.short_pulse, self.config.drive(0)))
     sched1 = sched1.insert(10, Acquire(5, self.config.acquire(0), MemorySlot(0)))
     sched2 = pulse.Schedule(name="fake_experiment")
     sched2 = sched2.insert(3, Play(self.short_pulse, self.config.drive(0)))
     sched2 = sched2.insert(25, Acquire(5, self.config.acquire(0), MemorySlot(0)))
     schedules = transforms.align_measures([sched1, sched2], self.inst_map)
     for time, inst in schedules[0].instructions:
         if isinstance(inst, Acquire):
             self.assertEqual(time, 25)
     for time, inst in schedules[0].instructions:
         if isinstance(inst, Acquire):
             self.assertEqual(time, 25)
示例#20
0
    def test_can_create_valid_schedule(self):
        """Test valid schedule creation without error."""
        gp0 = library.gaussian(duration=20, amp=0.7, sigma=3)
        gp1 = library.gaussian(duration=20, amp=0.7, sigma=3)

        sched = Schedule()
        sched = sched.append(Play(gp0, self.config.drive(0)))
        sched = sched.insert(60, ShiftPhase(-1.57, self.config.drive(0)))
        sched = sched.insert(30, Play(gp1, self.config.drive(0)))
        sched = sched.insert(60, Play(gp0, self.config.control([0, 1])[0]))
        sched = sched.insert(80, Snapshot("label", "snap_type"))
        sched = sched.insert(90, ShiftPhase(1.57, self.config.drive(0)))
        sched = sched.insert(
            90, Acquire(10, self.config.acquire(0), MemorySlot(0), RegisterSlot(0))
        )
        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)
        ids = set()
        for _, inst in sched.instructions:
            self.assertFalse(inst.id in ids)
            ids.add(inst.id)
示例#21
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')
示例#22
0
    def test_can_create_valid_schedule(self):
        """Test valid schedule creation without error."""
        gp0 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3)
        gp1 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3)

        sched = Schedule()
        sched = sched.append(Play(gp0, self.config.drive(0)))
        with self.assertWarns(DeprecationWarning):
            sched = sched.insert(
                0,
                PersistentValue(value=0.2 + 0.4j)(self.config.control([0,
                                                                       1])[0]))
        sched = sched.insert(60, ShiftPhase(-1.57, self.config.drive(0)))
        sched = sched.insert(30, Play(gp1, self.config.drive(0)))
        sched = sched.insert(60, Play(gp0, self.config.control([0, 1])[0]))
        sched = sched.insert(80, Snapshot("label", "snap_type"))
        sched = sched.insert(90, ShiftPhase(1.57, self.config.drive(0)))
        sched = sched.insert(
            90,
            Acquire(10, self.config.acquire(0), MemorySlot(0),
                    RegisterSlot(0)))  # TODO: this shouldn't raise a warning
        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)
        ids = set()
        for _, inst in sched.instructions:
            self.assertFalse(inst.id in ids)
            ids.add(inst.id)
示例#23
0
    def test_default(self):
        """Test default discriminator and kernel.
        """
        kernel_opts = {'start_window': 0, 'stop_window': 10}
        kernel = Kernel(name='boxcar', **kernel_opts)

        discriminator_opts = {
            'neighborhoods': [{
                'qubits': 1,
                'channels': 1
            }],
            'cal': 'coloring',
            'resample': False
        }
        discriminator = Discriminator(name='linear_discriminator',
                                      **discriminator_opts)

        acq_command = Acquire(duration=10,
                              kernel=kernel,
                              discriminator=discriminator)

        self.assertEqual(acq_command.duration, 10)
        self.assertEqual(acq_command.discriminator.name,
                         'linear_discriminator')
        self.assertEqual(acq_command.discriminator.params, discriminator_opts)
        self.assertEqual(acq_command.kernel.name, 'boxcar')
        self.assertEqual(acq_command.kernel.params, kernel_opts)
示例#24
0
    def test_keep_original_schedule_after_attached_to_another_schedule(self):
        """Test if a schedule keeps its _children after attached to another schedule."""
        _children = (Acquire(10, self.config.acquire(0), MemorySlot(0)).shift(20) +
                     Acquire(10, self.config.acquire(0), MemorySlot(0)))
        self.assertEqual(2, len(list(_children.instructions)))

        sched = Acquire(10, self.config.acquire(0), MemorySlot(0)).append(_children)
        self.assertEqual(3, len(list(sched.instructions)))

        # add 2 instructions to _children (2 instructions -> 4 instructions)
        _children = _children.append(Acquire(10, self.config.acquire(0), MemorySlot(0)))
        _children = _children.insert(100, Acquire(10, self.config.acquire(0),
                                                  MemorySlot(0)))
        self.assertEqual(4, len(list(_children.instructions)))
        # sched must keep 3 instructions (must not update to 5 instructions)
        self.assertEqual(3, len(list(sched.instructions)))
示例#25
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)))
    def test_can_construct_valid_acquire_command(self):
        """Test if valid acquire command can be constructed.
        """
        kernel_opts = {'start_window': 0, 'stop_window': 10}
        kernel = Kernel(name='boxcar', **kernel_opts)

        discriminator_opts = {
            'neighborhoods': [{
                'qubits': 1,
                'channels': 1
            }],
            'cal': 'coloring',
            'resample': False
        }
        discriminator = Discriminator(name='linear_discriminator',
                                      **discriminator_opts)

        acq_command = Acquire(duration=10,
                              kernel=kernel,
                              discriminator=discriminator)

        self.assertEqual(acq_command.duration, 10)
        self.assertEqual(acq_command.discriminator.name,
                         'linear_discriminator')
        self.assertEqual(acq_command.discriminator.params, discriminator_opts)
        self.assertEqual(acq_command.kernel.name, 'boxcar')
        self.assertEqual(acq_command.kernel.params, kernel_opts)
        self.assertTrue(acq_command.name.startswith('acq'))
示例#27
0
    def setUp(self):
        self.backend_config = FakeOpenPulse2Q().configuration()

        test_pulse = pulse.SamplePulse(samples=np.array(
            [0.02739068, 0.05, 0.05, 0.05, 0.02739068], dtype=np.complex128),
                                       name='pulse0')

        self.schedule = pulse.Schedule(name='fake_experiment')
        self.schedule = self.schedule.insert(
            0, Play(test_pulse, self.backend_config.drive(0)))
        for i in range(self.backend_config.n_qubits):
            self.schedule = self.schedule.insert(
                5, Acquire(5, self.backend_config.acquire(i), MemorySlot(i)))

        self.user_lo_config_dict = {self.backend_config.drive(0): 4.91e9}
        self.user_lo_config = pulse.LoConfig(self.user_lo_config_dict)

        self.default_qubit_lo_freq = [4.9e9, 5.0e9]
        self.default_meas_lo_freq = [6.5e9, 6.6e9]

        self.config = {
            'meas_level': 1,
            'memory_slot_size': 100,
            'meas_return': 'avg',
            'rep_time': 0.0001,
        }

        self.header = {
            'backend_name': 'FakeOpenPulse2Q',
            'backend_version': '0.0.0'
        }
示例#28
0
    def test_assemble_with_unequal_kernels(self):
        """Test that assembly works with incorrect number of discriminators for
        number of qubits."""
        disc_one = Kernel('disc_one', test_params=True)
        disc_two = Kernel('disc_two', test_params=False)

        schedule = Schedule()
        schedule += Acquire(5, AcquireChannel(0), MemorySlot(0), kernel=disc_one)
        schedule += Acquire(5, AcquireChannel(1), MemorySlot(1), kernel=disc_two)
        schedule += Acquire(5, AcquireChannel(2), MemorySlot(2))

        with self.assertRaises(QiskitError):
            assemble(schedule,
                     qubit_lo_freq=self.default_qubit_lo_freq,
                     meas_lo_freq=self.default_meas_lo_freq,
                     meas_map=[[0, 1, 2]])
示例#29
0
    def test_can_construct_valid_acquire_command(self):
        """Test if valid acquire command can be constructed."""
        kernel_opts = {
            'start_window': 0,
            'stop_window': 10
        }
        kernel = Kernel(name='boxcar', **kernel_opts)

        discriminator_opts = {
            'neighborhoods': [{'qubits': 1, 'channels': 1}],
            'cal': 'coloring',
            'resample': False
        }
        discriminator = Discriminator(name='linear_discriminator', **discriminator_opts)

        acq = Acquire(10, AcquireChannel(0), MemorySlot(0),
                      kernel=kernel, discriminator=discriminator, name='acquire')

        self.assertEqual(acq.duration, 10)
        self.assertEqual(acq.discriminator.name, 'linear_discriminator')
        self.assertEqual(acq.discriminator.params, discriminator_opts)
        self.assertEqual(acq.kernel.name, 'boxcar')
        self.assertEqual(acq.kernel.params, kernel_opts)
        self.assertIsInstance(acq.id, int)
        self.assertEqual(acq.name, 'acquire')
        self.assertEqual(acq.operands, (10, AcquireChannel(0), MemorySlot(0), None))
    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