@@ -597,6 +597,12 @@ def random_noise(a):
597
597
)
598
598
and random_noise_retries
599
599
< varipeps_config .optimizer_random_noise_max_retries
600
+ and not (
601
+ varipeps_config .optimizer_preconverge_with_half_projectors
602
+ and not varipeps_global_state .basinhopping_disable_half_projector
603
+ and varipeps_global_state .ctmrg_projector_method
604
+ is Projector_Method .HALF
605
+ )
600
606
):
601
607
tqdm .write (
602
608
"Convergence is not sufficient. Retry with some random noise on best result."
@@ -685,6 +691,33 @@ def random_noise(a):
685
691
working_unitcell .get_unique_tensors ()[0 ].chi
686
692
)
687
693
694
+ if (
695
+ varipeps_config .optimizer_preconverge_with_half_projectors
696
+ and not varipeps_global_state .basinhopping_disable_half_projector
697
+ and varipeps_global_state .ctmrg_projector_method
698
+ is Projector_Method .HALF
699
+ and conv
700
+ < varipeps_config .optimizer_preconverge_with_half_projectors_eps
701
+ ):
702
+ varipeps_global_state .ctmrg_projector_method = (
703
+ varipeps_config .ctmrg_full_projector_method
704
+ )
705
+
706
+ working_value , (working_unitcell , max_trunc_error ) = (
707
+ calc_ctmrg_expectation (
708
+ working_tensors ,
709
+ working_unitcell ,
710
+ expectation_func ,
711
+ convert_to_unitcell_func ,
712
+ additional_input ,
713
+ enforce_elementwise_convergence = varipeps_config .ad_use_custom_vjp ,
714
+ )
715
+ )
716
+ descent_dir = None
717
+ working_gradient = None
718
+ signal_reset_descent_dir = True
719
+ conv = jnp .inf
720
+
688
721
if conv < varipeps_config .optimizer_convergence_eps :
689
722
working_value , (
690
723
working_unitcell ,
@@ -697,7 +730,6 @@ def random_noise(a):
697
730
additional_input ,
698
731
enforce_elementwise_convergence = varipeps_config .ad_use_custom_vjp ,
699
732
)
700
- varipeps_global_state .ctmrg_projector_method = None
701
733
702
734
try :
703
735
max_trunc_error_list [random_noise_retries ][- 1 ] = max_trunc_error
@@ -711,28 +743,6 @@ def random_noise(a):
711
743
712
744
break
713
745
714
- if (
715
- varipeps_config .optimizer_preconverge_with_half_projectors
716
- and not varipeps_global_state .basinhopping_disable_half_projector
717
- and conv
718
- < varipeps_config .optimizer_preconverge_with_half_projectors_eps
719
- ):
720
- varipeps_global_state .ctmrg_projector_method = (
721
- varipeps_config .ctmrg_full_projector_method
722
- )
723
-
724
- working_value , working_unitcell , _ = calc_ctmrg_expectation (
725
- working_tensors ,
726
- working_unitcell ,
727
- expectation_func ,
728
- convert_to_unitcell_func ,
729
- additional_input ,
730
- enforce_elementwise_convergence = varipeps_config .ad_use_custom_vjp ,
731
- )
732
- descent_dir = None
733
- working_gradient = None
734
- signal_reset_descent_dir = True
735
-
736
746
old_descent_dir = descent_dir
737
747
old_gradient = working_gradient
738
748
@@ -768,7 +778,12 @@ def random_noise(a):
768
778
additional_input ,
769
779
)
770
780
771
- if working_value < best_value :
781
+ if working_value < best_value and not (
782
+ varipeps_config .optimizer_preconverge_with_half_projectors
783
+ and not varipeps_global_state .basinhopping_disable_half_projector
784
+ and varipeps_global_state .ctmrg_projector_method
785
+ is Projector_Method .HALF
786
+ ):
772
787
_autosave_wrapper (
773
788
autosave_func ,
774
789
autosave_filename ,
@@ -786,7 +801,12 @@ def random_noise(a):
786
801
additional_input ,
787
802
)
788
803
789
- if working_value < best_value :
804
+ if working_value < best_value and not (
805
+ varipeps_config .optimizer_preconverge_with_half_projectors
806
+ and not varipeps_global_state .basinhopping_disable_half_projector
807
+ and varipeps_global_state .ctmrg_projector_method
808
+ is Projector_Method .HALF
809
+ ):
790
810
best_value = working_value
791
811
best_tensors = working_tensors
792
812
best_unitcell = working_unitcell
@@ -798,22 +818,29 @@ def random_noise(a):
798
818
best_unitcell = working_unitcell
799
819
best_run = random_noise_retries
800
820
801
- _autosave_wrapper (
802
- autosave_func ,
803
- autosave_filename ,
804
- working_tensors ,
805
- working_unitcell ,
806
- working_value ,
807
- "best" ,
808
- best_run ,
809
- max_trunc_error_list ,
810
- step_energies ,
811
- step_chi ,
812
- step_conv ,
813
- step_runtime ,
814
- spiral_indices ,
815
- additional_input ,
816
- )
821
+ if not (
822
+ varipeps_config .optimizer_preconverge_with_half_projectors
823
+ and not varipeps_global_state .basinhopping_disable_half_projector
824
+ and varipeps_global_state .ctmrg_projector_method is Projector_Method .HALF
825
+ ):
826
+ _autosave_wrapper (
827
+ autosave_func ,
828
+ autosave_filename ,
829
+ working_tensors ,
830
+ working_unitcell ,
831
+ working_value ,
832
+ "best" ,
833
+ best_run ,
834
+ max_trunc_error_list ,
835
+ step_energies ,
836
+ step_chi ,
837
+ step_conv ,
838
+ step_runtime ,
839
+ spiral_indices ,
840
+ additional_input ,
841
+ )
842
+
843
+ varipeps_global_state .ctmrg_projector_method = None
817
844
818
845
print (f"Best energy result found: { best_value } " )
819
846
0 commit comments