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
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
def pauli_basis(nbit_): M = 4**nbit_ for i in range(M): print(i, Opp2Str(Int2Bas(i, 4, nbit_)))
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])
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))