Пример #1
0
def get_3mmt_data(folder,folder_timestamp,RO_correct=True,ssro_calib_timestamp=None,tomo_bases='XXX',get_title=False,return_orientations=False):
    a = CP.ConditionalParityAnalysis(folder)
    #a.get_sweep_pts()
    a.get_readout_results(name='adwindata', post_select_QEC = True,orientation_correct=True)
    orientations = a.orientations
    orientation_c = a.orientations[2]
    if orientation_c == 'negative':
        multiply_by = -1
    else:
        multiply_by = 1
    #print(a.orientations,multiply_by)

    if RO_correct == True:
        if ssro_calib_timestamp == None: 
            ssro_calib_folder = toolbox.latest_data('SSRO',older_than=folder_timestamp)
            analysis_file=os.path.join(ssro_calib_folder,'analysis.hdf5')
            if not os.path.exists(analysis_file):
                ssro.ssrocalib(ssro_calib_folder)
        else:
            ssro_dstmp, ssro_tstmp = toolbox.verify_timestamp(ssro_calib_timestamp)
            ssro_calib_folder = toolbox.datadir + '\\'+ssro_dstmp+'\\'+ssro_tstmp+'_AdwinSSRO_SSROCalibration_111_1_sil18'#GHZ_'+tomo_bases
        
        #print ssro_calib_folder
        a.get_electron_ROC(ssro_calib_folder = ssro_calib_folder, post_select_QEC = True)

        #take the [0,0] part of the arrays right now; no sweep_pts
        p0_00,u_p0_00 = multiply_by*(a.p0_00[0,0]-0.5)*2,(2*a.u_p0_00[0,0]) 
        p0_01,u_p0_01 = multiply_by*(a.p0_01[0,0]-0.5)*2,(2*a.u_p0_01[0,0])
        p0_10,u_p0_10 = multiply_by*(a.p0_10[0,0]-0.5)*2,(2*a.u_p0_10[0,0])
        p0_11,u_p0_11 = multiply_by*(a.p0_11[0,0]-0.5)*2,(2*a.u_p0_11[0,0])

    else:
        p0_00,u_p0_00 = multiply_by*(a.normalized_ssro_00[0,0]-0.5)*2,(2*a.u_normalized_ssro_00[0,0])
        p0_01,u_p0_01 = multiply_by*(a.normalized_ssro_01[0,0]-0.5)*2,(2*a.u_normalized_ssro_01[0,0])
        p0_10,u_p0_10 = multiply_by*(a.normalized_ssro_10[0,0]-0.5)*2,(2*a.u_normalized_ssro_10[0,0])
        p0_11,u_p0_11 = multiply_by*(a.normalized_ssro_11[0,0]-0.5)*2,(2*a.u_normalized_ssro_11[0,0])

    if get_title:
        a_list_name = "".join(aa for aa in a.a_list)
        b_list_name = "".join(aa for aa in a.b_list)
        c_list_name = "".join(aa for aa in a.c_list)
        title = a_list_name+' '+b_list_name+' '+c_list_name
    else:
        title=''

    p = (a.p00[0,0],a.p01[0,0],a.p10[0,0],a.p11[0,0])
    y = (p0_00,p0_01,p0_10,p0_11)
    y_avg = np.mean(y, axis=0)
    #print y_avg
    y_err = (u_p0_00,u_p0_01,u_p0_10,u_p0_11)

    if return_orientations:
        return(p,y,y_err,title,orientations)

    return(p,y,y_err,title)
Пример #2
0
def get_debug_data(folder,folder_timestamp,RO_correct=True,ssro_calib_timestamp=None,tomo_bases="XXX"):
    a = CP.ConditionalParityAnalysis(folder)
    #a.get_sweep_pts()
    a.get_readout_results(name='adwindata', post_select = True, orientation_correct=True)
    orientation_b = a.orientations[1]
    if orientation_b == 'negative':
        multiply_by = -1
    else:
        multiply_by = 1
    #print(a.orientations,multiply_by)

    if RO_correct == True:
        if ssro_calib_timestamp == None: 
            ssro_calib_folder = toolbox.latest_data('SSRO',older_than=folder_timestamp)
            if not os.path.exists(os.path.join(ssro_calib_folder,'analysis.hdf5')):
                ssro.ssrocalib(ssro_calib_folder)
        else:
            ssro_dstmp, ssro_tstmp = toolbox.verify_timestamp(ssro_calib_timestamp)
            ssro_calib_folder = toolbox.datadir + '\\'+ssro_dstmp+'\\'+ssro_tstmp+'_AdwinSSRO_SSROCalibration_111_1_sil18'#GHZ_'+tomo_bases

        # print ssro_calib_folder
        a.get_electron_ROC(ssro_calib_folder = ssro_calib_folder)

        #take the [0,0] part of the arrays right now; no sweep_pts
        p0_0,u_p0_0 = multiply_by*(a.p0_0[0,0]-0.5)*2,(2*a.u_p0_0[0,0]) 
        p0_1,u_p0_1 = multiply_by*(a.p0_1[0,0]-0.5)*2,(2*a.u_p0_1[0,0])

    else:
        p0_0,u_p0_0 = multiply_by*(a.normalized_ssro_0[0,0]-0.5)*2,(2*a.u_normalized_ssro_0[0,0])
        p0_1,u_p0_1 = multiply_by*(a.normalized_ssro_1[0,0]-0.5)*2,(2*a.u_normalized_ssro_1[0,0])
  
    p = (a.p0,a.p1)
    y = (p0_0,p0_1)
    y_avg = np.mean(y, axis=0)
    #print y_avg
    y_err = (u_p0_0,u_p0_1)

    return(p,y,y_err)
Пример #3
0
def append_data(timestamps_1=[None, None],
                timestamps_2=[],
                timestamps_3=[],
                ssro_folder=None,
                det=False,
                ms=None):

    y_total = ([])
    y_err_total = ([])
    x_total = ([])
    x_labels_total = ([])
    p0 = ([])
    p1 = ([])
    time_list = [timestamps_1]
    if timestamps_2 != []:
        time_list = [timestamps_1, timestamps_2]
    if timestamps_3 != []:
        time_list = [timestamps_1, timestamps_2, timestamps_3]

    for timestamps in time_list:
        folder_a = toolbox.data_from_time(timestamps[0])
        folder_b = toolbox.data_from_time(timestamps[1])

        if det == False:
            a = mbi.MBIAnalysis(folder_a)
        else:
            a = CP.ConditionalParityAnalysis(folder_a)

        a.get_sweep_pts()
        a.get_readout_results(name='adwindata')
        a.get_electron_ROC(ssro_folder)
        y_a = ((a.p0.reshape(-1)[:]) - 0.5) * 2
        y_err_a = 2 * a.u_p0.reshape(-1)[:]

        if det == False:
            b = mbi.MBIAnalysis(folder_b)
        else:
            b = CP.ConditionalParityAnalysis(folder_b)
        b.get_sweep_pts()
        b.get_readout_results(name='adwindata')
        b.get_electron_ROC(ssro_folder)

        y_b = ((b.p0.reshape(-1)[:]) - 0.5) * 2
        y_err_b = 2 * b.u_p0.reshape(-1)[:]

        x_labels = a.sweep_pts.reshape(-1)[:]
        # x = range(len(y_a))

        y = (y_a - y_b) / 2.
        y_err = 1. / 2 * (y_err_a**2 + y_err_b**2)**0.5

        if ms == 0:
            a = CP.ConditionalParityAnalysis(folder_a)

            a.get_sweep_pts()
            a.get_readout_results(name='adwindata', post_select=True)
            a.get_electron_ROC(ssro_folder)

            c0_0_p, u_c0_0_p = a.convert_fidelity_to_contrast(a.p0_0, a.u_p0_0)
            c0_1_p, u_c0_1_p = a.convert_fidelity_to_contrast(a.p0_1, a.u_p0_1)

            b = CP.ConditionalParityAnalysis(folder_b)
            b.get_sweep_pts()
            b.get_readout_results(name='adwindata', post_select=True)
            b.get_electron_ROC(ssro_folder)

            c0_0_n, u_c0_0_n = b.convert_fidelity_to_contrast(b.p0_0, b.u_p0_0)
            c0_1_n, u_c0_1_n = b.convert_fidelity_to_contrast(b.p0_1, b.u_p0_1)

            ## ms=0 data
            y = (c0_0_p - c0_0_n) / 2.
            y_err = 1. / 2 * (u_c0_0_p**2 + u_c0_0_n**2)**0.5

        if ms == 1:
            a = CP.ConditionalParityAnalysis(folder_a)

            a.get_sweep_pts()
            a.get_readout_results(name='adwindata', post_select=True)
            a.get_electron_ROC(ssro_folder)
            c0_0_p, u_c0_0_p = a.convert_fidelity_to_contrast(a.p0_0, a.u_p0_0)
            c0_1_p, u_c0_1_p = a.convert_fidelity_to_contrast(a.p0_1, a.u_p0_1)

            b = CP.ConditionalParityAnalysis(folder_b)
            b.get_sweep_pts()
            b.get_readout_results(name='adwindata', post_select=True)

            b.get_electron_ROC(ssro_folder)

            c0_0_n, u_c0_0_n = b.convert_fidelity_to_contrast(b.p0_0, b.u_p0_0)
            c0_1_n, u_c0_1_n = b.convert_fidelity_to_contrast(b.p0_1, b.u_p0_1)
            ## ms=1 data
            y = (c0_1_p - c0_1_n) / 2.
            y_err = 1. / 2 * (u_c0_1_p**2 + u_c0_1_n**2)**0.5

        y_total = np.append(y_total, y)

        if det == True and ms != None:
            print 'PROBABILITIES'
            print 1 / 2. * (a.p0 + b.p0)
            print 1 / 2. * (a.p1 + b.p1)
            p0 = np.append(p0, 1 / 2. * (a.p0 + b.p0))
            p1 = np.append(p1, 1 / 2. * (a.p1 + b.p1))

        y_err_total = np.append(y_err_total, y_err)
        # x_total = np.append(x_total,x)
        x_labels_total = np.append(x_labels_total, x_labels)
    if det == True and ms != None:
        print 'PROBABILITIES'
        print p0
        print p1
        print np.average(p0)
        print np.average(p1)
    # print 1/2.*(a.p0+b.p0)

    # if ms ==1:
    # 	sign = [1,1,1,-1,1,-1,-1,1,-1,-1,1,-1,-1,1,-1]
    # 	print len(sign)
    # 	print len(y_total)
    # 	y_total = [y_total[i]*sign[i] for i in range(len(y_total))]

    x_total = range(len(y_total))
    return x_total, x_labels_total, y_total, y_err_total
Пример #4
0
def get_data(folder,folder_timestamp,RO_correct=True,ssro_calib_timestamp=None,tomo_bases='XXX',get_title=False, return_orientations=False, **kw):
    evaluate_both = kw.pop('evaluate_both',False)

    a = CP.ConditionalParityAnalysis(folder)
    #a.get_sweep_pts()
    a.get_readout_results(name='adwindata', post_select_GHZ = True)

    if a.orientations[3] == 'negative':
        multiply_by = -1
    else:
        multiply_by = 1

    print a.orientations

    if RO_correct == True:
        if ssro_calib_timestamp == None: 
            ssro_calib_folder = toolbox.latest_data('SSRO',older_than=folder_timestamp)
            analysis_file=os.path.join(ssro_calib_folder,'analysis.hdf5')
            if not os.path.exists(analysis_file):
                ssro.ssrocalib(ssro_calib_folder)
        else:
            ssro_dstmp, ssro_tstmp = toolbox.verify_timestamp(ssro_calib_timestamp)
            ssro_calib_folder = toolbox.datadir + '\\'+ssro_dstmp+'\\'+ssro_tstmp+'_AdwinSSRO_SSROCalibration_111_1_sil18'#GHZ_'+tomo_bases
        
        #print ssro_calib_folder
        a.get_electron_ROC(ssro_calib_folder = ssro_calib_folder, post_select_GHZ = True)
        #take the [0,0] part of the arrays; there are no sweep_pts
        p0_000,u_p0_000 = multiply_by*(a.p0_000[0,0]-0.5)*2,(2*a.u_p0_000[0,0]) 
        p0_001,u_p0_001 = multiply_by*(a.p0_001[0,0]-0.5)*2,(2*a.u_p0_001[0,0])
        p0_010,u_p0_010 = multiply_by*(a.p0_010[0,0]-0.5)*2,(2*a.u_p0_010[0,0])
        p0_011,u_p0_011 = multiply_by*(a.p0_011[0,0]-0.5)*2,(2*a.u_p0_011[0,0])
        p0_100,u_p0_100 = multiply_by*(a.p0_100[0,0]-0.5)*2,(2*a.u_p0_100[0,0])
        p0_101,u_p0_101 = multiply_by*(a.p0_101[0,0]-0.5)*2,(2*a.u_p0_101[0,0])
        p0_110,u_p0_110 = multiply_by*(a.p0_110[0,0]-0.5)*2,(2*a.u_p0_110[0,0])
        p0_111,u_p0_111 = multiply_by*(a.p0_111[0,0]-0.5)*2,(2*a.u_p0_111[0,0])
        print "probablity with ROC", a.p0_000[0,0]
        print "exp  with ROC",p0_000, u_p0_000

    if evaluate_both:
    #else:
        p0_000,u_p0_000 = multiply_by*(a.normalized_ssro_000[0,0]-0.5)*2,(2*a.u_normalized_ssro_000[0,0])
        p0_001,u_p0_001 = multiply_by*(a.normalized_ssro_001[0,0]-0.5)*2,(2*a.u_normalized_ssro_001[0,0])
        p0_010,u_p0_010 = multiply_by*(a.normalized_ssro_010[0,0]-0.5)*2,(2*a.u_normalized_ssro_010[0,0])
        p0_011,u_p0_011 = multiply_by*(a.normalized_ssro_011[0,0]-0.5)*2,(2*a.u_normalized_ssro_011[0,0])
        p0_100,u_p0_100 = multiply_by*(a.normalized_ssro_100[0,0]-0.5)*2,(2*a.u_normalized_ssro_100[0,0])
        p0_101,u_p0_101 = multiply_by*(a.normalized_ssro_101[0,0]-0.5)*2,(2*a.u_normalized_ssro_101[0,0])
        p0_110,u_p0_110 = multiply_by*(a.normalized_ssro_110[0,0]-0.5)*2,(2*a.u_normalized_ssro_110[0,0])
        p0_111,u_p0_111 = multiply_by*(a.normalized_ssro_111[0,0]-0.5)*2,(2*a.u_normalized_ssro_111[0,0])
        print "prob without ROC", a.normalized_ssro_000[0,0]
        print "exp without ROC",p0_000, u_p0_000
        print "WARNING WARNING REMOVE THIS STATEMENT. REMOVE EVALUATE_BOTH OPTION"

    if get_title:
        a_list_name = "".join(aa for aa in a.a_list)
        b_list_name = "".join(aa for aa in a.b_list)
        c_list_name = "".join(aa for aa in a.c_list)
        d_list_name = "".join(aa for aa in a.d_list)
        title = a_list_name+' '+b_list_name+' '+c_list_name+' '+d_list_name
    else:
        title=''

    p = (a.p000[0,0],a.p001[0,0],a.p010[0,0],a.p011[0,0],a.p100[0,0],a.p101[0,0],a.p110[0,0],a.p111[0,0])
    y = (p0_000,p0_001,p0_010,p0_011,p0_100,p0_101,p0_110,p0_111)
    y_err = (u_p0_000,u_p0_001,u_p0_010,u_p0_011,u_p0_100,u_p0_101,u_p0_110,u_p0_111)

    if return_orientations:
        return(p,y,y_err,title,a.orientations)

    return(p,y,y_err,title)
def BarPlotTomo_QEC(timestamp=None,
                    measurement_name=['adwindata'],
                    folder_name='Tomo',
                    plot_post_select=False,
                    ssro_calib_timestamp=None,
                    save=True,
                    do_plots=False,
                    title=None,
                    fontsize=10,
                    post_select_QEC=False):
    '''
    Function that makes a bar plot with errorbars of MBI type data
    '''
    plt.rc('font', size=fontsize)
    if timestamp == None:
        timestamp, folder = toolbox.latest_data(folder_name,
                                                return_timestamp=True)
    else:
        folder = toolbox.data_from_time(timestamp)

    if ssro_calib_timestamp == None:
        ssro_calib_folder = toolbox.latest_data('SSRO')
    else:
        ssro_dstmp, ssro_tstmp = toolbox.verify_timestamp(ssro_calib_timestamp)
        ssro_calib_folder = toolbox.datadir + '/' + ssro_dstmp + '/' + ssro_tstmp + '_AdwinSSRO_SSROCalibration_Hans_sil1'

    a = CP.ConditionalParityAnalysis(folder)
    a.get_sweep_pts()
    a.get_readout_results(name='adwindata', post_select_QEC=False)
    a.get_electron_ROC(ssro_calib_folder)

    x_labels = a.sweep_pts.reshape(-1)
    ''' all data '''

    c0, u_c0 = a.convert_fidelity_to_contrast(a.p0, a.u_p0)
    x = range(len(c0))

    if do_plots == True:
        fig, ax = plt.subplots()
        ax.bar(x, c0, yerr=u_c0, align='center', ecolor='k')
        ax.set_xticks(x)
        if title == None:
            ax.set_title(str(folder) + '/' + str(timestamp))
        else:
            ax.set_title(title)
        print x_labels
        ax.set_xticklabels(x_labels.tolist())
        ax.set_ylim(-1, 1)
        ax.hlines([-1, 0, 1], x[0] - 1, x[-1] + 1, linestyles='dotted')

        try:
            fig.savefig(os.path.join(folder, 'tomo.png'))
            fig.savefig(os.path.join(folder, title + '.pdf'),
                        format='pdf',
                        bbox_inches='tight')
        except:
            print 'Figure A has not been saved.'
    ''' postselected data '''

    a = CP.ConditionalParityAnalysis(folder)
    a.get_sweep_pts()
    a.get_readout_results(name='adwindata', post_select_QEC=True)
    a.get_electron_ROC(ssro_calib_folder, post_select_QEC=True)

    c0_00, u_c0_00 = a.convert_fidelity_to_contrast(a.p0_00, a.u_p0_00)
    c0_01, u_c0_01 = a.convert_fidelity_to_contrast(a.p0_01, a.u_p0_01)
    c0_10, u_c0_10 = a.convert_fidelity_to_contrast(a.p0_10, a.u_p0_10)
    c0_11, u_c0_11 = a.convert_fidelity_to_contrast(a.p0_11, a.u_p0_11)

    x = range(len(c0_00))

    if do_plots == True and plot_post_select == True:
        fig_00, ax_00 = plt.subplots()
        rects = ax_00.bar(x, c0_00, yerr=u_c0_00, align='center', ecolor='k')
        # ax_00.bar(x,a.p0_00,yerr = u_c0_00,align = 'center',ecolor = 'k')
        ax_00.set_xticks(x)
        if title == None:
            ax_00.set_title(str(folder) + '/' + str(timestamp) + '0')
        else:
            ax_00.set_title(str(title) + '0')

        ax_00.set_xticklabels(x_labels.tolist())
        # ax_00.set_ylim(-1,1)
        ax_00.hlines([-1, 0, 1], x[0] - 1, x[-1] + 1, linestyles='dotted')

        # print values on bar plot
        def autolabel(rects):
            for ii, rect in enumerate(rects):
                height = rect.get_height()
                plt.text(rect.get_x() + rect.get_width() / 2.,
                         1.02 * height,
                         str(round(c0_00[ii], 2)) + '(' +
                         str(int(round(u_c0_00[ii] * 100))) + ')',
                         ha='center',
                         va='bottom')

        autolabel(rects)

        fig_01, ax_01 = plt.subplots()
        rects = ax_01.bar(x, c0_01, yerr=u_c0_01, align='center', ecolor='k')
        ax_01.set_xticks(x)
        if title == None:
            ax_01.set_title(str(folder) + '/' + str(timestamp) + '1')
        else:
            ax_01.set_title(str(title) + '1')
        ax_01.set_xticklabels(x_labels.tolist())
        # ax_01.set_ylim(-1,1)
        ax_01.hlines([-1, 0, 1], x[0] - 1, x[-1] + 1, linestyles='dotted')

        # print values on bar plot
        def autolabel(rects):
            for ii, rect in enumerate(rects):
                height = rect.get_height()
                plt.text(rect.get_x() + rect.get_width() / 2.,
                         1.02 * height,
                         str(round(c0_01[ii], 2)) + '(' +
                         str(int(round(u_c0_01[ii] * 100))) + ')',
                         ha='center',
                         va='bottom')

        autolabel(rects)

        fig_10, ax_10 = plt.subplots()
        rects = ax_10.bar(x, c0_10, yerr=u_c0_10, align='center', ecolor='k')
        # ax_10.bar(x,a.p0_10,yerr = u_c0_10,align = 'center',ecolor = 'k')
        ax_10.set_xticks(x)
        if title == None:
            ax_10.set_title(str(folder) + '/' + str(timestamp) + '0')
        else:
            ax_10.set_title(str(title) + '0')

        ax_10.set_xticklabels(x_labels.tolist())
        # ax_10.set_ylim(-1,1)
        ax_10.hlines([-1, 0, 1], x[0] - 1, x[-1] + 1, linestyles='dotted')

        # print values on bar plot
        def autolabel(rects):
            for ii, rect in enumerate(rects):
                height = rect.get_height()
                plt.text(rect.get_x() + rect.get_width() / 2.,
                         1.02 * height,
                         str(round(c0_10[ii], 2)) + '(' +
                         str(int(round(u_c0_10[ii] * 100))) + ')',
                         ha='center',
                         va='bottom')

        autolabel(rects)

        fig_11, ax_11 = plt.subplots()
        rects = ax_11.bar(x, c0_11, yerr=u_c0_11, align='center', ecolor='k')
        ax_11.set_xticks(x)
        if title == None:
            ax_11.set_title(str(folder) + '/' + str(timestamp) + '1')
        else:
            ax_11.set_title(str(title) + '1')
        ax_11.set_xticklabels(x_labels.tolist())
        # ax_11.set_ylim(-1,1)
        ax_11.hlines([-1, 0, 1], x[0] - 1, x[-1] + 1, linestyles='dotted')

        # print values on bar plot
        def autolabel(rects):
            for ii, rect in enumerate(rects):
                height = rect.get_height()
                plt.text(rect.get_x() + rect.get_width() / 2.,
                         1.02 * height,
                         str(round(c0_11[ii], 2)) + '(' +
                         str(int(round(u_c0_11[ii] * 100))) + ')',
                         ha='center',
                         va='bottom')

        autolabel(rects)

        try:
            fig_00.savefig(os.path.join(folder,
                                        str(title) + '0.pdf'),
                           format='pdf',
                           bbox_inches='tight')

            fig_01.savefig(os.path.join(folder,
                                        str(title) + '1.pdf'),
                           format='pdf',
                           bbox_inches='tight')
            fig_10.savefig(os.path.join(folder,
                                        str(title) + '0.pdf'),
                           format='pdf',
                           bbox_inches='tight')

            fig_11.savefig(os.path.join(folder,
                                        str(title) + '1.pdf'),
                           format='pdf',
                           bbox_inches='tight')
        except:
            print 'Figure B has not been saved.'

    return x, c0, u_c0, c0_00, u_c0_00, c0_01, u_c0_01, c0_10, u_c0_10, c0_11, u_c0_11, x_labels, folder