def getfid(P , limit = np.Infinity):
    

    delta = 0.15
    g = 0.0038
    t_cr = P[0]
    omega_cr = P[1]
    wf_cr = P[2]
    D_cr = P[3]
    xita0 = P[4]
    xita1 = P[5]

    frequency = np.array([5.2 , 5.2-delta])*2*np.pi
    coupling = np.array([g])*2*np.pi
    eta_q=  np.array([-0.250 , -0.250]) * 2 * np.pi
    parameter = [frequency,coupling,eta_q]
    QBE = Qubits(qubits_parameter = parameter)

    args = {'T_P':70+2*t_cr,'T_copies':1001 , 'wf_x':QBE.frequency[0] , 'eta_q':QBE.eta_q , 
            't_cr': t_cr , 'wf_cr':wf_cr , 'omega_cr':omega_cr , 'D_cr':D_cr}

    H1 = [QBE.sm[0] + QBE.sm[0].dag() , CR_drive_1]
    H2 = [QBE.sm[0] + QBE.sm[0].dag() , X_drive_1]
    H3 = [QBE.sm[0] + QBE.sm[0].dag() , CR_drive_2]
    H4 = [QBE.sm[0] + QBE.sm[0].dag() , X_drive_2]
    Hdrive = [H1,H2,H3,H4]



    final = QBE.evolution(drive = Hdrive , psi = tensor(basis(3,0),basis(3,0)) ,  track_plot = True ,argument = args)
    fid = fidelity(final, tensor(basis(3,0),(basis(3,0)+1j*np.exp(-1j*xita1)*basis(3,1)).unit()))
    print(fid)
def getfid(P, parallel=True, limit=np.Infinity):
    T = P[0]
    xita0 = P[1]
    xita1 = P[2]

    frequency = np.array([4.8, 5.358]) * 2 * np.pi
    coupling = np.array([0.012]) * 2 * np.pi
    eta_q = np.array([-0.250, -0.250]) * 2 * np.pi
    N_level = 3
    parameter = [frequency, coupling, eta_q, N_level]
    QBE = Qubits(qubits_parameter=parameter)

    args = {'T_P': T, 'T_copies': 1001, 'delta': 0.0 * 2 * np.pi}

    H1 = [QBE.sm[1].dag() * QBE.sm[1], Z_pulse]
    Hdrive = [H1]

    final = QBE.evolution(drive=Hdrive,
                          psi=tensor(basis(3, 0),
                                     (basis(3, 0) + basis(3, 1)).unit()),
                          RWF='CpRWF',
                          track_plot=True,
                          argument=args)

    # final = QBE.process(drive = Hdrive,process_plot = False , parallel = parallel , argument = args)
    # final = QBE.phase_comp(final , [xita0 , xita1])
    # targetprocess = np.array([[1,0,0,0],[0,0,-1j,0],[0,-1j,0,0],[0,0,0,1]])
    # Ufidelity = np.abs(np.trace(np.dot(np.conjugate(np.transpose(targetprocess)),final)))/(2**QBE.num_qubits)
    # print(P,Ufidelity)

    return (final)
def CNOT(P):

    delta0 = P[0]
    delta1 = P[1]
    xita0 = P[2]
    xita1 = P[3]
    compen0_1 = P[4]
    compen0_2 = P[5]
    compen1_1 = P[6]
    compen1_2 = P[7]

    N_level = 3
    coupling = np.array([0.0138]) * 2 * np.pi
    frequency = np.array([4.3, 5.18]) * 2 * np.pi
    eta_q = np.array([-0.230, -0.216]) * 2 * np.pi
    parameter = [frequency, coupling, eta_q, N_level]
    QBE = Qubits(qubits_parameter=parameter)

    Hd0 = [QBE.sm[0].dag() * QBE.sm[0], CZ0]
    Hd1 = [QBE.sm[1].dag() * QBE.sm[1], CZ1]
    Hdrive = [Hd0, Hd1]

    args = {
        'T_P': 45,
        'T_copies': 1001,
        'delta0': delta0,
        'delta1': delta1,
        'xita0': xita0,
        'xita1': xita1,
        'compen0_1': compen0_1,
        'compen0_2': compen0_2,
        'compen1_1': compen1_1,
        'compen1_2': compen1_2
    }

    final = QBE.process(drive=Hdrive,
                        process_plot=False,
                        parallel=True,
                        argument=args)
    final = QBE.phase_comp(final, [xita0, xita1])
    targetprocess = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0],
                              [0, 0, 0, -1]])
    Ufidelity = np.abs(
        np.trace(np.dot(np.conjugate(np.transpose(targetprocess)),
                        final))) / (2**QBE.num_qubits)
    # print(P , Ufidelity)
    np.savetxt(
        'evolution _3.txt',
        final,
        fmt='%.8f',
        delimiter=',',
        newline='a',
    )
    return (final)
def getfid(P, parallel=False, limit=np.Infinity):

    delta = 0.15  # 频率
    g = 0.0007  #频率
    D_cr = -0.5
    t_cr = P[0]
    omega_cr = P[1] * 2 * np.pi
    wf_cr = P[2] * 2 * np.pi

    frequency = np.array([5.2, 5.2 - delta]) * 2 * np.pi
    coupling = np.array([g]) * 2 * np.pi
    eta_q = np.array([-0.250, -0.250]) * 2 * np.pi
    parameter = [frequency, coupling, eta_q]
    QBE = Qubits(qubits_parameter=parameter)

    args = {
        'T_P': 70 + 2 * t_cr,
        'T_copies': 1001,
        'wf_x': QBE.frequency[0],
        'eta_q': QBE.eta_q,
        't_cr': t_cr,
        'wf_cr': wf_cr,
        'omega_cr': omega_cr,
        'D_cr': D_cr
    }

    H1 = [QBE.sm[0] + QBE.sm[0].dag(), CR_drive_1]
    H2 = [QBE.sm[0] + QBE.sm[0].dag(), X_drive_1]
    H3 = [QBE.sm[0] + QBE.sm[0].dag(), CR_drive_2]
    H4 = [QBE.sm[0] + QBE.sm[0].dag(), X_drive_2]
    Hdrive = [H1, H2, H3, H4]

    # final = QBE.evolution(drive = Hdrive , psi = tensor(basis(3,0),basis(3,0)) ,  track_plot = True ,argument = args)
    # fid = fidelity(final, tensor(basis(3,0),basis(3,0)))
    # print(fid)

    final = QBE.process(drive=Hdrive,
                        process_plot=False,
                        parallel=parallel,
                        argument=args)
    xita0 = -np.angle(final[2][2])
    xita1 = -np.angle(final[1][1])
    final = QBE.phase_comp(final, [xita0, xita1])
    targetprocess = 1 / np.sqrt(2) * np.array([[1, 1j, 0, 0], [1j, 1, 0, 0],
                                               [0, 0, 1, -1j], [0, 0, -1j, 1]])

    Ufidelity = np.abs(
        np.trace(np.dot(np.conjugate(np.transpose(targetprocess)),
                        final))) / (2**QBE.num_qubits)
    fid = Ufidelity * np.exp(-(70 + 2 * t_cr) / 20000.0)
    # print(P , Ufidelity)

    return (1 - fid)
def getfid(P, g=0.001, parallel=False, limit=np.Infinity):

    delta = 0.15  # 频率
    g = g  #频率
    D_cr = -0.5
    t_cr = P[0]
    omega_cr = P[1] * 2 * np.pi
    wf_cr = P[2] * 2 * np.pi

    xita0 = P[3]
    xita1 = P[4]

    frequency = np.array([5.2, 5.2 - delta]) * 2 * np.pi
    coupling = np.array([g]) * 2 * np.pi
    eta_q = np.array([-0.250, -0.250]) * 2 * np.pi
    parameter = [frequency, coupling, eta_q]
    QBE = Qubits(qubits_parameter=parameter)

    args = {
        'T_P': 70 + 2 * t_cr,
        'T_copies': 1001,
        'wf_x': QBE.frequency[0],
        'eta_q': QBE.eta_q,
        't_cr': t_cr,
        'wf_cr': wf_cr,
        'omega_cr': omega_cr,
        'D_cr': D_cr
    }

    H1 = [QBE.sm[0] + QBE.sm[0].dag(), CR_drive_1]
    H2 = [QBE.sm[0] + QBE.sm[0].dag(), X_drive_1]
    H3 = [QBE.sm[0] + QBE.sm[0].dag(), CR_drive_2]
    H4 = [QBE.sm[0] + QBE.sm[0].dag(), X_drive_2]
    Hdrive = [H1, H2, H3, H4]

    final = QBE.process(drive=Hdrive,
                        process_plot=False,
                        parallel=parallel,
                        argument=args)
    final = QBE.phase_comp(final, [xita0, xita1])
    targetprocess = 1 / np.sqrt(2) * np.array([[1, 1j, 0, 0], [1j, 1, 0, 0],
                                               [0, 0, 1, -1j], [0, 0, -1j, 1]])

    Ufidelity = np.abs(
        np.trace(np.dot(np.conjugate(np.transpose(targetprocess)),
                        final))) / (2**QBE.num_qubits)

    return (Ufidelity)
Exemple #6
0
def get_max_entropy(Num_qubits):
    '''
    获得某个比特数目下的最大的renyi entropy及对应的态
    '''
    frequency = np.ones(Num_qubits) * 5.0 * 2 * np.pi
    coupling = np.ones(Num_qubits - 1) * 0.0125 * 2 * np.pi
    eta_q = np.ones(Num_qubits) * (-0.250) * 2 * np.pi
    N_level = 3
    parameter = [frequency, coupling, eta_q, N_level]
    QBC = Qubits(qubits_parameter=parameter)

    all_ini_state = generate_all_state(Num_qubits)
    t_total = 150

    subsystem = generate_subsys(Num_qubits)

    ##
    p = Pool()
    result = []
    for i in range(len(all_ini_state)):
        result.append(
            p.apply_async(EntropyEvolution, (
                QBC,
                all_ini_state[i],
                t_total,
                subsystem,
                False,
            )))
    max_list = np.abs(np.array([result[i].get() for i in range(len(result))]))
    p.close()
    p.join()
    ##
    loc = np.argmax(max_list)

    return (all_ini_state[loc], max_list[loc])
def spectrum(delta_list, psi, T_P, T_copies):
    '''
    以delta_list为横坐标,以tlist为纵坐标,比特0的P1为Z坐标,画出二维图
    '''
    frequency = np.array([4.8, 5.358]) * 2 * np.pi
    coupling = np.array([0.012]) * 2 * np.pi
    eta_q = np.array([-0.250, -0.250]) * 2 * np.pi
    N_level = 3
    parameter = [frequency, coupling, eta_q, N_level]
    QBE = Qubits(qubits_parameter=parameter)

    delta_list_lenght = len(delta_list)

    p = Pool()
    result_final = []
    for ii in range(delta_list_lenght):
        result_final.append(
            p.apply_async(spec_evolution,
                          (QBE, psi, delta_list[ii], T_P, T_copies)))
    evo_spec = np.array(
        [result_final[i].get() for i in range(len(result_final))])

    evo_spec = evo_spec.transpose()
    print('evolution end')
    tlist = np.linspace(0, T_P, T_copies)
    xx, yy = np.meshgrid((frequency + delta_list) / 2 / np.pi, tlist)
    plt.figure()
    plt.pcolor(xx, yy, evo_spec)
    plt.colorbar()
    plt.show()

    return (evo_spec)
Exemple #8
0
def get_all_evolution(Num_qubits):
    '''
    获得某个比特数目下所有比特初态编码的演化
    '''
    frequency = np.ones(Num_qubits) * 5.0 * 2 * np.pi
    coupling = np.ones(Num_qubits - 1) * 0.0125 * 2 * np.pi
    eta_q = np.ones(Num_qubits) * (-0.250) * 2 * np.pi
    N_level = 3
    parameter = [frequency, coupling, eta_q, N_level]
    QBC = Qubits(qubits_parameter=parameter)

    all_ini_state = generate_all_state(Num_qubits)
    t_total = 150
    plot_list = np.arange(0, t_total, 10)  #需要画出来的时间节点

    subsystem = generate_subsys(Num_qubits)

    ##
    p = Pool()
    result = []
    for i in range(len(all_ini_state)):
        result.append(
            p.apply_async(EntropyEvolution, (
                QBC,
                all_ini_state[i],
                t_total,
                subsystem,
                False,
            )))
    evo_list = np.abs(
        np.array([result[i].get()[0] for i in range(len(result))]))
    tlist = result[0].get()[1]
    p.close()
    p.join()
    ##
    evo_list = evo_list.transpose()
    for T_node in plot_list:
        node_list = evo_list[np.where(np.abs(tlist - T_node) <= 0.0001)][0]
        # plot and save
        fig, axes = plt.subplots(1, 1)
        axes.plot(np.arange(len(all_ini_state)), node_list, label='entropy')
        axes.set_xlabel('code of state')
        axes.set_ylabel('entropy of system')
        handles, labels = plt.gca().get_legend_handles_labels()
        plt.legend(handles, labels)
        maxloc = np.argmax(node_list)
        plt.title(
            str(T_node) + ',state=' + str(all_ini_state[maxloc]) +
            ',max entropy=' + str(node_list[maxloc])[0:6])
        if not os.path.exists('./one dimension_' + str(Num_qubits)):
            os.mkdir('./one dimension_' + str(Num_qubits))
        plt.savefig('./one dimension_' + str(Num_qubits) + '/t=' + str(T_node))

    # plt.figure()
    # # plt.pcolor(np.r_[np.arange(len(all_ini_state)),3], np.r_[tlist,3],evo_list)
    # plt.pcolor(np.r_[np.arange(len(all_ini_state)),len(all_ini_state)], tlist,evo_list)
    # plt.colorbar()
    # plt.show()
    return ([evo_list, all_ini_state])
def getfid_cross(omega_cross, wf_cross, limit = np.Infinity):
    Ec = 0.240 * 2 * np.pi
    Ej = 20 * 2 * np.pi
    phi_s = np.pi*0.00

    el = EL_qubit(Ej,Ec,phi_s)

    frequency = np.array([el[1]-el[0]])
    coupling = np.array([])*2*np.pi
    eta_q=  np.array([(el[2]-el[1])-(el[1]-el[0])]) 
    N_level= 3
    parameter = [frequency,coupling,eta_q,N_level]
    QB = Qubits(qubits_parameter = parameter)

    phi = (2*Ec/Ej/np.cos(phi_s))**(1/4)*(QB.sm[0].dag()+QB.sm[0])
    nn = 1j*(Ej*np.cos(phi_s)/2/Ec)**(1/4)*(QB.sm[0].dag()-QB.sm[0])/2
    cos_phi = -phi**2/2+phi**4/24
    sin_phi = phi-phi**3/6
    
    ## 单比特驱动参数 驱动强度4.53561162e-06 驱动频率3.73621365e+01 
    ## 电感驱动
    Mx = 0.1*10**(-12)
    Mz = 1.7*10**(-12)    
    driveX = partial(phix_drive,Mx = Mx)
    H1 = [Ej*np.cos(phi_s)*sin_phi,driveX] 
    crossX = partial(phix_cross,Mx = Mx)
    H2 = [Ej*np.cos(phi_s)*sin_phi,crossX] 
    Hdrive = [H1,H2]

    X = np.array([[0,1],[1,0]])
    Y = np.array([[0,-1j],[1j,0]])
    phi_x = 0
    gate =  expm(-1j*np.pi/4*(np.cos(phi_x)*X+np.sin(phi_x)*Y))

    omegaI = 4.53561162e-06
    wf = 3.73621365e+01 

    # omega_cross = P[0]
    # wf_cross = P[1]

    args = {'T_P':25,'T_copies':51 , 'omegaI':omegaI ,'phiI':0,'wf': wf,'omega_cross':omega_cross,'phi_cross':0,'wf_cross':wf_cross,'eta_q':eta_q}
    process = QB.process(drive = Hdrive, process_plot  = False , RWF = 'UnCpRWF' , RWA_freq = 0.0 ,parallel = False ,argument = args)
    Ufidelity = np.abs(np.trace(np.dot(np.conjugate(np.transpose(gate)),process)))/(2**QB.num_qubits)
    return(Ufidelity)
Exemple #10
0
def getfid(P , parallel = False , limit = np.Infinity):
    


    D_cr = -0.5
    t_cr = P[0]
    omega_cr = P[1] * 2 * np.pi
    wf_cr = P[2] * 2 * np.pi
   
    xita0 = P[3]
    xita1 = P[4]

    frequency = np.array([5.26 , 5.11])*2*np.pi
    coupling = np.array([0.0035])*2*np.pi
    eta_q=  np.array([-0.250 , -0.250]) * 2 * np.pi
    parameter = [frequency,coupling,eta_q]
    QBE = Qubits(qubits_parameter = parameter)

    args = {'T_P':70+2*t_cr,'T_copies':1001 , 'wf_x':QBE.E_eig[QBE.first_excited[0]] , 'eta_q':QBE.eta_q , 
            't_cr': t_cr , 'wf_cr':wf_cr , 'omega_cr':omega_cr , 'D_cr':D_cr}

    H1 = [QBE.sm[0] + QBE.sm[0].dag() , CR_drive_1]
    H2 = [QBE.sm[0] + QBE.sm[0].dag() , X_drive_1]
    H3 = [QBE.sm[0] + QBE.sm[0].dag() , CR_drive_2]
    H4 = [QBE.sm[0] + QBE.sm[0].dag() , X_drive_2]
    Hdrive = [H1,H2,H3,H4]

    # final = QBE.evolution(drive = Hdrive , psi = tensor(basis(3,0),basis(3,0)) ,  track_plot = True ,argument = args)
    # print(fidelity(final , tensor(basis(3,0),(basis(3,0)+1j*basis(3,1)).unit())))


    final = QBE.process(drive = Hdrive,process_plot = False , parallel = parallel , argument = args)
    final = QBE.phase_comp(final , [xita0 , xita1])
    targetprocess = 1/np.sqrt(2)*np.array([[1,1j,0,0],[1j,1,0,0],[0,0,1,-1j],[0,0,-1j,1]])

    Ufidelity = np.abs(np.trace(np.dot(np.conjugate(np.transpose(targetprocess)),final)))/(2**QBE.num_qubits)
    # print(P , Ufidelity)

    return(1-Ufidelity)
def getfid(P , parallel = False , limit = np.Infinity):
    

    delta = P[0] # 频率
    g = P[1] #频率
    
    t_cr = P[2]
    omega_cr = P[3] * 2 * np.pi
    wf_cr = P[4] * 2 * np.pi
   

    D_cr = -0.5

    frequency = np.array([5.2 , 5.2-delta])*2*np.pi
    coupling = np.array([g])*2*np.pi
    eta_q=  np.array([-0.250 , -0.250]) * 2 * np.pi
    parameter = [frequency,coupling,eta_q]
    QBE = Qubits(qubits_parameter = parameter)

    ZZ = QBE.E_eig[QBE._findstate('11')]-QBE.E_eig[QBE._findstate('01')]-QBE.E_eig[QBE._findstate('10')]+QBE.E_eig[QBE._findstate('00')]

    args = {'T_P':70+2*t_cr,'T_copies':1001 , 'wf_x':QBE.frequency[0] , 'eta_q':QBE.eta_q , 
            't_cr': t_cr , 'wf_cr':wf_cr , 'omega_cr':omega_cr , 'D_cr':D_cr}

    H1 = [QBE.sm[0] + QBE.sm[0].dag() , CR_drive_1]
    H2 = [QBE.sm[0] + QBE.sm[0].dag() , X_drive_1]
    H3 = [QBE.sm[0] + QBE.sm[0].dag() , CR_drive_2]
    H4 = [QBE.sm[0] + QBE.sm[0].dag() , X_drive_2]
    Hdrive = [H1,H2,H3,H4]



    final = QBE.process(drive = Hdrive,process_plot = False , parallel = parallel , argument = args)
    xita0 = -np.angle(final[2][2])
    xita1 = -np.angle(final[1][1])
    final = QBE.phase_comp(final , [xita0 , xita1])
    targetprocess = 1/np.sqrt(2)*np.array([[1,1j,0,0],[1j,1,0,0],[0,0,1,-1j],[0,0,-1j,1]])

    Ufidelity = np.abs(np.trace(np.dot(np.conjugate(np.transpose(targetprocess)),final)))/(2**QBE.num_qubits)

    Ufidelity = Ufidelity*np.exp(-(70+2*t_cr)/20000.0)
    N_gate = 1/ZZ/(2*t_cr+70)
    estimate = 0
    for index , II in enumerate(np.linspace(0.75,0.99,20)):
        estimate += (Ufidelity>II)*N_gate*0.02 if index !=0 else (Ufidelity>0.8)*N_gate*0.1
    for j in range(10):
        estimate += (Ufidelity>(0.99+j/2000.0))*N_gate*(0.06) if j !=0 else (Ufidelity>(0.99))*N_gate*(1)
    for jj in range(10):
        estimate += (Ufidelity>(0.995+j/2000.0))*N_gate*(0.15) if j !=0 else (Ufidelity>(0.99))*N_gate*(1)


    return(-estimate)
Exemple #12
0
        frequency_working[ii] = frequency_working[ii] + random.uniform(
            -disorder, disorder)
    return (frequency_working)


if __name__ == '__main__':
    Num_qubits = 12
    frequency = np.array([
        3.9750, 4.50500, 4.07000, 4.54800, 4.03000, 4.66400, 3.96400, 4.46000,
        4.00400, 4.50000, 4.06000, 4.57000
    ]) * 2 * np.pi
    coupling = np.ones(Num_qubits - 1) * 0.0115 * 2 * np.pi
    eta_q = np.ones(Num_qubits) * (-0.25) * 2 * np.pi
    N_level = 2
    parameter = [frequency, coupling, eta_q, N_level]
    QBC = Qubits(qubits_parameter=parameter)

    # frequency_working = np.array([4.43650 ,	4.42855 ,	4.41570 ,	4.41570 ,	4.42855 ,	4.43650 ,	4.42855 ,	4.41570 ,	4.41570 ,	4.42855 ])* 2*np.pi
    # # frequency_working = np.array([4.43650 ,	4.42855 ,	4.41570 ,	4.41570 ,	4.42855 ,	4.43082 ,	4.40897 ,	4.45854 ,	4.41848 ,	4.39802 ])* 2*np.pi
    # frequency_working = np.array([4.43650 ,	4.42855 ,	4.41570 ,	4.41570 ,	4.42855 ,	4.42504 ,	4.40879 ,	4.50660 ,	4.33894 ,	4.37505 ])* 2*np.pi

    N = 3
    h0 = N * coupling[0]
    frequency_working = (4.335) * 2 * np.pi + h0 * np.cos(
        2 * np.pi * (12 - np.arange(12)) / 6)
    frequency_working = np.array([
        4.3695, 4.35225, 4.31775, 4.30050, 4.31775, 4.35225, 4.3695, 4.3235,
        4.32695, 4.27300, 4.35400, 4.3010
    ]) * 2 * np.pi
    # frequency_working = np.array([4.3695 ,	4.35225 ,	4.31775 ,	4.30050 ,	4.31775 ,	4.35225 ,	4.37025 ,	4.21300 ,	4.40900 ,	4.27100 ,	4.21400 ,	4.2810 ])* 2*np.pi
    # frequency_working = frequency_working_setup(frequency_working,5*coupling[0])
Exemple #13
0
    if t > 0 and t <= tp:
        w = amp * np.sin(np.pi * t / tp)
    else:
        w = 0
    return (w)


if __name__ == '__main__':

    Num_qubits = 3
    frequency = np.array([5.27, 6.74, 4.62]) * 2 * np.pi
    coupling = np.array([0.122, 0.105]) * 2 * np.pi
    eta_q = np.array([-0.210, -0.37, -0.24]) * 2 * np.pi
    N_level = 3
    parameter = [frequency, coupling, eta_q, N_level]
    QBE = Qubits(qubits_parameter=parameter)
    couple_qq = 0.012 * 2 * np.pi
    QBE.H0 = QBE.H0 + couple_qq * (QBE.sm[0].dag() +
                                   QBE.sm[0]) * (QBE.sm[2].dag() + QBE.sm[2])

    Hd0 = [QBE.sm[1].dag() * QBE.sm[1], CZ]
    Hdrive = [Hd0]

    amp = -1.5 * 2 * np.pi
    psi = tensor((basis(3, 1)).unit(), (basis(3, 0)).unit(),
                 (basis(3, 0) + basis(3, 1)).unit())
    args = {'T_P': 30, 'T_copies': 101, 'amp': amp}

    final = QBE.evolution(drive=Hdrive,
                          psi=psi,
                          RWF='CpRWF',
Exemple #14
0
if __name__ == '__main__':

    fid_list = []
    t_list = []
    omega_list = []
    N_list = []
    estimate_list = []
    ZZ_list = []

    glist = np.array([0.0005 , 0.0008 , 0.001 , 0.0015 , 0.002 , 0.0025 , 0.003 , 0.004 , 0.008 , 0.01 , ])
    for index , g in enumerate(glist):
        frequency = np.array([5.2 , 5.05])*2*np.pi
        coupling = np.array([g])*2*np.pi
        eta_q=  np.array([-0.250 , -0.250]) * 2 * np.pi
        parameter = [frequency,coupling,eta_q]
        QB = Qubits(qubits_parameter = parameter)

        ZZ = QB.E_eig[QB._findstate('11')]-QB.E_eig[QB._findstate('01')]-QB.E_eig[QB._findstate('10')]+QB.E_eig[QB._findstate('00')]
        # swarmops
        func = partial(getfid , QB = QB , parallel = False , limit = np.Infinity)

        lower_bound = [20 , 0.02 , (5.2-0.152) ]
        upper_bound = [150 , 0.40 , (5.2-0.148) ]
        lower_init=[20 , 0.1 , (5.2-0.152) ]
        upper_init=[90 , 0.2 , (5.2-0.148) ]

        problem = Problem(name="CNOT_OPT_"+str(index), dim=3, fitness_min=0.0,
                                        lower_bound=lower_bound, 
                                        upper_bound=upper_bound,
                                        lower_init=lower_init, 
                                        upper_init=upper_init,
Exemple #15
0
def getfid(P, parallel=False, limit=np.Infinity):
    '''
    three qubits
    '''

    delta0 = 0.150  # 频率
    delta2 = 0.080
    g = 0.0038  #频率
    D_cr = -0.5
    t_cr = P[0]
    omega_cr = P[1] * 2 * np.pi
    wf_cr = P[2] * 2 * np.pi

    xita0 = P[3]
    xita1 = P[4]
    xita2 = P[5]

    frequency = np.array([5.2 - delta0, 5.2, 5.2 - delta2]) * 2 * np.pi
    coupling = np.array([g, g]) * 2 * np.pi
    eta_q = np.array([-0.250, -0.250, -0.250]) * 2 * np.pi
    parameter = [frequency, coupling, eta_q]
    QBE = Qubits(qubits_parameter=parameter)

    args = {
        'T_P': 70 + 2 * t_cr,
        'T_copies': 1001,
        'wf_x': QBE.frequency[1],
        'eta_q': QBE.eta_q,
        't_cr': t_cr,
        'wf_cr': wf_cr,
        'omega_cr': omega_cr,
        'D_cr': D_cr
    }

    H1 = [QBE.sm[1] + QBE.sm[1].dag(), CR_drive_1]
    H2 = [QBE.sm[1] + QBE.sm[1].dag(), X_drive_1]
    H3 = [QBE.sm[1] + QBE.sm[1].dag(), CR_drive_2]
    H4 = [QBE.sm[1] + QBE.sm[1].dag(), X_drive_2]
    Hdrive = [H1, H2, H3, H4]

    # final = QBE.evolution(drive = Hdrive , psi = tensor(basis(3,0),basis(3,0) , (basis(3,0)+1j*basis(3,1)).unit()) ,  track_plot = True ,argument = args)
    # fid = fidelity(final, tensor((basis(3,0)+1j*basis(3,1)).unit(),basis(3,0),  (basis(3,0)+1j*basis(3,1)).unit()))
    # print(fid)

    final = QBE.process(drive=Hdrive,
                        process_plot=False,
                        parallel=parallel,
                        argument=args)
    final = QBE.phase_comp(final, [xita0, xita1, xita2])

    # targetprocess = 1/np.sqrt(2)*np.array([[1,1j,0,0],[1j,1,0,0],[0,0,1,-1j],[0,0,-1j,1]])
    # targetprocess = (tensor( qeye(2) , Qobj(targetprocess))).full()

    targetprocess = 1 / np.sqrt(2) * np.array([[1, 0, 1j, 0], [0, 1, 0, -1j],
                                               [1j, 0, 1, 0], [0, -1j, 0, 1]])
    targetprocess = (tensor(Qobj(targetprocess), qeye(2))).full()

    Ufidelity = np.abs(
        np.trace(np.dot(np.conjugate(np.transpose(targetprocess)),
                        final))) / (2**QBE.num_qubits)
    fid = Ufidelity * np.exp(-(70 + 2 * t_cr) / 20000.0)
    # print(P , Ufidelity)

    return (1 - fid)
Exemple #16
0
from scipy.optimize import *
import numpy as np
from functools import partial
from Qubits import Qubits
from multiprocessing import Pool
import copy
from qutip import *
import matplotlib.pyplot as plt

if __name__ == '__main__':

    frequency = np.array([5.1, 6.558]) * 2 * np.pi
    coupling = np.array([0.040]) * 2 * np.pi
    eta_q = np.array([-0.250, 0]) * 2 * np.pi
    N_level = [3, 40]
    parameter = [frequency, coupling, eta_q, N_level]
    QBE = Qubits(qubits_parameter=parameter)
def getfid(P, limit=np.Infinity):
    Ec = 0.240 * 2 * np.pi
    Ej = 20 * 2 * np.pi
    phi_s = np.pi * 0.05
    ## 互感
    ## 3.07432332e-07 3.73621922e+01 0.0
    Mx = 0.1 * 10**(-12)
    Mz = 1.7 * 10**(-12)
    ##
    el = EL_qubit(Ej, Ec, phi_s)

    frequency = np.array([el[1] - el[0]])
    coupling = np.array([]) * 2 * np.pi
    eta_q = np.array([(el[2] - el[1]) - (el[1] - el[0])])
    N_level = 3
    parameter = [frequency, coupling, eta_q, N_level]
    QB = Qubits(qubits_parameter=parameter)

    phi = (2 * Ec / Ej / np.cos(phi_s))**(1 / 4) * (QB.sm[0].dag() + QB.sm[0])
    nn = 1j * (Ej * np.cos(phi_s) / 2 / Ec)**(1 / 4) * (QB.sm[0].dag() -
                                                        QB.sm[0]) / 2
    cos_phi = -phi**2 / 2 + phi**4 / 24
    sin_phi = phi - phi**3 / 6

    ## 电感驱动
    driveX = partial(phix_drive, Mx=Mx)
    driveZ = partial(phiz_drive, Mz=Mz)
    driveXX = partial(phix_drive_2, Mx=Mx)
    driveZZ = partial(phiz_drive_2, Mz=Mz)
    driveXZ = partial(phiz_x_drive, Mx=Mx, Mz=Mz)
    H1 = [Ej * np.cos(phi_s) * sin_phi, driveX]
    H2 = [Ej * np.sin(phi_s) * cos_phi, driveZ]
    H3 = [Ej * np.cos(phi_s) / 2 * cos_phi, driveXX]
    H4 = [Ej * np.cos(phi_s) / 2 * cos_phi, driveZZ]
    H5 = [-Ej * np.sin(phi_s) * sin_phi, driveXZ]
    Hdrive = [H1, H2, H3, H4, H5]
    ## 电容驱动
    # Cc = 30e-18;
    # C = 80e-15;
    # e = 1.60217662*10**(-19);
    # Z0 = 50;
    # hbar=1.054560652926899*10**(-34);
    # H1 = [2*Cc*Z0/(C+Cc)*e/hbar*nn/10**9,I_drive_real]
    # Hdrive = [H1]
    ##

    X = np.array([[0, 1], [1, 0]])
    Y = np.array([[0, -1j], [1j, 0]])
    phi_x = 0
    gate = expm(-1j * np.pi / 4 * (np.cos(phi_x) * X + np.sin(phi_x) * Y))

    args = {
        'T_P': 20,
        'T_copies': 101,
        'omegaI': P[0],
        'phiI': 0,
        'wf': P[1],
        'eta_q': eta_q
    }
    # final = QB.evolution(drive = Hdrive , psi = basis(2,0),  RWF = 'UnCpRWF' , RWA_freq = 0,track_plot = True ,argument = args);
    process = QB.process(drive=Hdrive,
                         process_plot=False,
                         RWF='UnCpRWF',
                         RWA_freq=0.0,
                         parallel=False,
                         argument=args)
    Ufidelity = np.abs(
        np.trace(np.dot(np.conjugate(np.transpose(gate)),
                        process))) / (2**QB.num_qubits)
    # print(process)
    print(P)
    print(Ufidelity)

    return (1 - Ufidelity)
    Ec = 0.240 * 2 * np.pi
    Ej = 20 * 2 * np.pi
    phi_s = np.pi * 0.25

    Mx = 0.1 * 10**(-12)
    Mz = 1.7 * 10**(-12)
    ##
    el = EL_qubit(Ej, Ec, phi_s)

    frequency = np.array([el[1] - el[0]])
    coupling = np.array([]) * 2 * np.pi
    eta_q = np.array([(el[2] - el[1]) - (el[1] - el[0])])
    N_level = 3
    parameter = [frequency, coupling, eta_q, N_level]
    QB = Qubits(qubits_parameter=parameter)

    phi = (2 * Ec / Ej / np.cos(phi_s))**(1 / 4) * (QB.sm[0].dag() + QB.sm[0])
    nn = 1j * (Ej * np.cos(phi_s) / 2 / Ec)**(1 / 4) * (QB.sm[0].dag() -
                                                        QB.sm[0]) / 2
    cos_phi = -phi**2 / 2 + phi**4 / 24
    sin_phi = phi - phi**3 / 6

    ##
    driveX = partial(phix_drive, Mx=Mx)
    driveZ = partial(phiz_drive, Mz=Mz)
    driveXX = partial(phix_drive_2, Mx=Mx)
    driveZZ = partial(phiz_drive_2, Mz=Mz)
    driveXZ = partial(phiz_x_drive, Mx=Mx, Mz=Mz)
    H1 = [Ej * np.cos(phi_s) * sin_phi, driveX]
    H2 = [Ej * np.sin(phi_s) * cos_phi, driveZ]
def getfid(P , parallel = True , limit = np.Infinity):
    

    D_cr = -0.5
    t_cr = P[0]
    omega_cr = P[1] * 2 * np.pi
    wf_cr = P[2] * 2 * np.pi
   
    xita = [P[3],P[4]]
    

    frequency = np.array([5.26 , 5.6478 , 5.11])*2*np.pi
    coupling = np.array([0.0395 , 0.04 ])*2*np.pi
    eta_q=  np.array([-0.250 , 0 , -0.250]) * 2 * np.pi
    parameter = [frequency,coupling,eta_q]
    QBE = Qubits(qubits_parameter = parameter)

    args = {'T_P':70+2*t_cr,'T_copies':1001 , 'wf_x':QBE.E_eig[QBE.first_excited[0]] , 'eta_q':QBE.eta_q , 
            't_cr': t_cr , 'wf_cr':wf_cr , 'omega_cr':omega_cr , 'D_cr':D_cr}

    H1 = [QBE.sm[0] + QBE.sm[0].dag() , CR_drive_1]
    H2 = [QBE.sm[0] + QBE.sm[0].dag() , X_drive_1]
    H3 = [QBE.sm[0] + QBE.sm[0].dag() , CR_drive_2]
    H4 = [QBE.sm[0] + QBE.sm[0].dag() , X_drive_2]
    Hdrive = [H1,H2,H3,H4]

    Psi = []
    Psi.append(tensor(basis(3,0),basis(3,0),basis(3,0)))
    Psi.append(tensor(basis(3,0),basis(3,0),basis(3,1)))
    Psi.append(tensor(basis(3,1),basis(3,0),basis(3,0)))
    Psi.append(tensor(basis(3,1),basis(3,0),basis(3,1)))
    
    # final = QBE.evolution(drive = Hdrive , psi = tensor(basis(3,0),basis(3,0),basis(3,0)) ,  track_plot = True ,argument = args)
    # print(fidelity(final , tensor(basis(3,0),basis(3,0),basis(3,0))))

    final_state = [] #基矢演化得到的末态
    if parallel:
        p = Pool()
        result_final = []
        for i in range(len(Psi)):
            result_final.append(p.apply_async(QBE.evolution , (Hdrive , Psi[i] , [] , False , args)))
        final_state = [result_final[i].get() for i in range(len(result_final))]
        p.close()
        p.join()
    else:
        for Phi in Psi:
            final_state.append(QBE.evolution(Hdrive , Phi , [] , False , argument= args))

    l000 = QBE._findstate('000');l001 = QBE._findstate('001');l100 = QBE._findstate('100');l101 = QBE._findstate('101');
    process = np.column_stack([final_state[i].data.toarray() for i in range(len(final_state))])[(l000,l001,l100,l101),:] #只取演化矩阵中二能级部分
    angle = np.angle(process[0][0])
    process = process*np.exp(-1j*angle)#消除global phase
    for index in range(2**2):
        II = index
        for JJ in range(2):
            number = np.int(np.mod(II,2))
            if number == 1:
                process[:,index] = process[:,index]*np.exp(1j*xita[-1-JJ])
            II = np.int(np.floor(II/2))

    targetprocess = 1/np.sqrt(2)*np.array([[1,-1j,0,0],[-1j,1,0,0],[0,0,1,1j],[0,0,1j,1]]) # 由于比特间的等效耦合强度为负数

    Ufidelity = np.abs(np.trace(np.dot(np.conjugate(np.transpose(targetprocess)),process)))/(2**2)


    return(1-Ufidelity)
def opt_Xgate(ratio, QB):
    P = [0.23724056, 34.55760448, -0.43552389]
    func = partial(getfid_Xgate, ratio=ratio, QB=QB)
    result = minimize(func, P, method="Nelder-Mead", options={'disp': True})

    return ([result.x, 1 - result.fun])


if __name__ == '__main__':
    frequency = np.array([5.5]) * 2 * np.pi
    coupling = np.array([]) * 2 * np.pi
    eta_q = np.array([-0.250]) * 2 * np.pi
    N_level = 3
    parameter = [frequency, coupling, eta_q, N_level]
    QBC = Qubits(qubits_parameter=parameter)

    H0 = QBC.H0
    X_bias = 0.8 * 2 * np.pi
    H0 = H0 + X_bias * (QBC.sm[0] + QBC.sm[0].dag())
    QBC.H0 = H0
    [QBC.E_eig, QBC.State_eig] = QBC.H0.eigenstates()
    QBC.first_excited = QBC._FirstExcite()

    print(opt_Xgate(0, QBC))
    # P = [0.03*2*np.pi*4,QBC.frequency[0],-0.5]
    # func = partial(getfid_Xgate , ratio = 0,QB=QBC )

    # NM算法  [  0.23724056,  34.55760448,  -0.43552389]
    # result = minimize(func, P, method="Nelder-Mead",options={'disp': True})
    # print(result.x)
Exemple #21
0
    readoutfreq = args['readoutfreq']
    # intensity = args['intensity']
    # w = 0.1*2*np.pi*np.cos(readoutfreq*(t))
    w = 0.02*2*np.pi*np.cos(readoutfreq*t)
    return(w)


if __name__ == '__main__':

    Num_qubits = 4
    frequency = np.array([5.1 , 5.1 , 5.1 , 5.1])*2*np.pi
    coupling = np.array([0.012,0.012,0.012])*2*np.pi
    eta_q=  np.array([-0.250 , -0.25, -0.25, -0.25]) * 2 * np.pi
    N_level= 2
    parameter = [frequency,coupling,eta_q,N_level]
    QBE = Qubits(qubits_parameter = parameter)
    # QBE.H0 = QBE.H0 + coupling[0]*(QBE.sm[0]+QBE.sm[0].dag())*(QBE.sm[3]+QBE.sm[3].dag()) 
    print(QBE.H0)
    
    args = {'T_P':100,'T_copies':101 , 'readoutfreq':frequency[0]}
    # H1 = [QBE.sm[0].dag()+QBE.sm[0],readoutwave]
    # Hdrive = [H1]

    final = QBE.evolution(drive = None , psi = tensor((basis(2,1)).unit(),(basis(2,0)).unit(),(basis(2,0)).unit(),(basis(2,0)).unit()) ,  RWF = 'UnCpRWF' , RWA_freq = 0,track_plot = True ,argument = args)


    # Num_qubits = 1
    # frequency = np.array([5.0])*2*np.pi
    # coupling = np.array([])*2*np.pi
    # eta_q=  np.array([-0.250]) * 2 * np.pi
    # N_level= 3
Exemple #22
0
    if np.cos(readoutfreq * (t - t_start)) == 0:
        w = readoutwave(t, args)
    else:
        w = readoutwave(t, args) / np.cos(readoutfreq * (t - t_start))
    return (w)


if __name__ == '__main__':

    frequency = np.array([5.0, 6.5]) * 2 * np.pi
    coupling = np.array([0.05]) * 2 * np.pi
    # coupling = np.array([0.0 , 0.000])*2*np.pi
    eta_q = np.array([-0.250, 0]) * 2 * np.pi
    N_level = [2, 200]
    parameter = [frequency, coupling, eta_q, N_level]
    QBE = Qubits(qubits_parameter=parameter)

    t_total = 6000
    T_copies = 5 * int(t_total) + 1
    t_start = 0
    t_end = t_total
    readoutfreq = QBE.E_eig[QBE.first_excited[1]]
    print(readoutfreq / 2 / np.pi)
    intensity = 0.050 * 2 * np.pi
    Kr = 0.3 * 2 * np.pi

    args = {
        'T_P': t_total,
        'T_copies': T_copies,
        't_start': t_start,
        't_end': t_end,
Exemple #23
0
def EigStateAdiabatic(level, t_rise, t_total, freq_target, traceplot=False):
    '''
    '''
    qubit_row = 2
    qubit_column = 2
    frequency = np.array([5.28, 5.43, 5.11, 5.26], ) * 2 * np.pi
    coupling = np.ones(len(frequency) - 1) * 0.0030 * 2 * np.pi
    eta_q = np.ones(len(frequency)) * (-0.250) * 2 * np.pi
    N_level = 2
    parameter = [frequency, coupling, eta_q, N_level]
    QBC_2 = Qubits(qubits_parameter=parameter)
    state = find_initial(QBC_2, level)

    N_level = 3
    parameter = [frequency, coupling, eta_q, N_level]
    QBC_3 = Qubits(qubits_parameter=parameter)
    initial_state = InitialState(QBC_3.num_qubits, [i for i in state],
                                 QBC_3.N_level)
    state_loc = QBC_3._findstate(state)
    # initial_state = QBC_3.State_eig[level]

    print(state, fidelity(initial_state, QBC_3.State_eig[state_loc]))

    args = {'T_P': t_total, 'T_copies': int(t_total / 5) + 1, 't_rise': t_rise}
    Z_pulse = Z_pulse_generator(QBC_3, freq_target)
    # print(Z_pulse[0][0])
    H1 = []
    for ii in range(QBC_3.num_qubits):
        H1.append([QBC_3.sm[ii].dag() * QBC_3.sm[ii], Z_pulse[ii]])

    finalstate = QBC_3.evolution(drive=H1,
                                 psi=initial_state,
                                 track_plot=False,
                                 RWF='UnCpRWF',
                                 argument=args)

    tlist = QBC_3.tlist
    subsystem = generate_subsys(QBC_3.num_qubits)
    entropylist = np.zeros([len(subsystem), len(tlist)], dtype=complex)

    if traceplot:
        GHZ_entrpy_state = get_GHZ_entrpy(QBC_3.num_qubits)
        GHZ_entrpy_list = np.zeros(len(subsystem), dtype=complex)
        max_entrpy_list = np.zeros(len(subsystem), dtype=complex)

    if type(subsystem) == np.ndarray:
        subsystem = subsystem.tolist()
    for ii, subsys in enumerate(subsystem):
        if traceplot:
            max_entrpy_list[ii] = len(subsys)
            GHZ_entrpy_list[ii] = np.abs(
                dmToentropy(ptrace(GHZ_entrpy_state, subsys), 2))
        for jj in range(len(tlist)):
            sub_desitymatrix = ptrace(QBC_3.result.states[jj], subsys)
            entropylist[ii, jj] = np.abs(dmToentropy(sub_desitymatrix, 2))
    global_entropy = np.sum(entropylist, 0)

    fid1 = fidelity(finalstate, QBC_3.State_eig[state_loc])
    fid2 = fidelity(finalstate, initial_state)

    if traceplot:
        max_entrpy = np.ones_like(global_entropy) * np.sum(max_entrpy_list)
        GHZ_entrpy = np.ones_like(global_entropy) * np.sum(GHZ_entrpy_list)
        # fig,axes = plt.subplots(len(subsystem)+1,1)
        # for ii in range(len(subsystem)):
        #     axes[ii].plot(tlist,entropylist[ii])
        #     axes[ii].set_xlabel('t(ns)');axes[ii].set_ylabel('entropy of Q'+str(subsystem[ii]))
        # axes[len(subsystem)].plot(tlist,whole_entropy)
        # axes[len(subsystem)].set_xlabel('t(ns)');axes[len(subsystem)].set_ylabel('entropy of system')
        # plt.show()

        plt.rcParams['figure.figsize'] = (6.0, 4.0)  # 设置figure_size尺寸
        fig, axes = plt.subplots(1, 1)
        axes.plot(tlist, global_entropy, label='entropy')
        axes.plot(tlist, max_entrpy, label='max entropy', linestyle='--')
        axes.plot(tlist, GHZ_entrpy, label='GHZ entropy', linestyle='--')
        axes.set_xlabel('t(ns)')
        axes.set_ylabel('entropy of system')
        handles, labels = plt.gca().get_legend_handles_labels()
        plt.legend(handles, labels)
        maxloc = np.argmax(global_entropy)
        plt.tight_layout()
        plt.title(
            str(N_level) + 'level=' + str(level) + ',t_rise=' + str(t_rise) +
            ',t_total=' + str(t_total) + ',entropy=' +
            str(global_entropy[maxloc])[1:6] + ',time=' +
            str(QBC_3.tlist[maxloc])[0:6])
        plt.savefig('./adiabatic/' + str(N_level) + 'level_t_rise=' +
                    str(t_rise) + ',t_total=' + str(t_total) + ',level=' +
                    str(level))

        plt.show()
    print('evolution end')
    print([fid1, fid2])
    # return([global_entropy,tlist,[fid1,fid2]])
    return (fid1)
Exemple #24
0
    if t < 20 or t > tp - 20:
        w = 0
    else:
        w = omega * (1 - np.cos(2 * np.pi / 20 * (t - 20))) * np.cos(
            wf * t) + D * (2 * np.pi / 20) * np.sin(
                2 * np.pi / 20 *
                (t - 20)) / (eta_q[0]) * np.cos(t * wf - np.pi / 2)
    return (w)


if __name__ == '__main__':
    frequency = np.array([5.6]) * 2 * np.pi
    coupling = np.array([]) * 2 * np.pi
    eta_q = np.array([-0.250]) * 2 * np.pi
    parameter = [frequency, coupling, eta_q]
    QB = Qubits(qubits_parameter=parameter)

    omega = 0.025078 * 2 * np.pi
    wf = 5.6 * 2 * np.pi
    D = -0.07805211

    args = {
        'T_P': 60,
        'T_copies': 101,
        'omega': omega,
        'D': D,
        'wf': wf,
        'eta_q': QB.eta_q
    }
    Hdrive = [[QB.sm[0] + QB.sm[0].dag(), X_drive]]