def pre_pulse_set(device, qubit_id):
    exitation_channel = [
        i for i in device.get_qubit_excitation_channel_list(qubit_id).keys()
    ][0]
    ex_channel = device.awg_channels[exitation_channel]

    if ex_channel.is_iq():
        control_seq_id = ex_channel.parent.sequencer_id
    else:
        control_seq_id = ex_channel.channel // 2
    ex_sequencers = []
    for seq_id in device.pre_pulses.seq_in_use:
        if seq_id != control_seq_id:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id,
                                               awg=device.modem.awg,
                                               awg_amp=1,
                                               use_modulation=True,
                                               pre_pulses=[])
        else:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id,
                                               awg=device.modem.awg,
                                               awg_amp=1,
                                               use_modulation=True,
                                               pre_pulses=[],
                                               control=True)
        ex_seq.stop()
        device.pre_pulses.set_seq_offsets(ex_seq)
        device.pre_pulses.set_seq_prepulses(ex_seq)
        ex_sequencers.append(ex_seq)
        device.modem.awg.set_sequence(ex_seq.params['sequencer_id'], ex_seq)
        ex_seq.start()
Example #2
0
def define_qubit_control_seq(device, ex_sequence, ex_channel,
                             exitation_amplitude, readout_delay):
    if hasattr(ex_channel.parent, 'sequencer_id'):
        ex_sequence.stop()
        # Mixer calibrations result
        calib_dc_ex = ex_channel.parent.calib_dc()
        calib_rf_ex = ex_channel.parent.calib_rf(ex_channel)
        ex_sequence.set_amplitude_i(np.abs(calib_rf_ex['I']))
        ex_sequence.set_amplitude_q(np.abs(calib_rf_ex['Q']))
        ex_sequence.set_awg_amp(exitation_amplitude)
        ex_sequence.set_phase_i(np.angle(calib_rf_ex['I']) * 360 / np.pi)
        ex_sequence.set_phase_q(np.angle(calib_rf_ex['Q']) * 360 / np.pi)
        ex_sequence.set_offset_i(np.real(calib_dc_ex['dc']))
        ex_sequence.set_offset_q(np.imag(calib_dc_ex['dc']))
        ex_sequence.set_frequency(np.abs(ex_channel.get_if()))
    else:
        ex_sequence.stop()
        ex_sequence.set_awg_amp(exitation_amplitude)
        ex_sequence.set_frequency_qubit(np.abs(ex_channel.get_frequency()))
    ex_sequencers = []
    control_seq_id = ex_sequence.params['sequencer_id']
    for seq_id in device.pre_pulses.seq_in_use:
        if seq_id != control_seq_id:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id,
                                               awg=device.modem.awg,
                                               readout_delay=readout_delay,
                                               awg_amp=1,
                                               use_modulation=True,
                                               pre_pulses=[])
            ex_seq.stop()
            device.pre_pulses.set_seq_offsets(ex_seq)
            device.pre_pulses.set_seq_prepulses(ex_seq)
            ex_sequencers.append(ex_seq)
            device.modem.awg.set_sequence(ex_seq.params['sequencer_id'],
                                          ex_seq)
            #ex_seq.start()
        else:
            device.pre_pulses.set_seq_offsets(ex_sequence)
            device.pre_pulses.set_seq_prepulses(ex_sequence)
            ex_sequencers.append(ex_sequence)
            device.modem.awg.set_sequence(ex_sequence.params['sequencer_id'],
                                          ex_sequence)
            #ex_sequence.start()

    return ex_sequencers
Example #3
0
def calibrate_preparation_and_readout_confusion(device, qubit_readout_pulse, readout_device, *extra_sweep_args,
                                                pause_length=0, middle_seq_generator = None,
                                                additional_references = {}, additional_metadata = {}):
    qubit_ids = qubit_readout_pulse.metadata['qubit_ids'].split(',')
    target_qubit_states = [0] * len(qubit_ids)
    # TODO
    '''Warning'''
    excitation_pulses = {qubit_id: excitation_pulse.get_excitation_pulse(device, qubit_id, rotation_angle=np.pi) for
                         qubit_id in qubit_ids}
    ''''''
    references = {('excitation_pulse', qubit_id): pulse.id for qubit_id, pulse in excitation_pulses.items()}
    references['readout_pulse'] = qubit_readout_pulse.id

    re_sequence = sequence_control.define_readout_control_seq(device, qubit_readout_pulse)

    #TODO
    exitation_channel = [i for i in device.get_qubit_excitation_channel_list(qubit_ids[0]).keys()][0]
    ex_channel = device.awg_channels[exitation_channel]
    if ex_channel.is_iq():
        control_seq_id = ex_channel.parent.sequencer_id
    else:
        control_seq_id = ex_channel.channel//2
    ex_sequencers = []
    for seq_id in device.pre_pulses.seq_in_use:
        if seq_id != control_seq_id:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses = [])
        else:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses=[], control=True)
            control_sequence = ex_seq

        device.pre_pulses.set_seq_offsets(ex_seq)
        device.pre_pulses.set_seq_prepulses(ex_seq)
        ex_seq.start()
        ex_sequencers.append(ex_seq)

    #sequence_control.set_preparation_sequence(device, ex_sequencers, [other_qubit_pulse_sequence+
    #                                                                   qubit_excitation_pulse.get_pulse_sequence(0)])


    def set_target_state(state):
        re_sequence.awg.stop_seq(re_sequence.params['sequencer_id'])
        preparation_sequence = []
        for _id, qubit_id in enumerate(qubit_ids):
            qubit_state = (1 << _id) & state
            if qubit_state:
                # TODO
                '''Warning'''
                preparation_sequence.extend(excitation_pulses[qubit_id].get_pulse_sequence(0))
        if middle_seq_generator is not None:
            # TODO
            '''Warning'''
            middle_pulse = middle_seq_generator()
            preparation_sequence.extend(middle_pulse)
        else:
            middle_pulse = []
        # TODO
        '''Warning'''
        sequence_control.set_preparation_sequence(device, ex_sequencers, preparation_sequence)
        re_sequence.awg.start_seq(re_sequence.params['sequencer_id'])
    if middle_seq_generator is not None:
        measurement_type = 'confusion_matrix_middle_seq'
    else:
        measurement_type = 'confusion_matrix'
    metadata = {'qubit_ids': qubit_readout_pulse.metadata['qubit_ids'],
                'pause_length': str(pause_length)}
    references.update(additional_references)
    metadata.update(additional_metadata)

    return device.sweeper.sweep(readout_device,
                                *extra_sweep_args,
                                (np.arange(2 ** len(qubit_ids)), set_target_state, 'Target state', ''),
                                measurement_type=measurement_type,
                                references=references,
                                metadata=metadata)
Example #4
0
def readout_fidelity_scan(device, qubit_id, readout_pulse_lengths, readout_pulse_amplitudes,
                          recalibrate_excitation=True, ignore_other_qubits=False, channel_amplitudes=None):
    adc, mnames = device.setup_adc_reducer_iq(qubit_id, raw=True)
    nums = int(device.get_qubit_constant(qubit_id=qubit_id, name='readout_background_nums'))
    adc.set_adc_nop(int(device.get_sample_global('readout_adc_points')))
    old_nums = adc.get_adc_nums()

    readout_channel = [i for i in device.get_qubit_readout_channel_list(qubit_id).keys()][0]

    other_qubit_pulse_sequence = []
    references = {'frequency_controls': device.get_frequency_control_measurement_id(qubit_id=qubit_id)}
    if hasattr(device.awg_channels[readout_channel], 'get_calibration_measurement'):
        references['channel_calibration'] = device.awg_channels[readout_channel].get_calibration_measurement()

    if not ignore_other_qubits:
        for other_qubit_id in device.get_qubit_list():
            if other_qubit_id != qubit_id:

                '''Warning'''
                #TODO
                half_excited_pulse = excitation_pulse.get_excitation_pulse(device, other_qubit_id,
                                                                           rotation_angle=np.pi / 2.,
                                                                           recalibrate=recalibrate_excitation)
                references[('other_qubit_pulse', other_qubit_id)] = half_excited_pulse.id
                other_qubit_pulse_sequence.extend(half_excited_pulse.get_pulse_sequence(0))

    '''Warning'''
    # TODO
    qubit_excitation_pulse = excitation_pulse.get_excitation_pulse(device, qubit_id, rotation_angle=np.pi, channel_amplitudes_override=channel_amplitudes,
                                                                   recalibrate=recalibrate_excitation)
    metadata = {'qubit_id': qubit_id,
                'averages': nums,
                'channel': readout_channel,
                'ignore_other_qubits': ignore_other_qubits}

    # print ('len(readout_pulse_lengths): ', len(readout_pulse_lengths))
    if len(readout_pulse_lengths) == 1:
        metadata['length'] = str(readout_pulse_lengths[0])

    references.update({'excitation_pulse': qubit_excitation_pulse.id,
                       'delay_calibration': device.modem.delay_measurement.id})

    #TODO
    exitation_channel = [i for i in device.get_qubit_excitation_channel_list(qubit_id).keys()][0]
    ex_channel = device.awg_channels[exitation_channel]
    if ex_channel.is_iq():
        control_seq_id = ex_channel.parent.sequencer_id
    else:
        control_seq_id = ex_channel.channel//2
    ex_sequencers = []
    for seq_id in device.pre_pulses.seq_in_use:
        if seq_id != control_seq_id:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses = [])
        else:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses=[], control=True)
            control_sequence = ex_seq

        device.pre_pulses.set_seq_offsets(ex_seq)
        device.pre_pulses.set_seq_prepulses(ex_seq)
        ex_seq.start()
        ex_sequencers.append(ex_seq)
    sequence_control.set_preparation_sequence(device, ex_sequencers, other_qubit_pulse_sequence+
                                                                       qubit_excitation_pulse.get_pulse_sequence(0))

    '''Warning'''
    #readout_sequencer = sequence_control.define_readout_control_seq(device, readout_channel)
    #raise ValueError('fallos')
    re_channel = device.awg_channels[readout_channel]
    readout_sequencer = zi_scripts.READSequence(re_channel.parent.sequencer_id, device.modem.awg)

    def_frag, play_frag = device.pg.readout_rect(channel=readout_channel, length=readout_pulse_lengths[0],
                                                 amplitude=readout_pulse_amplitudes[0])
    readout_sequencer.add_readout_pulse(def_frag, play_frag)
    readout_sequencer.stop()
    device.modem.awg.set_sequence(readout_sequencer.params['sequencer_id'], readout_sequencer)
    readout_sequencer.set_delay(device.modem.trigger_channel.delay)
    readout_sequencer.start()

    classifier = single_shot_readout.single_shot_readout(device=device,
                                                         adc=adc,
                                                         prepare_seqs=[other_qubit_pulse_sequence,
                                                                       other_qubit_pulse_sequence +
                                                                       qubit_excitation_pulse.get_pulse_sequence(0)],
                                                         ex_seqs=ex_sequencers,
                                                         ro_seq=readout_sequencer,
                                                         control_seq=control_sequence,
                                                         #pulse_generator=device.pg,
                                                         ro_delay_seq=None,
                                                         _readout_classifier=readout_classifier.binary_linear_classifier(),
                                                         adc_measurement_name='Voltage',
                                                         dbg_storage=False)

    classifier.readout_classifier.cov_mode = 'equal'

    # setters for sweep
    readout_amplitude = 0
    readout_length = 0

    class ParameterSetter:
        def __init__(self):
            self.readout_amplitude = 0
            self.readout_length = 0
            self.channel = readout_channel

        def set_readout_amplitude(self, x):
            #nonlocal readout_amplitude
            self.readout_amplitude = x
            #classifier.ro_seq = device.trigger_readout_seq + [
            #    device.pg.p(readout_channel, readout_length, device.pg.rect, readout_amplitude)]
            classifier.ro_seq.set_awg_amp(x)

        def set_readout_length(self, x):
            #nonlocal readout_length
            self.readout_length = x
            #classifier.ro_seq = device.trigger_readout_seq + [
            #    device.pg.p(readout_channel, readout_length, device.pg.rect, readout_amplitude)]
            classifier.ro_seq.awg.stop_seq(classifier.ro_seq.params['sequencer_id'])
            def_frag, play_frag = device.pg.readout_rect(channel=self.channel,
                                                        length=self.readout_length,
                                                        amplitude=self.readout_amplitude)
            classifier.ro_seq.clear_readout_pulse()
            classifier.ro_seq.add_readout_pulse(def_frag, play_frag)
            device.modem.awg.set_sequence(classifier.ro_seq.params['sequencer_id'], classifier.ro_seq)
            classifier.ro_seq.awg.start_seq(classifier.ro_seq.params['sequencer_id'])

    setter = ParameterSetter()

    try:
        adc.set_adc_nums(nums)
        measurement = device.sweeper.sweep(classifier,
                                           (readout_pulse_lengths, setter.set_readout_length, 'length', 's'),
                                           (readout_pulse_amplitudes, setter.set_readout_amplitude, 'amplitude', ''),
                                           measurement_type='readout_fidelity_scan',
                                           metadata=metadata,
                                           references=references)
    except:
        raise
    finally:
        adc.set_adc_nums(old_nums)

    return measurement
Example #5
0
def calibrate_readout(device, qubit_id, qubit_readout_pulse, transition='01', ignore_other_qubits=None):
    adc, mnames = device.setup_adc_reducer_iq(qubit_id, raw=True)
    nums = int(device.get_qubit_constant(qubit_id=qubit_id, name='readout_background_nums'))
    old_nums = adc.get_adc_nums()
    adc.set_adc_nop(int(device.get_sample_global('readout_adc_points')))
    if ignore_other_qubits is None:
        ignore_other_qubits = (device.get_qubit_constant(qubit_id=qubit_id, name='readout_calibration_ignore_other_qubits') == 'True')
    print ('ignore_other_qubits', ignore_other_qubits)

    other_qubit_pulse_sequence = []
    references = {}
    if not ignore_other_qubits:
        for other_qubit_id in device.get_qubit_list():
            if other_qubit_id != qubit_id:
                # TODO
                '''Warning'''
                half_excited_pulse = excitation_pulse.get_excitation_pulse(device, other_qubit_id,
                                                                           rotation_angle=np.pi / 2.)
                references[('other_qubit_pulse', other_qubit_id)] = half_excited_pulse.id
                other_qubit_pulse_sequence.extend(half_excited_pulse.get_pulse_sequence(0))
    # TODO
    '''Warning'''
    qubit_excitation_pulse = excitation_pulse.get_excitation_pulse(device, qubit_id, rotation_angle=np.pi)
    metadata = {'qubit_id': qubit_id,
                'averages': nums,
                'ignore_other_qubits': ignore_other_qubits}

    references.update({'readout_pulse': qubit_readout_pulse.id,
                       'excitation_pulse': qubit_excitation_pulse.id,
                       'delay_calibration': device.modem.delay_measurement.id})

    #TODO
    exitation_channel = [i for i in device.get_qubit_excitation_channel_list(qubit_id).keys()][0]
    ex_channel = device.awg_channels[exitation_channel]
    if ex_channel.is_iq():
        control_seq_id = ex_channel.parent.sequencer_id
    else:
        control_seq_id = ex_channel.channel//2
    ex_sequencers = []
    for seq_id in device.pre_pulses.seq_in_use:
        if seq_id != control_seq_id:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses = [])
        else:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses=[], control=True)
            control_sequence = ex_seq

        device.pre_pulses.set_seq_offsets(ex_seq)
        device.pre_pulses.set_seq_prepulses(ex_seq)
        ex_seq.start()
        ex_sequencers.append(ex_seq)
    sequence_control.set_preparation_sequence(device, ex_sequencers, other_qubit_pulse_sequence+
                                                                       qubit_excitation_pulse.get_pulse_sequence(0))

    '''Warning'''
    #readout_sequencer = sequence_control.define_readout_control_seq(device, readout_channel)
    #raise ValueError('fallos')

    readout_sequencer = sequence_control.define_readout_control_seq(device, qubit_readout_pulse)
    readout_sequencer.start()

    classifier = single_shot_readout.single_shot_readout(device=device,
                                                         adc=adc,
                                                         prepare_seqs=[other_qubit_pulse_sequence,
                                                                       other_qubit_pulse_sequence +
                                                                       qubit_excitation_pulse.get_pulse_sequence(0)],
                                                         ex_seqs=ex_sequencers,
                                                         ro_seq=readout_sequencer,
                                                         control_seq = control_sequence,
                                                         #pulse_generator=device.pg,
                                                         ro_delay_seq=None,
                                                         _readout_classifier=readout_classifier.binary_linear_classifier(),
                                                         adc_measurement_name='Voltage',
                                                         dbg_storage=False)

    classifier.readout_classifier.cov_mode = 'equal'

    try:
        adc.set_adc_nums(nums)
        measurement = device.sweeper.sweep(classifier,
                                           measurement_type='readout_calibration',
                                           metadata=metadata,
                                           references=references)
    except:
        raise
    finally:
        adc.set_adc_nums(old_nums)

    return measurement
Example #6
0
def measure_readout(device,
                    qubit_readout_pulse,
                    excitation_pulse=None,
                    nums=None):
    qubit_id = qubit_readout_pulse.metadata['qubit_id']
    readout_channel = [
        i for i in device.get_qubit_readout_channel_list(qubit_id).keys()
    ][0]
    adc, mnames = device.setup_adc_reducer_iq(qubit_id, raw=True)
    adc.set_adc_nop(int(device.get_sample_global('readout_adc_points')))
    exitation_channel = [
        i for i in device.get_qubit_excitation_channel_list(qubit_id).keys()
    ][0]

    if not nums:
        nums = int(
            device.get_qubit_constant(name='uncalibrated_readout_nums',
                                      qubit_id=qubit_id))
        adc.set_adc_nums(nums)

    mean_sample = data_reduce.data_reduce(adc)
    mean_sample.filters['Mean_Voltage_AC'] = data_reduce.mean_reducer_noavg(
        adc, 'Voltage', 0)
    mean_sample.filters['Std_Voltage_AC'] = data_reduce.std_reducer_noavg(
        adc, 'Voltage', 0, 1)
    mean_sample.filters['S21'] = data_reduce.thru(adc,
                                                  mnames[qubit_id],
                                                  diff=0,
                                                  scale=nums)

    excitation_pulse_sequence = excitation_pulse.get_pulse_sequence(
        0) if excitation_pulse is not None else []
    ex_channel = device.awg_channels[exitation_channel]

    if hasattr(ex_channel.parent, 'sequencer_id'):
        control_seq_id = ex_channel.parent.sequencer_id
    else:
        control_seq_id = ex_channel.channel // 2
    '''Warning'''
    #TODO
    ex_sequencers = []
    for seq_id in device.pre_pulses.seq_in_use:
        if seq_id != control_seq_id:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id,
                                               awg=device.modem.awg,
                                               awg_amp=1,
                                               use_modulation=True,
                                               pre_pulses=[])
        else:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id,
                                               awg=device.modem.awg,
                                               awg_amp=1,
                                               use_modulation=True,
                                               pre_pulses=[],
                                               control=True)
        ex_seq.stop()
        device.pre_pulses.set_seq_offsets(ex_seq)
        device.pre_pulses.set_seq_prepulses(ex_seq)
        ex_sequencers.append(ex_seq)
        device.modem.awg.set_sequence(ex_seq.params['sequencer_id'], ex_seq)
        ex_seq.start()

    # We neet to set readout sequence to awg readout channel
    # readout pulse parameters ('length' and 'amplitude') we get from qubit_readout_pulse.metadata
    # device.pg.set_seq(device.pre_pulses + excitation_pulse_sequence + device.trigger_readout_seq + qubit_readout_pulse.get_pulse_sequence())
    re_channel = device.awg_channels[readout_channel]
    sequence = zi_scripts.READSequence(re_channel.parent.sequencer_id,
                                       device.modem.awg)
    def_frag, play_frag = device.pg.readout_rect(
        channel=readout_channel,
        length=float(qubit_readout_pulse.metadata['length']),
        amplitude=float(qubit_readout_pulse.metadata['amplitude']))
    sequence.add_readout_pulse(def_frag, play_frag)
    sequence.stop()
    device.modem.awg.set_sequence(re_channel.parent.sequencer_id, sequence)
    sequence.set_delay(device.modem.trigger_channel.delay)
    sequence.start()

    #Here we need to set exitation pulse sequense with pre pulses for qubit control channels

    # refers to Awg_iq_multi calibrations
    metadata = {'qubit_id': qubit_id, 'averages': nums}
    references = {
        'readout_pulse':
        qubit_readout_pulse.id,
        'modem_calibration':
        device.modem.calibration_measurements[readout_channel].id,
        'frequency_controls':
        device.get_frequency_control_measurement_id(qubit_id=qubit_id)
    }
    if excitation_pulse is not None:
        references['excitation_pulse'] = excitation_pulse.id
    if hasattr(device.awg_channels[readout_channel],
               'get_calibration_measurement'):
        references[('channel_calibration',
                    readout_channel)] = device.awg_channels[
                        readout_channel].get_calibration_measurement()

    try:
        measurement = device.sweeper.sweep(mean_sample,
                                           measurement_type='readout_response',
                                           metadata=metadata,
                                           references=references)
    except:
        raise

    return measurement
Example #7
0
def gauss_hd_Rabi_amplitude_adaptive(device, qubit_id, inverse_rotation_cycles, preferred_length=None, transition='01',
                                     alpha=0, phase=0):
    # max_num_pulses =
    # get T2 result
    # coherence_measurement = get_Ramsey_coherence_measurement(device=device, qubit_id=qubit_id)
    # T2 = float(coherence_measurement.metadata['T'])
    # get default (rectangular) excitation pulse
    readout_pulse, measurer = get_uncalibrated_measurer(device, qubit_id)

    #min_step = float(device.get_qubit_constant(qubit_id=qubit_id, name='adaptive_Rabi_min_step'))
    #scan_points = int(device.get_qubit_constant(qubit_id=qubit_id, name='adaptive_Rabi_amplitude_scan_points'))
    scan_points = 32
    _range = float(device.get_qubit_constant(qubit_id=qubit_id, name='adaptive_Rabi_amplitude_range'))
    max_scan_length = float(device.get_qubit_constant(qubit_id=qubit_id, name='adaptive_Rabi_max_scan_length'))
    sigmas_in_gauss = float(device.get_qubit_constant(qubit_id=qubit_id, name='sigmas_in_gauss'))

    adaptive_measurements = []

    def infer_amplitude_from_measurements():
        amplitudes = adaptive_measurements[-1].datasets['iq' + qubit_id].parameters[0].values
        measurement_interpolated_combined = np.zeros(amplitudes.shape)
        measurement_projector = np.conj(np.mean(adaptive_measurements[0].datasets['iq' + qubit_id].data))
        for measurement in adaptive_measurements:
            measurement_interpolated_combined += np.interp(amplitudes,
                                                           measurement.datasets['iq' + qubit_id].parameters[0].values,
                                                           np.real(measurement.datasets[
                                                                       'iq' + qubit_id].data * measurement_projector), )
        return amplitudes[np.argmin(measurement_interpolated_combined)]

    rotation_angle = 2 * np.pi / inverse_rotation_cycles
    rect_pulse = get_rect_excitation_pulse(device, qubit_id, rotation_angle, transition=transition)
    channel_amplitudes = device.exdir_db.select_measurement_by_id(rect_pulse.references['channel_amplitudes'])
    if len(channel_amplitudes.metadata) > 2:
        raise ValueError('Default excitation pulse has more than one excitation channel')
    channel = [channel for channel in channel_amplitudes.metadata.keys()][0]
    if preferred_length is None:
        pulse_length = get_preferred_length(device, qubit_id, channel)
    else:
        pulse_length = preferred_length

    num_pulses = int(inverse_rotation_cycles)
    max_num_pulses = max_scan_length / pulse_length

    amplitude_guess = float(rect_pulse.metadata['length']) / per_amplitude_angle_guess(pulse_length,
                                                                                       pulse_length / sigmas_in_gauss)
    amplitude_range = 1.0*amplitude_guess
    # print ('rect_pulse.metadata[length]:', rect_pulse.metadata['length'])
    # print ('rotation_angle: ', rotation_angle)
    # print ('amplitude_guess: ', amplitude_guess)
    sigma = pulse_length / sigmas_in_gauss

    #TODO
    exitation_channel = [i for i in device.get_qubit_excitation_channel_list(qubit_id).keys()][0]
    ex_channel = device.awg_channels[exitation_channel]
    if ex_channel.is_iq():
        control_seq_id = ex_channel.parent.sequencer_id
    else:
        control_seq_id = ex_channel.channel // 2
    ex_sequencers = []

    for seq_id in device.pre_pulses.seq_in_use:
        if seq_id != control_seq_id:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses = [])
        else:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses=[], control=True)
            control_sequence = ex_seq
        device.pre_pulses.set_seq_offsets(ex_seq)
        device.pre_pulses.set_seq_prepulses(ex_seq)
        #device.modem.awg.set_sequence(ex_seq.params['sequencer_id'], ex_seq)
        ex_seq.start()
        ex_sequencers.append(ex_seq)
    fast_control = True
    channel_pulses = [(c, device.pg.gauss_hd, 1, sigma, alpha, phase, fast_control)
                      for c, a in channel_amplitudes.metadata.items()]
    prepare_seq = []
    prepare_seq.append(device.pg.pmulti(device, pulse_length, *tuple(channel_pulses)))
    sequence_control.set_preparation_sequence(device, ex_sequencers, prepare_seq)
    readout_sequencer = sequence_control.define_readout_control_seq(device, readout_pulse)
    readout_sequencer.start()


    while (num_pulses <= max_num_pulses):
        amplitudes = np.linspace(amplitude_guess - 0.5 * amplitude_range, amplitude_guess + 0.5 * amplitude_range,
                                 scan_points)

        control_sequence.awg.set_register(control_sequence.params['sequencer_id'], control_sequence.params['var_reg1'],
                                          int(inverse_rotation_cycles))
        measurement = gauss_hd_Rabi_amplitude(device, qubit_id, channel_amplitudes, rotation_angle, amplitudes,
                                              pulse_length, sigma, alpha, int(num_pulses/int(inverse_rotation_cycles)), control_sequence)

        adaptive_measurements.append(measurement)
        amplitude_guess = infer_amplitude_from_measurements()
        num_pulses *= int(_range)
        amplitude_range /= int(_range)

    references = {('gauss_hd_Rabi_amplitude', measurement.metadata['num_pulses']): measurement.id
                  for measurement in adaptive_measurements}
    references['channel_amplitudes'] = channel_amplitudes.id
    references['frequency_controls'] = device.get_frequency_control_measurement_id(qubit_id)
    metadata = {'amplitude_guess': amplitude_guess,
                'qubit_id': qubit_id,
                'alpha': alpha,
                'phase': phase,
                'inverse_rotation_cycles': inverse_rotation_cycles,
                'length': pulse_length,
                'sigma': sigma,
                'transition': transition}

    for seq in ex_sequencers:
        seq.stop()
    readout_sequencer.stop()

    return device.exdir_db.save(measurement_type='gauss_hd_Rabi_amplitude_adaptive',
                                references=references,
                                metadata=metadata)
Example #8
0
def benchmarking_pi2_multi(device,
                           qubit_ids,
                           *params,
                           interleaver=None,
                           two_qubit_gate=None,
                           max_pulses=None,
                           pause_length=0,
                           random_sequence_num=1,
                           seq_lengths_num=400,
                           two_qubit_num=0,
                           random_gate_num=1):
    channel_amplitudes_ = {}
    pi2_pulses = {}
    pi_pulses = {}
    generators = {}
    if max_pulses is None:
        max_pulses = []
        for qubit_id in qubit_ids:
            coherence_measurement = Ramsey.get_Ramsey_coherence_measurement(
                device, qubit_id)
            T2 = float(coherence_measurement.metadata['T'])
            pi2_pulses[qubit_id] = excitation_pulse.get_excitation_pulse(
                device, qubit_id, np.pi / 2.)
            pi2_pulse_length = float(pi2_pulses[qubit_id].metadata['length'])
            pi_pulses[qubit_id] = excitation_pulse.get_excitation_pulse(
                device, qubit_id, np.pi)
            pi_pulse_length = float(pi_pulses[qubit_id].metadata['length'])
            max_pulses.append(T2 / pi2_pulse_length)

        if two_qubit_gate is not None:
            max_pulses = np.asarray(max_pulses) / 3.

        max_pulses = min(max_pulses)

    for qubit_id in qubit_ids:
        pi2_pulses[qubit_id] = excitation_pulse.get_excitation_pulse(
            device, qubit_id, np.pi / 2.)
        pi_pulses[qubit_id] = excitation_pulse.get_excitation_pulse(
            device, qubit_id, np.pi)
        channel_amplitudes_[qubit_id] = channel_amplitudes.channel_amplitudes(
            device.exdir_db.select_measurement_by_id(
                pi2_pulses[qubit_id].references['channel_amplitudes']))

    seq_lengths = np.asarray(
        np.round(np.linspace(0, max_pulses, seq_lengths_num)), int)

    def get_pulse_seq_z(z_phase, length, qubit_id):
        fast_control = False
        z_pulse = [(c, device.pg.virtual_z, z_phase * 360 / 2 / np.pi,
                    fast_control)
                   for c, a in channel_amplitudes_[qubit_id].items()]
        sequence_z = [device.pg.pmulti(device, length, *tuple(z_pulse))]
        return sequence_z

    def tensor_product(unitary, qubit_id):
        U = [[1]]
        for i in qubit_ids:
            U = np.kron(U, np.identity(2) if i != qubit_id else unitary)
        return U

    #TODO
    qubit_readout_pulse, readout_device = calibrated_readout.get_calibrated_measurer(
        device, qubit_ids)

    generators = {}
    for qubit_id in qubit_ids:
        HZ = {
            'X': {
                'pulses': pi_pulses[qubit_id].get_pulse_sequence(0),
                'unitary': tensor_product(np.asarray([[0, 1], [1, 0]]),
                                          qubit_id),
                'price': 1.0
            },
            'X/2': {
                'pulses':
                pi2_pulses[qubit_id].get_pulse_sequence(0),
                'unitary':
                np.sqrt(0.5) *
                tensor_product(np.asarray([[1, -1j], [-1j, 1]]), qubit_id),
                'price':
                1.0
            },
            '-X/2': {
                'pulses':
                pi2_pulses[qubit_id].get_pulse_sequence(np.pi),
                'unitary':
                np.sqrt(0.5) *
                tensor_product(np.asarray([[1, 1j], [1j, 1]]), qubit_id),
                'price':
                1.0
            },
            'Z': {
                'pulses': get_pulse_seq_z(np.pi, pi2_pulse_length, qubit_id),
                'unitary': tensor_product([[1, 0], [0, -1]], qubit_id),
                'price': 0.1
            },
            'Z/2': {
                'pulses': get_pulse_seq_z(np.pi / 2, pi2_pulse_length,
                                          qubit_id),
                'unitary': tensor_product([[1, 0], [0, 1j]], qubit_id),
                'price': 0.1
            },
            '-Z/2': {
                'pulses': get_pulse_seq_z(-np.pi / 2., pi2_pulse_length,
                                          qubit_id),
                'unitary': tensor_product([[1, 0], [0, -1j]], qubit_id),
                'price': 0.1
            },
            'I': {
                'pulses': get_pulse_seq_z(0, pi2_pulse_length, qubit_id),
                'unitary': tensor_product([[1, 0], [0, 1]], qubit_id),
                'price': 0.1
            }
        }

        generators[qubit_id] = HZ

    if len(qubit_ids) == 2:
        #TODO
        HZ_group = clifford.two_qubit_clifford(
            *tuple([g for g in generators.values()]),
            plus_op_parallel=device.pg.parallel,
            two_qubit_gate=two_qubit_gate)
    elif len(qubit_ids) == 1:
        HZ_group = clifford.generate_group(generators[qubit_ids[0]])
    else:
        raise ValueError('More than two qubits are unsupported')

    print('group length:', len(HZ_group))

    # TODO qubit sequencer
    exitation_channel = [
        i
        for i in device.get_qubit_excitation_channel_list(qubit_ids[0]).keys()
    ][0]
    ex_channel = device.awg_channels[exitation_channel]
    if ex_channel.is_iq():
        control_seq_id = ex_channel.parent.sequencer_id
    else:
        control_seq_id = ex_channel.channel // 2
    ex_sequencers = []

    for seq_id in device.pre_pulses.seq_in_use:
        if seq_id != control_seq_id:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id,
                                               awg=device.modem.awg,
                                               awg_amp=1,
                                               use_modulation=True,
                                               pre_pulses=[])
        else:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id,
                                               awg=device.modem.awg,
                                               awg_amp=1,
                                               use_modulation=True,
                                               pre_pulses=[],
                                               control=True)
            control_sequence = ex_seq
        device.pre_pulses.set_seq_offsets(ex_seq)
        device.pre_pulses.set_seq_prepulses(ex_seq)
        ex_seq.start()
        ex_sequencers.append(ex_seq)

    seeds = np.random.randint(100000,
                              size=(random_sequence_num, len(qubit_ids),
                                    len(seq_lengths)))
    references = {'seeds': seeds}

    pi2_bench = interleaved_benchmarking.interleaved_benchmarking(
        readout_device,
        ex_sequencers,
        seeds,
        seq_lengths,
        interleavers=HZ_group,
        random_sequence_num=random_sequence_num,
        two_qubit_num=two_qubit_num,
        random_gate_num=random_gate_num)

    #TODO prepare_seq
    prepare_seq = pi2_bench.create_hdawg_generator()
    sequence_control.set_preparation_sequence(device, ex_sequencers,
                                              prepare_seq)

    #TODO readout sequence
    #ro_seq = [device.pg.pmulti(pause_length)]+device.trigger_readout_seq+qubit_readout_pulse.get_pulse_sequence()
    readout_sequencer = sequence_control.define_readout_control_seq(
        device, qubit_readout_pulse)
    readout_sequencer.start()

    pi2_bench.random_sequence_num = random_sequence_num
    seeds_ids = np.arange(seeds.shape[0])

    references = references.update({('pi2_pulse', qubit_id):
                                    pi2_pulses[qubit_id].id
                                    for qubit_id in qubit_ids})
    references = references.update({('pi_pulse', qubit_id):
                                    pi_pulses[qubit_id].id
                                    for qubit_id in qubit_ids})

    # TODO
    # pi2_bench.prepare_random_interleaving_sequences()

    ### search db for previous version of the interleaver measurement
    found = False
    try:
        clifford_bench = device.exdir_db.select_measurement(
            measurement_type='clifford_bench',
            metadata={'qubit_ids': ','.join(qubit_ids)},
            references_that=references)
        found = True
    except IndexError:
        pass

    if random_sequence_num > 1:
        params = tuple([(seeds_ids, pi2_bench.set_interleaved_sequence,
                         'Random seeds id', '')] + [p for p in params])

    if (not found) or (interleaver is None):
        measurement_name = [m for m in pi2_bench.get_points().keys()][0]
        fitter_arguments = (measurement_name, exp.exp_fitter(), 0,
                            np.arange(len(params)).tolist())

        clifford_bench = device.sweeper.sweep_fit_dataset_1d_onfly(
            pi2_bench,
            (seq_lengths, pi2_bench.set_sequence_length, 'Gate number', ''),
            *params,
            fitter_arguments=fitter_arguments,
            measurement_type='clifford_bench',
            metadata={'qubit_ids': ','.join(qubit_ids)},
            shuffle=True,
            references=references)

    ## interleaver measurement is found, bench "interleaver" gate
    references['Clifford-bench'] = clifford_bench.id
    if interleaver is not None:
        if 'references' in interleaver:
            references.update(interleaver['references'])

        pi2_bench.set_target_pulse(interleaver)

        measurement_name = [m for m in pi2_bench.get_points().keys()][0]
        fitter_arguments = (measurement_name, exp.exp_fitter(), 0,
                            np.arange(len(params)).tolist())

        interleaved_bench = device.sweeper.sweep_fit_dataset_1d_onfly(
            pi2_bench,
            (seq_lengths, pi2_bench.set_sequence_length, 'Gate number', ''),
            *params,
            fitter_arguments=fitter_arguments,
            measurement_type='interleaved_bench',
            metadata={'qubit_ids': ','.join(qubit_ids)},
            shuffle=True,
            references=references)

        return interleaved_bench

    return clifford_bench
Example #9
0
def gauss_hd_Rabi_alpha_adaptive(device, qubit_id, preferred_length=None, transition='01'):
    # min_step = float(device.get_qubit_constant(qubit_id=qubit_id, name='adaptive_Rabi_min_step'))
    readout_pulse, measurer = get_uncalibrated_measurer(device=device, qubit_id=qubit_id)

    #scan_points = int(device.get_qubit_constant(qubit_id=qubit_id, name='adaptive_Rabi_alpha_scan_points'))
    scan_points = 32
    _range = float(device.get_qubit_constant(qubit_id=qubit_id, name='adaptive_Rabi_alpha_range'))
    max_scan_length = float(device.get_qubit_constant(qubit_id=qubit_id, name='adaptive_Rabi_max_scan_length'))
    sigmas_in_gauss = float(device.get_qubit_constant(qubit_id=qubit_id, name='sigmas_in_gauss'))

    adaptive_measurements = []

    def infer_alpha_from_measurements():
        alphas = adaptive_measurements[-1].datasets['iq' + qubit_id].parameters[0].values
        measurement_interpolated_combined = np.zeros(alphas.shape)
        measurement_projector = np.conj(np.mean(adaptive_measurements[0].datasets['iq' + qubit_id].data))
        for measurement in adaptive_measurements:
            measurement_interpolated_combined += np.interp(alphas,
                                                           measurement.datasets['iq' + qubit_id].parameters[0].values,
                                                           np.real(measurement.datasets[
                                                                       'iq' + qubit_id].data * measurement_projector), )
        return alphas[np.argmin(measurement_interpolated_combined)]

    pi2_pulse = get_excitation_pulse_from_gauss_hd_Rabi_amplitude(device=device, qubit_id=qubit_id,
                                                                  rotation_angle=np.pi / 2.)
    channel_amplitudes_ = device.exdir_db.select_measurement_by_id(pi2_pulse.references['channel_amplitudes'])
    if len(channel_amplitudes_.metadata) > 2:
        raise ValueError('Default excitation pulse has more than one excitation channel')
    channel = [channel for channel in channel_amplitudes_.metadata.keys()][0]

    if preferred_length is None:
        pulse_length = float(pi2_pulse.metadata['length'])
    else:
        pulse_length = preferred_length
    #amplitude = float(pi2_pulse.metadata['amplitude'])
    #sigma = pulse_length / sigmas_in_gauss

    max_num_pulses = max_scan_length / pulse_length
    num_pulses = 1
    #alpha_guess = 0.0  # np.pi
    #alpha_range = 1e-8  # 2*np.pi
    #alphas = np.linspace(alpha_guess - 0.5 * alpha_range, alpha_guess + 0.5 * alpha_range, scan_points)
    #measurement = gauss_hd_ape_alpha(device, qubit_id, alphas, 0, phase_sign='+')
    #adaptive_measurements.append(measurement)

    amplitude = float(pi2_pulse.metadata['amplitude'])
    sigma = float(pi2_pulse.metadata['sigma'])
    length = float(pi2_pulse.metadata['length'])

    fast_control = False
    alpha1 = 0
    phase = 0
    channel_pulses_xp = [(c, device.pg.gauss_hd, float(a) * amplitude, sigma, alpha1, phase, fast_control)
                             for c, a in channel_amplitudes_.metadata.items()]
    channel_pulses_xm = [(c, device.pg.gauss_hd, -float(a) * amplitude, sigma, alpha1, phase, fast_control)
                             for c, a in channel_amplitudes_.metadata.items()]
    fast_control = 'phase_correction'
    channel_pulses = [(c, device.pg.gauss_hd, float(a) * amplitude, sigma, alpha1, phase, fast_control)
                      for c, a in channel_amplitudes_.metadata.items()]

    prepare_seq = []
    prepare_seq.append(device.pg.pmulti(device, length, *tuple(channel_pulses_xp)))
    prepare_seq.append(device.pg.pmulti(device, length, *tuple(channel_pulses)))
    prepare_seq.append(device.pg.pmulti(device, length, *tuple(channel_pulses_xm)))

    #TODO
    exitation_channel = [i for i in device.get_qubit_excitation_channel_list(qubit_id).keys()][0]
    ex_channel = device.awg_channels[exitation_channel]
    if ex_channel.is_iq():
        control_seq_id = ex_channel.parent.sequencer_id
    else:
        control_seq_id = ex_channel.channel // 2
    ex_sequencers = []

    for seq_id in device.pre_pulses.seq_in_use:
        if seq_id != control_seq_id:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses = [])
        else:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses=[], control=True)
            control_sequence = ex_seq
        device.pre_pulses.set_seq_offsets(ex_seq)
        device.pre_pulses.set_seq_prepulses(ex_seq)
        ex_seq.start()
        ex_sequencers.append(ex_seq)
    control_sequence.awg.set_register(control_sequence.params['sequencer_id'],
                                      control_sequence.params['var_reg1'], int(1))

    sequence_control.set_preparation_sequence(device, ex_sequencers, prepare_seq)
    readout_sequencer = sequence_control.define_readout_control_seq(device, readout_pulse)
    readout_sequencer.start()

    alpha_guess = 0
    alpha_range = 2*np.pi
    alphas = np.linspace(alpha_guess - 0.5 * alpha_range, alpha_guess + 0.5 * alpha_range, scan_points)
    measurement = gauss_hd_ape_alpha(device, qubit_id, alphas, 0, ex_sequencers,
                                     control_sequence, readout_sequencer, phase_sign='+')
    adaptive_measurements.append(measurement)
    alpha_range /= int(_range)


    while (num_pulses <= max_num_pulses):
        # adaptive_measurements = []
        alphas = np.linspace(alpha_guess - 0.5 * alpha_range, alpha_guess + 0.5 * alpha_range, scan_points)
        measurement = gauss_hd_ape_alpha(device, qubit_id, alphas, num_pulses, ex_sequencers,
                                         control_sequence, readout_sequencer, phase_sign='+')
        adaptive_measurements.append(measurement)
        alpha_guess = infer_alpha_from_measurements()
        num_pulses *= int(_range)
        alpha_range /= int(_range)

    references = {('gauss_hd_Rabi_alpha', measurement.metadata['num_pulses']): measurement.id
                  for measurement in adaptive_measurements}
    references['channel_amplitudes'] = channel_amplitudes_.id
    references['frequency_controls'] = device.get_frequency_control_measurement_id(qubit_id)
    references['gauss_hd_Rabi_amplitude_adaptive'] = pi2_pulse.id

    metadata = {'amplitude': amplitude,
                'qubit_id': qubit_id,
                'alpha_guess': alpha1,
                'phase_guess': alpha_guess,
                'length': pulse_length,
                'sigma': sigma,
                'transition': transition
                }

    return device.exdir_db.save(measurement_type='gauss_hd_Rabi_alpha_adaptive',
                                references=references,
                                metadata=metadata)
Example #10
0
def benchmarking_pi2(device,
                     qubit_id,
                     *params,
                     pause_length=0,
                     random_sequence_num=1,
                     seq_lengths_num=400):
    coherence_measurement = Ramsey.get_Ramsey_coherence_measurement(
        device, qubit_id)
    T2 = float(coherence_measurement.metadata['T'])
    pi2_pulse = excitation_pulse.get_excitation_pulse(device, qubit_id,
                                                      np.pi / 2.)
    pi2_pulse_length = float(pi2_pulse.metadata['length'])

    pi_pulse = excitation_pulse.get_excitation_pulse(device, qubit_id, np.pi)
    pi_pulse_length = float(pi_pulse.metadata['length'])
    channel_amplitudes_ = channel_amplitudes.channel_amplitudes(
        device.exdir_db.select_measurement_by_id(
            pi2_pulse.references['channel_amplitudes']))
    max_pulses = T2 / pi2_pulse_length
    seq_lengths = np.asarray(
        np.round(np.linspace(0, max_pulses, seq_lengths_num)), int)

    def get_pulse_seq_z(z_phase, length):
        fast_control = False
        z_pulse = [(c, device.pg.virtual_z, z_phase * 360 / 2 / np.pi,
                    fast_control) for c, a in channel_amplitudes_.items()]
        sequence_z = [device.pg.pmulti(device, length, *tuple(z_pulse))]
        return sequence_z

    #TODO
    qubit_readout_pulse, readout_device = calibrated_readout.get_calibrated_measurer(
        device, [qubit_id])
    #HZ = {'X': {'pulses': pi_pulse.get_pulse_sequence(0), 'unitary': np.asarray([[0, 1], [1, 0]]), 'price': 1.0},
    #    'X/2': {'pulses': pi2_pulse.get_pulse_sequence(0), 'unitary': np.sqrt(0.5) * np.asarray([[1, -1j], [-1j, 1]]), 'price': 1.0},
    #    '-X/2': {'pulses': pi2_pulse.get_pulse_sequence(np.pi), 'unitary': np.sqrt(0.5) * np.asarray([[1, 1j], [1j, 1]]), 'price': 1.0},
    #    'Z': {'pulses': get_pulse_seq_z(np.pi), 'unitary': np.asarray([[1, 0], [0, -1]]), 'price':0.1},
    #    'Z/2': {'pulses': get_pulse_seq_z(np.pi / 2), 'unitary': np.asarray([[1, 0], [0, 1j]]), 'price':0.1},
    #    '-Z/2': {'pulses': get_pulse_seq_z(-np.pi / 2.), 'unitary': np.asarray([[1, 0], [0, -1j]]), 'price':0.1},
    #   'I': {'pulses': get_pulse_seq_z(0, qubit_id), 'unitary': np.asarray([[1, 0], [0, 1]]), 'price':0.1}
    #   }
    #X_metadata = pi_pulse.metadata()
    #X2_metadata = pi2_pulse.metadata()
    #X_2_metadata = pi2_pulse.metadata()
    #X_2_metadata['amplitude'] = float(a) * float(self.metadata['amplitude']) * np.exp(1j * phase)
    HZ = {
        'X': {
            'pulses': pi_pulse.get_pulse_sequence(0),
            'unitary': np.asarray([[0, 1], [1, 0]]),
            'price': 1.0
        },
        'X/2': {
            'pulses': pi2_pulse.get_pulse_sequence(0),
            'unitary': np.sqrt(0.5) * np.asarray([[1, -1j], [-1j, 1]]),
            'price': 1.0
        },
        '-X/2': {
            'pulses': pi2_pulse.get_pulse_sequence(np.pi),
            'unitary': np.sqrt(0.5) * np.asarray([[1, 1j], [1j, 1]]),
            'price': 1.0
        },
        'Z': {
            'pulses': get_pulse_seq_z(np.pi, pi2_pulse_length),
            'unitary': np.asarray([[1, 0], [0, -1]]),
            'price': 0.1
        },
        'Z/2': {
            'pulses': get_pulse_seq_z(np.pi / 2, pi2_pulse_length),
            'unitary': np.asarray([[1, 0], [0, 1j]]),
            'price': 0.1
        },
        '-Z/2': {
            'pulses': get_pulse_seq_z(-np.pi / 2., pi2_pulse_length),
            'unitary': np.asarray([[1, 0], [0, -1j]]),
            'price': 0.1
        },
        'I': {
            'pulses': get_pulse_seq_z(0, pi2_pulse_length),
            'unitary': np.asarray([[1, 0], [0, 1]]),
            'price': 0.1
        }
    }

    HZ_group = clifford.generate_group(HZ)

    #TODO qubit sequencer
    exitation_channel = [
        i for i in device.get_qubit_excitation_channel_list(qubit_id).keys()
    ][0]
    ex_channel = device.awg_channels[exitation_channel]
    if ex_channel.is_iq():
        control_seq_id = ex_channel.parent.sequencer_id
    else:
        control_seq_id = ex_channel.channel // 2
    ex_sequencers = []

    for seq_id in device.pre_pulses.seq_in_use:
        if seq_id != control_seq_id:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id,
                                               awg=device.modem.awg,
                                               awg_amp=1,
                                               use_modulation=True,
                                               pre_pulses=[])
        else:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id,
                                               awg=device.modem.awg,
                                               awg_amp=1,
                                               use_modulation=True,
                                               pre_pulses=[],
                                               control=True)
            control_sequence = ex_seq
        device.pre_pulses.set_seq_offsets(ex_seq)
        device.pre_pulses.set_seq_prepulses(ex_seq)
        ex_seq.start()
        ex_sequencers.append(ex_seq)

    pi2_bench = interleaved_benchmarking.interleaved_benchmarking(
        readout_device, ex_sequencers, HZ_group)
    #pi2_bench.interleavers = HZ_group

    #TODO prepare_seq
    prepare_seq = pi2_bench.create_hdawg_generator()
    sequence_control.set_preparation_sequence(device, ex_sequencers,
                                              prepare_seq)

    # TODO Readout sequencer
    #ro_seq = [device.pg.pmulti(pause_length)]+device.trigger_readout_seq+qubit_readout_pulse.get_pulse_sequence()
    readout_sequencer = sequence_control.define_readout_control_seq(
        device, qubit_readout_pulse)
    readout_sequencer.start()

    #pi2_bench = interleaved_benchmarking.interleaved_benchmarking(readout_device,
    #        set_seq = lambda x: device.pg.set_seq(device.pre_pulses+x+ro_seq))
    #pi2_bench.interleavers = HZ_group

    pi2_bench.random_sequence_num = random_sequence_num
    random_sequence_ids = np.arange(random_sequence_num)

    pi2_bench.prepare_random_interleaving_sequences()
    clifford_bench = device.sweeper.sweep(
        pi2_bench, (seq_lengths, pi2_bench.set_sequence_length_and_regenerate,
                    'Gate number', ''),
        *params, (random_sequence_ids, pi2_bench.set_interleaved_sequence,
                  'Random sequence id', ''),
        shuffle=True,
        measurement_type='pi2_bench',
        metadata={'qubit_id': qubit_id},
        references={
            'pi2_pulse': pi2_pulse.id,
            'pi_pulse': pi_pulse.id
        })
    return clifford_bench
Example #11
0
def relaxation(device,
               qubit_id,
               transition='01',
               *extra_sweep_args,
               channel_amplitudes=None,
               lengths=None,
               readout_delay=0,
               delay_seq_generator=None,
               measurement_type='decay',
               ex_pulse=None,
               additional_references={},
               additional_metadata={}):
    from .readout_pulse import get_uncalibrated_measurer
    from ..fitters.exp import exp_fitter
    if type(lengths) is type(None):
        lengths = np.arange(
            0,
            float(
                device.get_qubit_constant(qubit_id=qubit_id,
                                          name='Ramsey_length')),
            float(
                device.get_qubit_constant(qubit_id=qubit_id,
                                          name='Ramsey_step')))

    #readout_pulse = get_qubit_readout_pulse(device, qubit_id)
    readout_pulse, measurer = get_uncalibrated_measurer(
        device, qubit_id, transition)
    if ex_pulse is None:
        ex_pulse = excitation_pulse.get_excitation_pulse(
            device,
            qubit_id,
            np.pi,
            channel_amplitudes_override=channel_amplitudes)

    exitation_channel = [
        i for i in device.get_qubit_excitation_channel_list(qubit_id).keys()
    ][0]
    ex_channel = device.awg_channels[exitation_channel]
    if ex_channel.is_iq():
        control_seq_id = ex_channel.parent.sequencer_id
    else:
        control_seq_id = ex_channel.channel // 2
    ex_sequencers = []

    for seq_id in device.pre_pulses.seq_in_use:
        if seq_id != control_seq_id:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id,
                                               awg=device.modem.awg,
                                               awg_amp=1,
                                               use_modulation=True,
                                               pre_pulses=[])
        else:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id,
                                               awg=device.modem.awg,
                                               awg_amp=1,
                                               use_modulation=True,
                                               pre_pulses=[],
                                               control=True)
            control_sequence = ex_seq
        device.pre_pulses.set_seq_offsets(ex_seq)
        device.pre_pulses.set_seq_prepulses(ex_seq)
        #device.modem.awg.set_sequence(ex_seq.params['sequencer_id'], ex_seq)
        ex_seq.start()
        ex_sequencers.append(ex_seq)
    readout_sequencer = sequence_control.define_readout_control_seq(
        device, readout_pulse)
    readout_sequencer.start()

    class ParameterSetter:
        def __init__(self):
            self.ex_sequencers = ex_sequencers
            self.prepare_seq = []
            self.readout_sequencer = readout_sequencer
            self.delay_seq_generator = delay_seq_generator
            self.lengths = lengths
            self.control_sequence = control_sequence
            # Create preparation sequence
            self.prepare_seq.extend(ex_pulse.get_pulse_sequence(0))
            if self.delay_seq_generator is None:
                self.prepare_seq.extend([device.pg.pmulti(device, 0)])
                self.prepare_seq.extend(
                    [device.pg.pmulti(device, self.lengths)])
                self.prepare_seq.extend([device.pg.pmulti(device, 0)])
            else:
                self.pre_pause, self.delay_sequence, self.post_pause = self.delay_seq_generator(
                    self.lengths)
                self.prepare_seq.extend(self.pre_pause)
                self.prepare_seq.extend(self.delay_sequence)
                self.prepare_seq.extend(self.post_pause)

            # Set preparation sequence
            sequence_control.set_preparation_sequence(device,
                                                      self.ex_sequencers,
                                                      self.prepare_seq)
            self.readout_sequencer.start()

        def set_delay(self, length):
            if self.delay_seq_generator is None:
                for ex_seq in self.ex_sequencers:
                    ex_seq.set_length(length)
            else:
                if length == self.lengths[0]:
                    self.readout_sequencer.awg.stop_seq(
                        self.readout_sequencer.params['sequencer_id'])
                    self.pre_pause, self.delay_sequence, self.post_pause = self.delay_seq_generator(
                        self.lengths)
                    self.prepare_seq[-2] = self.delay_sequence[0]
                    sequence_control.set_preparation_sequence(
                        device, self.ex_sequencers, self.prepare_seq,
                        self.control_sequence)
                    for ex_seq in self.ex_sequencers:
                        ex_seq.set_length(length)
                    self.readout_sequencer.awg.start_seq(
                        self.readout_sequencer.params['sequencer_id'])
                else:
                    for ex_seq in self.ex_sequencers:
                        ex_seq.set_length(length)

    setter = ParameterSetter()

    references = {
        'ex_pulse':
        ex_pulse.id,
        'frequency_controls':
        device.get_frequency_control_measurement_id(qubit_id=qubit_id)
    }
    references.update(additional_references)

    if hasattr(measurer, 'references'):
        references.update(measurer.references)

    fitter_arguments = ('iq' + qubit_id, exp_fitter(), -1,
                        np.arange(len(extra_sweep_args)))

    metadata = {
        'qubit_id': qubit_id,
        'transition': transition,
        'extra_sweep_args': str(len(extra_sweep_args)),
        'readout_delay': str(readout_delay)
    }
    metadata.update(additional_metadata)

    measurement = device.sweeper.sweep_fit_dataset_1d_onfly(
        measurer,
        *extra_sweep_args, (lengths, setter.set_delay, 'Delay', 's'),
        fitter_arguments=fitter_arguments,
        measurement_type=measurement_type,
        metadata=metadata,
        references=references)

    return measurement
Example #12
0
def Ramsey(device, qubit_id, transition='01', *extra_sweep_args, channel_amplitudes1=None, channel_amplitudes2=None, lengths=None,
           target_freq_offset=None, readout_delay=0, delay_seq_generator=None, measurement_type='Ramsey',
           additional_references = {}, additional_metadata = {}):
    from .readout_pulse2 import get_uncalibrated_measurer
    if type(lengths) is type(None):
        lengths = np.arange(0,
                            float(device.get_qubit_constant(qubit_id=qubit_id, name='Ramsey_length')),
                            float(device.get_qubit_constant(qubit_id=qubit_id, name='Ramsey_step')))
    #readout_pulse = get_qubit_readout_pulse(device, qubit_id)
    readout_pulse, measurer = get_uncalibrated_measurer(device, qubit_id, transition)
    ex_pulse1 = excitation_pulse.get_excitation_pulse(device, qubit_id, np.pi/2., channel_amplitudes_override=channel_amplitudes1)
    ex_pulse2 = excitation_pulse.get_excitation_pulse(device, qubit_id, np.pi/2., channel_amplitudes_override=channel_amplitudes2)


    exitation_channel = [i for i in device.get_qubit_excitation_channel_list(qubit_id).keys()][0]
    ex_channel = device.awg_channels[exitation_channel]
    if ex_channel.is_iq():
        control_seq_id = ex_channel.parent.sequencer_id
    else:
        control_seq_id = ex_channel.channel//2
    ex_sequencers = []

    for seq_id in device.pre_pulses.seq_in_use:
        if seq_id != control_seq_id:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses = [])
        else:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses=[], control=True)
            control_sequence = ex_seq
        device.pre_pulses.set_seq_offsets(ex_seq)
        device.pre_pulses.set_seq_prepulses(ex_seq)
        #device.modem.awg.set_sequence(ex_seq.params['sequencer_id'], ex_seq)
        ex_seq.start()
        ex_sequencers.append(ex_seq)
    readout_sequencer = sequence_control.define_readout_control_seq(device, readout_pulse)
    readout_sequencer.start()

    class ParameterSetter:
        def __init__(self):
            self.ex_sequencers=ex_sequencers
            self.prepare_seq = []
            self.readout_sequencer = readout_sequencer
            self.delay_seq_generator = delay_seq_generator
            self.lengths = lengths
            self.control_sequence = control_sequence
            # Create preparation sequence
            self.prepare_seq.extend(ex_pulse1.get_pulse_sequence(0))
            if self.delay_seq_generator is None:
                self.prepare_seq.extend([device.pg.pmulti(device, 0)])
                self.prepare_seq.extend([device.pg.pmulti(device, self.lengths)])
                self.prepare_seq.extend([device.pg.pmulti(device, 0)])
            else:
                self.pre_pause, self.delay_sequence, self.post_pause = self.delay_seq_generator(self.lengths)
                self.prepare_seq.extend(self.pre_pause)
                self.prepare_seq.extend(self.delay_sequence)
                self.prepare_seq.extend(self.post_pause)
            self.prepare_seq.extend(excitation_pulse.get_s(device, qubit_id,
                                                           phase=(64/self.control_sequence.clock)*target_freq_offset*360 % 360,
                                                           fast_control='quasi-binary'))
            self.prepare_seq.extend(ex_pulse2.get_pulse_sequence(0))
            # Set preparation sequence
            sequence_control.set_preparation_sequence(device, self.ex_sequencers, self.prepare_seq)
            self.readout_sequencer.start()

        def set_delay(self, length):
            phase = int(np.round((length+140e-9)*self.control_sequence.clock)+64)/self.control_sequence.clock*target_freq_offset*360 % 360
            #print ('length: ', length, ', phase: ', phase, ', phase register: ', int(phase/360*(2**6)))

            if self.delay_seq_generator is None:
                for ex_seq in self.ex_sequencers:
                    ex_seq.set_length(length)
                self.control_sequence.set_phase(int(phase/360*(2**8)))
            else:
                if length == self.lengths[0]:
                    self.readout_sequencer.awg.stop_seq(self.readout_sequencer.params['sequencer_id'])
                    self.pre_pause, self.delay_sequence, self.post_pause = self.delay_seq_generator(self.lengths)
                    self.prepare_seq[-4] = self.delay_sequence[0]
                    #sequence_control.set_preparation_sequence(device, self.ex_sequencers, self.prepare_seq,
                                                              #self.control_sequence)
                    sequence_control.set_preparation_sequence(device, self.ex_sequencers, self.prepare_seq)

                    for ex_seq in self.ex_sequencers:
                        ex_seq.set_length(length)
                    self.control_sequence.set_phase(int(phase/360*(2**8)))
                    self.readout_sequencer.awg.start_seq(self.readout_sequencer.params['sequencer_id'])

                else:
                    for ex_seq in self.ex_sequencers:
                        ex_seq.set_length(length)
                    self.control_sequence.set_phase(int(phase/360*(2**8)))

        def set_delay1(self, length):
            self.prepare_seq[-2] = excitation_pulse.get_s(device, qubit_id,
                                        phase=(int(np.round(length*self.control_sequence.clock)+64)/self.control_sequence.clock)*target_freq_offset*360)

            if self.delay_seq_generator is None:
                self.readout_sequencer.awg.stop_seq(self.readout_sequencer.params['sequencer_id'])
                for ex_seq in self.ex_sequencers:
                    ex_seq.set_length(length)
                    if ex_seq.params['sequencer_id'] == self.control_sequence.params['sequencer_id']:
                        ex_seq.awg.stop_seq(ex_seq.params['sequencer_id'])
                        ex_seq.clear_pulse_sequence()
                        for prep_seq in self.prepare_seq:
                            for seq_id, single_sequence in prep_seq[0].items():
                                if seq_id == ex_seq.params['sequencer_id']:
                                    ex_seq.add_definition_fragment(single_sequence[0])
                                    ex_seq.add_play_fragment(single_sequence[1])
                        device.modem.awg.set_sequence(ex_seq.params['sequencer_id'], ex_seq)
                        ex_seq.awg.start_seq(ex_seq.params['sequencer_id'])
                self.readout_sequencer.awg.start_seq(self.readout_sequencer.params['sequencer_id'])

            else:
                if length == self.lengths[0]:
                    self.readout_sequencer.awg.stop_seq(self.readout_sequencer.params['sequencer_id'])
                    self.pre_pause, self.delay_sequence, self.post_pause = self.delay_seq_generator(self.lengths)
                    self.prepare_seq[-4] = self.delay_sequence
                    sequence_control.set_preparation_sequence(device, self.ex_sequencers, self.prepare_seq)
                    for ex_seq in self.ex_sequencers:
                        ex_seq.set_length(length)
                    self.readout_sequencer.awg.start_seq(self.readout_sequencer.params['sequencer_id'])
                else:
                    self.readout_sequencer.awg.stop_seq(self.readout_sequencer.params['sequencer_id'])
                    for ex_seq in self.ex_sequencers:
                        ex_seq.set_length(length)
                        if ex_seq.params['sequencer_id'] == self.control_sequence.params['sequencer_id']:
                            ex_seq.awg.stop_seq(ex_seq.params['sequencer_id'])
                            ex_seq.clear_pulse_sequence()
                            for prep_seq in self.prepare_seq:
                                for seq_id, single_sequence in prep_seq[0].items():
                                    if seq_id == ex_seq.params['sequencer_id']:
                                        ex_seq.add_definition_fragment(single_sequence[0])
                                        ex_seq.add_play_fragment(single_sequence[1])
                            device.modem.awg.set_sequence(ex_seq.params['sequencer_id'], ex_seq)
                            ex_seq.awg.start_seq(ex_seq.params['sequencer_id'])
                    self.readout_sequencer.awg.start_seq(self.readout_sequencer.params['sequencer_id'])

    setter = ParameterSetter()

    references = {'ex_pulse1':ex_pulse1.id,
                  'ex_pulse2':ex_pulse2.id,
                  'frequency_controls':device.get_frequency_control_measurement_id(qubit_id=qubit_id),
                  'readout_pulse':readout_pulse.id }
    references.update(additional_references)

    if hasattr(measurer, 'references'):
        references.update(measurer.references)

    fitter_arguments = ('iq'+qubit_id, exp_sin_fitter(), -1, np.arange(len(extra_sweep_args)))

    metadata = {'qubit_id': qubit_id,
                'transition': transition,
              'extra_sweep_args':str(len(extra_sweep_args)),
              'target_offset_freq': str(target_freq_offset),
              'readout_delay':str(readout_delay)}
    metadata.update(additional_metadata)

    measurement = device.sweeper.sweep_fit_dataset_1d_onfly(measurer,
                                              *extra_sweep_args,
                                              (lengths, setter.set_delay, 'Delay','s'),
                                              fitter_arguments = fitter_arguments,
                                              measurement_type=measurement_type,
                                              metadata=metadata,
                                              references=references,
                                              on_update_divider=10)

    for ex_seq in ex_sequencers:
        ex_seq.stop()
    readout_sequencer.stop()
    return measurement
Example #13
0
def Ramsey_process(device, qubit_id1, qubit_id2, process, channel_amplitudes1=None, channel_amplitudes2=None):
    '''
    :param device QubitDevice:
    '''
    from .readout_pulse2 import get_uncalibrated_measurer
    readout_pulse, measurer = get_uncalibrated_measurer(device, qubit_id2) # we want to measure qubit 2 because otherwise wtf are we are doing the second pi/2 pulse for
    phase_scan_points = int(device.get_sample_global(name='process_phase_scan_points'))
    phases = np.linspace(0, 2*np.pi, phase_scan_points, endpoint=False)
    ex_pulse1 = excitation_pulse.get_excitation_pulse(device, qubit_id1, np.pi/2., channel_amplitudes_override=channel_amplitudes1)
    ex_pulse2 = excitation_pulse.get_excitation_pulse(device, qubit_id2, np.pi/2., channel_amplitudes_override=channel_amplitudes2)
    #TODO
    #New sequencer
    exitation_channel = [i for i in device.get_qubit_excitation_channel_list(qubit_id1).keys()][0]
    ex_channel = device.awg_channels[exitation_channel]
    if ex_channel.is_iq():
        control_seq_id = ex_channel.parent.sequencer_id
    else:
        control_seq_id = ex_channel.channel // 2
    ex_sequencers = []

    for seq_id in device.pre_pulses.seq_in_use:
        if seq_id != control_seq_id:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses=[])
        else:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses=[], control=True)
            control_sequence = ex_seq
        device.pre_pulses.set_seq_offsets(ex_seq)
        device.pre_pulses.set_seq_prepulses(ex_seq)
        ex_sequencers.append(ex_seq)

    # Create preparation sequence
    prepare_seq = []
    prepare_seq.extend(ex_pulse1.get_pulse_sequence(0))
    # prepare_seq.append(excitation_pulse.get_s(device, qubit_id,
    #                                          phase=(round(float(ex_pulse1.metadata['length'])*control_sequence.clock/32)*32/control_sequence.clock)*target_freq_offset*360))
    prepare_seq.extend(process.get_pulse_sequence())
    prepare_seq.extend(excitation_pulse.get_s(device, qubit_id2, phase=phases[0]/2/np.pi*360,))
    prepare_seq.extend(ex_pulse2.get_pulse_sequence(0))
    # Set preparation sequence
    sequence_control.set_preparation_sequence(device, ex_sequencers, prepare_seq)
    readout_sequencer = sequence_control.define_readout_control_seq(device, readout_pulse)
    readout_sequencer.start()

    def set_phase(phase):
        readout_sequencer.awg.stop_seq(readout_sequencer.params['sequencer_id'])
        for ex_seq in ex_sequencers:
            ex_seq.clear_pulse_sequence()
            prepare_seq[-2] = excitation_pulse.get_s(device, qubit_id2, phase=phase / 2 / np.pi * 360)
            sequence_control.set_preparation_sequence(device, ex_sequencers, prepare_seq)
        readout_sequencer.awg.start_seq(readout_sequencer.params['sequencer_id'])

    references = {'ex_pulse1':ex_pulse1.id,
                  'ex_pulse2':ex_pulse2.id,
                  ('frequency_controls', qubit_id1): device.get_frequency_control_measurement_id(qubit_id=qubit_id1),
                  ('frequency_controls', qubit_id2): device.get_frequency_control_measurement_id(qubit_id=qubit_id2),
                  'process': process.id}
    metadata = {'q1': qubit_id1,
                'q2': qubit_id2}
    if hasattr(measurer, 'references'):
        references.update(measurer.references)

    fitter_arguments = ('iq'+qubit_id2, SinglePeriodSinFitter(), -1, [])

    measurement = device.sweeper.sweep_fit_dataset_1d_onfly(measurer,
                                                            (phases, set_phase, 'Phase','radians'),
                                                            fitter_arguments = fitter_arguments,
                                                            measurement_type='Ramsey_process',
                                                            metadata=metadata,
                                                            references=references)

    return measurement
Example #14
0
def Rabi_rect(device, qubit_id, channel_amplitudes, transition='01', lengths=None, *extra_sweep_args, tail_length=0, readout_delay=0,
              pre_pulses=tuple(), repeats=1, measurement_type='Rabi_rect', samples=False, additional_metadata={}):
    from .readout_pulse2 import get_uncalibrated_measurer
    from .calibrated_readout import get_calibrated_measurer

    if type(qubit_id) is not list and type(qubit_id) is not tuple:  # if we are working with a single qubit, use uncalibrated measurer
        readout_pulse, measurer = get_uncalibrated_measurer(device, qubit_id, transition=transition, samples=samples)
        measurement_name = 'iq'+qubit_id
        qubit_id = [qubit_id]
        exp_sin_fitter_mode = 'unsync'
        exitation_channel = [i for i in device.get_qubit_excitation_channel_list(qubit_id[0]).keys()][0]
    else: # otherwise use calibrated measurer
        readout_pulse, measurer = get_calibrated_measurer(device, qubit_id)
        measurement_name = 'resultnumbers'
        exp_sin_fitter_mode = 'unsync'
        exitation_channel = [i for i in device.get_qubit_excitation_channel_list(qubit_id).keys()][0]

    #pre_pulse_sequences = []
    #for pulse in pre_pulses:
    #    if hasattr(pulse, 'get_pulse_sequence'):
    #        pre_pulse_sequences += pulse.get_pulse_sequence(0.0)
    #    else:
    #        pre_pulse_sequences += pulse

    #pre_pulse_sequences = [p for pulse in pre_pulses for p in pulse.get_pulse_sequence(0)]
    # Exitation sequencer
    # Nado zagrusit pre rulse vo vse sequencery
    #print(qubit_id)

    ex_channel = device.awg_channels[exitation_channel]
    if ex_channel.is_iq():
        control_seq_id = ex_channel.parent.sequencer_id
    else:
        control_seq_id = ex_channel.channel//2
    ex_sequencers = []

    # Pulse definition
    for a, c in channel_amplitudes.items():
        if a == exitation_channel:
            exitation_amplitude = np.abs(c)
    def_frag, play_frag = device.pg.rect_cos(channel=exitation_channel,
                                             length=0, amp=exitation_amplitude,
                                             length_tail=tail_length, fast_control=True)

    for seq_id in device.pre_pulses.seq_in_use:
        if seq_id != control_seq_id:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses = [])
        else:
            ex_seq = zi_scripts.SIMPLESequence(sequencer_id=seq_id, awg=device.modem.awg,
                                               awg_amp=1, use_modulation=True, pre_pulses=[], control=True)
            control_sequence = ex_seq
            ex_seq.add_definition_fragment(def_frag)
            ex_seq.add_play_fragment(play_frag*repeats)

        ex_sequencers.append(ex_seq)
    control_sequence.set_frequency(np.abs(ex_channel.get_frequency()))
    for sequence in ex_sequencers:
        sequence.stop()
        device.pre_pulses.set_seq_offsets(sequence)
        device.pre_pulses.set_seq_prepulses(sequence)
        device.modem.awg.set_sequence(sequence.params['sequencer_id'], sequence)
        sequence.start()

    '''#There is no more special delay_seq and special readout_trigger_seq due to the new pulse generation structure
    #Now delay_seq and special readout_trigger_seq replace with new sequencer READSequence

    #delay_seq = [device.pg.pmulti(readout_delay)]
    #readout_trigger_seq = device.trigger_readout_seq

    # There is no more special sequence for readout. We need only readout_channel, frequency, length, amplitude
    #readout_pulse_seq = readout_pulse.pulse_sequence

    # There is no more set_seq
    #device.pg.set_seq(device.pre_pulses+pre_pulse_sequences+delay_seq+ex_pulse_seq+delay_seq+readout_trigger_seq+readout_pulse_seq)'''

    re_sequence = sequence_control.define_readout_control_seq(device, readout_pulse)
    re_sequence.start()

    def set_ex_length(length, ex_sequence = control_sequence):
        ex_sequence.set_length(length)
        #time.sleep(0.05)

    times = np.zeros(len(lengths))
    for _i in range(len(lengths)):
        times[_i] = int(round(lengths[_i] * control_sequence.clock))
    lengths = times / control_sequence.clock

    #def set_coil_offset(coil_name,x, ex_sequence=ex_sequence):
    #    ex_sequence.set_offset(device.awg_channels[coil_name].channel, x)

    references = {('frequency_controls', qubit_id_): device.get_frequency_control_measurement_id(qubit_id=qubit_id_) for qubit_id_ in qubit_id}
    references['channel_amplitudes'] = channel_amplitudes.id
    references['readout_pulse'] = readout_pulse.id

    if hasattr(measurer, 'references'):
        references.update(measurer.references)

    for pre_pulse_id, pre_pulse in enumerate(pre_pulses):
        if hasattr(pre_pulse, 'id'):
            references.update({('pre_pulse', str(pre_pulse_id)): pre_pulse.id})

    if len(qubit_id)>1:
        arg_id = -2 # the last parameter is resultnumbers, so the time-like argument is -2
    else:
        arg_id = -1
    fitter_arguments = (measurement_name, exp_sin_fitter(mode=exp_sin_fitter_mode), arg_id, np.arange(len(extra_sweep_args)))

    metadata = {'qubit_id': ','.join(qubit_id),
                'extra_sweep_args': str(len(extra_sweep_args)),
                'tail_length': str(tail_length),
                'readout_delay': str(readout_delay),
                'repeats': str(repeats),
                'transition':transition}
    metadata.update(additional_metadata)

    measurement = device.sweeper.sweep_fit_dataset_1d_onfly(measurer,
                                                            *extra_sweep_args,
                                                            (lengths, set_ex_length, 'Excitation length', 's'),
                                                            fitter_arguments=fitter_arguments,
                                                            measurement_type=measurement_type,
                                                            metadata=metadata,
                                                            references=references,
                                                            on_update_divider=5)

    return measurement