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 analyze_data(timestamp, output=False): #, guess_frq = 1 / 20e9, guess_amp = 0.5): if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data('ElectronT1') print folder a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') a.get_electron_ROC() # print a.p0 ax = a.plot_result_vs_sweepparam(ret='ax') # plt.ylim([0,0.052]) x = a.sweep_pts y = a.p0 if output: return x, y, ax else: return ax
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 analyze_data(timestamp, output=False): #, guess_frq = 1 / 20e9, guess_amp = 0.5): # o = fit.Parameter(guess_of, 'o') # f = fit.Parameter(guess_frq, 'f') # A = fit.Parameter(guess_amp, 'A') # phi = fit.Parameter(guess_phi, 'phi') # k = fit.Parameter(guess_k, 'k') # p0 = [f, A, phi, o, k] # fitfunc_str = '' if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data('Pi_Calibration') print folder a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') a.get_electron_ROC() ax = a.plot_result_vs_sweepparam(ret='ax') # plt.ylim([0,0.052]) x = a.sweep_pts y = a.p0 if output: return folder, x, y
def load_data(self): a = sequence.SequenceAnalysis(self.folder) a.get_sweep_pts() a.get_magnetometry_data(name='adwindata', ssro=False) self.msmnt_results = a.clicks self.reps, self.N = np.shape(a.clicks) self.msmnt_times = np.zeros(len(a.ramsey_time)) for j in np.arange(len(a.ramsey_time)): self.msmnt_times[j] = a.ramsey_time[j] self.msmnt_phases = 2 * np.pi * a.set_phase / 255. print ' ---- phases_detuning' print a.phases_detuning print ' ---- adptv_phases:' print np.unique(self.msmnt_phases * 180 / np.pi) phases_detuning = 2 * np.pi * a.phases_detuning / 360. b = np.ones(self.reps) self.msmnt_phases = np.mod( self.msmnt_phases - np.outer(b, phases_detuning), 2 * np.pi) print 'Some examples: ' print self.msmnt_phases[0, :] * 180 / np.pi print self.msmnt_phases[1, :] * 180 / np.pi print self.msmnt_phases[10, :] * 180 / np.pi
def clean_data_different_folders(folder='', sub_string=''): #takes all files in the folder with a given sub-strin gin the filename, #bins the data and checks at which point the data becomes zero due to ionization. #Only datasets with a number of valid data greater then 'threshold_data' are kept b_size = 50 threshold_data = 1200 thr_ind = threshold_data / b_size ind = 0 all_results = {} for d in os.listdir(folder): if (d.find(sub_string) > -1): #print d folder0 = folder + d a = sequence.SequenceAnalysis(folder0) a.get_sweep_pts() a.get_readout_results(name='ssro') results = a.ssro_results binned = bin_data(data=results, bin_size=b_size) binned.append(0) binned = np.array(binned) indice = np.nonzero(binned < 0.001)[0][0] if (indice > thr_ind): results = results[:(indice - 1) * b_size] all_results[str(ind)] = results ind = ind + 1 a.finish() all_results['max_ind'] = ind print 'Nr of good datasets: ' + str(ind) return all_results
def analyse_Ramsey(folder='', T2=3e3, Ampl=-1. / 3, detuning=3e-3, hf_N=2.17e-3, *arg): timestamp = kw.pop(timestamp, None) guess_tau = T2 guess_a = 0.5 guess_A = Ampl guess_hf_N = hf_N guess_det = detuning guess_hf_C = hf_C if timestamp != None: folder = toolbox.data_from_time(timestamp) elif folder != '': folder = toolbox.latest_data('Ramsey') a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='ssro') a.get_electron_ROC() x = a.sweep_pts y = a.p0 ax = a.plot_result_vs_sweepparam(ret='ax', name='ssro') params_0, fitfunc_0, fitfunc_str_0 = ramsey.fit_ramsey_14N_fixed_13C_opt( guess_tau, guess_A, guess_a, guess_det, guess_hf_N) x_0 = np.linspace(0, a.sweep_pts[-1], 1000) ax.plot(x_0, fitfunc_0(x_0), 'r--', lw=1) #fit_xvals=np.linspace(res['x'][0],res['x'][-1],fit_num_points) fit_result = fit.fit1d(x, y, ramsey.fit_ramsey_14N_fixed_13C_opt, guess_tau, guess_A, guess_a, guess_det, guess_hf_N, fixed=[], do_print=True, ret=True) #fit_result = False if fit_result != False: plot.plot_fit1d(fit_result, np.linspace(0, a.sweep_pts[-1], 201), ax=ax, plot_data=False) plt.savefig(os.path.join(folder, 'electronramsey_analysis.pdf'), format='pdf')
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 bloch_vector_length(name='', multiplicity='01', timestamp=None, guess_x0=None): ### parameters if guess_x0 == None: guess_x0 = 0.5 guess_of = 0.973 guess_a = 0. ### script x_dict = {} y_dict = {} y_err_dict = {} for RO in ['X', '-X', 'Y', '-Y', 'Z', '-Z']: if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data(name + RO + multiplicity) print folder a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') a.get_electron_ROC() # ax = a.plot_result_vs_sweepparam(ret='ax') x_dict[RO] = {} y_dict[RO] = {} y_err_dict[RO] = {} x_dict[RO] = a.sweep_pts y_dict[RO] = ((a.p0.reshape(-1)[:]) - 0.5) * 2 y_err_dict[RO] = 2 * a.u_p0.reshape(-1)[:] y_f = (((y_dict['X'] - y_dict['-X']) / 2.)**2 + ((y_dict['Y'] - y_dict['-Y']) / 2.)**2 + ((y_dict['Z'] - y_dict['-Z']) / 2.)**2)**(1 / 2.) print y_f fig, ax = plt.subplots() ax.plot(x_dict['X'], y_f, 'o', color='k') ax.set_ylim(-0.1, 1.1) # ax.set_xlim(x_dict['X'][0]-0.01,x_dict['X'][:]+0.01) ax.set_title(folder) # ax.hlines([-1,0],x_dict['X'][0]-1,x_dict['X'][-1]+1,linestyles='dotted') ax.set_xlabel('Amplitude') ax.set_ylabel('Bloch vector length') res = funcs.calibrate_pulse_amplitude(x_dict['X'], y_f, ax, guess_x0, guess_of, guess_a) plt.savefig(os.path.join(folder, 'bloch_length.pdf'), format='pdf') plt.savefig(os.path.join(folder, 'bloch_length.png'), format='png')
def analyze_dark_esr_single(guess_offset=1, guess_width=0.2e-3, guess_amplitude=0.3, timestamp=None, add_folder=None, ret='f0', ssro_calib_folder='', **kw): if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data('DarkESR') if add_folder != None: folder = add_folder a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') a.get_electron_ROC() x = a.sweep_pts # convert to MHz y = a.p0.reshape(-1)[:] guess_ctr = x[y.argmin()] print 'guess_ctr = ' + str(guess_ctr) ## I added this to be more robust for SSRO calibration.Please monitor if this is better - Machiel may-2014 guess_offset = np.average(y) dip_threshold = guess_offset - 1.5 * np.std(y) print guess_offset print dip_threshold # if min(y) > dip_threshold: # print 'Could not find dip' # return fit_result = fit.fit1d(x, y, esr.fit_ESR_gauss, guess_offset, guess_amplitude, guess_width, guess_ctr, do_print=True, ret=True, fixed=[]) if ret == 'f0': f0 = fit_result['params_dict']['x0'] u_f0 = fit_result['error_dict']['x0'] return f0, u_f0
def fit_Ramsey_6_cos_hf_fixed(timestamp, ssro_calib_folder, g_tau, g_A, g_a, g_det, g_hf_N, g_hf_C, fixed=[], folder=None): if folder is None: if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data('ElectronRamsey') a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='ssro') if ssro_calib_folder != None: a.get_electron_ROC(ssro_calib_folder=ssro_calib_folder) else: a.get_electron_ROC() # Plot data ax = a.plot_result_vs_sweepparam(ret='ax', name='ssro') p0, fitfunc_0, fitfunc_str_0 = ramsey.fit_ramsey_hyperfinelines_fixed_6cos( g_tau, g_A, g_a, g_det, g_hf_N, g_hf_C) fit_result = fit.fit1d(a.sweep_pts, a.p0.reshape(-1), ramsey.fit_ramsey_hyperfinelines_fixed_6cos, g_tau, g_A, g_a, g_det, g_hf_N, g_hf_C, fixed=fixed, do_print=True, ret=True) if fit_result != False: plot.plot_fit1d(fit_result, np.linspace(0, a.sweep_pts[-1], 201), ax=ax, plot_data=False) plt.savefig(os.path.join(folder, 'electronramsey_analysis.png'), format='png')
def electron_T2_anal(timestamp=None, measurement_name=['ms0'], Amplitude=1 / 2., T2=10e3, offset=1. / 2, k=4, do_print=False, ylim=(0., 1.)): ''' Function to analyze simple decoupling measurements. Loads the results and fits them to a simple exponential. Inputs: timestamp: in format yyyymmdd_hhmmss or hhmmss or None. measurement_name: list of measurement names Based on electron_T1_anal, modified by Adriaan Rol ''' if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data('Decoupling') print folder fit_results = [] for k in range(0, len(measurement_name)): a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results(measurement_name[k]) a.get_electron_ROC() ax = a.plot_result_vs_sweepparam(ret='ax') ax.set_ylim(ylim) x = a.sweep_pts p0, fitfunc, fitfunc_str = SE.fit_echo(T2, Amplitude, offset, k) y = a.p0 fit_result = fit.fit1d(x, y, None, p0=p0, fitfunc=fitfunc, do_print=do_print, ret=True, fixed=[3]) #fit_result = False if fit_result != False: plot.plot_fit1d(fit_result, np.linspace(0, x[-1], 201), ax=ax, plot_data=False) fit_results.append(fit_result) plot.ylim = ([0, 0.2]) return fit_results
def get_T1_data_uncorrected(folder): a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') #a.get_electron_ROC() #a.get_cr_results('ssro') #a.plot_cr_vs_sweep() x = a.sweep_pts #y = a.p0 y = a.normalized_ssro print y #y_err = a.u_p0 y_err = a.u_normalized_ssro #ax = a.plot_result_vs_sweepparam(ret='ax') return x, y, y_err
def electron_T1_anal(timestamp=None, measurement_name=['ms0'], Amplitude=0.1, T1=1000, offset=1, do_print=False): ''' Function to analyze T1 measurements. Loads the results and fits them to a simple exponential. Inputs: timestamp: in format yyyymmdd_hhmmss or hhmmss or None. measurement_name: list of measurement names ''' if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data('ElectronT1') fit_results = [] for k in range(0, len(measurement_name)): a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') #a.get_readout_results(measurement_name[k]) #commented out since newer measurements are no longer grouped which renders the whole for-loop obsolete. NK 20141110 a.get_electron_ROC() ax = a.plot_result_vs_sweepparam(ret='ax') x = a.sweep_pts p0, fitfunc, fitfunc_str = common.fit_exp_decay_with_offset( offset, Amplitude, T1) y = a.p0 #print y fit_result = fit.fit1d(x, y, None, p0=p0, fitfunc=fitfunc, do_print=do_print, ret=True) plot.plot_fit1d(fit_result, np.linspace(0, x[-1], 201), ax=ax, plot_data=False) fit_results.append(fit_result) plt.savefig(os.path.join(folder, 'analyzed_result.pdf'), format='pdf') plt.savefig(os.path.join(folder, 'analyzed_result.png'), format='png') return fit_results
def electron_T1_mul_3_uncorrected(older_than='20161111_091500',newer_than='20161110_224400', Amplitude=1, offset=1, T1=1e9, do_print = False,contains='T1'): Folder_list = toolbox.latest_data(contains=contains,older_than=older_than,newer_than=newer_than,return_all=True) x_tot=np.zeros(3) y_tot=np.zeros(3) reps_tot=np.zeros(3) y_var_tot=np.zeros(3) for i in range(len(Folder_list)): print Folder_list[len(Folder_list)-i-1] Folder = Folder_list[len(Folder_list)-i-1] x,y,reps = get_T1_data_uncorrected(Folder) y_tot+=y reps_tot+=reps a = sequence.SequenceAnalysis(Folder) a.get_sweep_pts() a.get_readout_results('ssro') print reps_tot a.ssro_results=y_tot a.reps=reps_tot print a.reps a.normalized_ssro = a.ssro_results/((a.reps)/len(a.sweep_pts)) a.u_normalized_ssro = \ (a.normalized_ssro*(1.-a.normalized_ssro)/((a.reps)/len(a.sweep_pts)))**0.5 #this is quite ugly, maybe replace? a.get_electron_ROC() y_tot=a.p0 y_var_tot=a.u_p0 return x_tot,y_tot,y_var_tot ################################################################# # x1,y1,y_var1 = electron_T1_mul_3(older_than='20161119_205000',newer_than='20161118_110000',contains='10_min') # x_tot.append(x1) # y_tot.append(y1) # y_var_tot.append(y_var1) # x_tot=[] # y_tot=[] # y_var_tot=[]
def analyse_pulse_calibration(name='Pi', timestamp=None, guess_x0=None): ### parameters if guess_x0 == None: guess_x0 = 0.5 msmt_type = 'sequence' guess_of = 0.973 guess_a = 0. ### script if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data(name) if msmt_type == 'sequence': a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') a.get_electron_ROC() ax = a.plot_result_vs_sweepparam(ret='ax') x = a.sweep_pts y = a.p0 elif msmt_type == 'mbi': a = mbi.MBIAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_electron_ROC() ax = a.plot_results_vs_sweepparam(name='adwindata', ret='ax') else: raise Exception('Unknown msmt type') ax.set_ylim(-0.1, 1) x = a.sweep_pts.reshape(-1)[:] y = a.p0.reshape(-1)[:] res = funcs.calibrate_pulse_amplitude(x, y, ax, guess_x0, guess_of, guess_a) plt.savefig(os.path.join(folder, 'pulse_calibration.pdf'), format='pdf') plt.savefig(os.path.join(folder, 'pulse_calibration.png'), format='png')
def calibrate_epulse_rabi(folder, ax, *args, **kws): fit_phi = kws.pop('fit_phi', True) fit_k = kws.pop('fit_k', True) 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) f = fit.Parameter(args[0], 'f') A = fit.Parameter(args[1], 'A') x0 = fit.Parameter(0, 'x0') k = fit.Parameter(0, 'k') p0 = [f, A] if fit_phi: 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 analyze_dark_esr(folder, ax=None, **kw): if ax == None: fig, ax = plt.subplots(1, 1) ssro_calib_folder = toolbox.latest_data( contains='AdwinSSRO_SSROCalibration') a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') a.get_electron_ROC(ssro_calib_folder=ssro_calib_folder) x = a.sweep_pts # convert to MHz y = a.p0.reshape(-1)[:] a.plot_result_vs_sweepparam(ret=None, name='ssro', ax=ax) guess_ctr = x[np.floor(len(x) / 2.)] fit_result = fit.fit1d( x, y, esr.fit_ESR_gauss, guess_offset, guess_amplitude, guess_width, guess_ctr, # (2, guess_splitN), #(2, guess_splitC), # (2, guess_splitB), #(3, guess_splitN), do_print=True, ret=True, fixed=[]) plot.plot_fit1d(fit_result, np.linspace(min(x), max(x), 1000), ax=ax, plot_data=False, **kw) ax.set_xlabel('MW frq (GHz)') ax.set_ylabel(r'fidelity wrt. $|0\rangle$') ax.set_title(a.timestamp + '\n' + a.measurementstring) plt.savefig(os.path.join(folder, 'darkesr_analysis.png'), format='png') return fit_result
def plot_result(folder=None, ax=None, ret=True, save_name='ssro', **kw): if folder == None: folder = tb.latest_data('CORPSEPiCalibration') if ax == None: fig, ax = plt.subplots(1, 1, figsize=(4.5, 4)) a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name=save_name) a.get_electron_ROC() print len(a.p0), len(a.sweep_pts) a.plot_result_vs_sweepparam(ax=ax, name=save_name) # print a.normalized_ssro x = a.sweep_pts.reshape(-1)[:] y = a.p0.reshape(-1)[:] print 'min x = ', x[np.argmin(y)] print 'min y =', np.amin(y) ax.set_title(a.timestamp) if ret: return a, ax, x, y
def clean_data(folder=''): #takes all hdf5 data in the folder #bins the data and checks at which point the data becomes zero due to ionization. #Only datasets with a number of valid data greater then 'threshold_data' are kept b_size = 500 threshold_data = 1000 thr_ind = threshold_data / b_size ind = 0 all_results = {} final = True i = -1 a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() print folder while ((final) & (i < 500)): i = i + 1 try: a.get_readout_results(name='rep_' + str(i)) print str('analysing rep. #' + str(i)) results = a.ssro_results a.get_sweep_pts() binned = bin_data(data=results, bin_size=b_size) binned.append(0) binned = np.array(binned) indice = np.nonzero(binned < 0.001)[0][0] print indice if (indice > thr_ind): results = results[:(indice - 1) * b_size] all_results[str(ind)] = results ind = ind + 1 except: final = False print 'done' a.finish() all_results['max_ind'] = ind print 'Nr of good datasets: ' + str(ind) return all_results
def fit_gaussian(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') a = fit.Parameter(0.5, 'a') o = fit.Parameter(0.5, 'o') c = fit.Parameter(15, 'c') f = fit.Parameter(1. / 500, 'f') fitfunc_str = 'o + a * exp( - ( (x-x0)/c )^2) ' def fitfunc(x): return o() + a() * np.exp(-((x - x0()) / c())**2) fit_result = fit.fit1d(x, y, None, p0=[o, x0, a, c], fixed=[], 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) return fit_result
def analyze_dark_esr_double(guess_offset=1, guess_A_min=0.3, guess_A_plus=0.3, guess_width=0.2e-3, guess_amplitude=0.3, guess_Csplit=0.100e-3, timestamp=None, add_folder=None, ret='f0', ssro_calib_folder='', do_ROC=True, ret_folder=False, do_plot=True, **kw): if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data('DarkESR') print folder if add_folder != None: folder = add_folder a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') if do_ROC == True: a.get_electron_ROC() y = a.p0.reshape(-1)[:] else: y = a.get_readout_results('ssro') x = a.sweep_pts # convert to MHz ### create a guess for the center frequency guess_ctr1 = x[y.argmin()] + guess_Csplit * 1.2 guess_ctr2 = x[y.argmin()] - guess_Csplit * 1.2 # # guess_ctr1 =x[len(x)/2.] print 'guess_ctr1 = ' + str(guess_ctr1) print 'guess_ctr2 = ' + str(guess_ctr2) ### First fit attempt: guess_ctr1 ### fitfunction A_min = fit.Parameter(guess_A_min, 'A_min') A_plus = fit.Parameter(guess_A_plus, 'A_plus') o = fit.Parameter(guess_offset, 'o') ctr = fit.Parameter(guess_ctr1, 'ctr') width = fit.Parameter(guess_width, 'width') Csplit = fit.Parameter(guess_Csplit, 'Csplit') def fitfunc(x): return o() - A_min()*np.exp(-((x-(ctr()-Csplit()))/width())**2) \ - A_plus()*np.exp(-((x-(ctr()+Csplit()))/width())**2) \ print 'running fit1' fit_result = fit.fit1d(x, y, None, p0=[A_min, A_plus, o, ctr, width, Csplit], fitfunc=fitfunc, do_print=False, ret=True, fixed=[]) do_another_fit = False if fit_result['success'] == False: do_another_fit = True elif fit_result['error_dict']['ctr'] > 8e-6: do_another_fit = True if do_another_fit == True: print 'first fit failed' ### Second fit attempt: guess_ctr2 A_min = fit.Parameter(guess_A_min, 'A_min') A_plus = fit.Parameter(guess_A_plus, 'A_plus') o = fit.Parameter(guess_offset, 'o') ctr = fit.Parameter(guess_ctr2, 'ctr') width = fit.Parameter(guess_width, 'width') Csplit = fit.Parameter(guess_Csplit, 'Csplit') def fitfunc(x): return o() - A_min()*np.exp(-((x-(ctr()-Csplit()))/width())**2) \ - A_plus()*np.exp(-((x-(ctr()+Csplit()))/width())**2) \ print 'running fit2' fit_result = fit.fit1d(x, y, None, p0=[A_min, A_plus, o, ctr, width, Csplit], fitfunc=fitfunc, do_print=False, ret=True, fixed=[]) if do_plot == True: fig, ax = plt.subplots(1, 1) plot.plot_fit1d(fit_result, np.linspace(min(x), max(x), 1000), ax=ax, plot_data=True, **kw) plt.savefig(os.path.join(folder, 'darkesr_analysis.png'), format='png') #plt.show() plt.close(fig) if ret == 'f0' and ret_folder == False: if fit_result['success'] == False: print 'Fit failed, returned dummy values for frequency' f0 = 0 u_f0 = 1e-3 #large arbitrary uncertainty makes sure the data is filtered out later return f0, u_f0 else: f0 = fit_result['params_dict']['ctr'] u_f0 = fit_result['error_dict']['ctr'] return f0, u_f0 elif ret == 'f0' and ret_folder == True: return f0, u_f0, folder
def analyze_dark_esr(guess_ctr, guess_splitN, guess_offset=1, guess_width=0.2e-3, guess_amplitude=0.3, min_dip_depth=0.9, timestamp=None, add_folder=None, ret='f0', ssro_calib_folder='', do_save=True, sweep_direction='right', **kw): if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data('DarkESR') if add_folder != None: folder = add_folder print 'analysis script!' print folder a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') a.get_electron_ROC() x = a.sweep_pts # convert to MHz y = a.p0.reshape(-1)[:] # Find the esr resonance j = 0 print 'j = ' + str(j) print folder print y[21] k = len(y) # min_dip_depth = np.amin(y) # min_index = np.argmin(y) print 'min_dip_depth = ' + str(min_dip_depth) ### Option to make the dip search sweep towards left or right, usefull in case of N polarization if sweep_direction == 'left': y1 = y[::-1] x1 = x[::-1] guess_splitN = -1 * guess_splitN elif sweep_direction == 'right': y1 = y x1 = x while y1[j] > min_dip_depth and j < len( y) - 2: #y[j]>0.93*y[j+1]: # such that we account for noise k = j j += 1 #j = len(y)-2 if k > len(y) - 3: print 'Could not find dip' return else: guess_ctr = x1[k] + guess_splitN #convert to GHz and go to middle dip print 'guess_ctr= ' + str(guess_ctr) print 'k' + str(k) ## I added this to be more robust for SSRO calibration.Please monitor if this is better - Machiel may-2014 fit_result = fit.fit1d(x, y, esr.fit_ESR_gauss, guess_offset, guess_amplitude, guess_width, guess_ctr, (3, guess_splitN), do_print=True, ret=True, fixed=[]) print 'fit finished' if do_save: print 'saving data and fit' if fit_result: fig, ax = plt.subplots(1, 1) plot.plot_fit1d(fit_result, np.linspace(min(x), max(x), 1000), ax=ax, plot_data=True, **kw) plt.savefig(os.path.join(folder, 'darkesr_analysis.png'), format='png') #plt.show() plt.close(fig) if ret == 'f0': f0 = fit_result['params_dict']['x0'] u_f0 = fit_result['error_dict']['x0'] return f0, u_f0
def analyse_dark_esr(**kw): timestamp = kw.pop('timestamp', None) ax = kw.pop('ax', None) ret = kw.pop('ret', None) min_dip_depth = kw.pop('min_dip_depth', 0.85) do_print = kw.pop('do_print', False) plot_initial_guess = kw.pop('plot_initial_guess', False) guess_amplitude = kw.pop('guess_amplitude', 0.3) guess_width = kw.pop('guess_width', 0.2e-3) guess_offset = kw.pop('guess_offset', 1) guess_x0 = kw.pop('guess_x0', 2.805) guess_Nsplit = kw.pop('guess_Nsplit', 2.196e-3) if timestamp != None: folder = toolbox.data_from_time(timestamp) if folder == None: folder = toolbox.latest_data(timestamp) else: folder = toolbox.latest_data('DarkESR') print 'Folder for the Dark ESR analysis : ', folder if ax == None: fig, ax = plt.subplots(1, 1) ssro_calib_folder = toolbox.latest_data( contains='130113_AdwinSSRO_SSROCalibration') print ssro_calib_folder a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') a.get_electron_ROC(ssro_calib_folder=ssro_calib_folder) x = a.sweep_pts # convert to MHz y = a.p0.reshape(-1)[:] a.plot_result_vs_sweepparam(ret=ret, name='ssro', ax=ax) #ax.set_ylim(0.1,1.05) j = 0 while y[j] > min_dip_depth and j < len( y) - 2: #y[j]>0.93*y[j+1]: # such that we account for noise k = j j += 1 #j = len(y)-2 if k > len(y) - 5: print 'Could not find dip' return else: guess_ctr = x[k] + guess_Nsplit #convert to GHz and go to middle dip print 'guess_ctr= ' + str(guess_ctr) fit_result = fit.fit1d( x, y, esr.fit_ESR_gauss, guess_offset, guess_amplitude, guess_width, guess_ctr, # (2, guess_splitN), # (2, guess_splitC), # (2, guess_splitB), (3, guess_Nsplit), do_print=do_print, ret=True, fixed=[]) plot.plot_fit1d(fit_result, np.linspace(min(x), max(x), 1000), ax=ax, plot_data=False, **kw) plot_initial_guess = False if plot_initial_guess: params_0, fitfunc_0, fitfunc_str = esr.fit_ESR_gauss( guess_offset, guess_amplitude, guess_width, guess_ctr, (2, guess_splitC), (3, guess_splitN)) ax.set_xlabel('MW frq (GHz)') ax.set_ylabel(r'fidelity wrt. $|0\rangle$') ax.set_title(a.timestamp + '\n' + a.measurementstring) plt.savefig(os.path.join(folder, 'darkesr_analysis.png'), format='png') if ret == 'f0': f0 = fit_result['params_dict']['x0'] u_f0 = fit_result['error_dict']['x0'] ax.text(f0, 0.8, '$f_0$ = ({:.3f} +/- {:.3f})'.format((f0 - 2.8) * 1e3, u_f0 * 1e3), ha='center') return (f0 - 2.8) * 1e3, u_f0 * 1e3 return fit_result
def analyse_pi4_pulse(**kw): timestamp = kw.pop('timestamp', None) do_print = kw.pop('do_print', False) pi4_calib = kw.pop('pi4_calib', '1') if timestamp != None: folder = toolbox.data_from_time(timestamp) if folder == None: folder = toolbox.latest_data(timestamp) else: folder = toolbox.latest_data('Pi4') 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] 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) if pi4_calib == '1': ax1.set_title('Difference btw. Pi/4-Pi-Pi/4 and Pi/2') elif pi4_calib == '2': ax1.set_title('Difference btw. Pi/2-Pi-Pi/4 and Pi/4') ax1.set_ylabel('Difference') ax2.set_title(a.timestamp) 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=do_print, ret=True) if pi4_calib == '1': ax2.errorbar(x2, y[0::2], yerr=u_y[0::2], fmt='o', label='Pi/4 - Pi - Pi/4') ax2.errorbar(x2, y[1::2], yerr=u_y[1::2], fmt='o', label='Pi/2') elif pi4_calib == '2': ax2.errorbar(x2, y[0::2], yerr=u_y[0::2], fmt='o', label='Pi/2 - Pi - Pi/4') ax2.errorbar(x2, y[1::2], yerr=u_y[1::2], fmt='o', label='Pi/4') ax2.legend(frameon=True, framealpha=0.5) ax2.set_ylabel('P(0)') ax2.set_xlabel(n) if fit_result != False: plot.plot_fit1d(fit_result, np.linspace(x2[0], x2[-1], 201), ax=ax1, plot_data=False, print_info=do_print) if a.sweep_pts[0] < x0() < a.sweep_pts[-1]: ax2.axvline(x0(), c='k', lw=2) if pi4_calib == '1': ax2.axhline(0.5, c='k', lw=2) elif pi4_calib == '2': ax2.axhline(np.sqrt(np.sin(np.pi / 4.)), c='k', lw=2) ax2.set_title('X marks the spot') if pi4_calib == '1': fig.savefig(os.path.join(folder, 'pi4_calibration_1.png')) elif pi4_calib == '2': fig.savefig(os.path.join(folder, 'pi4_calibration_2.png')) return fit_result
def analyse_Rabi(guess_frq=2., guess_amp=0.2, guess_of=0.1, **kw): timestamp = kw.pop('timestamp', None) guess_phi = kw.pop('guess_phi', 0.) guess_k = kw.pop('guess_k', 0.) mbi_analysis = kw.pop('mbi_analysis', False) do_print = kw.pop('do_print', False) o = fit.Parameter(guess_of, 'o') f = fit.Parameter(guess_frq, 'f') A = fit.Parameter(guess_amp, 'A') phi = fit.Parameter(guess_phi, 'phi') k = fit.Parameter(guess_k, 'k') p0 = [f, A, phi, o, k] fitfunc_str = '' if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data('ElectronRabi') if mbi_analysis: a = mbi.MBIAnalysis(folder) a.get_sweep_pts() a.get_readout_results('adwindata') a.get_electron_ROC() ax = a.plot_results_vs_sweepparam(ret='ax', name='adwindata') else: a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') a.get_electron_ROC() ax = a.plot_result_vs_sweepparam(ret='ax') x = a.sweep_pts y = a.p0 fitfunc_str = 'o - A + A*e^(-kx)*cos(2pi (fx-phi))' def fitfunc(x): return (o() - A()) + A() * np.exp(-k() * x) * np.cos(2 * np.pi * (f() * x - phi())) fit_result = fit.fit1d(x, y, None, p0=p0, fitfunc=fitfunc, fixed=[2], do_print=do_print, ret=True) plot.plot_fit1d(fit_result, np.linspace(0, x[-1], 201), ax=ax, plot_data=False) print "\npi pulse at {:.3f} for .\n".format(1 / f() / 2.) + a.sweep_name # ax.set_title(a.timestamp+'\n'+a.measurementstring) plt.savefig(os.path.join(folder, 'electronrabi_analysis_fit.png')) return fit_result
from analysis.lib.tools import plot from analysis.lib.m2.ssro import ssro from analysis.lib.m2.ssro import sequence reload(sequence) folder = None timestamp = None#'095551'#'180057'# None if folder == None: if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data('AdwinSSRO') a = ssro.SSROAnalysis(folder) b = sequence.SequenceAnalysis(folder) runs = 1 debug = False if debug: runs =2 max_ts = [ ] taus = [ ] u_taus =[ ] means = [ ] u_means = [] percentage_passes = [ ] # analyze the data
def fit_B_msmt_loop(older_than = None, newer_than = None): ZFS = 2.877480e9 f0m = []; u_f0m = []; f0p = [] ;u_f0p = [] Bx_field_measured = [] Bz_field_measured = [] f_centre_list = []; f_diff_list=[] timestamp_list = [] f_centre_error_list= [] it_list = [] f_diff_error_list = [] #msm print 'start' older_than_SSRO = older_than # print older_than, newer_than iteration = 0 while toolbox.latest_data(contains='msmt_msm_', older_than=older_than, newer_than=newer_than,raise_exc = False)!=False: print 'iteration'+str(iteration) timestamp,folder = toolbox.latest_data(contains='msmt_msm_', older_than=older_than, newer_than=newer_than,return_timestamp = True) print 'm folder '+folder ## Data location ## ssro_calib_folder = toolbox.latest_data(contains='AdwinSSRO_SSROCalibration', older_than=older_than_SSRO) a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') a.get_electron_ROC(ssro_calib_folder=ssro_calib_folder) f0m_temp,u_f0m_temp = dark_esr_auto_analysis.analyze_dark_esr(None, 2.196*1e-3, add_folder = folder ) #msp folder = toolbox.latest_data(contains='msmt_msp_', older_than=older_than, newer_than=newer_than,) print folder a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') a.get_electron_ROC(ssro_calib_folder=ssro_calib_folder) f0p_temp,u_f0p_temp = dark_esr_auto_analysis.analyze_dark_esr(None, 2.196*1e-3, add_folder = folder ) print f0p_temp >0 and f0m_temp >0 if f0p_temp >0 and f0m_temp >0: Bz_measured, Bx_measured = amt.get_B_field(msm1_freq=f0m_temp*1e9, msp1_freq=f0p_temp*1e9, u_msm1_freq =u_f0m_temp ,u_msp1_freq=u_f0p_temp) f_centre = (f0m_temp+f0p_temp)/2 f_centre_error = np.sqrt(u_f0m_temp**2+u_f0p_temp**2)/2 f_diff = (f_centre-ZFS*1e-9)*1e6 f_diff_error = f_centre_error*1e6 f0m.append(f0m_temp) u_f0m.append(u_f0m_temp) f0p.append(f0p_temp) u_f0p.append(u_f0p_temp) f_centre_list.append(f_centre) f_centre_error_list.append(f_centre_error) f_diff_list.append(f_diff) f_diff_error_list.append(f_diff_error) Bx_field_measured.append(Bx_measured) Bz_field_measured.append(Bz_measured) timestamp_list.append(timestamp) it_list.append(iteration) older_than = str(int(timestamp)-1) iteration = iteration+1 print iteration it_list = linspace(0,len(it_list)-1,len(it_list)) outfile = TemporaryFile() np.savez('test_B_field_meas',f0m=f0m, u_f0m=u_f0m, f0p=f0p, u_f0p=u_f0p, f_centre_list=f_centre_list, f_centre_error_list=f_centre_error_list, f_diff_list=f_diff_list, f_diff_error_list=f_diff_error_list, Bx_field_measured=Bx_field_measured, Bz_field_measured=Bz_field_measured, timestamp_list=timestamp_list, it_list=it_list)
def analyze_dark_esr_double(timestamp=None, center_guess=False, ax=None, ret=None, min_dip_depth=0.85, do_ROC=True, **kw): if ax == None: fig, ax = plt.subplots(1, 1) if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data('DarkESR') a = sequence.SequenceAnalysis(folder) a.get_sweep_pts() a.get_readout_results('ssro') # a.get_electron_ROC() x = a.sweep_pts # convert to MHz # y = a.get_readout_results('ssro') if do_ROC == True: a.get_electron_ROC() y = a.p0.reshape(-1)[:] else: y = a.get_readout_results('ssro') # y = a.p0.reshape(-1)[:] a.plot_result_vs_sweepparam(ret=ret, name='ssro', ax=ax) ax.set_ylim(0.6, 1.05) # try fitting guess_offset = 1.0 guess_A_min = 0.3 guess_A_plus = 0.3 guess_x0 = 1.74666 guess_sigma = 0.100e-3 guess_Csplit = 0.210e-3 / 2 if center_guess == True: guess_x0 = float(raw_input('Center guess?')) else: guess_x0 = x[y.argmin()] guess_x0 = x[len(x) / 2.] print 'guess_ctr = ' + str(guess_x0) ### fitfunction A_min = fit.Parameter(guess_A_min, 'A_min') A_plus = fit.Parameter(guess_A_plus, 'A_plus') o = fit.Parameter(guess_offset, 'o') x0 = fit.Parameter(guess_x0, 'x0') sigma = fit.Parameter(guess_sigma, 'sigma') Csplit = fit.Parameter(guess_Csplit, 'Csplit') def fitfunc(x): return o() - A_min()*np.exp(-((x-(x0()-Csplit()))/sigma())**2) \ - A_plus()*np.exp(-((x-(x0()+Csplit()))/sigma())**2) \ fit_result = fit.fit1d(x, y, None, p0=[A_min, A_plus, o, x0, sigma, Csplit], fitfunc=fitfunc, do_print=True, ret=True, fixed=[]) plot.plot_fit1d(fit_result, np.linspace(min(x), max(x), 1000), ax=ax, plot_data=False, **kw) ax.set_xlabel('MW frq (GHz)') ax.set_ylabel(r'fidelity wrt. $|0\rangle$') ax.set_title(a.timestamp + '\n' + a.measurementstring) plt.savefig(os.path.join(folder, 'darkesr_analysis.png'), format='png') if ret == 'f0': f0 = fit_result['params_dict']['x0'] u_f0 = fit_result['error_dict']['x0'] ax.text(f0, 0.8, '$f_0$ = ({:.3f} +/- {:.3f})'.format((f0 - 2.8) * 1e3, u_f0 * 1e3), ha='center') return (f0 - 2.8) * 1e3, u_f0 * 1e3