def TransverseIsing(nspin, R, J, h): H = [] for i in range(nspin): j = (i + 1) % nspin active = [ k for k in range(nspin) if dpbc(i, k, nspin) < R or dpbc(j, k, nspin) < R ] active = np.asarray(active) print(active) nact = len(active) h_alpha = np.zeros(4**nact) ii = np.where(active == i)[0][0] jj = np.where(active == j)[0][0] idx = [0] * nact idx[ii] = 1 h_alpha[Bas2Int(idx, 4)] = h idx = [0] * nact idx[ii] = 3 idx[jj] = 3 if np.abs(i - j) == 1 and j != 0: h_alpha[Bas2Int(idx, 4)] = J imap, gmap = pauli_action(active, nspin) H.append((active, h_alpha, imap, gmap)) Hm = Hmat(H) print() print_Hamiltonian(H) return H
def Ising(nspin,R,psi): H = [] for i in range(nspin): j = (i+1)%nspin # ----- active = [k for k in range(nspin) if dpbc(i,k,nspin)<R or dpbc(j,k,nspin)<R] active = np.asarray(active) nact = len(active) # ----- h_alpha = np.zeros(4**nact) ii = np.where(active==i)[0][0] jj = np.where(active==j)[0][0] idx = [0]*nact idx[ii] = 3 h_alpha[Bas2Int(idx,4)] = np.sin(psi)/2.0 idx = [0]*nact idx[jj] = 3 h_alpha[Bas2Int(idx,4)] = np.sin(psi)/2.0 idx = [0]*nact idx[ii] = 1 idx[jj] = 1 h_alpha[Bas2Int(idx,4)] = np.cos(psi) # ----- imap,gmap = pauli_action(active,nspin) H.append((active,h_alpha,imap,gmap)) return H
def MaxCut(graph, R): VV, EE = graph nbit = len(VV) H = [] for (i, j) in EE: # ----- active = [ k for k in range(nbit) if dgr(graph, i, k) < R or dgr(graph, j, k) < R ] active = np.asarray(active) nact = len(active) # ----- h_alpha = np.zeros(4**nact) ii = np.where(active == i)[0][0] jj = np.where(active == j)[0][0] idx = [0] * nact h_alpha[Bas2Int(idx, 4)] = -0.5 idx[ii] = 3 idx[jj] = 3 h_alpha[Bas2Int(idx, 4)] = 0.5 # ----- imap, gmap = pauli_action(active, nbit) H.append((active, h_alpha, imap, gmap)) return H
def single_qubit_field(psi): H = [] nspin = 1 active = [0] nact = len(active) h_alpha = np.zeros(4**nact) h_alpha[Bas2Int([1], 4)] = np.sin(psi) h_alpha[Bas2Int([3], 4)] = np.cos(psi) imap, gmap = pauli_action(active, nspin) H.append((active, h_alpha, imap, gmap)) return H
def Heisenberg_LR(nspin, R): H = [] for i in range(nspin): for j in range(i + 1, nspin): print(i, j) # ----- active = [ k for k in range(nspin) if dobc(i, k, nspin) < R or dobc(j, k, nspin) < R ] active = np.asarray(active) nact = len(active) print(active) # ----- h_alpha = np.zeros(4**nact) ii = np.where(active == i)[0][0] jj = np.where(active == j)[0][0] for alpha in range(1, 4): idx = [0] * nact idx[ii] = alpha idx[jj] = alpha h_alpha[Bas2Int(idx, 4)] = 1.0 / (dobc(i, j, nspin) + 1.0) # ----- #print h_alpha imap, gmap = pauli_action(active, nspin) H.append((active, h_alpha, imap, gmap)) return H
def Heisenberg_SR(nspin, R): H = [] imax = nspin if (nspin == 2): imax = nspin - 1 for i in range(imax): j = (i + 1) % nspin active = [ k for k in range(nspin) if dpbc(i, k, nspin) < R or dpbc(j, k, nspin) < R ] active = np.asarray(active) nact = len(active) # ----- h_alpha = np.zeros(4**nact) ii = np.where(active == i)[0][0] jj = np.where(active == j)[0][0] for alpha in range(1, 4): idx = [0] * nact idx[ii] = alpha idx[jj] = alpha h_alpha[Bas2Int(idx, 4)] = 1.0 # ----- imap, gmap = pauli_action(active, nspin) H.append((active, h_alpha, imap, gmap)) return H
def lie_algebra(mu, nu, n): # Return coefficients and index for sigma mu,sigma nu index = '' coeff = 1 for i in range(n): tmpA, tmpB = PPmunu(mu[i] + nu[i]) index += tmpA coeff *= tmpB return coeff, Bas2Int(Str2Opp(index), 4)
def H_molecule(line): # from O'Malley et al, https://arxiv.org/pdf/1512.06860.pdf # H = \sum_i h[S_i] -> h_\alpha nspin = 2 V = np.loadtxt('../../code_v4/h2.dat').T V = V[:, line] print(V) H = [] active = [0, 1] active = np.asarray(active) nact = len(active) # ----- h_alpha = np.zeros(4**nact) h_alpha[Bas2Int([0, 0], 4)] = V[1] h_alpha[Bas2Int([3, 0], 4)] = V[2] h_alpha[Bas2Int([0, 3], 4)] = V[3] h_alpha[Bas2Int([3, 3], 4)] = V[4] h_alpha[Bas2Int([1, 1], 4)] = V[5] h_alpha[Bas2Int([2, 2], 4)] = V[6] # ----- imap, gmap = pauli_action(active, nspin) H.append((active, h_alpha, imap, gmap)) # print(H) return H
import numpy as np import sys sys.path.append('../../../../../code_v4/') from hamiltonian import Heisenberg_LR, print_Hamiltonian from mf import hom_mf_solution, hom_mf_state, hom_mf_energy, mf_solution, mf_state, mf_energy from ite import ITE_FCI from qite import QITE from binary_functions import Bas2Int nspin = 2 R = 0.50 db = 0.01 bmax = 4.00 H = Heisenberg_LR(nspin, R) print_Hamiltonian(H) # AFM initial guess psi_0 = np.zeros(2**nspin, dtype=complex) xvec = [0, 1] * (nspin / 2) xind = Bas2Int(xvec, 2) psi_0[xind] = 1.0 ITE_FCI(H, db, bmax, psi0=psi_0) QITE(H, db, bmax, lanczos=False, psi0=psi_0, ncheck=10)
def Hubbard(norb, R, U): H = [] nspin = 2 * norb # ----- encoding: # 0u 0d 1u 1d 2u 2d 3u 3d ... (n-1)u (n-1)d # 0 1 2 3 4 5 6 7 ... 2n-2 2n-1 # ----- formulas: # n0 => (1-Zp)/2 # (a*_p a_q + a*_q a_p) = (1/2) X_p X_q (prod_{k=q+1}^{p-1} Z_k ) (1- Z_p Z_q) with p>q # ----- potential energy: # n_iu n_id = (1-Z_{2i}) (1-Z_{2i+1})/4 for i = 0 ... n-1 # ----- kinetic energy (open boundary conditions): # a*_{iu} a_{i+1u} + hc => (a*_p a_q + a*_q a_p) with p=2i q=2i+2, i=0 ... n-2 # a*_{id} a_{i+1d} + hc => (a*_p a_q + a*_q a_p) with p=2i+1 q=2i+3, i=1 ... n-2 # ----- potential energy for i in range(norb - 1): print(">>>>>>> sites ", i, i + 1) print("neighborhood") dij = np.asarray( [min(np.abs(i - j), np.abs(i + 1 - j)) for j in range(norb)]) idx = np.where(dij < R)[0] print(idx) pmin = 2 * min(idx) pmax = 2 * max(idx) + 1 act = range(pmin, pmax + 1) nact = len(act) print(act) print("-----") h_alpha = np.zeros(4**nact) for k in (i, i + 1): pk = 2 * k - pmin print("interaction on site ", k) wk = 0.5 #idx = [0]*nact #h_alpha[Bas2Int(idx,4)] += U*wk/4.0+(U/2)*wk/2.0 if (k == 0 or k == norb - 1): wk = 1.0 print("indices", pk, pk + 1, nact, wk) # ----- idx = [0] * nact idx[pk] = 3 print(idx) h_alpha[Bas2Int( idx, 4 )] = -U * wk / 4.0 + (U / 2) * wk / 2.0 # half-filling Hubbard # ----- idx = [0] * nact idx[pk + 1] = 3 print(idx) h_alpha[Bas2Int( idx, 4 )] = -U * wk / 4.0 + (U / 2) * wk / 2.0 # half-filling Hubbard # ----- idx = [0] * nact idx[pk] = 3 idx[pk + 1] = 3 print(idx) h_alpha[Bas2Int(idx, 4)] = U * wk / 4.0 # ----- print("kinetic") for sigma in (0, 1): print("spin ", sigma) p = (2 * i + sigma) - pmin q = p + 2 # ----- idx = [0] * nact idx[p] = 1 idx[p + 1] = 3 idx[q] = 1 print(idx) h_alpha[Bas2Int(idx, 4)] = -0.5 # ----- idx = [0] * nact idx[p] = 2 idx[p + 1] = 3 idx[q] = 2 print(idx) h_alpha[Bas2Int(idx, 4)] = -0.5 imap, gmap = pauli_action(act, nspin) H.append((act, h_alpha, imap, gmap)) print("remember to add the constant correction ", U * norb / 4.0 - (U / 2) * 2 * norb / 2.0) return H
# First populate the Lie algebra rules index = np.zeros([4**2, 4**2], dtype=int) coeff = np.zeros([4**2, 4**2], dtype=complex) row = 0 for i in range(4**2): column = 0 for j in range(4**2): Pnu = Opp2Str(Int2Bas(column, 4, 2)) Pmu = Opp2Str(Int2Bas(row, 4, 2)) A = Pmu[0] + Pnu[0] B = Pmu[1] + Pnu[1] A, intA = PPmunu(A) B, intB = PPmunu(B) index[i, j] = Bas2Int(Str2Opp(A + B), 4) coeff[i, j] = intA * intB column += 1 row += 1 # phi = psi # Store the energy for initial wavefunction e = np.matmul(Hamiltonian, phi) e = np.real(np.matmul(np.transpose(np.conj(phi)), e)) energy_qite_list.append(e) alist = [] print('We start QITE now') for i in range(0, N): # First construct Pmu_expectation matrices