@@ -597,6 +597,12 @@ def random_noise(a):
597597 )
598598 and random_noise_retries
599599 < 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+ )
600606 ):
601607 tqdm .write (
602608 "Convergence is not sufficient. Retry with some random noise on best result."
@@ -685,6 +691,33 @@ def random_noise(a):
685691 working_unitcell .get_unique_tensors ()[0 ].chi
686692 )
687693
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+
688721 if conv < varipeps_config .optimizer_convergence_eps :
689722 working_value , (
690723 working_unitcell ,
@@ -697,7 +730,6 @@ def random_noise(a):
697730 additional_input ,
698731 enforce_elementwise_convergence = varipeps_config .ad_use_custom_vjp ,
699732 )
700- varipeps_global_state .ctmrg_projector_method = None
701733
702734 try :
703735 max_trunc_error_list [random_noise_retries ][- 1 ] = max_trunc_error
@@ -711,28 +743,6 @@ def random_noise(a):
711743
712744 break
713745
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-
736746 old_descent_dir = descent_dir
737747 old_gradient = working_gradient
738748
@@ -768,7 +778,12 @@ def random_noise(a):
768778 additional_input ,
769779 )
770780
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+ ):
772787 _autosave_wrapper (
773788 autosave_func ,
774789 autosave_filename ,
@@ -786,7 +801,12 @@ def random_noise(a):
786801 additional_input ,
787802 )
788803
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+ ):
790810 best_value = working_value
791811 best_tensors = working_tensors
792812 best_unitcell = working_unitcell
@@ -798,22 +818,29 @@ def random_noise(a):
798818 best_unitcell = working_unitcell
799819 best_run = random_noise_retries
800820
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
817844
818845 print (f"Best energy result found: { best_value } " )
819846
0 commit comments