Example #1
0
 def matvec(self, v):
     v_ = v.clone(
     )  # if don't clone, vectordot Tr in Lanczos_ER will not be rank-1
     psi_u = cytnx.UniTensor(v_, 0)  ## share memory, no copy
     psi_u.reshape_(*self.shapes)
     self.anet.PutUniTensor("psi", psi_u, False)
     out = self.anet.Launch(
         optimal=True).get_block_()  # get_block_ without copy
     out.flatten_()  # only change meta, without copy.
     return out
Example #2
0
    def matvec(self, psi):

        psi_p = cytnx.UniTensor(psi.clone(), 0)  ## clone here
        psi_p.reshape_(*self.psi_shape)

        self.anet.PutUniTensor("psi", psi_p,
                               False)  ## no- redundant clone here
        H_psi = self.anet.Launch(
            optimal=True).get_block_()  # get_block_ without copy

        H_psi.flatten_()
        return H_psi
Example #3
0
def Projector(psi, L, M1, M2, R):
    ''' psi is Tensor, while L,M1,M2,R are UniTensor.
    Return: h|psi> (Tensor)'''
    psi_p = cytnx.UniTensor(psi, 0)  ## share memory, no copy
    psi_p.reshape_(L.shape()[1], M1.shape()[2], M2.shape()[2], R.shape()[1])
    anet = cytnx.Network("projector.net")
    anet.PutUniTensor("M2", M2)
    anet.PutUniTensors(["psi", "L", "M1", "R"], [psi_p, L, M1, R], False)
    H_psi = anet.Launch(optimal=True).get_block_()  # get_block_ without copy
    H_psi.flatten_()  # only change meta, without copy.
    psi.flatten_()  ## this just in case psi is something shared.
    return H_psi
Example #4
0
#print(Sz,Sx)

## Build Evolution Operator
TFterm = cytnx.linalg.Kron(Sx,I) + cytnx.linalg.Kron(I,Sx)
ZZterm = cytnx.linalg.Kron(Sz,Sz)

H = Hx*TFterm + J*ZZterm 
del TFterm, ZZterm

eH = cytnx.linalg.ExpH(H,-dt) ## or equivantly ExpH(-dt*H)
eH.reshape_(2,2,2,2)
print(eH)
H.reshape_(2,2,2,2)

eH = cytnx.UniTensor(eH,2)
eH.print_diagram()
print(eH)


H = cytnx.UniTensor(H,2)
H.print_diagram()


## Create MPS:
#
#     |    |     
#   --A-la-B-lb-- 
#
A = cytnx.UniTensor([cytnx.Bond(chi),cytnx.Bond(2),cytnx.Bond(chi)],rowrank=1,labels=[-1,0,-2]); 
B = cytnx.UniTensor(A.bonds(),rowrank=1,labels=[-3,1,-4]);                                
Example #5
0
#     -------
#      ^   ^
#      0   1
#
TFterm = cytnx.linalg.Kron(Sx, I) + cytnx.linalg.Kron(I, Sx)
ZZterm = cytnx.linalg.Kron(Sz, Sz)

H = Hx * TFterm + J * ZZterm
del TFterm, ZZterm

eH = cytnx.linalg.ExpH(H, -dt)  ## or equivantly ExpH(-dt*H)
eH.reshape_(2, 2, 2, 2)
print(eH)
H.reshape_(2, 2, 2, 2)

eH = cytnx.UniTensor(eH, 2)
eH.tag()  # this will tag with in/out(ket/bra) on each bond.
eH.print_diagram()

H = cytnx.UniTensor(H, 2)
H.tag()
H.print_diagram()

## Create MPS, with bond tagged with direction in/out(ket/bra):
#     ^             ^
#     |             |
#  ->-A-> ->la->  ->B-> ->lb->
#
A = cytnx.UniTensor([
    cytnx.Bond(chi, cytnx.BD_KET),
    cytnx.Bond(2, cytnx.BD_BRA),
Example #6
0
## 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
#      |           |           |               |
#      1           3           5              2k+1
#
##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
A = [None for i in range(Nsites)]
A[0] = cytnx.UniTensor(cytnx.random.normal([1, d, min(chi, d)], 0., 1.), 2)
Example #7
0
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
Hdown = Hup.clone()

## Hamiltonain
Hu = cy.UniTensor(Hup, 3)
Hd = cy.UniTensor(Hdown, 3)

## create 3PESS:
s1 = cy.UniTensor(cy.random.normal([D, D, D], 0, 0.5), 0)
s2 = s1.clone()
A = cy.UniTensor(cy.random.normal([D, 2, D], 0, 0.5), 2)
B = cy.UniTensor(cy.random.normal([D, 2, D], 0, 0.5), 2)
C = cy.UniTensor(cy.random.normal([D, 2, D], 0, 0.5), 2)
Ls1 = [
    cy.UniTensor([cy.Bond(D), cy.Bond(D)], rowrank=1, is_diag=True)
    for i in range(3)
]
for i in Ls1:
    i.put_block(cy.ones(D))
Ls2 = [i.clone() for i in Ls1]
Example #8
0
W[1,1] = -np.sqrt(np.sinh(beta)) 

## Method-1 (faster): 
T = cLA.Kron(cLA.Kron(W[0],W[0]),cLA.Kron(W[0],W[0]))+\
    cLA.Kron(cLA.Kron(W[1],W[1]),cLA.Kron(W[1],W[1])) 
T.reshape_(2,2,2,2)

## Method-2 (slower in python):
#Tchk = cytnx.zeros([2,2,2,2])
#for i in range(2):
#    for j in range(2):
#        for k in range(2):
#            for l in range(2):
#                for a in range(2):
#                    Tchk[i,j,k,l] += W[a,i]*W[a,j]*W[a,k]*W[a,l]
cT = cytnx.UniTensor(T,2)


## Let's start by normalize the block with it's local partition function 
## to avoid the blow-up of partition function:
#
#         1
#         |  
#     0--cT--2
#         |
#         3
#
Nrm = cT.get_block().Trace(0,2).Trace(0,1).item()
cT/=Nrm

Example #9
0
print(Tn2a)
print(Tn3a)

##=============================
## Bond
##=============================
bd_in = cytnx.Bond(10, cytnx.bondType.BD_BRA)
print(bd_in)

bd_sym = cytnx.Bond(3,cytnx.bondType.BD_KET,\
                        [[0,2],[1,2],[1,3]],\
                        [cytnx.Symmetry.Zn(2),\
                         cytnx.Symmetry.U1()])
print(bd_sym)

print(bd_sym == bd_sym)
bd_1 = cytnx.Bond(3)
bd_2 = cytnx.Bond(2)
bd_3 = cytnx.Bond(4)

U = cytnx.UniTensor([bd_1, bd_2, bd_3], Rowrank=2, dtype=cytnx.Type.Double)
U.print_diagram()
U.permute_(0, 2, 1, Rowrank=1)
U.print_diagram()
print(U)
X = U[0, :, :]
X.print_diagram()

U.reshape_(6, -1)
U.print_diagram()
Example #10
0
#
#    [J]*SzSz + 2[Hx]*Sx
#
#
J = 1.0
Hx = 1.0

d = 2
sx = cytnx.physics.pauli('x').real()
sz = cytnx.physics.pauli('z').real()
eye = cytnx.eye(d)
M = cytnx.zeros([3, 3, d, d])
M[0, 0] = M[2, 2] = eye
M[0, 1] = M[1, 2] = sz
M[0, 2] = 2 * Hx * sx
M = cytnx.UniTensor(M, 0)

L0 = cytnx.UniTensor(cytnx.zeros([3, 1, 1]), 0)  #Left boundary
R0 = cytnx.UniTensor(cytnx.zeros([3, 1, 1]), 0)  #Right boundary
L0.get_block_()[0, 0, 0] = 1.
R0.get_block_()[2, 0, 0] = 1.

## Local Measurement Operator:
## Here, we consider a local measurement of energy.
H = J * cytnx.linalg.Kron(
    sz, sz) + Hx * (cytnx.linalg.Kron(sx, eye) + cytnx.linalg.Kron(eye, sx))
H = cytnx.UniTensor(H.reshape(2, 2, 2, 2), 2)

## Init the left and right enviroment
#
#   L[0]:       R[0]:
Example #11
0
##

#Example of 1D Heisenberg model
## iTEBD
##-------------------------------------

chi = 40
J = 1.0
CvgCrit = 1.0e-12
dt = 0.1

## Create Si Sj local H with symmetry:
## SzSz + S+S- + h.c.
bdi = cytnx.Bond(2, cytnx.BD_KET, [[1], [-1]])
bdo = bdi.clone().set_type(cytnx.BD_BRA)
H = cytnx.UniTensor([bdi, bdi, bdo, bdo], labels=[2, 3, 0, 1], rowrank=2)

## assign:
# Q = 2  # Q = 0:    # Q = -2:
# [1]    [[ -1, 1]     [1]
#         [  1,-1]]
H.get_block_([2])[0] = 1
T0 = H.get_block_([0])
T0[0, 0] = T0[1, 1] = -1
T0[0, 1] = T0[1, 0] = 1
H.get_block_([-2])[0] = 1

## create gate:
eH = cytnx.linalg.ExpH(H, -dt)

## Create MPS: