Пример #1
0
def prepare_cos_fit_dict(data_dict, keys_in=None, **params):
    fit_dicts = OrderedDict()
    data_to_proc_dict = hlp_mod.get_data_to_process(data_dict, keys_in)
    cp, sp, mospm, mobjn = hlp_mod.get_measurement_properties(
        data_dict, props_to_extract=['cp', 'sp', 'mospm', 'mobjn'], **params)
    indep_var_array = hlp_mod.get_param('indep_var_array',
                                        data_dict,
                                        raise_error=False,
                                        **params)
    if indep_var_array is None:
        indep_var_array = sp[0][mospm[mobjn][0]][0]
    plot_params = hlp_mod.get_param('plot_params',
                                    data_dict,
                                    default_value={},
                                    **params)
    if 'setlabel' not in plot_params:
        plot_params['setlabel'] = 'CosFit'
    params_to_print = hlp_mod.get_param('params_to_print',
                                        data_dict,
                                        default_value=None,
                                        **params)

    fit_name = hlp_mod.get_param('fit_name',
                                 data_dict,
                                 raise_error=False,
                                 **params)
    for keyi, data in data_to_proc_dict.items():
        data_fit = hlp_mod.get_msmt_data(data, cp, mobjn)
        cos_mod = lmfit.Model(fit_mods.CosFunc)
        guess_pars = fit_mods.Cos_guess(model=cos_mod,
                                        t=indep_var_array,
                                        data=data_fit)
        guess_pars['amplitude'].vary = True
        guess_pars['amplitude'].min = -10
        guess_pars['offset'].vary = True
        guess_pars['frequency'].vary = True
        guess_pars['phase'].vary = True

        fit_name_to_set = fit_name
        if fit_name_to_set is None:
            fit_name_to_set = 'CosFit'
        fit_name_to_set += keyi
        fit_dicts[fit_name_to_set] = {
            'fit_fn': fit_mods.CosFunc,
            'fit_xvals': {
                't': indep_var_array
            },
            'fit_yvals': {
                'data': data_fit
            },
            'guess_pars': guess_pars,
            'params_to_print': params_to_print,
            **plot_params
        }

    hlp_mod.add_param('fit_dicts',
                      fit_dicts,
                      data_dict,
                      add_param_method='update')
Пример #2
0
def prepare_rbleakage_fit_dict(data_dict, keys_in=None, **params):
    """
    :param data_dict: OrderedDict containing data to be processed and where
                    processed data is to be stored
    :param keys_in: list of key names or dictionary keys paths in
                    data_dict for the data to be processed
    :param params: keyword args
        do_fitting (bool, default: False): whether to perform the fit
        guess_params (dict, default: dict()): dict of guess pars for fit
    :return: adds fit_dicts to data_dict
    """
    fit_dicts = OrderedDict()
    data_to_proc_dict = hlp_mod.get_data_to_process(data_dict, keys_in)
    cp, sp, mospm, mobjn = hlp_mod.get_measurement_properties(
        data_dict, props_to_extract=['cp', 'sp', 'mospm', 'mobjn'], **params)
    indep_var_array = hlp_mod.get_param('indep_var_array',
                                        data_dict,
                                        raise_error=False,
                                        **params)
    if indep_var_array is None:
        indep_var_array = sp[0][mospm[mobjn][0]][0]
    plot_params = hlp_mod.get_param('plot_params',
                                    data_dict,
                                    default_value={},
                                    **params)
    if 'setlabel' not in plot_params:
        plot_params['setlabel'] = 'RBLeakageFit'
    params_to_print = hlp_mod.get_param('params_to_print',
                                        data_dict,
                                        default_value=None,
                                        **params)

    fit_name = hlp_mod.get_param('fit_name',
                                 data_dict,
                                 raise_error=False,
                                 **params)
    for keyi, data in data_to_proc_dict.items():
        data_fit = hlp_mod.get_msmt_data(data, cp, mobjn)
        rbleak_mod = lmfit.Model(fit_mods.RandomizedBenchmarkingLeakage)
        guess_pars = rbleak_mod.make_params(pu=0.01, pd=0.05, p0=0)

        guess_params_new = hlp_mod.get_param('guess_params',
                                             data_dict,
                                             default_value=dict(),
                                             raise_error=False,
                                             **params)
        update_fit_guess_pars(guess_params_new, guess_pars)

        fit_name_to_set = fit_name
        if fit_name_to_set is None:
            fit_name_to_set = 'rbleak_fit'
        fit_name_to_set += keyi
        fit_dicts[fit_name_to_set] = {
            'fit_fn': fit_mods.RandomizedBenchmarkingLeakage,
            'fit_xvals': {
                'numCliff': indep_var_array
            },
            'fit_yvals': {
                'data': data_fit
            },
            'guess_pars': guess_pars,
            'params_to_print': params_to_print,
            **plot_params
        }

    hlp_mod.add_param('fit_dicts',
                      fit_dicts,
                      data_dict,
                      add_param_method='update')
    if params.get('do_fitting', False):
        run_fitting(data_dict, keys_in=list(fit_dicts), **params)
Пример #3
0
def prepare_residzz_fit_dict(data_dict, keys_in=None, **params):
    """
    This function does a fit to Ramsey data with the other
    qubit in the |e> state.
    :param data_dict: OrderedDict containing data to be processed and where
                    processed data is to be stored
    :param keys_in: list of key names or dictionary keys paths in
                    data_dict for the data to be processed
    :param params: keyword args
        do_fitting (bool, default: False): whether to perform the fit
        guess_params (dict, default: dict()): dict of guess pars for fit
    :return: adds fit_dicts to data_dict
    """
    fit_dicts = OrderedDict()
    data_to_proc_dict = hlp_mod.get_data_to_process(data_dict, keys_in)
    cp, sp, mospm, mobjn = hlp_mod.get_measurement_properties(
        data_dict, props_to_extract=['cp', 'sp', 'mospm', 'mobjn'], **params)
    indep_var_array = hlp_mod.get_param('indep_var_array',
                                        data_dict,
                                        raise_error=False,
                                        **params)
    if indep_var_array is None:
        indep_var_array = sp[0][mospm[mobjn][0]][0]
    plot_params = hlp_mod.get_param('plot_params',
                                    data_dict,
                                    default_value={},
                                    **params)
    if 'setlabel' not in plot_params:
        plot_params['setlabel'] = 'ResidZZFit'
    params_to_print = hlp_mod.get_param('params_to_print',
                                        data_dict,
                                        default_value=None,
                                        **params)

    fit_name = hlp_mod.get_param('fit_name',
                                 data_dict,
                                 raise_error=False,
                                 **params)
    for keyi, data in data_to_proc_dict.items():
        data_fit = hlp_mod.get_msmt_data(data, cp, mobjn)
        residzz_mod = lmfit.Model(fit_mods.ResidZZFunc)
        guess_pars = fit_mods.exp_damp_osc_guess(model=residzz_mod,
                                                 t=indep_var_array,
                                                 data=data_fit)
        guess_pars['alpha'].value = -50e3
        guess_pars['x'].value = 12e-6 * guess_pars['alpha'].value
        guess_pars['offset'].value = np.mean(data_fit)
        # guess_pars['amplitude'].min = -1
        # guess_pars['amplitude'].max = 1

        guess_params_new = hlp_mod.get_param('guess_params',
                                             data_dict,
                                             default_value=dict(),
                                             raise_error=False,
                                             **params)
        update_fit_guess_pars(guess_params_new, guess_pars)

        fit_name_to_set = fit_name
        if fit_name_to_set is None:
            fit_name_to_set = 'residzz_fit'
        fit_name_to_set += keyi
        fit_dicts[fit_name_to_set] = {
            'fit_fn': fit_mods.ResidZZFunc,
            'fit_xvals': {
                't': indep_var_array
            },
            'fit_yvals': {
                'data': data_fit
            },
            'guess_pars': guess_pars,
            'params_to_print': params_to_print,
            **plot_params
        }

    hlp_mod.add_param('fit_dicts',
                      fit_dicts,
                      data_dict,
                      add_param_method='update')
    if params.get('do_fitting', False):
        run_fitting(data_dict, keys_in=list(fit_dicts), **params)
Пример #4
0
def prepare_expdamposc_fit_dict(data_dict, keys_in=None, **params):
    """
    This function does a to Ramsey data
    :param data_dict: OrderedDict containing data to be processed and where
                    processed data is to be stored
    :param keys_in: list of key names or dictionary keys paths in
                    data_dict for the data to be processed
    :param params: keyword args
        do_fitting (bool, default: False): whether to perform the fit
        guess_params (dict, default: dict()): dict of guess pars for fit
        fit_name
        indep_var_array
        plot_params
        params_to_print
    :return: adds fit_dicts to data_dict
    """
    fit_dicts = OrderedDict()
    data_to_proc_dict = hlp_mod.get_data_to_process(data_dict, keys_in)
    cp, sp, mospm, mobjn = hlp_mod.get_measurement_properties(
        data_dict, props_to_extract=['cp', 'sp', 'mospm', 'mobjn'], **params)
    indep_var_array = hlp_mod.get_param('indep_var_array',
                                        data_dict,
                                        raise_error=False,
                                        **params)
    if indep_var_array is None:
        indep_var_array = sp[0][mospm[mobjn][0]][0]
    plot_params = hlp_mod.get_param('plot_params',
                                    data_dict,
                                    default_value={},
                                    **params)
    if 'setlabel' not in plot_params:
        plot_params['setlabel'] = 'ExpDampOscFit'
    params_to_print = hlp_mod.get_param('params_to_print',
                                        data_dict,
                                        default_value=None,
                                        **params)

    fit_name = hlp_mod.get_param('fit_name',
                                 data_dict,
                                 raise_error=False,
                                 **params)
    for keyi, data in data_to_proc_dict.items():
        data_fit = hlp_mod.get_msmt_data(data, cp, mobjn)
        exp_damped_decay_mod = lmfit.Model(fit_mods.ExpDampOscFunc)
        guess_pars = fit_mods.exp_damp_osc_guess(model=exp_damped_decay_mod,
                                                 data=data_fit,
                                                 t=indep_var_array,
                                                 n_guess=1)
        guess_pars['amplitude'].vary = False
        guess_pars['amplitude'].value = 0.5
        guess_pars['frequency'].vary = True
        guess_pars['tau'].vary = True
        guess_pars['phase'].vary = True
        guess_pars['n'].vary = False
        guess_pars['oscillation_offset'].vary = False
        guess_pars['exponential_offset'].vary = True
        guess_params_new = hlp_mod.get_param('guess_params',
                                             data_dict,
                                             default_value=dict(),
                                             raise_error=False,
                                             **params)
        update_fit_guess_pars(guess_params_new, guess_pars)

        fit_name_to_set = fit_name
        if fit_name_to_set is None:
            fit_name_to_set = 'expdamposc_fit'
        fit_name_to_set += keyi
        fit_dicts[fit_name_to_set] = {
            'fit_fn': fit_mods.ExpDampOscFunc,
            'fit_xvals': {
                't': indep_var_array
            },
            'fit_yvals': {
                'data': data_fit
            },
            'guess_pars': guess_pars,
            'params_to_print': params_to_print,
            'plot_params': plot_params
        }

    hlp_mod.add_param('fit_dicts',
                      fit_dicts,
                      data_dict,
                      add_param_method='update')

    if params.get('do_fitting', False):
        run_fitting(data_dict, keys_in=list(fit_dicts), **params)
Пример #5
0
def prepare_joint_residzz_fit_dict(data_dict, keys_in=None, **params):
    """
    This function does a joint fit to Ramsey data without and with the other
    qubit in the |e> state.
    keys_in should have two entries corresponding to two 1d arrays for the
    data mentioned above, IN THAT ORDER.
    :param data_dict: OrderedDict containing data to be processed and where
                    processed data is to be stored
    :param keys_in: list of key names or dictionary keys paths in
                    data_dict for the data to be processed
    :param params: keyword args
        do_fitting (bool, default: False): whether to perform the fit
        guess_params (dict, default: dict()): dict of guess pars for fit
    :return: adds fit_dicts to data_dict
    """
    if len(keys_in) != 2:
        raise ValueError('keys_in must have two entries.')
    fit_dicts = OrderedDict()
    data_to_proc_dict = hlp_mod.get_data_to_process(data_dict, keys_in)
    cp, sp, mospm, mobjn = hlp_mod.get_measurement_properties(
        data_dict, props_to_extract=['cp', 'sp', 'mospm', 'mobjn'], **params)
    indep_var_array = hlp_mod.get_param('indep_var_array',
                                        data_dict,
                                        raise_error=False,
                                        **params)
    if indep_var_array is None:
        indep_var_array = sp[0][mospm[mobjn][0]][0]
    plot_params = hlp_mod.get_param('plot_params',
                                    data_dict,
                                    default_value={},
                                    **params)
    if 'setlabel' not in plot_params:
        plot_params['setlabel'] = 'JointResidZZFit'
    params_to_print = hlp_mod.get_param('params_to_print',
                                        data_dict,
                                        default_value=None,
                                        **params)

    data_wo_pulse = hlp_mod.get_msmt_data(
        list(data_to_proc_dict.values())[0], cp, mobjn)
    data_w_pulse = hlp_mod.get_msmt_data(
        list(data_to_proc_dict.values())[1], cp, mobjn)

    residzz_mod = lmfit.Model(fit_mods.ResidZZFuncJoint)
    guess_pars = fit_mods.exp_damp_osc_guess(model=residzz_mod,
                                             t=indep_var_array,
                                             data=data_wo_pulse)

    guess_pars['alpha'].value = -50e3
    guess_pars['alpha'].max = 0
    # guess_pars['x'].value = 12e-6*guess_pars['alpha'].value
    guess_pars['t11'].value = 12e-6
    guess_pars['t11'].min = 0
    guess_pars['offset'].value = np.mean(data_wo_pulse)
    guess_pars['amplitude1'].value = guess_pars['amplitude'].value
    # guess_pars['phase1'].value = guess_pars['phase'].value + np.pi/2
    # guess_pars['amplitude'].min = -1
    # guess_pars['amplitude1'].min = -1
    # guess_pars['amplitude'].max = 1
    # guess_pars['amplitude1'].max = 1
    for par in guess_pars:
        guess_pars[par].vary = True
    guess_pars['offset'].vary = False
    guess_params_new = hlp_mod.get_param('guess_params',
                                         data_dict,
                                         default_value=dict(),
                                         raise_error=False,
                                         **params)
    update_fit_guess_pars(guess_params_new, guess_pars)

    fit_name = hlp_mod.get_param('fit_name',
                                 data_dict,
                                 raise_error=False,
                                 **params)
    fit_name_to_set = fit_name
    if fit_name_to_set is None:
        fit_name_to_set = 'residzz_fit'
    fit_name_to_set += ','.join(mobjn)
    fit_dicts[fit_name] = {
        'fit_fn': fit_mods.ResidZZFuncJoint,
        'fit_xvals': {
            't': indep_var_array
        },
        'fit_yvals': {
            'data': (data_wo_pulse, data_w_pulse)
        },
        'guess_pars': guess_pars,
        'params_to_print': params_to_print,
        **plot_params
    }

    hlp_mod.add_param('fit_dicts',
                      fit_dicts,
                      data_dict,
                      add_param_method='update')
    if params.get('do_fitting', False):
        run_fitting(data_dict, keys_in=list(fit_dicts), **params)