Ejemplo n.º 1
0
def pauli_action(active_, nbit_, verbose=False):
    nact = len(active_)
    N = 2**nbit_
    M = 4**nact
    dot = [2**(nbit_ - 1 - i) for i in range(nbit_)]
    ind_sx = np.zeros((M, N), dtype=int)
    gmm_sx = np.zeros((M, N), dtype=complex) + 1

    svec = np.zeros((M, nbit_), dtype=int)
    for mu in range(M):
        svec[mu, active_] = Int2Bas(mu, 4, nact)

    sxyvec = d12f(svec)
    nyvec = d2f(svec)
    syzvec = d23f(svec)
    nyvec = np.einsum('ab->a', nyvec)

    xvec = np.zeros((N, nbit_), dtype=int)
    for xi in range(N):
        xvec[xi, :] = np.asarray(Int2Bas(xi, 2, nbit_))

    gmm_sx = np.einsum('am,bm->ba', xvec, syzvec) + 0j
    gmm_sx[:, :] = (-1)**gmm_sx[:, :]

    for mu in range(M):
        gmm_sx[mu, :] *= 1j**nyvec[mu]
        yvec = (xvec[:, :] + sxyvec[mu, :]) % 2
        ind_sx[mu, :] = np.einsum('a,ba->b', dot, yvec)

    return ind_sx, gmm_sx
Ejemplo n.º 2
0
def RTE(H_, dT, Tmax, lanczos=False, psi0=None):
    # --- diagonalization ---
    N = H_[0][2].shape[1]
    nbit = int(np.log2(N))
    hdiag = np.zeros(N, dtype=complex)
    ei = np.zeros(N, dtype=complex)
    for i in range(N):
        xi = Int2Bas(i, 2, nbit)
        for (A, h, imp, gmp) in H_:
            nact = len(A)
            for m in np.where(np.abs(h) > 1e-8)[0]:
                sm = Int2Bas(m, 4, nact)
                #print A,sm,[xi[A[i]] for i in range(nact)]
                smx = [
                    sigma_matrices[xi[A[w]], xi[A[w]], sm[w]]
                    for w in range(nact)
                ]
                hdiag[i] += h[m] * np.prod(smx)
        if (i % 1000 == 0): print i, N, hdiag[i]

    precond = lambda x, e, *args: x / (hdiag - e + 1e-4)

    def hop(c_):
        return Hpsi(H_, c_)

    epsm0, Um0 = davidson(hop, psi0, precond)

    fout = open('RTE_davidson.out', 'w')
    fout.write("gs energy %.6f \n" % epsm0)

    # --- initial state ---
    if (psi0 is None):
        i0 = np.argmin(hdiag)
        psi0 = np.zeros(N, dtype=complex)
        psi0[i0] = 1.0

    # --- real-time evolution ---
    bra_RTE = psi0[:]
    braH_RTE = Hpsi(H_, psi0[:])[:]
    ket_RTE = psi0[:]

    nbeta = int(Tmax / dT) + 1
    hvect_LANZ = np.zeros(nbeta + 1, dtype=complex)
    svect_LANZ = np.zeros(nbeta + 1, dtype=complex)

    fout.write("ITE\n")
    for ib in range(nbeta):
        hvect_LANZ[ib] = np.einsum('a,a', np.conj(braH_RTE), ket_RTE)
        svect_LANZ[ib] = np.einsum('a,a', np.conj(bra_RTE), ket_RTE)
        ket_RTE = ExpitH(H_, ket_RTE, dT)[0]
        print ib, hvect_LANZ[ib]

    dump_lanz_rte(hvect_LANZ[:nbeta], svect_LANZ[:nbeta], 'qlanz.vecs')

    fout.close()
Ejemplo n.º 3
0
def Hii(H_,i):
 N     = H_[0][2].shape[1]
 nbit  = int(np.log2(N))
 hii = 0.0
 xi  = Int2Bas(i,2,nbit)
 for (A,h,imp,gmp) in H_:
  nact = len(A)
  for m in np.where(np.abs(h)>1e-8)[0]:
   sm   = Int2Bas(m,4,nact)
   smx  = [ sigma_matrices[xi[A[w]],xi[A[w]],sm[w]] for w in range(nact)]
   hii += np.real(h[m]*np.prod(smx))
 return hii
Ejemplo n.º 4
0
def print_state(psi_, nbit, outf):
    for i in range(psi_.shape[0]):
        if (np.abs(psi_[i]) > 1e-4):
            for x in Int2Bas(i, 2, nbit):
                outf.write(str(x))
            outf.write(" %.12f %.12f I \n" %
                       (np.real(psi_[i]), np.imag(psi_[i])))
Ejemplo n.º 5
0
def hom_mf_state(theta_, nbit_):
    chi = np.zeros(2)
    chi[0] = np.cos(theta_)
    chi[1] = np.sin(theta_)
    N = 2**nbit_
    phi = np.zeros(N, dtype=complex)
    for i in range(N):
        x = Int2Bas(i, 2, nbit_)
        phi[i] = np.prod([chi[x[k]] for k in range(nbit_)])
    return phi
Ejemplo n.º 6
0
def print_Hamiltonian(H_):
 mu = 0
 for (A,h,imp,gmp) in H_:
  nact = len(A)
  print "term ",mu
  print "active qubits ",A
  print "operators: "
  for m in np.where(np.abs(h)>1e-8)[0]:
   print Opp2Str(Int2Bas(m,4,nact)),h[m]
  mu += 1
Ejemplo n.º 7
0
def print_Hamiltonian(H_):
    mu = 0

    for (A, h, imp, gmp) in H_:
        #print('A: ',A)
        nact = len(A)
        print("active qubits ", A)
        print("operators: ")
        for m in np.where(np.abs(h) > 1e-8)[0]:
            print(Opp2Str(Int2Bas(m, 4, nact)), h[m])
        mu += 1
Ejemplo n.º 8
0
def hom_mf_energy(theta, nbit, H_):
    chi = np.zeros(2)
    chi[0] = np.cos(theta)
    chi[1] = np.sin(theta)
    xjm = np.einsum('a,abc,b->c', chi, sigma_matrices, chi)
    xjm = np.real(xjm)
    ea = 0.0
    for (A, h, imp, gmp) in H_:
        nact = len(A)
        for m in np.where(np.abs(h) > 1e-8)[0]:
            xm = Int2Bas(m, 4, nact)
            ea += h[m] * np.prod([xjm[xm[k]] for k in range(nact)])
    return ea
Ejemplo n.º 9
0
def mf_state(theta_):
    nbit = theta_.shape[0]
    chi = np.zeros((nbit, 2))
    for i in range(nbit):
        chi[i, 0] = np.cos(theta_[i])
        chi[i, 1] = np.sin(theta_[i])
    # -----
    N = 2**nbit
    phi = np.zeros(N, dtype=complex)
    for i in range(N):
        x = Int2Bas(i, 2, nbit)
        phi[i] = np.prod([chi[k, x[k]] for k in range(nbit)])
    # -----
    return phi
Ejemplo n.º 10
0
def mf_energy(theta_, H_):
    nbit = theta_.shape[0]
    chi = np.zeros((nbit, 2))
    for i in range(nbit):
        chi[i, 0] = np.cos(theta_[i])
        chi[i, 1] = np.sin(theta_[i])
    # -----
    xjm = np.einsum('ja,abc,jb->jc', chi, sigma_matrices, chi)
    xjm = np.real(xjm)
    ea = 0.0
    for (A, h, imp, gmp) in H_:
        nact = len(A)
        for m in np.where(np.abs(h) > 1e-8)[0]:
            xm = Int2Bas(m, 4, nact)
            ea += h[m] * np.prod([xjm[A[k], xm[k]] for k in range(nact)])
    return ea
Ejemplo n.º 11
0
def pauli_basis(nbit_):
    M = 4**nbit_
    for i in range(M):
        print(i, Opp2Str(Int2Bas(i, 4, nbit_)))
Ejemplo n.º 12
0
def computational_basis(nbit_):
    N = 2**nbit_
    for i in range(N):
        print(i, Psi2Str(Int2Bas(i, 2, nbit_)))
Ejemplo n.º 13
0
    elif Oppstr == "ZX":
        return "Y", 1j
    elif Oppstr == "ZY":
        return "X", -1j
    elif Oppstr == "ZZ":
        return "I", 1
    else:
        raise ValueError


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)


if __name__ == '__main__':
    n = 2
    index = np.zeros([4**n, 4**n], dtype=int)
    coeff = np.zeros([4**n, 4**n], dtype=complex)
    for i in range(4**n):
        for j in range(4**n):
            coeff[i, j], index[i, j] = lie_algebra(Opp2Str(Int2Bas(i, 4, n)),
                                                   Opp2Str(Int2Bas(j, 4, n)),
                                                   n)
            print(i, j, index[i, j])
Ejemplo n.º 14
0
    e = np.matmul(Hamiltonian, phi)
    e = np.real(np.matmul(np.transpose(np.conj(phi)), e))
    energy_classical_list.append(e)
print('Final energy at beta', beta, 'is ', e)

# Qite approximation

# 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))