def fit_rabi_simple(g_f, g_A, g_a, g_phi, *arg): """ fits a cosine, y(x) = a + A * cos(2pi*f*x) Initial guesses, in this order: g_f : frequency g_A : initial amplitude of the oscillation g_a : offset """ fitfunc_str = "a + A * cos(2pi*(f*x + phi/360))" f = fit.Parameter(g_f, 'f') A = fit.Parameter(g_A, 'A') a = fit.Parameter(g_a, 'a') phi = fit.Parameter(g_phi, 'phi') # tau = fit.Parameter(g_tau, 'tau') p0 = [f, A, a, phi] def fitfunc(x): return a() + A() * cos(2 * pi * (f() * x + phi() / 360.)) return p0, fitfunc, fitfunc_str
def fit_calibration(V, freq): guess_b = (freq[-1] - freq[0]) / (V[-1] - V[0]) guess_a = freq[0] print 'Initial guess: ', guess_a, guess_b a = fit.Parameter(guess_a, 'a') b = fit.Parameter(guess_b, 'b') p0 = [a, b] fitfunc_str = '' def fitfunc(x): return a() + b() * x fit_result = fit.fit1d(V, freq, None, p0=p0, fitfunc=fitfunc, fixed=[], do_print=False, ret=True) a_fit = fit_result['params_dict']['a'] b_fit = fit_result['params_dict']['b'] print 'a= ', a_fit print 'b=', b_fit return a_fit, b_fit
def fit_sweep_pump_power(x, y, L=0.042): guess_b = 1 guess_a = max(y) a = fit.Parameter(guess_a, 'a') b = fit.Parameter(guess_b, 'b') p0 = [a, b] fitfunc_str = '' def fitfunc(x): return a() * np.sin(L * (b() * x)**0.5)**2 fit_result = fit.fit1d(x, y, None, p0=p0, fitfunc=fitfunc, fixed=[], do_print=True, ret=True) a_fit = fit_result['params_dict']['a'] b_fit = fit_result['params_dict']['b'] print 'a= ', a_fit print 'b=', b_fit return a_fit, b_fit
def epulse_fidelity(folder, ax, *args): a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='ssro') a.get_electron_ROC() a.plot_result_vs_sweepparam(ax=ax, name='ssro') x = a.sweep_pts.reshape(-1)[:] y = a.p0.reshape(-1)[:] of = fit.Parameter(args[0], 'of') of2 = fit.Parameter(0, 'of2') of3 = fit.Parameter(0, 'of3') fitfunc_str = '(1-of)' def fitfunc_fid(x): return (1. - of()) fit_result = fit.fit1d(x, y, None, p0=[of], fixed=[], fitfunc=fitfunc_fid, fitfunc_str=fitfunc_str, do_print=True, ret=True) #plot.plot_fit1d(fit_result, np.linspace(x[0],x[-1],201), ax=ax, # plot_data=False, print_info=False) return fit_result
def calibrate_epulse_amplitude(folder, ax, *args): a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='ssro') a.get_electron_ROC() a.plot_result_vs_sweepparam(ax=ax, name='ssro') x = a.sweep_pts.reshape(-1)[:] y = a.p0.reshape(-1)[:] ax.set_title(a.timestamp) x0 = fit.Parameter(args[0], 'x0') of = fit.Parameter(args[1], 'of') a = fit.Parameter(args[2], 'a') fitfunc_str = '(1-of) + a (x-x0)**2' def fitfunc_parabolic(x): return (1. - of()) + a() * (x - x0())**2 fit_result = fit.fit1d(x, y, None, p0=[of, a, x0], fitfunc=fitfunc_parabolic, fitfunc_str=fitfunc_str, do_print=True, ret=True) plot.plot_fit1d(fit_result, np.linspace(x[0], x[-1], 201), ax=ax, plot_data=False, print_info=True) return fit_result
def fit_linear(folder, ax, value, *args): a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='ssro') a.get_electron_ROC() a.plot_result_vs_sweepparam(ax=ax, name='ssro') x = a.sweep_pts.reshape(-1)[:] y = a.p0.reshape(-1)[:] ax.set_title(a.timestamp) a = fit.Parameter(args[0], 'a') b = fit.Parameter(args[0], 'b') fitfunc_str = 'a x + b' def fitfunc(x): return a() * x + b() fit_result = fit.fit1d(x, y, None, p0=[a, b], fitfunc=fitfunc, fitfunc_str=fitfunc_str, do_print=True, ret=True) plot.plot_fit1d(fit_result, np.linspace(x[0], x[-1], 201), ax=ax, plot_data=False, print_info=False) return fit_result
def fit_rabi_on_linslope(g_f, g_A, g_a, g_b, *arg): """ fits (and plots) a cosine on a slope, with offset, y(x) = a + bx + Acos(f*x + phi) Initial guesses (1st args, in this order): g_f : float guess for the frequency g_A : float guess for amplitude g_a : float guess for offset g_b = 0. : float guess for slope """ fitfunc_str = "a + b*x + A*cos(2pi*f*x + phi)" f = fit.Parameter(g_f, 'frequency') A = fit.Parameter(g_A, 'amplitude') a = fit.Parameter(g_a, 'offset') b = fit.Parameter(g_b, 'slope') p0 = [f, A, a, b] def fitfunc(x): return a() + b() * x + A() * cos(2 * pi * f() * x) return p0, fitfunc, fitfunc_str
def fit_correlation_parabolic(folder, ax, *args, **kw): which_correlation = kw.pop('which_correlation', 2) a = mbi.MBIAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_correlations(name='adwindata') a.plot_results_vs_sweepparam(ax=ax, mode='correlations') x = a.sweep_pts.reshape(-1)[:] y = a.normalized_correlations[:, which_correlation] x0 = fit.Parameter(args[0], 'x0') of = fit.Parameter(args[1], 'of') a = fit.Parameter(args[2], 'a') fitfunc_str = '(1-of) + a (x-x0)**2' def fitfunc_parabolic(x): return (1. - of()) + a() * (x - x0())**2 fit_result = fit.fit1d(x, y, None, p0=[of, a, x0], fitfunc=fitfunc_parabolic, fitfunc_str=fitfunc_str, do_print=True, ret=True) plot.plot_fit1d(fit_result, np.linspace(x[0], x[-1], 201), ax=ax, plot_data=False, print_info=False) return fit_result
def fit_rabi_damped_exp(g_f, g_A, g_a, g_tau, *arg): """ fits a cosine thats damped exponentially, y(x) = a + A * exp(-x/tau) * cos(f*x + phi) Initial guesses, in this order: g_f : frequency g_A : initial amplitude of the oscillation g_a : offset1 ### g_phi : phase g_tau : decay constant """ fitfunc_str = "a + A * exp(-x/tau) * cos(f*x + phi)" f = fit.Parameter(g_f, 'f') A = fit.Parameter(g_A, 'A') a = fit.Parameter(g_a, 'a') phi = fit.Parameter(0., 'phi') tau = fit.Parameter(g_tau, 'tau') p0 = [f, A, a, tau, phi] #print tau def fitfunc(x): return a() + A() * exp(-x / tau()) * cos(2 * pi * (f() * x + phi() / 360.)) return p0, fitfunc, fitfunc_str
def fit_linear(folder=None, ax=None, a_guess=1., b_guess=0.): """ fit a x + b from Sequence in folder """ a, ax, x, y = plot_result(folder, ax) a = fit.Parameter(a_guess, 'a') b = fit.Parameter(b_guess, 'b') fitfunc_str = 'a x + b' def fitfunc(x): return a() * x + b() fit_result = fit.fit1d(x, y, None, p0=[a, b], fitfunc=fitfunc, fitfunc_str=fitfunc_str, do_print=True, ret=True) plot.plot_fit1d(fit_result, np.linspace(x[0], x[-1], 201), ax=ax, plot_data=False, print_info=False) return fit_result
def fit_calibration(self, V, freq, fixed): guess_b = -21.3 guess_c = -0.13 guess_d = 0.48 guess_a = freq[0] +3*guess_b-9*guess_c+27*guess_d a = fit.Parameter(guess_a, 'a') b = fit.Parameter(guess_b, 'b') c = fit.Parameter(guess_c, 'c') d = fit.Parameter(guess_d, 'd') p0 = [a, b, c, d] fitfunc_str = '' def fitfunc(x): return a()+b()*x+c()*x**2+d()*x**3 fit_result = fit.fit1d(V,freq, None, p0=p0, fitfunc=fitfunc, fixed=fixed, do_print=False, ret=True) if (len(fixed)==2): a_fit = fit_result['params_dict']['a'] c_fit = fit_result['params_dict']['c'] return a_fit, c_fit else: a_fit = fit_result['params_dict']['a'] b_fit = fit_result['params_dict']['b'] c_fit = fit_result['params_dict']['c'] d_fit = fit_result['params_dict']['d'] return a_fit, b_fit, c_fit, d_fit
def fast_pi2(): folder = toolbox.latest_data('cal_fast_pi_over_2') a = mbi.MBIAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_electron_ROC() #a.plot_results_vs_sweepparam(ax=ax, name='adwindata') x = a.sweep_pts y = a.p0.reshape(-1) u_y = a.u_p0.reshape(-1) n = a.sweep_name x2 = x[::2] y2 = y[1::2] - y[::2] u_y2 = np.sqrt(u_y[1::2]**2 + u_y[::2]**2) fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4), sharex=True) ax1.errorbar(x2, y2, yerr=u_y2, fmt='o') ax1.set_xlabel(n) ax1.set_title('Difference btw. Pi/2-Pi and Pi/2' + '\n' + a.timestamp) ax1.set_ylabel('Difference') m = fit.Parameter((y[-1] - y[0]) / (x[-1] - x[0]), 'm') x0 = fit.Parameter(x2.mean(), 'x0') p0 = [m, x0] def ff(x): return m() * (x - x0()) fitfunc_str = 'm * (x - x0)' fit_result = fit.fit1d(x2, y2, None, p0=p0, fitfunc=ff, fitfunc_str=fitfunc_str, do_print=True, ret=True) ax2.errorbar(x2, y[0::2], yerr=u_y[0::2], fmt='o', label='Pi/2') ax2.errorbar(x2, y[1::2], yerr=u_y[1::2], fmt='o', label='Pi/2 - Pi') ax2.legend(frameon=True, framealpha=0.5) ax2.set_ylabel('P(0)') ax2.set_xlabel(n) if fit_result != False: ax2.axvline(x0(), c='k', lw=2) ax2.axhline(0.5, c='k', lw=2) ax2.set_title('X marks the spot') plot.plot_fit1d(fit_result, np.linspace(x2[0], x2[-1], 201), ax=ax1, plot_data=False, print_info=True) return x0(), 0
def fit_5msmt_proc_fid(g_A0, g_offset0, g_t, g_p): ''' g_offset0 - Offset, derived from the 0 msmt case. Fixed. g_A0 - Amplitude derived from the 0 msmt case. Fixed. g_p - Probability for faulty parity measurement g_t - Decay of Ramsey. Fixed. The function should take the data set for 5 Zeno-measurements and fit the process fidelity with a prederived function. That depends on one parameter. The fidelity of the parity measurement. ''' fitfunc_str = '''analyitcal solution''' ### Parameters A0 = fit.Parameter(g_A0, 'A0') offset0 = fit.Parameter(g_offset0, 'offset0') ### Ramsey t = fit.Parameter(g_t, 't') ### Zeno p = fit.Parameter(g_p, 'p') p0 = [A0, offset0, t, p] def fitfunc(x): decay = -np.exp(-(x**2 / (2. * (t()**2)))) / 64. decay2 = 6. * np.exp((5. / 18.) * (x**2 / ((t()**2)))) decay3 = 15. * np.exp((4. / 9.) * (x**2 / ((t()**2)))) * (p() - 1.)**5 bracket1 = 10 + (-5 + p()) * p() bracket2 = (bracket1 * p() - 10) * p() + 5 bracket3 = (bracket2 * 5 * p() - 21) * 2. / 64. Hahn = np.exp(-(x / 604.)**1.6162) #### decaying parts + the constant part which arises from the measurement echo. Fx = decay * ((p() - 1)**5 * (1 + decay2) + decay3) - (bracket3 + 0.5) * Hahn + 0.5 Fz0 = 2. * offset0() Con0 = 2. * (Fz0 - 0.5) Conp = Con0 * (1 - p())**5 Fzp = Conp / 2. + 0.5 # am = (2*A0()+1)/2. # return (2.*am*Fx+Fzp-1.)/2. ### commented out because apparently wrong. Cx = 2 * Fx - 1. Cxred = 2 * A0() * Cx Fx = (Cxred + 1) / 2. return (2. * Fx + Fzp - 1.) / 2. return p0, fitfunc, fitfunc_str
def calibrate_pi2_noMBI(folder): a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') a.get_electron_ROC() x = a.sweep_pts y = a.p0 u_y = a.u_p0 n = a.sweep_name a.finish() x2 = x[::2] print x2 y2 = y[1::2] - y[::2] u_y2 = np.sqrt(u_y[1::2]**2 + u_y[::2]**2) fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4), sharex=True) ax1.errorbar(x2, y2, yerr=u_y2, fmt='o') ax1.set_xlabel(n) ax1.set_title('Difference btw. Pi/2-Pi and Pi/2') ax1.set_ylabel('Difference') m = fit.Parameter((y[-1] - y[0]) / (x[-1] - x[0]), 'm') x0 = fit.Parameter(y2.mean(), 'x0') p0 = [m, x0] def ff(x): return m() * (x - x0()) fitfunc_str = 'm * (x - x0)' fit_result = fit.fit1d(x2, y2, None, p0=p0, fitfunc=ff, fitfunc_str=fitfunc_str, do_print=True, ret=True) ax2.errorbar(x2, y[0::2], yerr=u_y[0::2], fmt='o', label='Pi/2') ax2.errorbar(x2, y[1::2], yerr=u_y[1::2], fmt='o', label='Pi/2 - Pi') ax2.legend(frameon=True, framealpha=0.5) ax2.set_ylabel('P(0)') ax2.set_xlabel(n) ax2.axvline(x0(), c='k', lw=2) ax2.axhline(0.5, c='k', lw=2) ax2.set_title('X marks the spot') plot.plot_fit1d(fit_result, np.linspace(x2[0], x2[-1], 201), ax=ax1, plot_data=False, print_info=True) fig.savefig(os.path.join(folder, 'pi2_calibration.png'))
def fit_ramsey_gaussian_decay(g_tau, g_a, *arg): """ fitfunction for a ramsey modulation, with gaussian decay, y(x) = a + A*exp(-(x/tau)**2) * mod, where: mod = sum_i(cos(2pi*f_i*x +phi) - 1) Initial guesses (in this order): g_tau : decay const g_A : Amplitude g_a : offset For the modulation: an arbitrary no of tuples, in the form (g_f, g_A)[i] = (frequency, Amplitude, phase)[i] """ fitfunc_str = 'y(x) = a + exp(-(x/tau)**2)*(' no_frqs = len(arg) if no_frqs == 0: print 'no modulation frqs supplied' return False tau = fit.Parameter(g_tau, 'tau') # A = fit.Parameter(g_A, 'A') a = fit.Parameter(g_a, 'a') p0 = [tau, a] print 'fitting with %d modulation frequencies' % no_frqs frqs = [] amplitudes = [] phases = [] print 'arg2 =' + str(arg) for i, m in enumerate(arg): fitfunc_str += 'A%d*cos(2pi*f%d*x+phi%d)' % (i, i, i) frqs.append(fit.Parameter(m[0], 'f%d' % i)) phases.append(fit.Parameter(m[2], 'phi%d' % i)) amplitudes.append(fit.Parameter(m[1], 'A%d' % i)) p0.append(frqs[i]) p0.append(amplitudes[i]) p0.append(phases[i]) fitfunc_str += ')' def fitfunc(x): prd = exp(-(x / tau())**2) mod = 0 for i in range(no_frqs): mod += amplitudes[i]() * (cos(2 * pi * frqs[i]() * x + phases[i]())) return a() + prd * mod return p0, fitfunc, fitfunc_str
def fit_parabolic(folder=None, ax=None, x0_guess=0., of_guess=0.5, a_guess=1., **kw): """ fit (1-of) + a (x-x0)**2 from Sequence in folder """ do_print = kw.pop('do_print', False) fixed = kw.pop('fixed', []) a0, ax, x, y = plot_result(folder, ax, **kw) x0 = fit.Parameter(x0_guess, 'x0') of = fit.Parameter(of_guess, 'of') a = fit.Parameter(a_guess, 'a') x_min = kw.pop("x_min", None) x_max = kw.pop("x_max", None) fit_x = x fit_y = y if x_min is not None: mask = fit_x > x_min fit_x = fit_x[mask] fit_y = fit_y[mask] if x_max is not None: mask = fit_x < x_max fit_x = fit_x[mask] fit_y = fit_y[mask] fitfunc_str = '(1-of) + a (x-x0)**2' def fitfunc_parabolic(x): return (1. - of()) + a() * (x - x0())**2 fit_result = fit.fit1d(fit_x, fit_y, None, p0=[of, a, x0], fitfunc=fitfunc_parabolic, fitfunc_str=fitfunc_str, do_print=do_print, ret=True) fit_result['u_y'] = a0.u_p0 plot.plot_fit1d(fit_result, np.linspace(np.min(fit_x), np.max(fit_x), 201), ax=ax, plot_data=False, **kw) return fit_result
def fit_8msmt_state_fid(g_A0, g_t, g_p, contrast=False): ''' g_A0 - Amplitude derived from the 0 msmt case. Fixed. g_p - Probability for faulty parity measurement g_t - Decay of Ramsey. Fixed. The function should take the data set for 8 Zeno-measurements and fit the state fidelity with a prederived function. That depends on one parameter. The Probability of the parity measurement to mix the state. ''' fitfunc_str = '''analyitcal solution''' ### Parameters A0 = fit.Parameter(g_A0, 'A0') ### Ramsey (decay time divided by sqrt(2).) t = fit.Parameter(g_t, 't') ### Zeno p = fit.Parameter(g_p, 'p') p0 = [A0, t, p] def fitfunc(x): decay = np.exp(-(x**2 / (2. * (t()**2)))) / 512. decay2 = 9. * np.exp((16. / 81.) * (x**2 / ((t()**2)))) * (p() - 1.)**8 decay3 = 36. * np.exp( (28. / 81.) * (x**2 / ((t()**2)))) * (p() - 1.)**8 decay4 = 84. * np.exp( (36. / 81.) * (x**2 / ((t()**2)))) * (p() - 1.)**8 decay5 = 126. * np.exp( (40. / 81.) * (x**2 / ((t()**2)))) * (p() - 1.)**8 #### decay to 0.5 only for 6 measurements no other constant parts of the function due to echo effects. Fx = 0.5 + decay * ((p() - 1)**8 + decay2 + decay3 + decay4 + decay5) Cx = A0() * 2. * (Fx - 0.5) Fx = Cx / 2. + 0.5 if contrast: return Cx else: return Fx return p0, fitfunc, fitfunc_str
def fit_3msmt_proc_fid(g_A0, g_offset0, g_t, g_p): ''' g_offset0 - Offset, derived from the 0 msmt case. Fixed. g_A0 - Amplitude derived from the 0 msmt case. Fixed. g_p - Probability for faulty parity measurement g_t - Decay of Ramsey. Fixed. The function should take the data set for 3 Zeno-measurements and fit the process fidelity with a prederived function. That depends on one parameter. The fidelity of the parity measurement. ''' fitfunc_str = '''analyitcal solution''' ### Parameters A0 = fit.Parameter(g_A0, 'A0') offset0 = fit.Parameter(g_offset0, 'offset0') ### Ramsey t = fit.Parameter(g_t, 't') ### Zeno p = fit.Parameter(g_p, 'p') p0 = [A0, offset0, t, p] def fitfunc(x): decay = -0.0625 * np.exp(-(x**2 / (2. * (t()**2)))) decay2 = np.exp((3. / 8.) * (x**2 / ((t()**2)))) Hahn = np.exp(-(x / 604.)**1.6162) Fx = -Hahn * ((-11. + 3 * p() * (3 + (3 - p()) * p())) / 16. + 0.5) + decay * ( (p() - 1.)**3 + 4. * decay2 * (p() - 1.)**3) + 0.5 Fz0 = 2. * offset0() Con0 = 2. * (Fz0 - 0.5) Conp = Con0 * (1 - p())**3 Fzp = Conp / 2. + 0.5 # am = (2*A0()+1)/2. # return (2.*am*Fx+Fzp-1.)/2. ### commented out because apparently wrong. Cx = 2 * Fx - 1. Cxred = 2 * A0() * Cx Fx = (Cxred + 1) / 2. return (2. * Fx + Fzp - 1.) / 2. return p0, fitfunc, fitfunc_str
def fit_5msmt_state_fid(g_A0, g_t, g_p, contrast=False): ''' g_A0 - Amplitude derived from the 0 msmt case. Fixed. g_p - Probability for faulty parity measurement g_t - Decay of Ramsey. Fixed. The function should take the data set for 5 Zeno-measurements and fit the process fidelity with a prederived function. That depends on one parameter. The fidelity of the parity measurement. ''' fitfunc_str = '''analyitcal solution''' ### Parameters A0 = fit.Parameter(g_A0, 'A0') ### Ramsey t = fit.Parameter(g_t, 't') ### Zeno p = fit.Parameter(g_p, 'p') p0 = [A0, t, p] def fitfunc(x): Hahn = np.exp(-(x / 604.)**1.6162) decay = -np.exp(-(x**2 / (2. * (t()**2)))) / 64. decay2 = 6. * np.exp((5. / 18.) * (x**2 / ((t()**2)))) decay3 = 15. * np.exp((4. / 9.) * (x**2 / ((t()**2)))) * (p() - 1.)**5 bracket1 = 10 + (-5 + p()) * p() bracket2 = (bracket1 * p() - 10) * p() + 5 bracket3 = (bracket2 * 5 * p() - 21) * 2. / 64. #### decaying parts + the constant part which arises from the measurement echo. Fx = decay * ((p() - 1)**5 * (1 + decay2) + decay3) - (bracket3 + 0.5) * Hahn + 0.5 Cx = A0() * 2. * (Fx - 0.5) Fx = Cx / 2. + 0.5 if contrast: return Cx else: return Fx return p0, fitfunc, fitfunc_str
def fit_4msmt_proc_fid(g_A0, g_offset0, g_t, g_p): ''' g_offset0 - Offset, derived from the 0 msmt case. Fixed. g_A0 - Amplitude derived from the 0 msmt case. Fixed. g_p - Probability for faulty parity measurement g_t - Decay of Ramsey. Fixed. The function should take the data set for 4 Zeno-measurements and fit the process fidelity with a prederived function. That depends on one parameter. The fidelity of the parity measurement. ''' fitfunc_str = '''analyitcal solution''' ### Parameters A0 = fit.Parameter(g_A0, 'A0') offset0 = fit.Parameter(g_offset0, 'offset0') ### Ramsey t = fit.Parameter(g_t, 't') ### Zeno p = fit.Parameter(g_p, 'p') p0 = [A0, offset0, t, p] def fitfunc(x): decay = np.exp(-(x**2 / (2. * (t()**2)))) / 32. decay2 = 5. * np.exp((8. / 25.) * (x**2 / ((t()**2)))) * (p() - 1.)**4 decay3 = 10. * np.exp( (12. / 25.) * (x**2 / ((t()**2)))) * (p() - 1.)**4 Fx = 0.5 + decay * ((p() - 1)**4 + decay2 + decay3) Fz0 = 2. * offset0() Con0 = 2. * (Fz0 - 0.5) Conp = Con0 * (1 - p())**4 Fzp = Conp / 2. + 0.5 # am = (2*A0()+1)/2. # return (2.*am*Fx+Fzp-1.)/2. ### commented out because apparently wrong. Cx = 2 * Fx - 1. Cxred = 2 * A0() * Cx Fx = (Cxred + 1) / 2. return (2. * Fx + Fzp - 1.) / 2. return p0, fitfunc, fitfunc_str
def calibrate_epulse_rabi(folder, ax, *args, **kws): fit_x0 = kws.pop('fit_x0', True) fit_k = kws.pop('fit_k', True) double_ro = kws.pop('double_ro', 'False') guess_x0 = kws.pop('guess_x0', 0) a = mbi.MBIAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_electron_ROC() a.plot_results_vs_sweepparam(ax=ax, name='adwindata') x = a.sweep_pts.reshape(-1)[:] if double_ro == 'electron': y = a.p0[:, 0] elif double_ro == 'nitrogen': y = a.p0[:, 1] else: y = a.p0.reshape(-1)[:] f = fit.Parameter(args[0], 'f') A = fit.Parameter(args[1], 'A') x0 = fit.Parameter(guess_x0, 'x0') k = fit.Parameter(0, 'k') p0 = [f, A] if fit_x0: p0.append(x0) if fit_k: p0.append(k) fitfunc_str = '(1 - A) + A * exp(-kx) * cos(2pi f (x - x0))' def fitfunc(x): return (1.-A()) + A() * np.exp(-k()*x) * \ np.cos(2*np.pi*f()*(x - x0())) fit_result = fit.fit1d(x, y, None, p0=p0, fitfunc=fitfunc, fitfunc_str=fitfunc_str, do_print=True, ret=True) plot.plot_fit1d(fit_result, np.linspace(x[0], x[-1], 201), ax=ax, plot_data=False, print_info=False) return fit_result
def fit_bi_exp(g_A1, g_A2, g_t1, g_t2,*arg): fitfunc_str = 'A1 *exp(-x/t1) + A2 *exp(-x/t2)' A1 = fit.Parameter(g_A1, 'A1') A2 = fit.Parameter(g_A2, 'A2') t1 = fit.Parameter(g_t1, 't1') t2 = fit.Parameter(g_t2, 't2') p0 = [A1,A2,t1,t2] def fitfunc(x): return A1()*np.exp(-x/t1()) + A2()*np.exp(-x/t2()) return p0, fitfunc, fitfunc_str
def fit_rabi_fixed_upper(g_f, g_A, g_phi, g_k, *arg): fitfunc_str = '(1-A) + A * exp(-kx) *cos(2pi*(f*x + phi/360))' f = fit.Parameter(g_f, 'f') A = fit.Parameter(g_A, 'A') phi = fit.Parameter(g_phi, 'phi') k = fit.Parameter(g_k, 'k') p0 = [f, A, phi, k] def fitfunc(x): return (1. - A()) + A() * exp(-k() * x) * cos(2 * pi * (f() * x + phi() / 360.)) return p0, fitfunc, fitfunc_str
def fit_population_vs_detuning(g_a, g_A, g_F, g_x0, *arg): fitfunc_str = 'a + A * F**2/(F**2+(x-x0)**2) * sin(pi/(2F) * sqrt(F**2+(x-x0)**2))**2' A = fit.Parameter(g_A, 'A') a = fit.Parameter(g_a, 'a') F = fit.Parameter(g_F, 'F') x0 = fit.Parameter(g_x0, 'x0') p0 = [a, A, F, x0] def fitfunc(x): return a() + A() * F()**2 / (F()**2 + (x - x0())**2) * sin( pi / F() / 2. * sqrt(F()**2 + (x - x0())**2))**2 return p0, fitfunc, fitfunc_str
def fit_ramsey_hyperfinelines_fixed(g_tau, g_A, g_a, g_det, g_hf, g_phi1, g_phi2, g_phi3, *arg): """ fitfunction for a gaussian decay, y(x) = a + A*exp(-(x/tau)**2) Initial guesses (in this order): g_tau : decay constant g_A : amplitude g_a : offset """ tau = fit.Parameter(g_tau, 'tau') A = fit.Parameter(g_A, 'A') a = fit.Parameter(g_a, 'a') det = fit.Parameter(g_det, 'det') hf = fit.Parameter(g_hf, 'hf') phi1 = fit.Parameter(g_phi1, 'phi1') phi2 = fit.Parameter(g_phi2, 'phi2') phi3 = fit.Parameter(g_phi3, 'phi3') p0 = [tau, A, a, det, hf, phi1, phi2, phi3] fitfunc_str = 'sumf of three cos and decay' def fitfunc(x): return a() + A() * exp(-(x / tau())**2) * ( cos(2 * pi * det() * x + phi1()) + cos(2 * pi * (det() - hf()) * x + phi2()) + cos(2 * pi * (det() + hf()) * x + phi3())) / 3. return p0, fitfunc, fitfunc_str
def fit_general_exponential(g_a, g_A, g_x0, g_T, g_n): fitfunc_str = 'a + A * exp(-((x-x0)/T )**n)' a = fit.Parameter(g_a, 'a') A = fit.Parameter(g_A, 'A') x0 = fit.Parameter(g_x0, 'x0') T = fit.Parameter(g_T, 'T') n = fit.Parameter(g_n, 'n') p0 = [a, A, x0, T, n] def fitfunc(x): return a() + A() * np.exp(-(x-x0())**n()/(T()**n())) return p0, fitfunc, fitfunc_str
def fit_rabi_multiple_detunings(g_A, g_a, g_F, g_tau, *arg): """ fitfunction for an oscillation that drives several transitions (several nuclear lines, for instance) y(x) = a + A * sum_I[ F**2/(F**2 + delta_i**2) * (cos(sqrt(F**2 + delta_i**2 + phi_i)) - 1) * exp(-x/tau) Initial guesses: g_A : full Rabi amplitude g_a : offset g_F : Rabi frequency g_tau : exp decay constant For the driven levels: all successive args are treated as detunings for additional levels, (delta_i, g_phi_i) -- given as tuples! detuning is not a free param, but is given exactly. """ fitfunc_str = "a + A * sum_I[ F**2/(F**2 + delta_i**2) * (cos(sqrt(F**2 + delta_i**2 + phi_i)) - 1) * exp(-x/tau)" no_detunings = len(arg) A = fit.Parameter(g_A, 'A') a = fit.Parameter(g_a, 'a') F = fit.Parameter(g_F, 'F') tau = fit.Parameter(g_tau, 'tau') p0 = [A, a, F, tau] detunings = [] phases = [] for i, d in enumerate(arg): fitfunc_str += '\ndetuning d%d := %f' % (i, d[0]) detunings.append(d[0]) #phases.append(fit.Parameter(d[1], 'phi%d'%i)) #p0.append(phases[i]) def fitfunc(x): val = a() for i, d in enumerate(detunings): f2 = F()**2 + d**2 val += A() * (F()**2 / f2) * (cos(2 * pi * sqrt(f2) * x + 0.) - 1) return val * exp(-x / tau()) return p0, fitfunc, fitfunc_str
def fit_exp(x=[], y=[], plot_fits=False): guess_b = 10. guess_c = 0. b = fit.Parameter(guess_b, 'b') def fitfunc(x): return np.exp(-np.abs((x) / b())) xx = np.linspace(0, x[-1], 1000) fit_result = fit.fit1d(x, y, None, p0=[b], fitfunc=fitfunc, do_print=False, ret=True) b_fit = fit_result['params_dict']['b'] err_b = fit_result['error_dict']['b'] if plot_fits: plt.figure() plt.plot(x * 1000, y, '.b') plt.plot(xx * 1000, np.exp(-np.abs((xx) / b_fit)), 'r') plt.xlabel('time [msec]') plt.show() return b_fit, err_b
def g2_hist(self, range=(-520,520), bins=2*52): # NOTE bins should be an even number! self.peaks = {} self.amplitudes = [] self.normpeaks = {} for i,d in enumerate(self.deltas): hy,hx = np.histogram(self.coincidences[i]+self.offset, bins=bins, range=range) self.peaks[d] = (hy,hx) self.fitdt = hx[1]-hx[0] if d != 0: A = fit.Parameter(max(hy)) def fitfunc(x): return A()*np.exp(-abs(x)/self.tau) fit.fit1d(hx[:-1]+(hx[1]-hx[0])/2., hy, None, fitfunc=fitfunc, p0=[A], do_print=True, fixed=[]) self.amplitudes.append(A()) # normalize peaks self.meanamp = np.mean(self.amplitudes) for d in self.peaks: self.normpeaks[d] = (self.peaks[d][0]/self.meanamp, self.peaks[d][1]) return True
def fit_16msmt_state_fid(g_A0, g_t, g_p, contrast=False): ''' g_A0 - Amplitude derived from the 0 msmt case. Fixed. g_p - Probability for faulty parity measurement g_t - Decay of Ramsey. Fixed. The function should take the data set for 16 Zeno-measurements and fit the state fidelity with a prederived function. That depends on one parameter. The Probability of the parity measurement to mix the state. ''' fitfunc_str = '''analyitcal solution''' ### Parameters A0 = fit.Parameter(g_A0, 'A0') ### Ramsey (decay time divided by sqrt(2).) t = fit.Parameter(g_t, 't') ### Zeno p = fit.Parameter(g_p, 'p') p0 = [A0, t, p] def fitfunc(x): N = 16 Coefficients = [] for k in range(N + 1): Coefficients.append( sp.special.binom(N + 1, k) * np.exp(-(((N + 1 - 2 * k) * x / (N + 1) / t())**2) / 2.) / 2**(N + 1)) Cx = A0() * (1 - p())**N * ( np.sum(Coefficients, axis=0) ) # WATCH OUT, need to sepcify axis (the axis of coefficients.) Fx = Cx / 2. + 0.5 if contrast: return Cx else: return Fx return p0, fitfunc, fitfunc_str