Advanced Computing Platform for Theoretical Physics

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

Commit b4485128 authored by Lei Wang's avatar Lei Wang
Browse files

add h in the ising tensor

parent c734f9b7
......@@ -3,6 +3,18 @@ from itertools import permutations
from adlib import SVD
svd = SVD.apply
def build_tensor(K, H):
c = torch.sqrt(torch.cosh(K))
s = torch.sqrt(torch.sinh(K))
Q = [c, s, c, -s]
Q = torch.stack(Q).view(2, 2)
M = [torch.exp(H), torch.exp(-H)]
M = torch.stack(M).view(2)
T = torch.einsum('a,ai,aj,ak,al->ijkl', (M, Q, Q, Q, Q))
return T
def ctmrg(T, d, Dcut, max_iter):
......@@ -71,14 +83,23 @@ def ctmrg(T, d, Dcut, max_iter):
if __name__=='__main__':
torch.set_num_threads(1)
K = torch.tensor([0.44], dtype=torch.float64)
Dcut = 180
max_iter = 1000
c = torch.sqrt(torch.cosh(K)/2.)
s = torch.sqrt(torch.sinh(K)/2.)
M = torch.stack([torch.cat([c+s, c-s]), torch.cat([c-s, c+s])])
T = torch.einsum('ai,aj,ak,al->ijkl', (M, M, M, M))
beta = 0.44
J = 1.0
h = 0.0
beta = torch.tensor(beta, dtype=torch.float64).requires_grad_()
h = torch.tensor(h, dtype=torch.float64).requires_grad_()
Dcut = 100
max_iter = 1000
T = build_tensor(beta*J, beta*h)
lnZ, error = ctmrg(T, 2, Dcut, max_iter)
print (lnZ.item(), error)
print (lnZ.item(), error.item())
dlnZ, = torch.autograd.grad(lnZ, h, create_graph=True)
dlnZ2, = torch.autograd.grad(dlnZ, h, create_graph=True)
print (dlnZ.item(), dlnZ2.item())
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