Advanced Computing Platform for Theoretical Physics

commit大文件会使得服务器变得不稳定,请大家尽量只commit代码,不要commit大的文件。

Commit 94759d68 authored by Lei Wang's avatar Lei Wang
Browse files

eigensolver instead of matrix product

parent 10f2d290
......@@ -6,21 +6,23 @@ def vmps(T, d, D, no_iter, Nepochs=5):
A = torch.nn.Parameter(0.01*torch.randn(D, d, D, dtype=T.dtype, device=T.device))
def mpsrg(B, C):
lnZ1 = 0.0
lnZ2 = 0.0
for i in range(no_iter):
s = B.norm(1)
lnZ1 = lnZ1 + torch.log(s)/2**i
B = B/s
B = torch.mm(B, B)
w, _ = torch.symeig(B, eigenvectors=True)
lnZ1 = torch.log(w.abs().max())
w, _ = torch.symeig(C, eigenvectors=True)
lnZ2 = torch.log(w.abs().max())
s = C.norm(1)
lnZ2 = lnZ2 + torch.log(s)/2**i
C = C/s
C = torch.mm(C, C)
#lnZ1 = lnZ1 + torch.log(torch.trace(B))/2**no_iter
#lnZ2 = lnZ2 + torch.log(torch.trace(C))/2**no_iter
#print (torch.log(torch.trace(B))/2**no_iter, torch.log(torch.trace(C))/2**no_iter)
#lnZ1 = 0.0
#lnZ2 = 0.0
#for i in range(no_iter):
# s = B.norm(1)
# lnZ1 = lnZ1 + torch.log(s)/2**i
# B = B/s
# B = torch.mm(B, B)
# s = C.norm(1)
# lnZ2 = lnZ2 + torch.log(s)/2**i
# C = C/s
# C = torch.mm(C, C)
return lnZ1 , lnZ2
optimizer = torch.optim.LBFGS([A], max_iter=10)
......@@ -31,6 +33,7 @@ def vmps(T, d, D, no_iter, Nepochs=5):
B = torch.einsum('ldr,adcb,icj->lairbj', (Asymm, T, Asymm)).contiguous().view(D**2*d, D**2*d)
C = torch.einsum('ldr,idj->lirj', (Asymm, Asymm)).contiguous().view(D**2, D**2)
#print ('einsum', time.time()- t0)
#print ((B-B.t()).abs().sum(), (C-C.t()).abs().sum())
#t0 = time.time()
lnZ1, lnZ2= mpsrg(B, C)
......@@ -40,7 +43,7 @@ def vmps(T, d, D, no_iter, Nepochs=5):
print (' loss', loss.item(), lnZ1.item(), lnZ2.item())
#t0 = time.time()
loss.backward(retain_graph=True)
loss.backward(retain_graph=False)
#print ('backward', time.time()- t0)
return loss
......
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