Skip to content

Commit d5ed50c

Browse files
committed
Add feature for overlaps to check if only the exp value converges
1 parent 9f5a63f commit d5ed50c

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

varipeps/overlap/overlap.py

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import jax.numpy as jnp
22

3-
from varipeps.ctmrg import calc_ctmrg_env
3+
from varipeps import varipeps_config
4+
from varipeps.ctmrg import calc_ctmrg_env, CTMRGNotConvergedError
45
from varipeps.peps import PEPS_Unit_Cell
56

67
from . import overlap_single_site
@@ -12,7 +13,9 @@
1213
}
1314

1415

15-
def calculate_overlap(unitcell_A, unitcell_B, chi, max_chi):
16+
def calculate_overlap(
17+
unitcell_A, unitcell_B, chi, max_chi, *, test_automatic_overlap_conv=True
18+
):
1619
structure_A = tuple(tuple(i) for i in unitcell_A.data.structure)
1720
structure_B = tuple(tuple(i) for i in unitcell_B.data.structure)
1821

@@ -43,10 +46,40 @@ def calculate_overlap(unitcell_A, unitcell_B, chi, max_chi):
4346

4447
overlap_unitcell = PEPS_Unit_Cell.from_tensor_list(overlap_tensors, structure_A)
4548

46-
overlap_unitcell, _ = calc_ctmrg_env(
47-
[i.tensor for i in overlap_tensors], overlap_unitcell
48-
)
49+
if test_automatic_overlap_conv:
50+
tmp_max_steps = varipeps_config.ctmrg_max_steps
51+
tmp_fail = varipeps_config.ctmrg_fail_if_not_converged
4952

50-
overlap_AB = overlap_func(overlap_unitcell)
53+
varipeps_config.ctmrg_fail_if_not_converged = False
54+
varipeps_config.ctmrg_max_steps = 10
55+
56+
overlap_unitcell, _ = calc_ctmrg_env(
57+
[i.tensor for i in overlap_tensors], overlap_unitcell
58+
)
59+
overlap_AB = overlap_func(overlap_unitcell)
60+
61+
for count in range(tmp_max_steps):
62+
old_overlap_AB = overlap_AB
63+
64+
overlap_unitcell, _ = calc_ctmrg_env(
65+
[i.tensor for i in overlap_tensors], overlap_unitcell
66+
)
67+
overlap_AB = overlap_func(overlap_unitcell)
68+
69+
if (
70+
jnp.abs(overlap_AB - old_overlap_AB)
71+
<= varipeps_config.ctmrg_convergence_eps
72+
):
73+
varipeps_config.ctmrg_fail_if_not_converged = tmp_fail
74+
varipeps_config.ctmrg_max_steps = tmp_max_steps
75+
break
76+
if count == (tmp_max_steps - 1):
77+
raise CTMRGNotConvergedError
78+
else:
79+
overlap_unitcell, _ = calc_ctmrg_env(
80+
[i.tensor for i in overlap_tensors], overlap_unitcell
81+
)
82+
83+
overlap_AB = overlap_func(overlap_unitcell)
5184

5285
return overlap_AB

0 commit comments

Comments
 (0)