示例#1
0
 def setUp(self) -> None:
     super().setUp()
     style = stylesheet.QiskitPulseStyle()
     self.formatter = style.formatter
     self.device = device_info.OpenPulseBackendInfo(
         name='test',
         dt=1,
         channel_frequency_map={
             pulse.DriveChannel(0): 5.0e9,
             pulse.DriveChannel(1): 5.1e9,
             pulse.MeasureChannel(0): 7.0e9,
             pulse.MeasureChannel(1): 7.1e9,
             pulse.ControlChannel(0): 5.0e9,
             pulse.ControlChannel(1): 5.1e9
         },
         qubit_channel_map={
             0: [
                 pulse.DriveChannel(0),
                 pulse.MeasureChannel(0),
                 pulse.AcquireChannel(0),
                 pulse.ControlChannel(0)
             ],
             1: [
                 pulse.DriveChannel(1),
                 pulse.MeasureChannel(1),
                 pulse.AcquireChannel(1),
                 pulse.ControlChannel(1)
             ]
         })
示例#2
0
    def test_delay_qubits(self):
        """Test delaying on multiple qubits to make sure we don't insert delays twice."""
        with pulse.build(self.backend) as schedule:
            pulse.delay_qubits(10, 0, 1)

        d0 = pulse.DriveChannel(0)
        d1 = pulse.DriveChannel(1)
        m0 = pulse.MeasureChannel(0)
        m1 = pulse.MeasureChannel(1)
        a0 = pulse.AcquireChannel(0)
        a1 = pulse.AcquireChannel(1)
        u0 = pulse.ControlChannel(0)
        u1 = pulse.ControlChannel(1)

        reference = pulse.Schedule()
        reference += instructions.Delay(10, d0)
        reference += instructions.Delay(10, d1)
        reference += instructions.Delay(10, m0)
        reference += instructions.Delay(10, m1)
        reference += instructions.Delay(10, a0)
        reference += instructions.Delay(10, a1)
        reference += instructions.Delay(10, u0)
        reference += instructions.Delay(10, u1)

        self.assertEqual(schedule, reference)
    def _valid_2q_schedule(self):
        """Returns a valid 2 qubit schedule."""

        valid_pulse = pulse_lib.gaussian(duration=128,
                                         amp=0.5,
                                         sigma=16,
                                         name='valid_pulse')
        valid_meas_pulse = pulse_lib.gaussian_square(duration=1200,
                                                     amp=0.025,
                                                     sigma=4,
                                                     risefall=25,
                                                     name='valid_meas_pulse')
        acq_cmd = pulse.Acquire(duration=10)

        acquires = [pulse.AcquireChannel(0), pulse.AcquireChannel(1)]
        memoryslots = [pulse.MemorySlot(0), pulse.MemorySlot(1)]

        # create measurement schedule
        measure_and_acquire = \
            valid_meas_pulse(pulse.MeasureChannel(0)) | acq_cmd(acquires, memoryslots)

        # add commands to schedule
        schedule = pulse.Schedule(name='valid_exp')

        schedule += valid_pulse(pulse.DriveChannel(0))
        schedule += measure_and_acquire << schedule.duration

        return schedule
    def test_channel_index_sort_grouped_control(self):
        """Test channel_index_grouped_sort_u."""
        out_layout = layouts.channel_index_grouped_sort_u(
            self.channels, formatter=self.formatter, device=self.device)

        ref_channels = [
            [pulse.DriveChannel(0)],
            [pulse.DriveChannel(1)],
            [pulse.MeasureChannel(1)],
            [pulse.AcquireChannel(1)],
            [pulse.DriveChannel(2)],
            [pulse.MeasureChannel(2)],
            [pulse.AcquireChannel(2)],
            [pulse.ControlChannel(0)],
            [pulse.ControlChannel(2)],
            [pulse.ControlChannel(5)],
        ]

        ref_names = [
            "D0", "D1", "M1", "A1", "D2", "M2", "A2", "U0", "U2", "U5"
        ]

        ref = list(zip(ref_names, ref_channels))

        self.assertListEqual(list(out_layout), ref)
示例#5
0
    def test_gen_filled_waveform_stepwise_acquire(self):
        """Test gen_filled_waveform_stepwise with acquire instruction."""
        acquire = pulse.Acquire(
            duration=4,
            channel=pulse.AcquireChannel(0),
            mem_slot=pulse.MemorySlot(0),
            discriminator=pulse.Discriminator(name="test_discr"),
            name="acquire",
        )
        inst_data = create_instruction(acquire, 0, 7e9, 5, 0.1)

        objs = waveform.gen_filled_waveform_stepwise(inst_data,
                                                     formatter=self.formatter,
                                                     device=self.device)

        # imaginary part is empty and not returned
        self.assertEqual(len(objs), 1)

        # type check
        self.assertEqual(type(objs[0]), drawings.LineData)

        y_ref = np.array([1, 1])

        # data check - data is compressed
        self.assertListEqual(objs[0].channels, [pulse.AcquireChannel(0)])
        self.assertListEqual(list(objs[0].xvals), [5, 9])
        np.testing.assert_array_almost_equal(objs[0].yvals, y_ref)

        # meta data check
        ref_meta = {
            "memory slot": "m0",
            "register slot": "N/A",
            "discriminator": "test_discr",
            "kernel": "N/A",
            "duration (cycle time)": 4,
            "duration (sec)": 0.4,
            "t0 (cycle time)": 5,
            "t0 (sec)": 0.5,
            "phase": 0,
            "frequency": 7e9,
            "qubit": 0,
            "name": "acquire",
            "data": "real",
        }

        self.assertDictEqual(objs[0].meta, ref_meta)

        # style check
        ref_style = {
            "alpha": self.formatter["alpha.fill_waveform"],
            "zorder": self.formatter["layer.fill_waveform"],
            "linewidth": self.formatter["line_width.fill_waveform"],
            "linestyle": self.formatter["line_style.fill_waveform"],
            "color": self.formatter["color.waveforms"]["A"][0],
        }
        self.assertDictEqual(objs[0].styles, ref_style)
示例#6
0
    def test_gen_filled_waveform_stepwise_acquire(self):
        """Test gen_filled_waveform_stepwise with acquire instruction."""
        acquire = pulse.Acquire(
            duration=4,
            channel=pulse.AcquireChannel(0),
            mem_slot=pulse.MemorySlot(0),
            discriminator=pulse.Discriminator(name='test_discr'),
            name='acquire')
        inst_data = create_instruction(acquire, 0, 7e9, 5, 0.1)

        objs = waveform.gen_filled_waveform_stepwise(inst_data,
                                                     formatter=self.formatter,
                                                     device=self.device)

        # imaginary part is empty and not returned
        self.assertEqual(len(objs), 1)

        # type check
        self.assertEqual(type(objs[0]), drawings.LineData)

        y_ref = np.array([1, 1])

        # data check - data is compressed
        self.assertListEqual(objs[0].channels, [pulse.AcquireChannel(0)])
        self.assertListEqual(list(objs[0].xvals), [5, 9])
        np.testing.assert_array_almost_equal(objs[0].yvals, y_ref)

        # meta data check
        ref_meta = {
            'memory slot': 'm0',
            'register slot': 'N/A',
            'discriminator': 'test_discr',
            'kernel': 'N/A',
            'duration (cycle time)': 4,
            'duration (sec)': 0.4,
            't0 (cycle time)': 5,
            't0 (sec)': 0.5,
            'phase': 0,
            'frequency': 7e9,
            'qubit': 0,
            'name': 'acquire',
            'data': 'real'
        }

        self.assertDictEqual(objs[0].meta, ref_meta)

        # style check
        ref_style = {
            'alpha': self.formatter['alpha.fill_waveform'],
            'zorder': self.formatter['layer.fill_waveform'],
            'linewidth': self.formatter['line_width.fill_waveform'],
            'linestyle': self.formatter['line_style.fill_waveform'],
            'color': self.formatter['color.waveforms']['A'][0]
        }
        self.assertDictEqual(objs[0].styles, ref_style)
示例#7
0
    def test_gen_filled_waveform_stepwise_acquire(self):
        """Test gen_filled_waveform_stepwise with acquire instruction."""
        acquire = pulse.Acquire(
            duration=4,
            channel=pulse.AcquireChannel(0),
            mem_slot=pulse.MemorySlot(0),
            discriminator=pulse.Discriminator(name='test_discr'),
            name='acquire')
        inst_data = self.create_instruction(acquire, 0, 7e9, 5, 0.1)

        objs = generators.gen_filled_waveform_stepwise(inst_data)

        # imaginary part is empty and not returned
        self.assertEqual(len(objs), 1)

        # type check
        self.assertEqual(type(objs[0]), drawing_objects.FilledAreaData)

        y1_ref = np.array([1, 1, 1, 1, 1, 1, 1, 1])
        y2_ref = np.array([0, 0, 0, 0, 0, 0, 0, 0])

        # data check
        self.assertEqual(objs[0].channel, pulse.AcquireChannel(0))
        self.assertListEqual(list(objs[0].x), [5, 6, 6, 7, 7, 8, 8, 9])
        np.testing.assert_array_almost_equal(objs[0].y1, y1_ref)
        np.testing.assert_array_almost_equal(objs[0].y2, y2_ref)

        # meta data check
        ref_meta = {
            'memory slot': 'm0',
            'register slot': 'N/A',
            'discriminator': 'test_discr',
            'kernel': 'N/A',
            'duration (cycle time)': 4,
            'duration (sec)': 0.4,
            't0 (cycle time)': 5,
            't0 (sec)': 0.5,
            'phase': 0,
            'frequency': 7e9,
            'name': 'acquire',
            'data': 'real'
        }

        self.assertDictEqual(objs[0].meta, ref_meta)

        # style check
        ref_style = {
            'alpha': self.style['formatter.alpha.fill_waveform'],
            'zorder': self.style['formatter.layer.fill_waveform'],
            'linewidth': self.style['formatter.line_width.fill_waveform'],
            'linestyle': self.style['formatter.line_style.fill_waveform'],
            'color': self.style['formatter.color.fill_waveform_a'][0]
        }
        self.assertDictEqual(objs[0].styles, ref_style)
    def test_set_parameter_to_acquire(self):
        """Test set parameters to acquire instruction."""
        test_obj = pulse.Acquire(16000, pulse.AcquireChannel(self.ch1),
                                 pulse.MemorySlot(self.ch1))

        value_dict = {self.ch1: 2}

        visitor = ParameterSetter(param_map=value_dict)
        assigned = visitor.visit(test_obj)

        ref_obj = pulse.Acquire(16000, pulse.AcquireChannel(2),
                                pulse.MemorySlot(2))

        self.assertEqual(assigned, ref_obj)
示例#9
0
    def test_barrier_on_qubits(self):
        """Test barrier directive on qubits."""
        with pulse.build(self.backend) as schedule:
            pulse.barrier(0, 1)

        reference = pulse.Schedule()
        reference += directives.RelativeBarrier(pulse.DriveChannel(0),
                                                pulse.DriveChannel(1),
                                                pulse.MeasureChannel(0),
                                                pulse.MeasureChannel(1),
                                                pulse.ControlChannel(0),
                                                pulse.ControlChannel(1),
                                                pulse.AcquireChannel(0),
                                                pulse.AcquireChannel(1))
        self.assertEqual(schedule, reference)
示例#10
0
    def test_channel_type_grouped_sort(self):
        """Test channel_type_grouped_sort."""
        out_layout = layouts.channel_type_grouped_sort(
            self.channels, formatter=self.formatter, device=self.device)

        ref_channels = [[pulse.DriveChannel(0)], [pulse.DriveChannel(1)],
                        [pulse.DriveChannel(2)], [pulse.ControlChannel(0)],
                        [pulse.ControlChannel(2)], [pulse.ControlChannel(5)],
                        [pulse.MeasureChannel(1)], [pulse.MeasureChannel(2)],
                        [pulse.AcquireChannel(1)], [pulse.AcquireChannel(2)]]
        ref_names = [
            'D0', 'D1', 'D2', 'U0', 'U2', 'U5', 'M1', 'M2', 'A1', 'A2'
        ]

        ref = list(zip(ref_names, ref_channels))

        self.assertListEqual(list(out_layout), ref)
    def test_acquire_duration(self):
        """Test parametrization of acquire duration."""
        dur = Parameter('dur')
        ch = pulse.AcquireChannel(0)
        mem_slot = pulse.MemorySlot(0)

        test_acquire = pulse.Acquire(dur, ch, mem_slot=mem_slot)
        test_acquire.assign_parameters({dur: 300})

        self.assertEqual(test_acquire.duration, 300)
    def test_get_parameter_from_acquire(self):
        """Test get parameters from acquire instruction."""
        test_obj = pulse.Acquire(16000, pulse.AcquireChannel(self.ch1),
                                 pulse.MemorySlot(self.ch1))

        visitor = ParameterGetter()
        visitor.visit(test_obj)

        ref_params = {self.ch1}

        self.assertSetEqual(visitor.parameters, ref_params)
示例#13
0
    def test_qubit_channels(self):
        """Test getting the qubit channels of the active builder's backend."""
        with pulse.build(self.backend):
            qubit_channels = pulse.qubit_channels(0)

        self.assertEqual(qubit_channels,
                         {pulse.DriveChannel(0),
                          pulse.MeasureChannel(0),
                          pulse.AcquireChannel(0),
                          pulse.ControlChannel(0),
                          pulse.ControlChannel(1)})
示例#14
0
    def test_acquire_qubit(self):
        """Test acquire instruction on qubit."""
        acquire0 = pulse.AcquireChannel(0)
        mem0 = pulse.MemorySlot(0)

        with pulse.build() as schedule:
            pulse.acquire(10, 0, mem0)

        reference = pulse.Schedule()
        reference += pulse.Acquire(10, acquire0, mem_slot=mem0)

        self.assertEqual(schedule, reference)
示例#15
0
    def test_acquire_register_slot(self):
        """Test acquire instruction into register slot."""
        acquire0 = pulse.AcquireChannel(0)
        reg0 = pulse.RegisterSlot(0)

        with pulse.build() as schedule:
            pulse.acquire(10, acquire0, reg0)

        reference = pulse.Schedule()
        reference += pulse.Acquire(10, acquire0, reg_slot=reg0)

        self.assertEqual(schedule, reference)
示例#16
0
 def setUp(self) -> None:
     super().setUp()
     self.channels = [
         pulse.DriveChannel(0),
         pulse.DriveChannel(1),
         pulse.DriveChannel(2),
         pulse.MeasureChannel(1),
         pulse.MeasureChannel(2),
         pulse.AcquireChannel(1),
         pulse.AcquireChannel(2),
         pulse.ControlChannel(0),
         pulse.ControlChannel(2),
         pulse.ControlChannel(5)
     ]
     self.formatter = {'control.show_acquire_channel': True}
     self.device = device_info.OpenPulseBackendInfo(
         name='test',
         dt=1,
         channel_frequency_map={
             pulse.DriveChannel(0): 5.0e9,
             pulse.DriveChannel(1): 5.1e9,
             pulse.DriveChannel(2): 5.2e9,
             pulse.MeasureChannel(1): 7.0e9,
             pulse.MeasureChannel(1): 7.1e9,
             pulse.MeasureChannel(2): 7.2e9,
             pulse.ControlChannel(0): 5.0e9,
             pulse.ControlChannel(1): 5.1e9,
             pulse.ControlChannel(2): 5.2e9,
             pulse.ControlChannel(3): 5.3e9,
             pulse.ControlChannel(4): 5.4e9,
             pulse.ControlChannel(5): 5.5e9
         },
         qubit_channel_map={
             0: [
                 pulse.DriveChannel(0),
                 pulse.MeasureChannel(0),
                 pulse.AcquireChannel(0),
                 pulse.ControlChannel(0)
             ],
             1: [
                 pulse.DriveChannel(1),
                 pulse.MeasureChannel(1),
                 pulse.AcquireChannel(1),
                 pulse.ControlChannel(1)
             ],
             2: [
                 pulse.DriveChannel(2),
                 pulse.MeasureChannel(2),
                 pulse.AcquireChannel(2),
                 pulse.ControlChannel(2),
                 pulse.ControlChannel(3),
                 pulse.ControlChannel(4)
             ],
             3: [
                 pulse.DriveChannel(3),
                 pulse.MeasureChannel(3),
                 pulse.AcquireChannel(3),
                 pulse.ControlChannel(5)
             ]
         })
示例#17
0
    def test_set_parameter_to_complex_schedule(self):
        """Test get parameters from complicated schedule."""
        test_block = deepcopy(self.test_sched)

        value_dict = {
            self.amp1_1: 0.1,
            self.amp1_2: 0.2,
            self.amp2: 0.3,
            self.amp3: 0.4,
            self.dur1: 100,
            self.dur2: 125,
            self.dur3: 150,
            self.ch1: 0,
            self.ch2: 2,
            self.ch3: 4,
            self.phi1: 1.0,
            self.phi2: 2.0,
            self.phi3: 3.0,
            self.meas_dur: 300,
            self.mem1: 3,
            self.reg1: 0,
            self.context_dur: 1000,
        }

        visitor = ParameterSetter(param_map=value_dict)
        assigned = visitor.visit(test_block)

        # create ref schedule
        subroutine = pulse.ScheduleBlock(alignment_context=AlignLeft())
        subroutine += pulse.ShiftPhase(1.0, pulse.DriveChannel(0))
        subroutine += pulse.Play(pulse.Gaussian(100, 0.3, 25),
                                 pulse.DriveChannel(0))

        sched = pulse.Schedule()
        sched += pulse.ShiftPhase(3.0, pulse.DriveChannel(4))

        ref_obj = pulse.ScheduleBlock(alignment_context=AlignEquispaced(1000),
                                      name="long_schedule")

        ref_obj += subroutine
        ref_obj += pulse.ShiftPhase(2.0, pulse.DriveChannel(2))
        ref_obj += pulse.Play(pulse.Gaussian(125, 0.3, 25),
                              pulse.DriveChannel(2))
        ref_obj += pulse.Call(sched)
        ref_obj += pulse.Play(pulse.Gaussian(150, 0.4, 25),
                              pulse.DriveChannel(4))

        ref_obj += pulse.Acquire(300, pulse.AcquireChannel(0),
                                 pulse.MemorySlot(3), pulse.RegisterSlot(0))

        self.assertEqual(assigned, ref_obj)
示例#18
0
    def setUp(self) -> None:
        super().setUp()

        self.style = stylesheet.QiskitPulseStyle()
        self.device = device_info.OpenPulseBackendInfo(
            name="test",
            dt=1,
            channel_frequency_map={
                pulse.DriveChannel(0): 5.0,
                pulse.MeasureChannel(0): 7.0,
                pulse.ControlChannel(0): 5.0,
            },
            qubit_channel_map={
                0: [
                    pulse.DriveChannel(0),
                    pulse.MeasureChannel(0),
                    pulse.AcquireChannel(0),
                    pulse.ControlChannel(0),
                ]
            },
        )

        # objects
        self.short_pulse = drawings.LineData(
            data_type=types.WaveformType.REAL,
            xvals=[0, 0, 1, 4, 5, 5],
            yvals=[0, 0.5, 0.5, 0.5, 0.5, 0],
            channels=[pulse.DriveChannel(0)],
        )
        self.long_pulse = drawings.LineData(
            data_type=types.WaveformType.REAL,
            xvals=[8, 8, 9, 19, 20, 20],
            yvals=[0, 0.3, 0.3, 0.3, 0.3, 0],
            channels=[pulse.DriveChannel(1)],
        )
        self.abstract_hline = drawings.LineData(
            data_type=types.LineType.BASELINE,
            xvals=[
                types.AbstractCoordinate.LEFT, types.AbstractCoordinate.RIGHT
            ],
            yvals=[0, 0],
            channels=[pulse.DriveChannel(0)],
        )
示例#19
0
    def test_delay_qubit(self):
        """Test delaying on a qubit macro."""
        with pulse.build(self.backend) as schedule:
            pulse.delay_qubits(10, 0)

        d0 = pulse.DriveChannel(0)
        m0 = pulse.MeasureChannel(0)
        a0 = pulse.AcquireChannel(0)
        u0 = pulse.ControlChannel(0)
        u1 = pulse.ControlChannel(1)

        reference = pulse.Schedule()
        reference += instructions.Delay(10, d0)
        reference += instructions.Delay(10, m0)
        reference += instructions.Delay(10, a0)
        reference += instructions.Delay(10, u0)
        reference += instructions.Delay(10, u1)

        self.assertEqual(schedule, reference)
示例#20
0
    def setUp(self) -> None:
        super().setUp()
        self.style = stylesheet.QiskitPulseStyle()
        self.device = device_info.OpenPulseBackendInfo(
            name="test",
            dt=1,
            channel_frequency_map={
                pulse.DriveChannel(0): 5.0,
                pulse.MeasureChannel(0): 7.0,
                pulse.ControlChannel(0): 5.0,
            },
            qubit_channel_map={
                0: [
                    pulse.DriveChannel(0),
                    pulse.MeasureChannel(0),
                    pulse.AcquireChannel(0),
                    pulse.ControlChannel(0),
                ]
            },
        )

        self.sched = pulse.Schedule()
        self.sched.insert(
            0,
            pulse.Play(pulse.Waveform([0.0, 0.1, 0.2, 0.3, 0.4, 0.5]),
                       pulse.DriveChannel(0)),
            inplace=True,
        )
        self.sched.insert(
            10,
            pulse.Play(pulse.Waveform([0.5, 0.4, 0.3, 0.2, 0.1, 0.0]),
                       pulse.DriveChannel(0)),
            inplace=True,
        )
        self.sched.insert(
            0,
            pulse.Play(pulse.Waveform([0.3, 0.3, 0.3, 0.3, 0.3, 0.3]),
                       pulse.DriveChannel(1)),
            inplace=True,
        )
示例#21
0
def freq_sweep_schedule(qbit, backend_config, drive_chan,
                        meas_samples=1000,):
    dt = backend_config.dt
    print(f"Sampling time: {dt} ns")

    drive_pulse = make_drive_pulse(dt)
    meas_pulse = make_meas_pulse(dt, samples=meas_samples)
    ### Construct the acquire pulse to trigger the acquisition
    # Acquire pulse samples
    acq_cmd = pulse.Acquire(duration=meas_samples)
    # Find out which group of qubits need to be acquired with this qubit
    meas_map_idx = None
    for i, measure_group in enumerate(backend_config.meas_map):
        if qbit in measure_group:
            meas_map_idx = i
            break
    assert meas_map_idx is not None, f"Couldn't find qubit {qbit} in the meas_map!"


    ### Collect the necessary channels
    #drive_chan = pulse.DriveChannel(qbit)
    meas_chan = pulse.MeasureChannel(qbit)
    #acq_chan = pulse.AcquireChannel(qbit)

    schedule = pulse.Schedule(name='Frequency sweep')
    schedule += drive_pulse(drive_chan)
    measure_schedule = meas_pulse(meas_chan)
    # Trigger data acquisition, and store measured values into respective memory slots
    measure_schedule += acq_cmd([pulse.AcquireChannel(i) for i 
                                 in backend_config.meas_map[meas_map_idx]],
                                [pulse.MemorySlot(i) for i 
                                 in backend_config.meas_map[meas_map_idx]])

    # shift the start time of the schedule by some duration
    schedule += measure_schedule << schedule.duration
    schedule += drive_pulse(drive_chan)<< schedule.duration - drive_pulse.duration
    schedule += measure_schedule << drive_pulse.duration

    return schedule
    assert backend_config.open_pulse, "Backend doesn't support OpenPulse"

    # Backend properties
    qubit = 0
    qubit_freq_est = backend_defaults.qubit_freq_est[qubit]
    dt = backend_config.dt
    print(f"Qubit: {qubit}")
    print(f"Hardware sampling time: {dt/ns} ns")
    print(f"Qubit frequency estimate: {qubit_freq_est/GHz} GHz")

    # Set command channels
    drive_chan = pulse.DriveChannel(qubit)

    # Set measurement channels
    meas_chan = pulse.MeasureChannel(qubit)
    acq_chan = pulse.AcquireChannel(qubit)

    # Measurement map
    meas_map_idx = None
    for i, measure_group in enumerate(backend_config.meas_map):
        if qubit in measure_group:
            meas_map_idx = i
            break
    assert meas_map_idx is not None, f"Couldn't find qubit {qubit} in the meas_map!"

else:
    qubit = 0
    dt = 2 / 9 * ns


# IBM-Q auxiliary functions
示例#23
0

qubit = 0
x_gate = cmd_def.get('u3', [qubit], P0=np.pi, P1=0.0, P2=np.pi)
measure_gate = cmd_def.get('measure', qubits=backend_config.meas_map[qubit])


# # Establishing Various channels
# Here we are establishing the various channels to be used.  Note: Measure channel refers to channel that send readout pulses whereas acquire channel refers to the actual download of the readout pulse. All acquire pulses must happen at the same time and no pulses can occur after (currently).

# In[17]:


drive_chan = pulse.DriveChannel(qubit)
meas_chan = pulse.MeasureChannel(qubit)
acq_chan = pulse.AcquireChannel(qubit)


# # Set common measurement time
# Readout can sometimes be sensitive to phase and timing.  For this reason it's useful to set a common readout time

# In[35]:


measure_time = 2000


# # Comparing |0> and |1> state distributions
# Here, using the default pulses from the backend, we will compare the distributions of measurment level 1 values and then construct a readout discriminator (which is equivalent to measurement level 2)

# In[36]:
示例#24
0
    def setUp(self):
        """Just some useful, reusable Parameters, constants, schedules."""
        super().setUp()

        self.amp1_1 = Parameter("amp1_1")
        self.amp1_2 = Parameter("amp1_2")
        self.amp2 = Parameter("amp2")
        self.amp3 = Parameter("amp3")

        self.dur1 = Parameter("dur1")
        self.dur2 = Parameter("dur2")
        self.dur3 = Parameter("dur3")

        self.parametric_waveform1 = pulse.Gaussian(duration=self.dur1,
                                                   amp=self.amp1_1 +
                                                   self.amp1_2,
                                                   sigma=self.dur1 / 4)

        self.parametric_waveform2 = pulse.Gaussian(duration=self.dur2,
                                                   amp=self.amp2,
                                                   sigma=self.dur2 / 5)

        self.parametric_waveform3 = pulse.Gaussian(duration=self.dur3,
                                                   amp=self.amp3,
                                                   sigma=self.dur3 / 6)

        self.ch1 = Parameter("ch1")
        self.ch2 = Parameter("ch2")
        self.ch3 = Parameter("ch3")

        self.d1 = pulse.DriveChannel(self.ch1)
        self.d2 = pulse.DriveChannel(self.ch2)
        self.d3 = pulse.DriveChannel(self.ch3)

        self.phi1 = Parameter("phi1")
        self.phi2 = Parameter("phi2")
        self.phi3 = Parameter("phi3")

        self.meas_dur = Parameter("meas_dur")
        self.mem1 = Parameter("s1")
        self.reg1 = Parameter("m1")

        self.context_dur = Parameter("context_dur")

        # schedule under test
        subroutine = pulse.ScheduleBlock(alignment_context=AlignLeft())
        subroutine += pulse.ShiftPhase(self.phi1, self.d1)
        subroutine += pulse.Play(self.parametric_waveform1, self.d1)

        sched = pulse.Schedule()
        sched += pulse.ShiftPhase(self.phi3, self.d3)

        long_schedule = pulse.ScheduleBlock(alignment_context=AlignEquispaced(
            self.context_dur),
                                            name="long_schedule")

        long_schedule += subroutine
        long_schedule += pulse.ShiftPhase(self.phi2, self.d2)
        long_schedule += pulse.Play(self.parametric_waveform2, self.d2)
        long_schedule += pulse.Call(sched)
        long_schedule += pulse.Play(self.parametric_waveform3, self.d3)

        long_schedule += pulse.Acquire(
            self.meas_dur,
            pulse.AcquireChannel(self.ch1),
            mem_slot=pulse.MemorySlot(self.mem1),
            reg_slot=pulse.RegisterSlot(self.reg1),
        )

        self.test_sched = long_schedule
示例#25
0
def cr_drive_experiments(drive_idx,
                         target_idx,
                         flip_drive_qubit = False,

                         #cr_drive_amps=np.linspace(0, 0.9, 16),
                         #cr_drive_samples=800,
                         #cr_drive_sigma=4,
                         #pi_drive_samples=128,
                         #pi_drive_sigma=16
                         #meas_amp = Dims/128*0.025/2
                         #meas_width = int(rows/128*1150/2)
                         cr_drive_amps=np.linspace(0, 0.9, meas_width**2),
                         cr_drive_samples=sum(label1[:] == label2[:]),
                         cr_drive_sigma=meas_sigma,
                         pi_drive_samples=sum((label1[:] ==1)*(label2[:] ==1)), #label1[:] ==1 and label2[:] ==1
                         pi_drive_sigma=cr_drive_sigma**2):
    """Generate schedules corresponding to CR drive experiments.

    Args:
        drive_idx (int): label of driven qubit
        target_idx (int): label of target qubit
        flip_drive_qubit (bool): whether or not to start the driven qubit in the ground or excited state
        cr_drive_amps (array): list of drive amplitudes to use
        cr_drive_samples (int): number samples for each CR drive signal
        cr_drive_sigma (float): standard deviation of CR Gaussian pulse
        pi_drive_samples (int): number samples for pi pulse on drive
        pi_drive_sigma (float): standard deviation of Gaussian pi pulse on drive

    Returns:
        list[Schedule]: A list of Schedule objects for each experiment
    """

    # Construct measurement commands to be used for all schedules
    #meas_amp = 0.025
    #meas_samples = 1200
    #meas_sigma = 4
    #meas_width = 1150
    meas_amp = 0.025
    meas_sigma = 4
    ni = int(np.ceil(cols/meas_sigma))
    print(ni)
    meas_samples = rows*ni
    meas_width = int(rows*ni*23/24)
    meas_pulse = GaussianSquare(duration=meas_samples, amp=meas_amp/np.linalg.norm(meas_amp),
                               sigma=meas_sigma, width=meas_width)

    acq_sched = pulse.Acquire(meas_samples, pulse.AcquireChannel(0), pulse.MemorySlot(0))
    acq_sched += pulse.Acquire(meas_samples, pulse.AcquireChannel(1), pulse.MemorySlot(1))

    # create measurement schedule
    measure_sched = (pulse.Play(meas_pulse, pulse.MeasureChannel(0)) |
                     pulse.Play(meas_pulse, pulse.MeasureChannel(1))|
                     acq_sched)

    # Create schedule
    schedules = []
    for ii, cr_drive_amp in enumerate(cr_drive_amps):

        # pulse for flipping drive qubit if desired
        pi_pulse = Gaussian(duration=pi_drive_samples, amp=pi_amps[drive_idx], sigma=pi_drive_sigma)

        # cr drive pulse
        cr_width = cr_drive_samples - 2*cr_drive_sigma*4
        cr_rabi_pulse = GaussianSquare(duration=cr_drive_samples,
                                       amp=cr_drive_amp/np.linalg.norm(cr_drive_amp),
                                       sigma=cr_drive_sigma,
                                       width=cr_width)

        # add commands to schedule
        schedule = pulse.Schedule(name='cr_rabi_exp_amp_%s' % cr_drive_amp)
        #schedule = pulse.Schedule(name='cr_rabi_exp_amp_%s' % cr_drive_amp/np.linalg.norm(cr_drive_amp))

        # flip drive qubit if desired
        if flip_drive_qubit:
            schedule += pulse.Play(pi_pulse, pulse.DriveChannel(drive_idx))

        # do cr drive
        # First, get the ControlChannel index for CR drive from drive to target
        cr_idx = two_qubit_model.control_channel_index((drive_idx, target_idx))
        schedule += pulse.Play(cr_rabi_pulse, pulse.ControlChannel(cr_idx))  << schedule.duration


        schedule += measure_sched << schedule.duration

        schedules.append(schedule)
    return schedules
示例#26
0
#4.1 Constructing the schedules
# list of qubits to be used throughout the notebook

qubits = [0, 1]
# Construct a measurement schedule and add it to an InstructionScheduleMap
meas_amp = 0.025
meas_sigma = 4
ni = int(np.ceil(cols/meas_sigma))
print(ni)
meas_samples = rows*ni
meas_width = int(rows*ni*23/24)

meas_pulse = GaussianSquare(duration=meas_samples, amp=meas_amp,
                            sigma=meas_sigma, width=meas_width)

acq_sched = pulse.Acquire(meas_samples, pulse.AcquireChannel(0), pulse.MemorySlot(0))
acq_sched += pulse.Acquire(meas_samples, pulse.AcquireChannel(1), pulse.MemorySlot(1))

measure_sched = pulse.Play(meas_pulse, pulse.MeasureChannel(0)) | pulse.Play(meas_pulse, pulse.MeasureChannel(1)) | acq_sched

inst_map = pulse.InstructionScheduleMap()
inst_map.add('measure', qubits, measure_sched)

#Rabi schedules
#recall: Rabii oscillation
# The magnetic moment is thus {\displaystyle {\boldsymbol {\mu }}={\frac {\hbar }{2}}\gamma {\boldsymbol {\sigma }}}{\boldsymbol {\mu }}={\frac {\hbar }{2}}\gamma {\boldsymbol {\sigma }}. 
# The Hamiltonian of this system is then given by {H} =-{{\mu }}\cdot{B} =-{\frac {\hbar }{2}}\omega _{0}\sigma _{z}-{\frac {\hbar }{2}}\omega _{1}(\sigma _{x}\cos \omega t-\sigma _{y}\sin \omega t)}\mathbf {H} =-{\boldsymbol {\mu }}\cdot \mathbf {B} =-{\frac {\hbar }{2}}\omega _{0}\sigma _{z}-{\frac {\hbar }{2}}\omega _{1}(\sigma _{x}\cos \omega t-\sigma _{y}\sin \omega t) where {\displaystyle \omega _{0}=\gamma B_{0}}\omega _{0}=\gamma B_{0} and {\displaystyle \omega _{1}=\gamma B_{1}}\omega _{1}=\gamma B_{1}
# Now, let the qubit be in state {\displaystyle |0\rangle }{\displaystyle |0\rangle } at time {\displaystyle t=0}t=0. Then, at time {\displaystyle t}t, the probability of it being found in state {\displaystyle |1\rangle }|1\rangle  is given by {\displaystyle P_{0\to 1}(t)=\left({\frac {\omega _{1}}{\Omega }}\right)^{2}\sin ^{2}\left({\frac {\Omega t}{2}}\right)}{\displaystyle P_{0\to 1}(t)=\left({\frac {\omega _{1}}{\Omega }}\right)^{2}\sin ^{2}\left({\frac {\Omega t}{2}}\right)} where {\displaystyle \Omega ={\sqrt {(\omega -\omega _{0})^{2}+\omega _{1}^{2}}}}\Omega ={\sqrt {(\omega -\omega _{0})^{2}+\omega _{1}^{2}}}
# the qubit oscillates between the {\displaystyle |0\rangle }|0\rang and {\displaystyle |1\rangle }|1\rangle  states. 
# The maximum amplitude for oscillation is achieved at {\displaystyle \omega =\omega _{0}}\omega =\omega _{0}, which is the condition for resonance. 
# At resonance, the transition probability is given by {\displaystyle P_{0\to 1}(t)=\sin ^{2}\left({\frac {\omega _{1}t}{2}}\right)}{\displaystyle P_{0\to 1}(t)=\sin ^{2}\left({\frac {\omega _{1}t}{2}}\right)}
示例#27
0
qubit = 0  # qubit we will analyze
default_qubit_freq = backend_defaults.qubit_freq_est[
    qubit]  # Default qubit frequency in Hz.
#print(f"Qubit {qubit} has an estimated frequency of {default_qubit_freq/ GHz} GHz.")

# scale data (specific to each device)
scale_factor = 1e-14

# number of shots for our experiments
NUM_SHOTS = 1024

### Collect the necessary channels
drive_chan = pulse.DriveChannel(qubit)
meas_chan = pulse.MeasureChannel(qubit)
acq_chan = pulse.AcquireChannel(qubit)

# Drive pulse parameters (us = microseconds)
drive_sigma_us = 0.075  # This determines the actual width of the gaussian
drive_samples_us = drive_sigma_us * 8  # This is a truncating parameter, because gaussians don't have
# a natural finite length
drive_sigma = get_closest_multiple_of_16(
    drive_sigma_us * us / dt)  # The width of the gaussian in units of dt
drive_samples = get_closest_multiple_of_16(drive_samples_us * us / dt)
# The truncating parameter in units of dt
# Find out which measurement map index is needed for this qubit
meas_map_idx = None
for i, measure_group in enumerate(backend_config.meas_map):
    if qubit in measure_group:
        meas_map_idx = i
        break
示例#28
0
MHz = 1.0e6  # Megahertz
us = 1.0e-6  # Microseconds
ns = 1.0e-9  # Nanoseconds
scale_factor = 1e-14

NUM_SHOTS = 8192
qubit = 0
default_qubit_freq = backend_defaults.qubit_freq_est[
    qubit]  # Default qubit frequency in Hz.
print(
    f"Qubit {qubit} has an estimated frequency of {default_qubit_freq/ GHz} GHz."
)

drive_chan = pulse.DriveChannel(qubit)
meas_chan = pulse.MeasureChannel(qubit)
acq_chan = pulse.AcquireChannel(qubit)


def get_job_data(job, average):
    """Retrieve data from a job that has already run.
    Args:
        job (Job): The job whose data you want.
        average (bool): If True, gets the data assuming data is an average.
                        If False, gets the data assuming it is for single shots.
    Return:
        list: List containing job result data. 
    """
    job_results = job.result(timeout=120)  # timeout parameter set to 120 s
    result_data = []
    for i in range(len(job_results.results)):
        if average:  # get avg data
示例#29
0
 def test_acquire_channel(self):
     """Text context builder acquire channel."""
     with pulse.build(self.backend):
         self.assertEqual(pulse.acquire_channel(0), pulse.AcquireChannel(0))