@@ -616,6 +616,12 @@ def calc_ctmrg_env(
616616 norm_smallest_S = jnp .nan
617617 already_tried_chi = {working_unitcell [0 , 0 ][0 ][0 ].chi }
618618
619+ best_chi = 0
620+ best_result = None
621+ best_norm_smallest_S = None
622+ best_truncation_eps = None
623+ have_been_increased = False
624+
619625 while True :
620626 tmp_count = 0
621627 corner_singular_vals = None
@@ -716,6 +722,14 @@ def calc_ctmrg_env(
716722 converged = False
717723 end_count = tmp_count
718724
725+ if converged and (
726+ working_unitcell [0 , 0 ][0 ][0 ].chi > best_chi or best_result is None
727+ ):
728+ best_chi = working_unitcell [0 , 0 ][0 ][0 ].chi
729+ best_result = working_unitcell
730+ best_norm_smallest_S = norm_smallest_S
731+ best_truncation_eps = varipeps_global_state .ctmrg_effective_truncation_eps
732+
719733 current_truncation_eps = (
720734 varipeps_config .ctmrg_truncation_eps
721735 if varipeps_global_state .ctmrg_effective_truncation_eps is None
@@ -747,11 +761,20 @@ def calc_ctmrg_env(
747761
748762 already_tried_chi .add (new_chi )
749763
764+ have_been_increased = True
765+
750766 continue
751- elif (
752- varipeps_config .ctmrg_heuristic_decrease_chi
753- and norm_smallest_S < current_truncation_eps
754- and working_unitcell [0 , 0 ][0 ][0 ].chi > 2
767+ elif varipeps_config .ctmrg_heuristic_decrease_chi and (
768+ (
769+ norm_smallest_S < current_truncation_eps
770+ and working_unitcell [0 , 0 ][0 ][0 ].chi > 2
771+ )
772+ or (
773+ not converged
774+ and not have_been_increased
775+ and norm_smallest_S
776+ < varipeps_config .ctmrg_heuristic_increase_chi_threshold
777+ )
755778 ):
756779 new_chi = (
757780 working_unitcell [0 , 0 ][0 ][0 ].chi
@@ -765,7 +788,7 @@ def calc_ctmrg_env(
765788
766789 if varipeps_config .ctmrg_print_steps :
767790 debug_print (
768- "CTMRG: Decreasing chi to {} since smallest SVD Norm was {}." ,
791+ "CTMRG: Decreasing chi to {} since smallest SVD Norm was {} or routine did not converge ." ,
769792 new_chi ,
770793 norm_smallest_S ,
771794 )
@@ -803,8 +826,15 @@ def calc_ctmrg_env(
803826
804827 if _return_truncation_eps :
805828 last_truncation_eps = varipeps_global_state .ctmrg_effective_truncation_eps
829+
806830 varipeps_global_state .ctmrg_effective_truncation_eps = None
807831
832+ if not converged and best_result is not None :
833+ working_unitcell = best_result
834+ norm_smallest_S = best_norm_smallest_S
835+ converged = True
836+ last_truncation_eps = best_truncation_eps
837+
808838 if (
809839 varipeps_config .ctmrg_fail_if_not_converged
810840 and end_count == varipeps_config .ctmrg_max_steps
0 commit comments