Skip to content

Commit cd3bcba

Browse files
committed
fixed issues reported by Leo
1 parent 2781dbc commit cd3bcba

16 files changed

+21
-17
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*~
22
__pycache__
33
.DS_Store
4+
data

ising.py 1_ising_TRG/ising.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import sys
2+
sys.path.insert(0, '../')
13
import torch
24
import numpy as np
35

4-
from rg import TRG
6+
from tensornets import TRG
57

68
def build_tensor(K):
79
lam = [torch.cosh(K)*2, torch.sinh(K)*2]
@@ -20,7 +22,7 @@ def build_tensor(K):
2022
if __name__=="__main__":
2123
import argparse
2224
parser = argparse.ArgumentParser(description='')
23-
parser.add_argument("-chi", type=int, default=24, help="chi")
25+
parser.add_argument("-chi", type=int, default=16, help="chi")
2426
parser.add_argument("-Niter", type=int, default=20, help="Niter")
2527
parser.add_argument("-use_checkpoint", action='store_true', help="use checkpoint")
2628
parser.add_argument("-float32", action='store_true', help="use float32")
File renamed without changes.

ipeps.py 2_variational_iPEPS/ipeps.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import sys
2+
sys.path.insert(0, '../')
3+
14
import torch
25
import time
3-
from rg import CTMRG
6+
from tensornets import CTMRG
47
from measure import get_obs
58
from utils import symmetrize
69
from args import args
File renamed without changes.

utils.py 2_variational_iPEPS/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def save_checkpoint(checkpoint_path, model, optimizer):
3838
'optimizer' : optimizer.state_dict()}
3939
#print(model.state_dict().keys())
4040
torch.save(state, checkpoint_path)
41-
print('model saved to %s' % checkpoint_path)
41+
#print('model saved to %s' % checkpoint_path)
4242

4343
def load_checkpoint(checkpoint_path, args, model):
4444
print( 'load old model from %s ' % checkpoint_path )

main.py 2_variational_iPEPS/variational.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'''
22
Variational PEPS with automatic differentiation and GPU support
33
'''
4+
45
import io
56
import torch
67
import numpy as np
@@ -68,18 +69,19 @@
6869
Mpx = kron(sx, id2)
6970
Mpy = kron(sy, id2)
7071
Mpz = kron(sz, id2)
71-
print (H)
7272
else:
7373
print ('what model???')
7474
sys.exit(1)
7575

76+
print ('Hamiltonian:\n', H)
77+
7678
def closure():
7779
optimizer.zero_grad()
7880
start = time.time()
7981
loss, Mx, My, Mz = model.forward(H, Mpx, Mpy, Mpz, args.chi)
8082
forward = time.time()
8183
loss.backward()
82-
print (model.A.norm().item(), model.A.grad.norm().item(), loss.item(), Mx.item(), My.item(), Mz.item(), torch.sqrt(Mx**2+My**2+Mz**2).item(), forward-start, time.time()-forward)
84+
#print (model.A.norm().item(), model.A.grad.norm().item(), loss.item(), Mx.item(), My.item(), Mz.item(), torch.sqrt(Mx**2+My**2+Mz**2).item(), forward-start, time.time()-forward)
8385
return loss
8486

8587
with io.open(key+'.log', 'a', buffering=1, newline='\n') as logfile:
@@ -91,6 +93,6 @@ def closure():
9193
with torch.no_grad():
9294
En, Mx, My, Mz = model.forward(H, Mpx, Mpy, Mpz, args.chi if args.chi_obs is None else args.chi_obs)
9395
Mg = torch.sqrt(Mx**2+My**2+Mz**2)
94-
message = ('{} ' + 5*'{:.16f} ').format(epoch, En, Mx, My, Mz, Mg)
96+
message = ('{} ' + 5*'{:.5f} ').format(epoch, En, Mx, My, Mz, Mg)
9597
print ('epoch, En, Mx, My, Mz, Mg', message)
9698
logfile.write(message + u'\n')

README.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Run this to compute the energy and specific heat of a 2D classical Ising model b
1212

1313

1414
```bash
15+
$ cd 1_ising_TRG
1516
$ python ising.py
1617
```
1718

@@ -23,20 +24,15 @@ Run this to optimize an iPEPS wavefuntion for 2D quantum Heisenberg model. Here,
2324

2425

2526
```bash
26-
$ python main.py -D 3 -chi 30
27+
$ cd 2_variational_iPEPS
28+
$ python variational.py -D 3 -chi 30
2729
```
2830

29-
In case of a question, can type `python main.py -h`. It is also possible to supply your own Hamiltonian and measure other physical observables of interests.
31+
In case of a question, you can type `python variational.py -h`. To make use GPU, you can add `-cuda <GPUID>`. It is also possible to supply Hamiltonian of your own interests.
3032

3133
### What is under the hood ?
3234

33-
Reverse mode AD computes gradient accurately and efficiently for you! Check the codes in [adlib](https://github.com/wangleiphy/tensorgrad/tree/master/rg/adlib) for backward functions which propagate gradients through tensor network contractions.
34-
35-
36-
37-
### Explore more
38-
39-
See [link]() for a Julia implementation
35+
Reverse mode AD computes gradient accurately and efficiently for you! Check the codes in [adlib](https://github.com/wangleiphy/tensorgrad/tree/master/tensornets/adlib) for backward functions which propagate gradients through tensor network contractions.
4036

4137

4238

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

rg/ctmrg.py tensornets/ctmrg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def CTMRG(T, chi, max_iter, use_checkpoint=False):
8383
if (diff < threshold):
8484
break
8585
sold = s
86-
print ('ctmrg iterations, diff, error', n, diff, truncation_error/n)
86+
#print ('ctmrg converged at iterations %d to %.5e, truncation error: %.5f'%(n, diff, truncation_error/n))
8787

8888
return C, E
8989

rg/trg.py tensornets/trg.py

File renamed without changes.

0 commit comments

Comments
 (0)