def Get_spin_operators(spin): #Returns tuple of 3 spin operators and a unit matrix for given value of spin. s = int(spin.split('/')[0]) / int(spin.split('/')[1]) if ( '/' in spin) else int(spin) d = int(2 * s + 1) return cytnx.physics.spin(s, 'x'), cytnx.physics.spin( s, 'y'), cytnx.physics.spin(s, 'z'), cytnx.eye(d).astype( cytnx.Type.ComplexDouble)
def Create_loop_gas_operator(spin): """Returns loop gas (LG) operator Q_LG for spin=1/2 or spin=1 Kitaev model.""" tau_tensor = cytnx.zeros( (2, 2, 2), dtype=cytnx.Type.ComplexDouble) # tau_tensor_{i j k} if '/' in spin: tau_tensor[0, 0, 0] = -1j else: tau_tensor[0, 0, 0] = 1 tau_tensor[0, 1, 1] = tau_tensor[1, 0, 1] = tau_tensor[1, 1, 0] = 1 sx, sy, sz, one = Get_spin_operators(spin) d = one.shape()[0] Q_LG = cytnx.zeros((d, d, 2, 2, 2), dtype=cytnx.Type.ComplexDouble) # Q_LG_{s s' i j k} u_gamma = None if '/' in spin: u_gamma = list( map(lambda x: -1j * cytnx.linalg.ExpM(1j * np.pi * x), (sx, sy, sz))) else: u_gamma = list( map(lambda x: cytnx.linalg.ExpM(1j * np.pi * x), (sx, sy, sz))) for i in range(2): for j in range(2): for k in range(2): temp = cytnx.eye(d) if i == 0: temp = cytnx.linalg.Matmul(temp, u_gamma[0]) if j == 0: temp = cytnx.linalg.Matmul(temp, u_gamma[1]) if k == 0: temp = cytnx.linalg.Matmul(temp, u_gamma[2]) for s in range(d): for sp in range(d): Q_LG[s, sp, i, j, k] = tau_tensor[i, j, k] * temp[s, sp] return Q_LG
chi = 32 Nsites = 20 numsweeps = 4 # number of DMRG sweeps maxit = 2 # iterations of Lanczos method krydim = 4 # dimension of Krylov subspace ## Initialiaze MPO ##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> d = 2 s = 0.5 sx = cytnx.physics.spin(0.5, 'x') sy = cytnx.physics.spin(0.5, 'y') sp = sx + 1j * sy sm = sx - 1j * sy eye = cytnx.eye(d) M = cytnx.zeros([4, 4, d, d]) M[0, 0] = M[3, 3] = eye M[0, 1] = M[2, 3] = 2**0.5 * sp.real() M[0, 2] = M[1, 3] = 2**0.5 * sm.real() M = cytnx.UniTensor(M, 0) L0 = cytnx.UniTensor(cytnx.zeros([4, 1, 1]), 0) #Left boundary R0 = cytnx.UniTensor(cytnx.zeros([4, 1, 1]), 0) #Right boundary L0.get_block_()[0, 0, 0] = 1. R0.get_block_()[3, 0, 0] = 1. ## Init MPS train # # 0-A[0]-2 2-A[1]-4 4-A[2]-6 ... 2k-A[k]-2k+2 # | | | |
OPTS_numsweeps = 6 # number of DMRG sweeps OPTS_dispon = 1 # level of output display OPTS_updateon = True # level of output display OPTS_maxit = 2 # iterations of Lanczos method OPTS_krydim = 4 # dimension of Krylov subspace ''' ########## Initialiaze MPO (quantum XX model) and random MPS ########## ''' d = 2 s = 0.5 sx = cytnx.physics.spin(0.5, 'x') sy = cytnx.physics.spin(0.5, 'y') sz = cytnx.physics.spin(0.5, 'y') sp = sx + 1j * sy sm = sx - 1j * sy eye = cytnx.eye(d).astype(cytnx.Type.ComplexDouble) if model == 'XX': W = cytnx.zeros([4, 4, d, d]).astype(cytnx.Type.ComplexDouble) W[0, 0, :, :] = W[3, 3, :, :] = eye W[0, 1, :, :] = W[2, 3, :, :] = 2**0.5 * sp W[0, 2, :, :] = W[1, 3, :, :] = 2**0.5 * sm WL = cytnx.zeros([4, 1, 1]).astype(cytnx.Type.ComplexDouble) WR = cytnx.zeros([4, 1, 1]).astype(cytnx.Type.ComplexDouble) WL[0, 0, 0] = 1. WR[3, 0, 0] = 1. if model == 'Ising': W = cytnx.zeros([3, 3, d, d]).astype(cytnx.Type.ComplexDouble) W[0, 0, :, :] = W[2, 2, :, :] = eye W[0, 1, :, :] = sx * 2 W[0, 2, :, :] = -1.0 * (sz * 2) ## g W[1, 2, :, :] = sx * 2
out = A.clone() b = out.get_block_() for i in range(b.shape()[0]): if (b[i].item() < clip): b[i] = 0 else: b[i] = 1. / b[i] return out ## create opeartor: Sz = cy.physics.spin(0.5, 'z') Sx = cy.physics.spin(0.5, 'x') Sy = cy.physics.spin(0.5, 'y') I = cy.eye(2) H = cy.linalg.Kron(Sz, Sz) + cy.linalg.Kron(Sx, Sx) + cy.linalg.Kron(Sy, Sy) H = H.real() # since it's real ,let's truncate imag part. H = cy.linalg.Kron(H, I) H.reshape_(2, 2, 2, 2, 2, 2) H = H + H.permute(0, 2, 1, 3, 5, 4) + H.permute(2, 0, 1, 5, 3, 4) ################### tau = 1.0 D = 3 maxit = 1000 # Here, we explicitly seperate up/down # which is the same in this model, but in general they could be different Hup = H