Beispiel #1
0
 def test_entropy(self):
     AA = np.array(
         [[
             0.68496971 - 7.94093388e-23j, 0.08253590 + 1.99931875e-03j,
             0.01708342 + 3.89802395e-05j, 0.07183789 - 1.73430033e-03j
         ],
          [
              0.08253590 - 1.99931875e-03j, 0.02126937 - 6.77626358e-21j,
              0.10761136 + 2.62667557e-03j, 0.01852958 + 8.20031300e-05j
          ],
          [
              0.01708342 - 3.89802395e-05j, 0.10761136 - 2.62667557e-03j,
              0.98542522 - 2.64697796e-23j, 0.09403497 + 2.28980269e-03j
          ],
          [
              0.07183789 + 1.73430033e-03j, 0.01852958 - 8.20031300e-05j,
              0.09403497 - 2.28980269e-03j, 0.01618254 - 6.77626358e-21j
          ]])
     result1, result2 = f.vonNeumann_entropy(AA)
     expected1 = 0.6126380194835308
     expected2 = np.array(
         [-2.32932085e-09, 4.55044753e-09, 6.97894284e-01, 1.00995255e+00])
     self.assertAlmostEqual(result1, expected1)
     self.assertTrue(np.allclose(result2, expected2))
def main_routine(arg, c):
    start_time = time.time()
    #Extract MPI paramteres
    mpi_size = c.Get_size()
    mpi_rank = c.Get_rank()
    #Define simulation paramteres
    L = arg.L
    J = 1.0
    mu0 = arg.mu0
    dJ = arg.delJ * J
    T = arg.T
    cyc = arg.cyc
    num_conf = arg.num_conf
    nT = 2 * cyc
    num_sub = 10  #number of subsystem
    list_sub = 10 * np.arange(1, num_sub + 1)
    save_data = True
    if nT < 40:
        num_CC_samples = cyc
    else:
        num_CC_samples = 20
    '''
		#########################################  Main Code  ##############################################
	'''
    #Initial correlation matrix
    HH_start = ham(J, dJ, L, np.zeros(L))
    CC_0 = alternate_occupy(L)
    #Initialize the storage matrices
    fname = "WDIR/Mar8/Data/SQ_ALT_ANDERSON_L_%d_dJ_%g_mu0_%g_T_%g_cyc_%d_ncnf_%g_" % (
        L, dJ, mu0, T, cyc, num_conf * mpi_size)
    #m_energy = np.zeros((num_conf,nT))
    #m_nbar = np.zeros((num_conf,nT))
    m_imb = np.zeros((num_conf, nT))
    #m_absb_energy = np.zeros((num_conf,nT))
    m_diag = np.zeros((num_conf, nT, L))
    #m_curr = np.zeros((num_conf,nT,L))
    #m_excit = np.zeros((num_conf,L))
    m_entropy = np.zeros((num_conf, nT, num_sub))
    #m_CC = np.zeros((num_conf,num_CC_samples,L,L),dtype=complex)
    #m_mu = np.zeros((num_conf,L))
    #tlist = []
    '''
		#########################################  Loop over configurations and time  ##############################################
	'''
    for k in range(num_conf):
        mu_array = np.random.uniform(-mu0, mu0, L)
        #m_mu[k,:] = mu_array.copy()
        #Define two Hamiltonians
        #Hamiltonian with (J+dJ)
        HH_h = ham(J, dJ, L, mu_array)
        v_eps_h, DD_h = np.linalg.eigh(HH_h)
        EE_h = np.diag(np.exp(-1j * 0.5 * T * v_eps_h))
        UU_h = np.dot(np.conj(DD_h), np.dot(EE_h, DD_h.T))
        #Hamiltonian with (J-dJ)
        HH_l = ham(J, -dJ, L, mu_array)
        v_eps_l, DD_l = np.linalg.eigh(HH_l)
        EE_l = np.diag(np.exp(-1j * 0.5 * T * v_eps_l))
        UU_l = np.dot(np.conj(DD_l), np.dot(EE_l, DD_l.T))
        #initialize correlation matrix to the ground state of HH_start
        CC_t = CC_0.copy()
        #j=0
        for i in range(nT):
            #if i in np.linspace(2,nT-1,num_CC_samples,endpoint=True):
            #	m_CC[k,j,:,:] = CC_t.copy()
            #	j = j+1
            #	tlist.append(i*T/2)
            #Calculate Hamiltonian
            #m_nbar[k,i] = np.trace(CC_t).real
            m_imb[k, i] = func.imbalance(np.diag(CC_t).real)
            m_diag[k, i, :] = np.diag(CC_t).real
            for ent_iter in range(num_sub):
                ent, eig_ent = func.vonNeumann_entropy(
                    CC_t[0:list_sub[ent_iter], 0:list_sub[ent_iter]])
                m_entropy[k, i, ent_iter] = ent
            if i % 2 == 0:
                #m_energy[k,i] = np.sum(np.multiply(HH_h,CC_t)).real
                # m_absb_energy[k,i] = (m_energy[k,i] - m_energy[k,0])
                #m_curr[k,i,:] = func.charge_current(J+dJ,0.,CC_t)
                CC_next = np.dot(np.conj(UU_h.T), np.dot(CC_t, UU_h))
            else:
                #m_energy[k,i] = np.sum(np.multiply(HH_l,CC_t)).real
                # m_absb_energy[k,i] = (m_energy[k,i] - m_energy[k,0])
                #m_curr[k,i,:] = func.charge_current(J-dJ,0.,CC_t)
                CC_next = np.dot(np.conj(UU_l.T), np.dot(CC_t, UU_l))
            CC_t = CC_next.copy()

        #m_absb_energy[k,:] = func.absorbed_energy(m_energy[k,:],HH_h)
        #m_excit[k,:] = func.energy_excitations(v_eps_h,DD_h,CC_t)
    '''
		############################	Gather the data to be saved 	##################################################
	'''
    #recv_energy = None
    #recv_nbar = None
    recv_imb = None
    #recv_absb_energy = None
    recv_diag = None
    #recv_curr = None
    #recv_excit = None
    recv_entropy = None
    #recv_CC = None
    #recv_mu = None
    if mpi_rank == 0:
        #recv_energy = np.empty([mpi_size,num_conf,nT])
        #recv_nbar = np.empty([mpi_size,num_conf,nT])
        recv_imb = np.empty([mpi_size, num_conf, nT])
        #recv_absb_energy = np.empty([mpi_size,num_conf,nT])
        recv_diag = np.empty([mpi_size, num_conf, nT, L])
        #recv_curr = np.empty([mpi_size,num_conf,nT,L])
        #recv_excit = np.empty([mpi_size,num_conf,L])
        recv_entropy = np.empty([mpi_size, num_conf, nT, num_sub])
        #recv_CC = np.empty([mpi_size,num_conf,num_CC_samples,L,L],dtype=complex)
        #recv_mu = np.empty([mpi_size,num_conf,L])
    #c.Gather(m_energy,recv_energy,root=0)
    #c.Gather(m_nbar,recv_nbar,root=0)
    c.Gather(m_imb, recv_imb, root=0)
    #c.Gather(m_absb_energy,recv_absb_energy,root=0)
    c.Gather(m_diag, recv_diag, root=0)
    #c.Gather(m_curr,recv_curr,root=0)
    #c.Gather(m_excit,recv_excit,root=0)
    c.Gather(m_entropy, recv_entropy, root=0)
    #c.Gather(m_CC,recv_CC,root=0)
    #c.Gather(m_mu,recv_mu,root=0)
    if mpi_rank == 0:
        recv_diag = np.mean(recv_diag, (0, 1))
        #recv_curr = np.mean(recv_curr,(0,1))
        if save_data == True:
            #np.save(fname+"tlist.npy",tlist)
            #np.save(fname+"energy.npy",recv_energy)
            #np.save(fname+"nbar.npy",recv_nbar)
            np.save(fname + "imb.npy", recv_imb)
            #np.save(fname+"absb.npy",recv_absb_energy)
            np.save(fname + "diag.npy", recv_diag)
            #np.save(fname+"curr.npy",recv_curr)
            #np.save(fname+"excit.npy",recv_excit)
            np.save(fname + "entropy.npy", recv_entropy)
            #np.save(fname+"CC.npy",recv_CC)
            #np.save(fname+"mu.npy",recv_mu)
            print("Data files saved at : %s" % fname)
    end_time = time.time()
    print('Time taken by rank %d : %g seconds' %
          (mpi_rank, end_time - start_time))
Beispiel #3
0
def main_routine(arg, c, start_time):
    #Extract MPI paramteres
    mpi_size = c.Get_size()
    mpi_rank = c.Get_rank()
    #Extract simulation parameters
    J = 1.0
    L = arg.L
    w = arg.w
    PERIOD = 2 * np.pi / w
    mu0_h = arg.mu0_h
    mu0_l = arg.mu0_l
    NUM_CONF = arg.NUM_CONF
    tf = arg.tf
    dt = arg.dt
    nT = int(tf / dt)
    if L < 20:
        l0 = 0
        l1 = L // 2
    else:
        l0 = L // 2 - 5
        l1 = L // 2 + 5
    sigma = 0.5 * (1. + np.sqrt(5.))
    save_data = True

    #Obtain alpha values for this thread
    alpha_min = mpi_rank * (2 * np.pi) / mpi_size
    alpha_max = (mpi_rank + 1) * (2 * np.pi) / mpi_size
    num_alpha = NUM_CONF // mpi_size
    m_alpha = np.linspace(alpha_min, alpha_max, num_alpha, endpoint=False)

    #initialize correlation matrix
    CC_0 = np.zeros((L, L), dtype=complex)
    for j in range(0, L, 2):
        CC_0[j, j] = 1.0

    #Initialize the storage matrices
    T = [dt * n for n in range(nT)]
    fname = "WDIR/L_%d/Nov26/Data/SQ_CHEM_L_%d_J_%g_w_%g_mu0H_%g_mu0L_%g_s_%g_conf_%d_tf_%g_dt_%g_" \
       %(L,L,J,w,mu0_h,mu0_l,sigma,NUM_CONF,tf,dt)

    m_S = np.zeros((num_alpha, nT))
    m_eigCC = np.zeros((num_alpha, nT, l1 - l0))
    m_energy = np.zeros((num_alpha, nT))
    m_nbar = np.zeros((num_alpha, nT))
    m_imbalance = np.zeros((num_alpha, nT))
    m_current = np.zeros((num_alpha, nT, L))
    m_nn_site = np.zeros((num_alpha, nT))
    m_subsystem = np.zeros((num_alpha, nT, l1 - l0, l1 - l0), dtype=complex)
    m_pulse = np.zeros((num_alpha, nT))
    pulse = 0
    #Loop over nT
    for k in range(num_alpha):

        alpha = m_alpha[k]
        '''
		High State
		'''
        HH_1 = func.ham_diagonal_sq_drive_PBC(L, J, mu0_h, sigma, alpha)
        v_eps_1, DD_1 = np.linalg.eigh(HH_1)
        EE_1 = np.diag(np.exp(-1j * dt * v_eps_1))
        UU_1 = np.dot(np.conj(DD_1), np.dot(EE_1, DD_1.T))
        '''
			Low State
		'''
        HH_2 = func.ham_diagonal_sq_drive_PBC(L, J, mu0_l, sigma, alpha)
        v_eps_2, DD_2 = np.linalg.eigh(HH_2)
        EE_2 = np.diag(np.exp(-1j * dt * v_eps_2))
        UU_2 = np.dot(np.conj(DD_2), np.dot(EE_2, DD_2.T))

        CC_t = CC_0.copy()

        for i in range(nT):
            if math.fmod(T[i], PERIOD) < 0.5 * PERIOD:  #High state
                HH = HH_1.copy()
                UU = UU_1.copy()
                pulse = 1
            else:  #Low state
                HH = HH_2.copy()
                UU = UU_2.copy()
                pulse = 0
            #Calculate Hamiltonian
            phi_hop = 0.0

            #Calculate entropy

            m_subsystem[k, i, :] = CC_t[l0:l1, l0:l1]
            entropy, spectrum = func.vonNeumann_entropy(CC_t[l0:l1, l0:l1])
            m_S[k, i] = entropy
            m_eigCC[k, i, :] = spectrum.copy()
            #Calculate energy
            m_energy[k, i] = np.sum(np.multiply(HH, CC_t)).real
            #Calculate occupation of subsystem
            diagonal = np.diag(CC_t).real
            m_nbar[k, i] = np.sum(diagonal[l0:l1]) / (l1 - l0)
            #Calculate imbalance in entire system
            n_e = np.sum(diagonal[range(0, L,
                                        2)])  #at position 0,2,4, ... ,L-1
            n_o = np.sum(diagonal[range(1, L, 2)])  #at position 1,3,5 ...
            m_imbalance[k, i] = (n_e - n_o) / (n_e + n_o)
            #Calculate current
            m_current[k, i, :] = func.charge_current(J, phi_hop, CC_t)
            #Calculate onsite occupation
            m_nn_site[k, i] = CC_t[L // 2, L // 2].real

            #Pulse
            m_pulse[k, i] = pulse

            #Time evolution of correlation matrix. Refer readme for formulae
            CC_next = np.dot(np.conj(UU.T), np.dot(CC_t, UU))
            CC_t = CC_next.copy()

        print('Done alpha = %g' % m_alpha[k])
    '''
		Declare recv_ variable to gather the data from all nodes. General shape of variales is 
	'''
    recv_S = None
    recv_eigCC = None
    recv_nbar = None
    recv_imbalance = None
    recv_current = None
    recv_energy = None
    recv_nn_site = None
    recv_alpha = None
    recv_subsystem = None
    recv_pulse = None
    if mpi_rank == 0:
        recv_S = np.empty([mpi_size, num_alpha, nT])
        recv_eigCC = np.empty([mpi_size, num_alpha, nT, l1 - l0])
        recv_nbar = np.empty([mpi_size, num_alpha, nT])
        recv_imbalance = np.empty([mpi_size, num_alpha, nT])
        recv_current = np.empty([mpi_size, num_alpha, nT, L])
        recv_energy = np.empty([mpi_size, num_alpha, nT])
        recv_nn_site = np.empty([mpi_size, num_alpha, nT])
        recv_alpha = np.empty([mpi_size, num_alpha])
        recv_subsystem = np.empty([mpi_size, num_alpha, nT, l1 - l0, l1 - l0],
                                  dtype=complex)
        recv_pulse = np.empty([mpi_size, num_alpha, nT])
    c.Gather(m_S, recv_S, root=0)
    c.Gather(m_eigCC, recv_eigCC, root=0)
    c.Gather(m_nbar, recv_nbar, root=0)
    c.Gather(m_imbalance, recv_imbalance, root=0)
    c.Gather(m_current, recv_current, root=0)
    c.Gather(m_energy, recv_energy, root=0)
    c.Gather(m_nn_site, recv_nn_site, root=0)
    c.Gather(m_alpha, recv_alpha, root=0)
    c.Gather(m_subsystem, recv_subsystem, root=0)
    c.Gather(m_pulse, recv_pulse, root=0)
    if mpi_rank == 0:
        #save data
        if save_data == True:
            np.save(fname + "entropy.npy", recv_S)
            np.save(fname + "CCspectrum.npy", recv_eigCC)
            np.save(fname + "nbar.npy", recv_nbar)
            np.save(fname + "imbalance.npy", recv_imbalance)
            np.save(fname + "current.npy", recv_current)
            np.save(fname + "energy.npy", recv_energy)
            np.save(fname + "nn_site.npy", recv_nn_site)
            np.save(fname + "conf.npy", recv_alpha)
            np.save(fname + "subsystem.npy", recv_subsystem)
            np.save(fname + "pulse.npy", recv_pulse)
            print('Data files saved successfully.')
        end_time = time.time()
        print("Total Simulation time = ", end_time - start_time, " seconds")