def fidelity_erorr(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] H = H_operations.add(Hp_total, Hm, np.array([1, 1])) H.sector.find_eig(k) psi_energy = np.dot(np.conj(np.transpose(H.sector.eigvectors(k))), psi) t = np.arange(0, 6, 0.001) # t=np.arange(0,20,0.01) f = np.zeros(np.size(t)) for n in range(0, np.size(t, axis=0)): evolved_state = time_evolve_state(psi_energy, H.sector.eigvalues(k), t[n]) f[n] = np.abs(np.vdot(evolved_state, psi_energy))**2 for n in range(0, np.size(f, axis=0)): if f[n] < 0.1: cut = n break f0 = np.max(f[cut:]) # plt.plot(t,f) # plt.show() # res = minimize_scalar(lambda t: -fidelity_eval(psi_energy,H.sector.eigvalues(),t),method="golden",bracket=(2.5,5.5)) # f0 = fidelity_eval(psi_energy,H.sector.eigvalues(),res.x) return 1 - f0
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() z=zm_state(3,1,pxp) from Calculations import gen_fsa_basis fsa_dim = int(2*pxp.N/3) fsa_basis = gen_fsa_basis(Hp_total.sector.matrix(),z.prod_basis(),fsa_dim) # for n in range(0,np.size(fsa_basis,axis=1)): # for m in range(0,np.size(fsa_basis,axis=1)): # temp = np.abs(np.vdot(fsa_basis[:,n],fsa_basis[:,m])) # if temp > 1e-5: # print(temp,n,m) fsa_basis,temp = np.linalg.qr(fsa_basis) H2 = np.dot(H.sector.matrix(),H.sector.matrix()) 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(),fsa_basis)) subspace_variance = np.real(np.trace(H2_fsa-np.dot(H_fsa,H_fsa))) return subspace_variance
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 fidelity_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_total = Hp_total.herm_conj() H = H_operations.add(Hp_total, Hm_total, np.array([1, 1])) H.sector.find_eig(k) psi_energy = np.dot(np.conj(np.transpose(H.sector.eigvectors(k))), psi_mom) t = np.arange(0, 20, 0.01) f = np.zeros(np.size(t)) for n in range(0, np.size(t, axis=0)): evolved_state = time_evolve_state(psi_energy, H.sector.eigvalues(k), t[n]) f[n] = np.abs(np.vdot(evolved_state, psi_energy))**2 for n in range(0, np.size(f, axis=0)): if f[n] < 0.5: cut = n break f_max = np.max(f[cut:]) error = 1 - f_max # res = minimize_scalar(lambda t: -fidelity_eval(psi_energy,H.sector.eigvalues(k),t),method="golden") # f0 = fidelity_eval(psi_energy,H.sector.eigvalues(k),res.x) # error = 1-f0 print(coef, error) # if (np.abs(coef)>1).any(): # return 1000 # else: return error
def fidelity_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 = np.conj(np.transpose(Hp_total.sector.matrix())) H = Hp_total.sector.matrix() + Hm e, u = np.linalg.eigh(H) z = zm_state(2, 1, pxp, 1) psi_energy = np.dot(np.conj(np.transpose(u)), z.prod_basis()) t = np.arange(0, 10, 0.01) f = np.zeros(np.size(t)) for n in range(0, np.size(t, axis=0)): f[n] = -fidelity_eval(psi_energy, e, t[n]) # plt.plot(t,f) # plt.show() for n in range(0, np.size(f, axis=0)): if f[n] < 0.1: cut = n break f_max = np.max(f[cut:]) res = minimize_scalar(lambda t: fidelity_eval(psi_energy, e, t), method="golden", bracket=(4.5, 5.5)) f = -fidelity_eval(psi_energy, e, res.x) print(coef, f) # print(f) if res.x < 1e-5: return 1000 else: return -f_max
def var_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 = np.conj(np.transpose(Hp_total.sector.matrix())) H = Hp_total.sector.matrix() + Hm Hz = 1 / 2 * com(Hp_total.sector.matrix(), Hm) z = zm_state(2, 1, pxp, 1) fsa_basis = z.prod_basis() current_state = fsa_basis for n in range(0, pxp.N): next_state = np.dot(Hp_total.sector.matrix(), current_state) next_state = next_state / np.power(np.vdot(next_state, next_state), 0.5) fsa_basis = np.vstack((fsa_basis, next_state)) current_state = next_state fsa_basis = np.transpose(fsa_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) print(coef, error) return error
def spacing_error(coef, psi): 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 = np.conj(np.transpose(Hp_total.sector.matrix())) Hz = 1 / 2 * com(Hp_total.sector.matrix(), Hm) from Calculations import gen_fsa_basis fsa_basis = gen_fsa_basis(Hp_total.sector.matrix(), psi, pxp.N) Hz_exp = np.zeros(np.size(fsa_basis, axis=1)) for n in range(0, np.size(fsa_basis, axis=1)): 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] = Hz_exp[n + 1] - Hz_exp[n] M = np.zeros((np.size(Hz_diff), np.size(Hz_diff))) for n in range(0, np.size(M, axis=0)): for m in range(0, np.size(M, axis=0)): M[n, m] = np.abs(Hz_diff[n] - Hz_diff[m]) error = np.power(np.trace(np.dot(M, np.conj(np.transpose(M)))), 0.5) print(coef, error) return error
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 overlap_error(coef): # coef = coef[0] H = H_operations.add(H0, V, np.array([1, coef])) H.sector.find_eig() overlap_no_log = np.abs(H.sector.eigvectors()[pxp.keys[z.ref], :])**2 overlap = np.log10(overlap_no_log) scar_indices_perturbed = np.flip( get_top_band_indices(H.sector.eigvalues(), overlap, pxp.N, 200, 150, 0.8)) # check got right scars # plt.scatter(H.sector.eigvalues(),overlap) # for n in range(0,np.size(scar_indices_perturbed,axis=0)): # plt.scatter(H.sector.eigvalues()[scar_indices_perturbed[n]],overlap[scar_indices_perturbed[n]],marker="x",color="red",s=100) # plt.show() for n in range(0, np.size(scar_indices_perturbed, axis=0)): overlap_no_log = np.delete(overlap_no_log, scar_indices_perturbed[n], axis=0) cost = np.sum(overlap_no_log) # cost = np.sum(scar_overlap_perturbed-scar_overlap) print(coef, cost) return cost
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(), Hm.sector.matrix()) z = zm_state(2, 1, pxp, 1) from Calculations import gen_fsa_basis fsa_basis = gen_fsa_basis(Hp_total.sector.matrix(), z.prod_basis(), pxp.N) 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 fidelity_error(coef): np.save("NEWising,pert_coef," + str(pxp.N), 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 = np.conj(np.transpose(Hp_total.sector.matrix())) Hz = 1 / 2 * com(Hp_total.sector.matrix(), Hm) e, u = np.linalg.eigh(Hz) psi = u[:, 0] H = Hp_total.sector.matrix() + Hm e, u = np.linalg.eigh(H) psi_energy = np.dot(np.conj(np.transpose(u)), psi) t = np.arange(0, 10, 0.01) f = np.zeros(np.size(t)) for n in range(0, np.size(t, axis=0)): f[n] = -fidelity_eval(psi_energy, e, t[n]) for n in range(0, np.size(f, axis=0)): if f[n] < 0.1: cut = n break f_max = np.max(f[cut:]) res = minimize_scalar(lambda t: fidelity_eval(psi_energy, e, t), method="golden", bracket=(4.5, 5.5)) f = -fidelity_eval(psi_energy, e, res.x) print(coef, f) # print(f) if res.x < 1e-5: return 1000 else: return -f_max
def fidelity_error(coef, plot=False): coef = coef[0] H = H_operations.add(H0, V, np.array([1, coef])) H = H.sector.matrix() e, u = np.linalg.eigh(H) z = zm_state(4, 1, pxp) psi_energy = np.dot(np.conj(np.transpose(u)), z.prod_basis()) if plot is True: t = np.arange(0, 20, 0.01) f = np.zeros(np.size(t)) for n in range(0, np.size(t, axis=0)): f[n] = -fidelity_eval(psi_energy, e, t[n]) plt.plot(t, f) plt.show() res = minimize_scalar(lambda t: fidelity_eval(psi_energy, e, t), method="golden", bracket=(4.5, 5.5)) f = -fidelity_eval(psi_energy, e, res.x) print(coef, f) if res.x < 1e-5: return 1000 else: return -f
def fidelity_erorr(coef): coef = coef[0] Hp_total = deepcopy(Hp[0]) Hp_total = H_operations.add(Hp_total,Hp[1],np.array([1,coef])) Hm = Hp_total.herm_conj() H = H_operations.add(Hp_total,Hm,np.array([1,1])) H.sector.find_eig() z=zm_state(2,2,pxp,1) psi_energy = np.dot(np.conj(np.transpose(H.sector.eigvectors())),z.prod_basis()) res = minimize_scalar(lambda t: -fidelity_eval(psi_energy,H.sector.eigvalues(),t),method="golden",bracket=(4.5,5.5)) f0 = fidelity_eval(psi_energy,H.sector.eigvalues(),res.x) print(coef,f0) return 1-f0
def subspace_variance(coef): coef = coef[0] Hp_total = deepcopy(Hp[0]) Hp_total = H_operations.add(Hp_total,Hp[1],np.array([1,coef])) Hm = Hp_total.herm_conj() H = H_operations.add(Hp_total,Hm,np.array([1,1])) H.sector.find_eig() z=zm_state(2,2,pxp,1) from Calculations import gen_fsa_basis fsa_dim = 2*pxp.N fsa_basis = gen_fsa_basis(Hp_total.sector.matrix(),z.prod_basis(),fsa_dim) H2 = np.dot(H.sector.matrix(),H.sector.matrix()) 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(),fsa_basis)) subspace_variance = np.real(np.trace(H2_fsa-np.dot(H_fsa,H_fsa))) return subspace_variance
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 = np.conj(np.transpose(Hp_total.sector.matrix())) Hp0 = Hp_total.sector.matrix() Hm0 = np.conj(np.transpose(Hp0)) Hz = 1 / 2 * com(Hp0, Hm0) #find lowest weight state e, u = np.linalg.eigh(Hz) lowest_weight = u[:, 0] z = zm_state(2, 1, pxp, 1) fsa_basis = z.prod_basis() current_state = fsa_basis fsa_dim = pxp.N for n in range(0, fsa_dim): next_state = np.dot(Hp0, current_state) if np.abs(np.vdot(next_state, next_state)) > 1e-5: next_state = next_state / np.power(np.vdot(next_state, next_state), 0.5) fsa_basis = np.vstack((fsa_basis, next_state)) current_state = next_state else: break fsa_basis = np.transpose(fsa_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(Hz_diff, axis=0)): for m in range(0, np.size(Hz_diff, 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
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()) z = zm_state(2, 1, pxp, 1) from Calculations import gen_fsa_basis fsa_basis = gen_fsa_basis(Hp_total.sector.matrix(), z.prod_basis(), pxp.N) 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): 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 = np.conj(np.transpose(Hp_total.sector.matrix())) H = Hp_total.sector.matrix() + Hm e, u = np.linalg.eigh(H) z = zm_state(3, 1, pxp) psi_energy = np.dot(np.conj(np.transpose(u)), z.prod_basis()) overlap = np.log10(np.abs(psi_energy)**2) scar_indices = get_top_band_indices(e, overlap, int(2 * N / 3), 150, 200, e_diff=0.5) # plt.scatter(e,overlap) # for n in range(0,np.size(scar_indices,axis=0)): # plt.scatter(e[scar_indices[n]],overlap[scar_indices[n]],marker="x",s=100,color="red") # plt.show() scar_e = np.zeros(np.size(scar_indices)) for n in range(0, np.size(scar_indices, axis=0)): scar_e[n] = e[scar_indices[n]] diffs = np.zeros(np.size(scar_e) - 1) for n in range(0, np.size(diffs, axis=0)): diffs[n] = scar_e[n + 1] - scar_e[n] diff_matrix = np.zeros((np.size(diffs), np.size(diffs))) for n in range(0, np.size(diff_matrix, axis=0)): for m in range(0, np.size(diff_matrix, axis=0)): diff_matrix[n, m] = diffs[n] - diffs[m] error = np.power( np.trace(np.dot(diff_matrix, np.conj(np.transpose(diff_matrix)))), 0.5) print(coef, error) print(scar_e) # print(coef) # if (np.abs(coef).any())>0.5: # return 1000 # else: return error
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 krylov_su2_coupling_error(coef): coef = coef[0] H = H_operations.add(H0,V,np.array([1,coef])) z=zm_state(2,1,pxp) krylov_basis = gen_krylov_basis(H.sector.matrix(),pxp.N,z.prod_basis(),pxp,orth="qr") H_krylov = np.dot(np.conj(np.transpose(krylov_basis)),np.dot(H.sector.matrix(),krylov_basis)) couplings = np.diag(H_krylov,1) s = pxp.N/4 m = np.arange(-s,s) su2_couplings_half = np.power(s*(s+1)-m*(m+1),0.5) s = pxp.N/2 m = np.arange(-s,s) su2_couplings_full = np.power(s*(s+1)-m*(m+1),0.5) coupling_diff_full = couplings - su2_couplings_full error = np.power(np.abs(np.vdot(coupling_diff_full,coupling_diff_full)),0.5) # error = np.abs(couplings[3] - su2_couplings_half[3]) print(coef,error) return error
def fidelity_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 = np.conj(np.transpose(Hp_total.sector.matrix())) H = Hp_total.sector.matrix() + Hm e, u = np.linalg.eigh(H) z = zm_state(3, 1, pxp) psi_energy = np.dot(np.conj(np.transpose(u)), z.prod_basis()) res = minimize_scalar(lambda t: fidelity_eval(psi_energy, e, t), method="golden", bracket=(2.5, 3.5)) f = -fidelity_eval(psi_energy, e, res.x) print(coef, f) # print(f) if res.x < 1e-5: return 1000 if (np.abs(coef) > 0.5).any(): return 1000 return -f
Ip.gen(k) Im.gen(k) Kp.gen(k) Km.gen(k) Lp.gen(k) Lm.gen(k) Ip_pert.gen(k) Im_pert.gen(k) Kp_pert.gen(k) Km_pert.gen(k) Lp_pert.gen(k) Lm_pert.gen(k) coef = 0 # coef = -0.0827840215 Ip_total = H_operations.add(Ip, Ip_pert, np.array([1, coef])) Im_total = H_operations.add(Im, Im_pert, np.array([1, coef])) Kp_total = H_operations.add(Kp, Kp_pert, np.array([1, coef])) Km_total = H_operations.add(Km, Km_pert, np.array([1, coef])) Lp_total = H_operations.add(Lp, Lp_pert, np.array([1, coef])) Lm_total = H_operations.add(Lm, Lm_pert, np.array([1, coef])) 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])) H.sector.find_eig(k) exact_energy = H.sector.eigvalues(k) exact_overlap = eig_overlap(z, H, k).eval()
H0.model = np.array([[1]]) H0.model_coef = np.array([1]) H1 = Hamiltonian(pxp, pxp_syms) H1.site_ops[1] = np.array([[0, 1], [1, 0]]) H1.model = np.array([[0, 1, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 1, 0]]) H1.model_coef = np.array([1, 1, 1, 1]) H1.uc_size = np.array([3, 3, 3, 3]) H1.uc_pos = np.array([1, 2, 2, 1]) k = [0] H0.gen(k) H1.gen(k) # H0.gen() # H1.gen() H = H_operations.add(H0, H1, np.array([1, -1])) from Calculations import plot_adjacency_graph, connected_comps comp = connected_comps(H, k) # comp = connected_comps(H) comp.find_connected_components() subspace_sizes = dict() for n in range(0, len(comp.components)): print("\n") print(np.size(comp.components[n])) for m in range(0, np.size(comp.components[n], axis=0)): print(pxp.basis[pxp.keys[comp.components[n][m]]]) size = np.size(comp.components[n]) if size not in list(subspace_sizes.keys()): subspace_sizes[size] = 1 else:
Hp[9].uc_pos = np.array([0, 0, 1, 1]) for n in range(0, len(Hp)): Hp[n].gen() # coef = np.array([0.0008,-1.43,0.0979,0.0980]) # coef = np.array([0.1897,0.2322,0.0312,0.0014,-0.0023,-0.00492,0.0056,0.0006,-0.0134,0.0130,-0.0138,-0.0253,-0.0623,0.0166,-0.0281,0.0200]) coef = np.array([ 0.11135, 0.000217, -0.000287, -0.00717, 0.00827, 0.00336, 0.00429, 0.0103, 0.00118 ]) from copy import deepcopy 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]])) Hp = Hp_total.sector.matrix() Hm = np.conj(np.transpose(Hp)) H = Hp + Hm z = zm_state(2, 1, pxp, 1) e, u = np.linalg.eigh(H) overlap = np.log10(np.abs(u[pxp.keys[z.ref], :])**2) psi_energy = np.conj(u[pxp.keys[z.ref], :]) t = np.arange(0, 20, 0.01) f = np.zeros(np.size(t)) for n in range(0, np.size(t, axis=0)): evolved_state = time_evolve_state(psi_energy, e, t[n]) f[n] = np.abs(np.vdot(evolved_state, psi_energy))**2
if np.abs(psi[m])>1e-5: refs_non_zeros = np.append(refs_non_zeros,pxp.basis_refs[m]) refs_non_zeros = np.unique(np.sort(refs_non_zeros)) return refs_non_zeros #PXP+PPXP from Hamiltonian_Classes import H_operations H0 = spin_Hamiltonian(pxp,"x") V = Hamiltonian(pxp) V.site_ops[1] = np.array([[0,1/2],[1/2,0]]) V.site_ops[2] = np.array([[-1/2,0],[0,1/2]]) V.model = np.array([[2,0,1,0],[0,1,0,2]]) V.model_coef = np.array([1,1]) H0.gen() V.gen() H = H_operations.add(H0,V,np.array([1,-0.02])) H.sector.find_eig() H = spin_Hamiltonian(pxp,"x") H.gen() H.sector.find_eig() # N=10 # root_refs = find_root_refs(np.array([3,0]),np.array([3,1]),H,sector_refs,from_sector,pxp,[]) # basis = subcube_basis(root_refs,"Left",4) # refs_found = non_zero_ref_in_basis(basis) # print("\n") # root_refs = find_root_refs(np.array([0,3]),np.array([1,3]),H,sector_refs,from_sector,pxp,refs_found) # if np.size(root_refs)>0: # temp = subcube_basis(root_refs,"Right",4)
# P+P on even sites pe = Hamiltonian(pxp,pxp_syms) # pe.site_ops[1] = np.array([[0,1],[0,0]]) pe.site_ops[1] = np.array([[0,1j,0],[0,0,1j],[1j,0,0]]) pe.model = np.array([[0,1,0]]) pe.model_coef = np.array([1]) pe.gen(parity=1) #P-P on odd sites mo = Hamiltonian(pxp,pxp_syms) # mo.site_ops[1] = np.array([[0,0],[1,0]]) mo.site_ops[1] = np.array([[0,0,-1j],[-1j,0,0],[0,-1j,0]]) mo.model = np.array([[0,1,0]]) mo.model_coef = np.array([1]) mo.gen(parity=0) #Raising op Hp = H_operations.add(pe,mo,np.array([1,1])) Hp = Hp.sector.matrix() Hm = np.conj(np.transpose(Hp)) fsa_basis = z.prod_basis() current_state = fsa_basis for n in range(0,krylov_dim): next_state = np.dot(Hm,current_state) next_state = next_state / np.power(np.vdot(next_state,next_state),0.5) fsa_basis = np.vstack((fsa_basis,next_state)) current_state = next_state fsa_basis = np.transpose(fsa_basis) # fsa_basis,temp = np.linalg.qr(fsa_basis) gs = gram_schmidt(fsa_basis) gs.ortho() fsa_basis = gs.ortho_basis
res = minimize(lambda coef: spacing_error(coef), method="Nelder-Mead", x0=coef) coef = res.x # coef = np.zeros(1) # # coef = np.load("./data/pxp,z4,pert_coef.npy") # # coef = res.x # # coef[1] = -1 # error = spacing_error(coef) # print("ERROR VALUE: "+str(error)) print(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]])) Hp_total = H_operations.add(Hp_total, Hp[1], np.array([1, coef])) Hp = Hp_total.sector.matrix() Hm = np.conj(np.transpose(Hp)) H = Hp + Hm # H = Hamiltonian(pxp) # H.site_ops[1] = np.array([[0,1],[1,0]]) # H.model = np.array([[0,1,0],[0,1,1,1,0]]) # H.model_coef = np.array([1,coef]) # H.gen() # H = H.sector.matrix() def com(a, b): return np.dot(a, b) - np.dot(b, a)
Hpo.model_coef = np.array([1]) Hpo.gen(parity=1) Hme = Hamiltonian(pxp, pxp_syms) Hme.site_ops[1] = np.array([[0, 0], [1, 0]]) Hme.model = np.array([[0, 1, 0]]) Hme.model_coef = np.array([1]) Hme.gen(parity=0) Hmo = Hamiltonian(pxp, pxp_syms) Hmo.site_ops[1] = np.array([[0, 0], [1, 0]]) Hmo.model = np.array([[0, 1, 0]]) Hmo.model_coef = np.array([1]) Hmo.gen(parity=1) Hp = H_operations.add(Hpe, Hmo, np.array([1, 1])) Hm = H_operations.add(Hme, Hpo, np.array([1, 1])) def com(a, b): return np.dot(a, b) - np.dot(b, a) Hz = com(Hp.sector.matrix(), Hm.sector.matrix()) z = zm_state(2, 1, pxp) z_prod_basis = z.prod_basis() fsa_basis = z.prod_basis() current_state = fsa_basis for n in range(0, pxp.N): new_state = np.dot(Hp.sector.matrix(), current_state)
V1_ops[2].site_ops[1] = np.array([[0, 1], [1, 0]]) V1_ops[2].model = np.array([[0, 1, 0, 0]]) V1_ops[2].model_coef = np.array([1]) for n in range(0, np.size(k)): V1_ops[2].gen(k_vec=k[n], uc_size=3, uc_pos=2) V1_ops[3] = Hamiltonian(pxp, pxp_syms) V1_ops[3].site_ops[1] = np.array([[0, 1], [1, 0]]) V1_ops[3].model = np.array([[0, 0, 1, 0]]) V1_ops[3].model_coef = np.array([1]) for n in range(0, np.size(k)): V1_ops[3].gen(k_vec=k[n], uc_size=3, uc_pos=1) V1 = V1_ops[0] for n in range(1, len(V1_ops)): V1 = H_operations.add(V1, V1_ops[n], np.array([1, 1])) V2_ops = dict() V2_ops[0] = Hamiltonian(pxp, pxp_syms) V2_ops[0].site_ops[1] = np.array([[0, 1], [1, 0]]) V2_ops[0].model = np.array([[0, 0, 1, 0]]) V2_ops[0].model_coef = np.array([1]) for n in range(0, np.size(k)): V2_ops[0].gen(k_vec=k[n], uc_size=3, uc_pos=0) V2_ops[1] = Hamiltonian(pxp, pxp_syms) V2_ops[1].site_ops[1] = np.array([[0, 1], [1, 0]]) V2_ops[1].model = np.array([[0, 1, 0, 0]]) V2_ops[1].model_coef = np.array([1]) for n in range(0, np.size(k)): V2_ops[1].gen(k_vec=k[n], uc_size=3, uc_pos=0)
#FSA basis # P+P on even sites pe = Hamiltonian(pxp, pxp_syms) pe.site_ops[1] = np.array([[0, 1, 1j], [-1, 0, 0], [-1j, 0, 0]]) pe.model = np.array([[0, 1, 0]]) pe.model_coef = np.array([1]) pe.gen(parity=1) #P-P on odd sites mo = Hamiltonian(pxp, pxp_syms) mo.site_ops[1] = np.array([[0, -1, 1j], [1, 0, 0], [-1j, 0, 0]]) mo.model = np.array([[0, 1, 0]]) mo.model_coef = np.array([1]) mo.gen(parity=0) #Raising op Hp = H_operations.add(pe, mo, np.array([1, 1])) Hp = Hp.sector.matrix() Hm = np.conj(np.transpose(Hp)) def com(a, b): return np.dot(a, b) - np.dot(b, a) Hz = 1 / 2 * com(Hp, Hm) e, u = np.linalg.eigh(Hz) psi = u[:, 0] # e,u = np.linalg.eigh(Hz) # from Diagnostics import print_wf # for n in range(0,np.size(u,axis=0)): # if np.abs(e[n]) < 1e-5:
Hp_test0.site_ops[2] = np.array([[0, 1], [0, 0]]) Hp_test0.model = np.array([[0, 1, 0], [0, 2, 0]]) Hp_test0.model_coef = np.array([1, 1]) Hp_test0.uc_size = np.array([2, 2]) Hp_test0.uc_pos = np.array([1, 0]) Hp_test = Hamiltonian(pxp) Hp_test.site_ops[1] = np.array([[0, 0], [1, 0]]) Hp_test.site_ops[2] = np.array([[0, 1], [0, 0]]) Hp_test.model = np.array([[0, 2, 1, 2, 0]]) Hp_test.model_coef = np.array([1]) Hp_test0.gen() Hp_test.gen() from Hamiltonian_Classes import H_operations Hp_test = H_operations.add(Hp_test0, Hp_test, np.array([1, coef_f0])) print((np.abs(Hp_test.sector.matrix() - Hp) < 1e-5).all()) Hz = 1 / 2 * com(Hp, Hm) e, u = np.linalg.eigh(Hz) z = zm_state(2, 1, pxp, 1) lw = u[:, 0] print("\n|<lw | Z_2 > |") print(np.abs(np.vdot(lw, z.prod_basis()))) print("\n") from Calculations import gen_fsa_basis, gram_schmidt fsa_basis = gen_fsa_basis(Hp, z.prod_basis(), pxp.N) gs = gram_schmidt(fsa_basis) gs.ortho()