Advanced Computing Platform for Theoretical Physics

Commit 9fa4665f authored by Lei Wang's avatar Lei Wang
Browse files

fix gauge of P, and use krylov solver

parent b202c35b
......@@ -18,16 +18,19 @@ def step(T, x, chi):
Rho = Rho/Rho.norm()
# step 2: Get Isometry P
#U, S, V = torch.svd(Rho)
#truncation_error = S[D_new:].sum()/S.sum()
#P = U[:, :D_new] # projection operator
U, S, V = torch.svd(Rho)
truncation_error = S[D_new:].sum()/S.sum()
P = U[:, :D_new] # projection operator
#can also do symeig since Rho is symmetric
S, U = torch.symeig(Rho, eigenvectors=True)
sorted, indices = torch.sort(S.abs(), descending=True)
truncation_error = sorted[D_new:].sum()/sorted.sum()
S = S[indices][:D_new]
P = U[:, indices][:, :D_new] # projection operator
#S, U = torch.symeig(Rho, eigenvectors=True)
#sorted, indices = torch.sort(S.abs(), descending=True)
#truncation_error = sorted[D_new:].sum()/sorted.sum()
#S = S[indices][:D_new]
#P = U[:, indices][:, :D_new] # projection operator
#fix gauge, first row should be positive
P = P*P[0, :].sign()
# step 3: renormalize C and E
C = (P.t() @ Rho @ P) #C(D_new, D_new)
......@@ -40,11 +43,6 @@ def step(T, x, chi):
# step 4: symmetrize C and E
C = 0.5*(C+C.t())
#trying to fix gauge of E tensor
s = E[:, 1, 0].sign()
E = (s[:, None]*E.view(chi, -1)).view(-1, chi)*s
E = E.view(chi, d, chi)
E = 0.5*(E + E.permute(2, 1, 0))
C = C.view(-1)/C.norm()
......@@ -59,18 +57,15 @@ class CTMRG(torch.autograd.Function):
diff = 1E10
for n in range(maxiter):
x_star = step(T, x, chi)
diff = (x_star- x).abs().max()
#diff1 = torch.dist(x_star[:D**2], x[:D**2])
#diff2 = torch.dist(x_star[D**2:], x[D**2:])
#print (diff1.item(), diff2.item())
diff1 = torch.dist(x_star[:chi**2], x[:chi**2])
diff2 = torch.dist(x_star[chi**2:], x[chi**2:])
print (n, diff1.item(), diff2.item())
#idx = torch.argmax( (x_star[D**2:] - x[D**2:]).abs())
#print ('diff', (x_star[D**2:][idx]+ x[D**2:][idx]).item() )
print (n, diff.item())
if (diff < tol):
break
else:
x = x_star
print ('forward converged to', n, diff.item())
ctx.save_for_backward(T, x_star)
return x_star
......@@ -97,7 +92,7 @@ if __name__=='__main__':
import time
torch.manual_seed(42)
d = 2
chi = 50
chi = 20
device = 'cpu'
dtype = torch.float64
......@@ -122,9 +117,9 @@ if __name__=='__main__':
x = ctmrg(T, x, chi, 100)
def fun(x):
return step(T, x, chi).numpy() -x
return step(T, x, chi).numpy() - x
from scipy import optimize
sol = optimize.root(fun, x.numpy(), method='anderson', options={'fatol':1E-10})
sol = optimize.root(fun, x.numpy(), method='krylov', options={'fatol':1E-10, 'disp': True})
print (sol)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment