def spacing_error(coef): Hp_total = deepcopy(Hp[0]) for n in range(1, len(Hp)): Hp_total = H_operations.add(Hp_total, Hp[n], np.array([1, coef[n - 1]])) Hm = Hp_total.herm_conj() Hz = 1 / 2 * com(Hp_total.sector.matrix(k), Hm.sector.matrix(k)) e, u = np.linalg.eigh(Hz) psi = u[:, 0] from Calculations import gen_fsa_basis, gram_schmidt fsa_dim = int(pxp.N) fsa_basis = gen_fsa_basis(Hp_total.sector.matrix(k), psi, fsa_dim) gs = gram_schmidt(fsa_basis) gs.ortho() fsa_basis = gs.ortho_basis exp_vals = np.zeros(np.size(fsa_basis, axis=1)) for n in range(0, np.size(exp_vals, axis=0)): exp_vals[n] = np.real(exp(Hz, fsa_basis[:, n])) exp_diff = np.zeros(np.size(exp_vals) - 1) for n in range(0, np.size(exp_diff, axis=0)): exp_diff[n] = exp_vals[n + 1] - exp_vals[n] M = np.zeros((np.size(exp_diff), np.size(exp_diff))) for n in range(0, np.size(M, axis=0)): for m in range(0, np.size(M, axis=1)): M[n, m] = np.abs(exp_diff[n] - exp_diff[m]) error = np.power(np.trace(np.dot(M, np.conj(np.transpose(M)))), 0.5) return error
def subspace_variance(coef): Hp_total = deepcopy(Hp[0]) for n in range(1, len(Hp)): Hp_total = H_operations.add(Hp_total, Hp[n], np.array([1, coef[n - 1]])) Hm = Hp_total.herm_conj() H = H_operations.add(Hp_total, Hm, np.array([1, 1])) H.sector.find_eig(k) Hz = 1 / 2 * com(Hp_total.sector.matrix(k), Hm.sector.matrix(k)) e, u = np.linalg.eigh(Hz) psi = u[:, 0] from Calculations import gen_fsa_basis, gram_schmidt fsa_dim = int(pxp.N) fsa_basis = gen_fsa_basis(Hp_total.sector.matrix(k), psi, fsa_dim) gs = gram_schmidt(fsa_basis) gs.ortho() fsa_basis = gs.ortho_basis H2 = np.dot(H.sector.matrix(k), H.sector.matrix(k)) H2_fsa = np.dot(np.conj(np.transpose(fsa_basis)), np.dot(H2, fsa_basis)) H_fsa = np.dot(np.conj(np.transpose(fsa_basis)), np.dot(H.sector.matrix(k), fsa_basis)) subspace_variance = np.real(np.trace(H2_fsa - np.dot(H_fsa, H_fsa))) return subspace_variance
def var_error(coef, pxp_config, pxxxp_config): Hp = gen_Hp(pxp_config, pxxxp_config, coef) Hm = np.conj(np.transpose(Hp)) H = Hp + Hm Hz = 1 / 2 * com(Hp, Hm) z = zm_state(2, 1, pxp, 1) fsa_basis = gen_fsa_basis(Hp, z.prod_basis(), pxp.N) gs = gram_schmidt(fsa_basis) gs.ortho() fsa_basis = gs.ortho_basis Hz_var = np.zeros(np.size(fsa_basis, axis=1)) for n in range(0, np.size(Hz_var, axis=0)): Hz_var[n] = var(Hz, fsa_basis[:, n]) # error = np.max(Hz_var) error = np.sum(Hz_var) print(coef, error) return error
def gen_krylov_basis(H, dim, init_state, system, orth=False): krylov_basis = init_state.prod_basis() current_state = krylov_basis for n in range(0, dim): next_state = np.dot(H, current_state) next_state = next_state / np.power(np.vdot(next_state, next_state), 0.5) krylov_basis = np.vstack((krylov_basis, next_state)) current_state = next_state krylov_basis = np.transpose(krylov_basis) if orth is False: return krylov_basis else: if orth == "qr": krylov_basis, temp = np.linalg.qr(krylov_basis) else: gs = gram_schmidt(krylov_basis) gs.ortho() krylov_basis = gs.ortho_basis return krylov_basis
def max_variance(coef): Hp_total = deepcopy(Hp[0]) for n in range(1,len(Hp)): Hp_total = H_operations.add(Hp_total,Hp[n],np.array([1,coef[n-1]])) Hm = Hp_total.herm_conj() Hz = 1/2 * com(Hp_total.sector.matrix(),Hm.sector.matrix()) e,u = np.linalg.eigh(Hz) psi = u[:,0] from Calculations import gen_fsa_basis,gram_schmidt fsa_dim = int(pxp.N) fsa_basis = gen_fsa_basis(Hp_total.sector.matrix(),psi,fsa_dim) gs = gram_schmidt(fsa_basis) gs.ortho() fsa_basis = gs.ortho_basis var_vals = np.zeros(np.size(fsa_basis,axis=1)) for n in range(0,np.size(var_vals,axis=0)): var_vals[n] = np.real(var(Hz,fsa_basis[:,n])) error = np.max(var_vals) return error
def spacing_error(coef, pxp_config, pxxxp_config): Hp = gen_Hp(pxp_config, pxp_config, coef) Hm = np.conj(np.transpose(Hp)) Hz = 1 / 2 * com(Hp, Hm) #find lowest weight state e, u = np.linalg.eigh(Hz) lowest_weight = u[:, 0] z = zm_state(2, 1, pxp, 1) fsa_basis = gen_fsa_basis(Hp, z.prod_basis(), pxp.N) gs = gram_schmidt(fsa_basis) gs.ortho() fsa_basis = gs.ortho_basis if np.size(np.shape(fsa_basis)) == 2: Hz_exp = np.zeros(np.size(fsa_basis, axis=1)) for n in range(0, np.size(Hz_exp, axis=0)): Hz_exp[n] = exp(Hz, fsa_basis[:, n]) Hz_diff = np.zeros(np.size(Hz_exp) - 1) for n in range(0, np.size(Hz_diff, axis=0)): Hz_diff[n] = np.abs(Hz_exp[n + 1] - Hz_exp[n]) #spacing error error_matrix = np.zeros((np.size(Hz_diff), np.size(Hz_diff))) for n in range(0, np.size(error_matrix, axis=0)): for m in range(0, np.size(error_matrix, axis=0)): error_matrix[n, m] = np.abs(Hz_diff[n] - Hz_diff[m]) error = np.power( np.trace(np.dot(error_matrix, np.conj(np.transpose(error_matrix)))), 0.5) print(coef, error) return error else: return 1000
application_index_dual = np.vstack( (application_index_dual, np.array([Im_app, Lp_app]))) current_state = np.dot(Lp.sector.matrix(k), tagged_state) current_state = current_state / np.power( np.vdot(current_state, current_state), 0.5) su3_basis_dual = np.vstack((su3_basis_dual, current_state)) current_S = current_S - 1 / 2 Im_app = 0 Lp_app += 1 application_index_dual = np.vstack( (application_index_dual, np.array([Im_app, Lp_app]))) su3_basis_dual = np.transpose(su3_basis_dual) su3_basis = np.hstack((su3_basis, su3_basis_dual)) from Calculations import gram_schmidt gs = gram_schmidt(su3_basis) gs.ortho() su3_basis = gs.ortho_basis I3 = 1 / 2 * com(Ip_total.sector.matrix(k), Im_total.sector.matrix(k)) root3 = np.power(3, 0.5) g8 = 1 / (2 * root3) * (com(Kp_total.sector.matrix(k), Km_total.sector.matrix(k)) + com(Lp_total.sector.matrix(k), Lm_total.sector.matrix(k))) e, u = np.linalg.eigh(I3) lw = u[:, 0] #generate new su3 rep su3_basis = lw for n in range(0, np.size(application_index, axis=0)): temp_state = lw
#need mapping from full basis to even/odd sub basis for n in range(0, krylov_dim): next_state_half_rep = gsa_Hp(current_state_half_rep) next_state_full_rep = half_rep_to_full(next_state_half_rep, M_basis_map, pxp_half, pxp) gfsa_basis = np.vstack((gfsa_basis, next_state_full_rep)) # gs = gram_schmidt(np.transpose(gfsa_basis)) # gs.ortho() # gfsa_basis = np.transpose(gs.ortho_basis) current_state_half_rep = next_state_half_rep gfsa_basis = np.transpose(gfsa_basis) # gfsa_basis,temp = np.linalg.qr(gfsa_basis) gs = gram_schmidt(gfsa_basis) gs.ortho() gfsa_basis = gs.ortho_basis #project hamiltonians H_krylov = np.dot(np.conj(np.transpose(krylov_basis)), np.dot(H.sector.matrix(), krylov_basis)) H_fsa = np.dot(np.conj(np.transpose(fsa_basis)), np.dot(H.sector.matrix(), fsa_basis)) H_gfsa = np.dot(np.conj(np.transpose(gfsa_basis)), np.dot(H.sector.matrix(), gfsa_basis)) e_krylov, u_krylov = np.linalg.eigh(H_krylov) e_fsa, u_fsa = np.linalg.eigh(H_fsa) e_gfsa, u_gfsa = np.linalg.eigh(H_gfsa) print(e_krylov)
# basis = np.hstack((L_cube_basis,basis)) # basis = np.hstack((basis,R_cube_basis)) # basis = np.hstack((L_cube_basis,basis)) # basis = np.hstack((basis,R_cube_basis)) basis = np.hstack((L_cube_basis, basis)) basis = np.hstack((basis, R_cube_basis)) basis = np.unique(basis, axis=1) # basis = np.hstack((basis,L_cube_basis)) # basis = np.hstack((basis,np.flip(R_cube_basis,axis=1))) #gram schmidt, QR ruins particle hole from Calculations import gram_schmidt gs = gram_schmidt(basis) gs.ortho() basis = gs.ortho_basis # include Neel fsa (orig) #fsa Hamiltonian, H= H+ + H- Hp1 = Hamiltonian(pxp) Hp1.site_ops[1] = np.array([[0, 1], [0, 0]]) Hp1.model = np.array([[1]]) Hp1.model_coef = np.array([1]) Hp1.gen(parity=0) Hp2 = Hamiltonian(pxp) Hp2.site_ops[1] = np.array([[0, 0], [1, 0]]) Hp2.model = np.array([[1]]) Hp2.model_coef = np.array([1]) Hp2.gen(parity=1)
def gen_su3Basis(coef): c = 0 Ip_total = deepcopy(Ip[0]) for n in range(1, len(Ip)): Ip_total = H_operations.add(Ip_total, Ip[n], np.array([1, coef[c + n - 1]])) Im_total = deepcopy(Im[0]) for n in range(1, len(Im)): Im_total = H_operations.add(Im_total, Im[n], np.array([1, coef[c + n - 1]])) c += len(Ip) - 1 Kp_total = deepcopy(Kp[0]) for n in range(1, len(Kp)): Kp_total = H_operations.add(Kp_total, Kp[n], np.array([1, coef[c + n - 1]])) Km_total = deepcopy(Km[0]) for n in range(1, len(Km)): Km_total = H_operations.add(Km_total, Km[n], np.array([1, coef[c + n - 1]])) c += len(Kp) - 1 Lp_total = deepcopy(Lp[0]) for n in range(1, len(Lp)): Lp_total = H_operations.add(Lp_total, Lp[n], np.array([1, coef[c + n - 1]])) Lm_total = deepcopy(Lm[0]) for n in range(1, len(Lm)): Lm_total = H_operations.add(Lm_total, Lm[n], np.array([1, coef[c + n - 1]])) H = H_operations.add(Ip_total, Im_total, np.array([1j, -1j])) H = H_operations.add(H, Kp_total, np.array([1, -1j])) H = H_operations.add(H, Km_total, np.array([1, 1j])) H = H_operations.add(H, Lp_total, np.array([1, 1j])) H = H_operations.add(H, Lm_total, np.array([1, -1j])) #su3 rep #0th order rep (no perts) root3 = np.power(3, 0.5) I3 = 1 / 2 * com(Ip[0].sector.matrix(k), Im[0].sector.matrix(k)) g8 = 1 / (2 * root3) * (com(Kp[0].sector.matrix(k), Km[0].sector.matrix(k)) + com(Lp[0].sector.matrix(k), Lm[0].sector.matrix(k))) def exp(Q, psi): return np.real(np.vdot(psi, np.dot(Q, psi))) def var(Q, psi): Q2 = np.dot(Q, Q) return exp(Q2, psi) - (exp(Q, psi))**2 e, u = np.linalg.eigh(I3) lw = u[:, 0] hw = u[:, np.size(u, axis=1) - 1] #generate su3 representation by applying I+,L- to lw state su3_basis_states = dict() su3_basis = lw current_state = su3_basis i3_lw = exp(I3, lw) g8_hw = exp(g8, lw) current_S = np.abs(i3_lw) Ip_app = 0 Lm_app = 0 application_index = np.zeros(2) while np.abs(current_S) > 1e-5: no_ip_apps = int(2 * current_S) tagged_state = current_state for n in range(0, no_ip_apps): Ip_app = Ip_app + 1 next_state = np.dot(Ip[0].sector.matrix(k), current_state) next_state = next_state / np.power(np.vdot(next_state, next_state), 0.5) su3_basis = np.vstack((su3_basis, next_state)) current_state = next_state application_index = np.vstack( (application_index, np.array([Ip_app, Lm_app]))) current_state = np.dot(Lm[0].sector.matrix(k), tagged_state) current_state = current_state / np.power( np.vdot(current_state, current_state), 0.5) su3_basis = np.vstack((su3_basis, current_state)) current_S = current_S - 1 / 2 Ip_app = 0 Lm_app += 1 application_index = np.vstack( (application_index, np.array([Ip_app, Lm_app]))) su3_basis = np.transpose(su3_basis) #generate su3 dual representation (starting from highest weight state) representation by applying I-,L+ to lw state su3_basis_dual = hw current_state = su3_basis_dual i3_hw = exp(I3, hw) g8_lw = exp(g8, hw) current_S = np.abs(i3_hw) Im_app = 0 Lp_app = 0 application_index_dual = np.zeros(2) while np.abs(current_S) > 1e-5: no_im_apps = int(2 * current_S) tagged_state = current_state for n in range(0, no_im_apps): Im_app = Im_app + 1 next_state = np.dot(Im[0].sector.matrix(k), current_state) next_state = next_state / np.power(np.vdot(next_state, next_state), 0.5) su3_basis_dual = np.vstack((su3_basis_dual, next_state)) current_state = next_state application_index_dual = np.vstack( (application_index_dual, np.array([Im_app, Lp_app]))) current_state = np.dot(Lp[0].sector.matrix(k), tagged_state) current_state = current_state / np.power( np.vdot(current_state, current_state), 0.5) su3_basis_dual = np.vstack((su3_basis_dual, current_state)) current_S = current_S - 1 / 2 Im_app = 0 Lp_app += 1 application_index_dual = np.vstack( (application_index_dual, np.array([Im_app, Lp_app]))) su3_basis_dual = np.transpose(su3_basis_dual) su3_basis = np.hstack((su3_basis, su3_basis_dual)) from Calculations import gram_schmidt gs = gram_schmidt(su3_basis) gs.ortho() su3_basis = gs.ortho_basis return su3_basis
def subspace_variance(coef): c=0 Ip_total = deepcopy(Ip[0]) for n in range(1,len(Ip)): Ip_total = H_operations.add(Ip_total,Ip[n],np.array([1,coef[c+n-1]])) Im_total = deepcopy(Im[0]) for n in range(1,len(Im)): Im_total = H_operations.add(Im_total,Im[n],np.array([1,coef[c+n-1]])) c += len(Ip)-1 Kp_total = deepcopy(Kp[0]) for n in range(1,len(Kp)): Kp_total = H_operations.add(Kp_total,Kp[n],np.array([1,coef[c+n-1]])) Km_total = deepcopy(Km[0]) for n in range(1,len(Km)): Km_total = H_operations.add(Km_total,Km[n],np.array([1,coef[c+n-1]])) c += len(Kp)-1 Lp_total = deepcopy(Lp[0]) for n in range(1,len(Lp)): Lp_total = H_operations.add(Lp_total,Lp[n],np.array([1,coef[c+n-1]])) Lm_total = deepcopy(Lm[0]) for n in range(1,len(Lm)): Lm_total = H_operations.add(Lm_total,Lm[n],np.array([1,coef[c+n-1]])) H=H_operations.add(Ip_total,Im_total,np.array([1j,-1j])) H=H_operations.add(H,Kp_total,np.array([1,-1j])) H=H_operations.add(H,Km_total,np.array([1,1j])) H=H_operations.add(H,Lp_total,np.array([1,1j])) H=H_operations.add(H,Lm_total,np.array([1,-1j])) #su3 rep #0th order rep (no perts) root3 = np.power(3,0.5) I3 = 1/2 * com(Ip[0].sector.matrix(k),Im[0].sector.matrix(k)) g8 = 1/(2*root3) * ( com(Kp[0].sector.matrix(k),Km[0].sector.matrix(k)) + com(Lp[0].sector.matrix(k),Lm[0].sector.matrix(k)) ) def exp(Q,psi): return np.real(np.vdot(psi,np.dot(Q,psi))) def var(Q,psi): Q2 = np.dot(Q,Q) return exp(Q2,psi)-(exp(Q,psi))**2 e,u = np.linalg.eigh(I3) lw = u[:,0] hw = u[:,np.size(u,axis=1)-1] #generate su3 representation by applying I+,L- to lw state su3_basis_states = dict() su3_basis = lw current_state = su3_basis i3_lw = exp(I3,lw) g8_hw = exp(g8,lw) current_S = np.abs(i3_lw) Ip_app= 0 Lm_app= 0 application_index = np.zeros(2) while np.abs(current_S)>1e-5: no_ip_apps = int(2*current_S) tagged_state = current_state for n in range(0,no_ip_apps): Ip_app = Ip_app + 1 next_state = np.dot(Ip[0].sector.matrix(k),current_state) next_state = next_state / np.power(np.vdot(next_state,next_state),0.5) su3_basis = np.vstack((su3_basis,next_state)) current_state = next_state application_index = np.vstack((application_index,np.array([Ip_app,Lm_app]))) current_state = np.dot(Lm[0].sector.matrix(k),tagged_state) current_state = current_state / np.power(np.vdot(current_state,current_state),0.5) su3_basis = np.vstack((su3_basis,current_state)) current_S = current_S - 1/2 Ip_app = 0 Lm_app += 1 application_index = np.vstack((application_index,np.array([Ip_app,Lm_app]))) su3_basis = np.transpose(su3_basis) #generate su3 dual representation (starting from highest weight state) representation by applying I-,L+ to lw state su3_basis_dual = hw current_state = su3_basis_dual i3_hw = exp(I3,hw) g8_lw = exp(g8,hw) current_S = np.abs(i3_hw) Im_app= 0 Lp_app= 0 application_index_dual = np.zeros(2) while np.abs(current_S)>1e-5: no_im_apps = int(2*current_S) tagged_state = current_state for n in range(0,no_im_apps): Im_app = Im_app + 1 next_state = np.dot(Im[0].sector.matrix(k),current_state) next_state = next_state / np.power(np.vdot(next_state,next_state),0.5) su3_basis_dual = np.vstack((su3_basis_dual,next_state)) current_state = next_state application_index_dual = np.vstack((application_index_dual,np.array([Im_app,Lp_app]))) current_state = np.dot(Lp[0].sector.matrix(k),tagged_state) current_state = current_state / np.power(np.vdot(current_state,current_state),0.5) su3_basis_dual = np.vstack((su3_basis_dual,current_state)) current_S = current_S - 1/2 Im_app = 0 Lp_app += 1 application_index_dual = np.vstack((application_index_dual,np.array([Im_app,Lp_app]))) su3_basis_dual = np.transpose(su3_basis_dual) su3_basis = np.hstack((su3_basis,su3_basis_dual)) from Calculations import gram_schmidt gs = gram_schmidt(su3_basis) gs.ortho() su3_basis = gs.ortho_basis I3 = 1/2 * com(Ip_total.sector.matrix(k),Im_total.sector.matrix(k)) root3=np.power(3,0.5) g8 = 1/(2*root3)*( com(Kp_total.sector.matrix(k),Km_total.sector.matrix(k)) + com(Lp_total.sector.matrix(k),Lm_total.sector.matrix(k)) ) e,u = np.linalg.eigh(I3) lw = u[:,0] #generate new su3 rep su3_basis= lw for n in range(0,np.size(application_index,axis=0)): temp_state = lw for u in range(0,int(application_index[n,1])): temp_state = np.dot(Lm_total.sector.matrix(k),temp_state) for u in range(0,int(application_index[n,0])): temp_state = np.dot(Ip_total.sector.matrix(k),temp_state) temp_state = temp_state / np.power(np.vdot(temp_state,temp_state),0.5) su3_basis = np.vstack((su3_basis,temp_state)) su3_basis = np.transpose(su3_basis) #generate new su3 rep dual su3_basis_dual= hw for n in range(0,np.size(application_index_dual,axis=0)): temp_state = hw for u in range(0,int(application_index_dual[n,1])): temp_state = np.dot(Lp_total.sector.matrix(k),temp_state) for u in range(0,int(application_index_dual[n,0])): temp_state = np.dot(Im_total.sector.matrix(k),temp_state) temp_state = temp_state / np.power(np.vdot(temp_state,temp_state),0.5) su3_basis_dual = np.vstack((su3_basis_dual,temp_state)) su3_basis_dual = np.transpose(su3_basis_dual) su3_basis = np.hstack((su3_basis,su3_basis_dual)) from Calculations import gram_schmidt gs = gram_schmidt(su3_basis) gs.ortho() su3_basis = gs.ortho_basis H2 = np.dot(H.sector.matrix(k),H.sector.matrix(k)) H2_fsa = np.dot(np.conj(np.transpose(su3_basis)),np.dot(H2,su3_basis)) H_fsa = np.dot(np.conj(np.transpose(su3_basis)),np.dot(H.sector.matrix(k),su3_basis)) subspace_variance = np.real(np.trace(H2_fsa-np.dot(H_fsa,H_fsa))) error = subspace_variance / np.size(su3_basis,axis=1) print(coef,error) e,u = np.linalg.eigh(H_fsa) plt.scatter(e,np.log10(np.abs(u[0,:])**2),marker="x",color="red",s=100) # np.save("pcp,2ndOrderSU3,coef,"+str(pxp.N),coef) # if (np.abs(coef)>0.5).any(): # return 1000 # else: return error