Exemplo n.º 1
0
def targetstate_analysis(foldernamez,foldernamex, filename='Spin_RO',date='',RO_time=''):
    zdata_norm,zdata_corr=sc.plot_feedback(foldernamez, filename='Spin_RO',d=date)
    print RO_time
    if ((RO_time=='2us') or (RO_time=='4us') or (RO_time=='6us')): 
        xdata_norm,xdata_corr=sc.plot_feedback(foldernamex, filename='Spin_RO',d=date)
        SNfit=sc.fit_sin(xdata_norm['sweep_par'],xdata_corr['FinalRO_SN'],xdata_corr['uFinalRO_SN'])
        FSfit=sc.fit_sin(xdata_norm['sweep_par'],xdata_corr['FinalRO_FS'],xdata_corr['uFinalRO_FS'])
        allfit=sc.fit_sin(xdata_norm['sweep_par'],xdata_corr['FinalRO_All'],xdata_corr['uFinalRO_All'])
        N=(xdata_norm['SN'][2]+xdata_norm['FS'][2])
        xsucces= (xdata_norm['SN'][2]*(abs(SNfit['params'][1])*2)+
			xdata_norm['FS'][2]*(abs(FSfit['params'][1])*2))/N
	uxsucces=np.sqrt(((xdata_norm['SN'][2]*abs(SNfit['error_dict']['a'])*2)/N)**2+
	                 ((xdata_norm['FS'][2]*abs(FSfit['error_dict']['a'])*2)/N)**2)
        Sx=[abs(FSfit['params'][1])*2,abs(SNfit['params'][1])*2,xsucces]
        uSx=[FSfit['error_dict']['a']*2,SNfit['error_dict']['a']*2,uxsucces,0]
	i=2
	Sz=[zdata_corr['FinalRO_FS'][i],zdata_corr['FinalRO_SN'][i],zdata_corr['FinalRO_Succes'][i]]
    else:
	Sx=[0,0,0]
	uSx=[0,0,0]
	i=1
	Sz=[1-zdata_corr['FinalRO_FS'][i],1-zdata_corr['FinalRO_SN'][i],1-zdata_corr['FinalRO_Succes'][i]]
    if (RO_time=='15us'):	
	i=2
	Sz=[zdata_corr['FinalRO_FS'][i],zdata_corr['FinalRO_SN'][i],zdata_corr['FinalRO_Succes'][i]]


    

    Sy=[0,0,0,0]
    fdata={}
    fdata['zdata_norm']=zdata_norm
    fdata['zdata_corr']=zdata_corr
    fdata['res_FS']=[2*(1-Sz[0])-1,Sx[0],Sy[0],0]
    fdata['res_SN']=[2*(1-Sz[1])-1,Sx[1],Sy[1],0]
    fdata['res_Succes']=[2*(1-Sz[2])-1,Sx[2],Sy[2],0]
    fdata['ures_FS']=[zdata_corr['uFinalRO_FS'][i]*2,uSx[0],0,0]
    fdata['ures_SN']=[zdata_corr['uFinalRO_SN'][i]*2,uSx[1],0,0]
    fdata['ures_Succes']=[zdata_corr['uFinalRO_Succes'][i]*2,uSx[2],0,0]
    #fdata['SNfit']=SNfit
    #fdata['FSfit']=FSfit
    #fdata['allfit']=allfit
    meas_strength = calc_meas_strength(50,12,1400)
    fdata['meas_strength'] = meas_strength
    fdata['res_ideal']=[np.sin(meas_strength*np.pi/2.),np.cos(meas_strength*np.pi/2.),0,0]
    fdata['dm'],fdata['f'],fdata['uf'],fdata['ideal']=tls.calc_fidelity_psi(tau,(fdata['res_Succes'][0]+1)/2.,fdata['res_Succes'][1]/2.+0.5,utau,fdata['ures_Succes'][0]/2.,fdata['ures_Succes'][1],th=th,dir=dir)
    tls.make_hist(fdata['dm'][0],np.array([[0,0],[0,0]]))

    #print 'Fidelity',f,'  +-',uf
    #print 'Ideal state:', ideal
    #print 'uz: ',uzcor,'  ux: ',uxcor
    np.savez(os.path.join(basepath,name+RO_time),**fdata)
Exemplo n.º 2
0
    data_norm['FinalRO_FF']=data['FinalRO_FF']/(data['FF']+0.)
    data_norm['FinalRO_Succes']=(data['FinalRO_SN']+data['FinalRO_FS'])/(data['SN']+data['FS']+0.)
    data_norm['FinalRO_All']=(data['FinalRO_SN']+data['FinalRO_FS']+data['FinalRO_FF'])/(reps+0.)

    print data['FS']
    for i in np.arange(len(data['SN'])):
        z+=data['FinalRO_FS'][i]
        zrep+=data['FS'][i]
    print zrep
    znorm=z/(zrep+0.)
    data.close()

phasecor,uphasecor=sc.get_nuclear_ROC(phasenorm,rep,sc.get_latest_data('SSRO',date=d))
zcor, uzcor=sc.get_nuclear_ROC(znorm,zrep,sc.get_latest_data('SSRO',date=zd))
figure1=plt.figure(2)
ax=figure1.add_subplot(111)
ax.errorbar(x,phasenorm,fmt='o',yerr=1/sqrt(rep),color='Crimson')
ax.errorbar(x,phasecor,fmt='o',yerr=uphasecor,color='RoyalBlue')
phase_fit=sc.fit_sin(x,phasecor,uphasecor)
xcor=np.abs(phase_fit['params'][1])+np.abs(phase_fit['params'][2])
uxcor=np.sqrt(phase_fit['error_dict']['A']**2+phase_fit['error_dict']['a']**2)

dm,f,uf,ideal=tls.calc_fidelity_psi(tau,1-zcor,xcor,utau,uzcor,uxcor,th=th,dir=dir)
idr=tls.make_rho(ideal[0]**2,ideal[1]*ideal[0])
print idr

tls.make_hist(dm[0],np.array([[0,0],[0,0]]))
print 'Fidelity',f,'  +-',uf
print 'Ideal state:', ideal
print 'uz: ',uzcor,'  ux: ',uxcor
Exemplo n.º 3
0
def segmented_N_ramsey(nr_of_datapoints=1,folder = r'D:\measuring\data\20130709\123046_Seg_RO__LT2_N_Ramsey_seg_RO_100us_750pW/'):
    a= np.load (folder+'Seg_RO-000_segment_number.npz')
    seg_nr=a['segment_number']
    a.close()
    
    a= np.load (folder+'Seg_RO-000_segment_number.npz')
    seg_nr=a['segment_number']
    a.close()
    
    c= np.load (folder+'Seg_RO-000_Spin_RO.npz')
    SSRO_counts=c['SSRO_counts']
    cond_RO_data=c['cond_RO_data']
    x=c['sweep_axis']
    c.close()
    
    nr_of_datapoints=len(SSRO_counts)
    reps=int(sum(seg_nr)/float(nr_of_datapoints))
    total_segments=len(seg_nr)
    #total_segments=45
    
    plt.figure()
    phase=[]
    segnr_phase=[]
    reconstr_sum=np.zeros(201)
    corrected=np.zeros(201)
    accum_seg_nr=np.zeros(len(seg_nr))
    for i in np.arange(total_segments):
        if i in [4,5,6,7,8]:
            do_plot=True
            print i
        else:
            do_plot=False
        y=cond_RO_data[nr_of_datapoints*i:nr_of_datapoints*(i+1)]
        #FIX: This normalization is very rough, we should devide each point with the number of repetitions (get it from segmented_RO_data.npz)
        y_norm=y/float(max(y))
        
        dict=sc.fit_sin(x,y,sqrt(max(y)),fixed=[0],fix_param=[1/360.],do_plot=do_plot)
        if dict:
            phase.append(dict['params'][2])
            segnr_phase.append(i)
            reconstr_sum=reconstr_sum+dict['fitfunc'](np.linspace(0,360,201))    
            A=dict['params'][0]
            a=dict['params'][1]
            phi=dict['params'][2]
            f=1/360.
            corrected=corrected+fit_func(abs(a),abs(A),f,100,np.linspace(0,360,201))
            accum_seg_nr[i]=sum(seg_nr[0:i])
   
    plt.show()    
    plt.figure()
    plt.errorbar(segnr_phase,phase,dict['error_dict']['phi'],fmt='o')
    plt.xlabel('Segment number of photon click',fontsize=14)
    plt.ylabel('Phase second RF pulse',fontsize=14)
    plt.yticks([-90,-45,0,45,90])
    plt.xticks([0,25,50,75,100])
    #plt.ylim([-180,180])
    plt.show()
    
    plt.clf()
    plt.show()    
    plt.figure()
    plt.plot(np.linspace(0,360,201),reconstr_sum/float(reps))
    plt.plot(np.linspace(0,360,201),corrected/float(reps))
    plt.xlabel('Phase',fontsize=14)
    plt.ylabel('P(ms=0) reconstructed from separate fits',fontsize=14)
    plt.legend(['Total','Corrected for phase shift'],loc=4)
    #plt.yticks([0,45,90,135,180])
    #plt.xticks([0,10,20,30,40])
    #plt.ylim([0.2,0.5])
    plt.show()
    
    plt.figure()
    plt.plot(np.arange(total_segments-1)+1,seg_nr[0:total_segments-1]/float(sum(seg_nr)),'o')
    plt.xlabel('Segment number',fontsize=14)
    plt.ylabel('P(click)',fontsize=14)
    plt.show()
      
    plt.figure()
    plt.plot(np.arange(total_segments-1)+1,accum_seg_nr[0:total_segments-1]/float(sum(seg_nr)),'o')
    plt.xlabel('Segment number',fontsize=14)
    plt.ylabel('P(click) accummulated',fontsize=14)
    plt.show()
    
    print 'Contrast for total:'
    print (max(reconstr_sum/float(reps))-min(reconstr_sum/float(reps)))/0.5
    print 'Contrast for corrected:'
    print (max(corrected/float(reps))-min(corrected/float(reps)))/0.5
    print dict['error_dict']['phi']
    
    return SSRO_counts, cond_RO_data, seg_nr
Exemplo n.º 4
0
def segmented_N_ramsey(
    nr_of_datapoints=1,
    folder=r'D:\measuring\data\20130709\123046_Seg_RO__LT2_N_Ramsey_seg_RO_100us_750pW/'
):
    a = np.load(folder + 'Seg_RO-000_segment_number.npz')
    seg_nr = a['segment_number']
    a.close()

    a = np.load(folder + 'Seg_RO-000_segment_number.npz')
    seg_nr = a['segment_number']
    a.close()

    c = np.load(folder + 'Seg_RO-000_Spin_RO.npz')
    SSRO_counts = c['SSRO_counts']
    cond_RO_data = c['cond_RO_data']
    x = c['sweep_axis']
    c.close()

    nr_of_datapoints = len(SSRO_counts)
    reps = int(sum(seg_nr) / float(nr_of_datapoints))
    total_segments = len(seg_nr)
    #total_segments=45

    plt.figure()
    phase = []
    segnr_phase = []
    reconstr_sum = np.zeros(201)
    corrected = np.zeros(201)
    accum_seg_nr = np.zeros(len(seg_nr))
    for i in np.arange(total_segments):
        if i in [4, 5, 6, 7, 8]:
            do_plot = True
            print i
        else:
            do_plot = False
        y = cond_RO_data[nr_of_datapoints * i:nr_of_datapoints * (i + 1)]
        #FIX: This normalization is very rough, we should devide each point with the number of repetitions (get it from segmented_RO_data.npz)
        y_norm = y / float(max(y))

        dict = sc.fit_sin(x,
                          y,
                          sqrt(max(y)),
                          fixed=[0],
                          fix_param=[1 / 360.],
                          do_plot=do_plot)
        if dict:
            phase.append(dict['params'][2])
            segnr_phase.append(i)
            reconstr_sum = reconstr_sum + dict['fitfunc'](np.linspace(
                0, 360, 201))
            A = dict['params'][0]
            a = dict['params'][1]
            phi = dict['params'][2]
            f = 1 / 360.
            corrected = corrected + fit_func(abs(a), abs(A), f, 100,
                                             np.linspace(0, 360, 201))
            accum_seg_nr[i] = sum(seg_nr[0:i])

    plt.show()
    plt.figure()
    plt.errorbar(segnr_phase, phase, dict['error_dict']['phi'], fmt='o')
    plt.xlabel('Segment number of photon click', fontsize=14)
    plt.ylabel('Phase second RF pulse', fontsize=14)
    plt.yticks([-90, -45, 0, 45, 90])
    plt.xticks([0, 25, 50, 75, 100])
    #plt.ylim([-180,180])
    plt.show()

    plt.clf()
    plt.show()
    plt.figure()
    plt.plot(np.linspace(0, 360, 201), reconstr_sum / float(reps))
    plt.plot(np.linspace(0, 360, 201), corrected / float(reps))
    plt.xlabel('Phase', fontsize=14)
    plt.ylabel('P(ms=0) reconstructed from separate fits', fontsize=14)
    plt.legend(['Total', 'Corrected for phase shift'], loc=4)
    #plt.yticks([0,45,90,135,180])
    #plt.xticks([0,10,20,30,40])
    #plt.ylim([0.2,0.5])
    plt.show()

    plt.figure()
    plt.plot(
        np.arange(total_segments - 1) + 1,
        seg_nr[0:total_segments - 1] / float(sum(seg_nr)), 'o')
    plt.xlabel('Segment number', fontsize=14)
    plt.ylabel('P(click)', fontsize=14)
    plt.show()

    plt.figure()
    plt.plot(
        np.arange(total_segments - 1) + 1,
        accum_seg_nr[0:total_segments - 1] / float(sum(seg_nr)), 'o')
    plt.xlabel('Segment number', fontsize=14)
    plt.ylabel('P(click) accummulated', fontsize=14)
    plt.show()

    print 'Contrast for total:'
    print(max(reconstr_sum / float(reps)) -
          min(reconstr_sum / float(reps))) / 0.5
    print 'Contrast for corrected:'
    print(max(corrected / float(reps)) - min(corrected / float(reps))) / 0.5
    print dict['error_dict']['phi']

    return SSRO_counts, cond_RO_data, seg_nr
Exemplo n.º 5
0
    for i in np.arange(len(data['SN'])):
        z += data['FinalRO_FS'][i]
        zrep += data['FS'][i]
    print zrep
    znorm = z / (zrep + 0.)
    data.close()

phasecor, uphasecor = sc.get_nuclear_ROC(phasenorm, rep,
                                         sc.get_latest_data('SSRO', date=d))
zcor, uzcor = sc.get_nuclear_ROC(znorm, zrep,
                                 sc.get_latest_data('SSRO', date=zd))
figure1 = plt.figure(2)
ax = figure1.add_subplot(111)
ax.errorbar(x, phasenorm, fmt='o', yerr=1 / sqrt(rep), color='Crimson')
ax.errorbar(x, phasecor, fmt='o', yerr=uphasecor, color='RoyalBlue')
phase_fit = sc.fit_sin(x, phasecor, uphasecor)
xcor = np.abs(phase_fit['params'][1]) + np.abs(phase_fit['params'][2])
uxcor = np.sqrt(phase_fit['error_dict']['A']**2 +
                phase_fit['error_dict']['a']**2)

dm, f, uf, ideal = tls.calc_fidelity_psi(tau,
                                         1 - zcor,
                                         xcor,
                                         utau,
                                         uzcor,
                                         uxcor,
                                         th=th,
                                         dir=dir)
idr = tls.make_rho(ideal[0]**2, ideal[1] * ideal[0])
print idr
Exemplo n.º 6
0
def targetstate_analysis(foldernamez,
                         foldernamex,
                         filename='Spin_RO',
                         date='',
                         RO_time=''):
    zdata_norm, zdata_corr = sc.plot_feedback(foldernamez,
                                              filename='Spin_RO',
                                              d=date)
    print RO_time
    if ((RO_time == '2us') or (RO_time == '4us') or (RO_time == '6us')):
        xdata_norm, xdata_corr = sc.plot_feedback(foldernamex,
                                                  filename='Spin_RO',
                                                  d=date)
        SNfit = sc.fit_sin(xdata_norm['sweep_par'], xdata_corr['FinalRO_SN'],
                           xdata_corr['uFinalRO_SN'])
        FSfit = sc.fit_sin(xdata_norm['sweep_par'], xdata_corr['FinalRO_FS'],
                           xdata_corr['uFinalRO_FS'])
        allfit = sc.fit_sin(xdata_norm['sweep_par'], xdata_corr['FinalRO_All'],
                            xdata_corr['uFinalRO_All'])
        N = (xdata_norm['SN'][2] + xdata_norm['FS'][2])
        xsucces = (xdata_norm['SN'][2] *
                   (abs(SNfit['params'][1]) * 2) + xdata_norm['FS'][2] *
                   (abs(FSfit['params'][1]) * 2)) / N
        uxsucces = np.sqrt(
            ((xdata_norm['SN'][2] * abs(SNfit['error_dict']['a']) * 2) /
             N)**2 +
            ((xdata_norm['FS'][2] * abs(FSfit['error_dict']['a']) * 2) / N)**2)
        Sx = [
            abs(FSfit['params'][1]) * 2,
            abs(SNfit['params'][1]) * 2, xsucces
        ]
        uSx = [
            FSfit['error_dict']['a'] * 2, SNfit['error_dict']['a'] * 2,
            uxsucces, 0
        ]
        i = 2
        Sz = [
            zdata_corr['FinalRO_FS'][i], zdata_corr['FinalRO_SN'][i],
            zdata_corr['FinalRO_Succes'][i]
        ]
    else:
        Sx = [0, 0, 0]
        uSx = [0, 0, 0]
        i = 1
        Sz = [
            1 - zdata_corr['FinalRO_FS'][i], 1 - zdata_corr['FinalRO_SN'][i],
            1 - zdata_corr['FinalRO_Succes'][i]
        ]
    if (RO_time == '15us'):
        i = 2
        Sz = [
            zdata_corr['FinalRO_FS'][i], zdata_corr['FinalRO_SN'][i],
            zdata_corr['FinalRO_Succes'][i]
        ]

    Sy = [0, 0, 0, 0]
    fdata = {}
    fdata['zdata_norm'] = zdata_norm
    fdata['zdata_corr'] = zdata_corr
    fdata['res_FS'] = [2 * (1 - Sz[0]) - 1, Sx[0], Sy[0], 0]
    fdata['res_SN'] = [2 * (1 - Sz[1]) - 1, Sx[1], Sy[1], 0]
    fdata['res_Succes'] = [2 * (1 - Sz[2]) - 1, Sx[2], Sy[2], 0]
    fdata['ures_FS'] = [zdata_corr['uFinalRO_FS'][i] * 2, uSx[0], 0, 0]
    fdata['ures_SN'] = [zdata_corr['uFinalRO_SN'][i] * 2, uSx[1], 0, 0]
    fdata['ures_Succes'] = [zdata_corr['uFinalRO_Succes'][i] * 2, uSx[2], 0, 0]
    #fdata['SNfit']=SNfit
    #fdata['FSfit']=FSfit
    #fdata['allfit']=allfit
    meas_strength = calc_meas_strength(50, 12, 1400)
    fdata['meas_strength'] = meas_strength
    fdata['res_ideal'] = [
        np.sin(meas_strength * np.pi / 2.),
        np.cos(meas_strength * np.pi / 2.), 0, 0
    ]
    fdata['dm'], fdata['f'], fdata['uf'], fdata[
        'ideal'] = tls.calc_fidelity_psi(tau,
                                         (fdata['res_Succes'][0] + 1) / 2.,
                                         fdata['res_Succes'][1] / 2. + 0.5,
                                         utau,
                                         fdata['ures_Succes'][0] / 2.,
                                         fdata['ures_Succes'][1],
                                         th=th,
                                         dir=dir)
    tls.make_hist(fdata['dm'][0], np.array([[0, 0], [0, 0]]))

    #print 'Fidelity',f,'  +-',uf
    #print 'Ideal state:', ideal
    #print 'uz: ',uzcor,'  ux: ',uxcor
    np.savez(os.path.join(basepath, name + RO_time), **fdata)