Skip to content

Commit 3045001

Browse files
fixes to the logger implementation
1 parent 78db0fc commit 3045001

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

varipeps/ctmrg/routine.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -724,11 +724,17 @@ def calc_ctmrg_env(
724724
else:
725725
converged = False
726726
end_count = tmp_count
727-
if logger.isEnabledFor(logging.INFO):
728-
if logger.isEnabledFor(logging.WARNING) and not converged:
729-
logger.warning("CTMRG: ❌ did not converge, took %.2f seconds. (Steps: %d, Smallest SVD Norm: %.3e)", time.perf_counter() - t0, end_count, norm_smallest_S)
730-
else:
731-
logger.info("CTMRG: ✅ converged, took %.2f seconds. (Steps: %d, Smallest SVD Norm: %.3e)", time.perf_counter() - t0, end_count, norm_smallest_S)
727+
728+
if not converged and logger.isEnabledFor(logging.WARNING):
729+
logger.warning(
730+
"CTMRG: ❌ did not converge, took %.2f seconds. (Steps: %d, Smallest SVD Norm: %.3e)",
731+
time.perf_counter() - t0, end_count, norm_smallest_S
732+
)
733+
elif logger.isEnabledFor(logging.INFO):
734+
logger.info(
735+
"CTMRG: ✅ converged, took %.2f seconds. (Steps: %d, Smallest SVD Norm: %.3e)",
736+
time.perf_counter() - t0, end_count, norm_smallest_S
737+
)
732738

733739
if converged and (
734740
working_unitcell[0, 0][0][0].chi > best_chi or best_result is None
@@ -762,7 +768,7 @@ def calc_ctmrg_env(
762768

763769
if logger.isEnabledFor(logging.INFO):
764770
logger.info(
765-
"Increasing chi to {} since smallest SVD Norm was {}.",
771+
"Increasing chi to %d since smallest SVD Norm was %.3e.",
766772
new_chi,
767773
norm_smallest_S,
768774
)
@@ -796,7 +802,7 @@ def calc_ctmrg_env(
796802

797803
if logger.isEnabledFor(logging.INFO):
798804
logger.info(
799-
"Decreasing chi to {} since smallest SVD Norm was {} or routine did not converge.",
805+
"Decreasing chi to %d since smallest SVD Norm was %.3e or routine did not converge.",
800806
new_chi,
801807
norm_smallest_S,
802808
)
@@ -820,7 +826,7 @@ def calc_ctmrg_env(
820826
):
821827
if logger.isEnabledFor(logging.INFO):
822828
logger.info(
823-
"Increasing SVD truncation eps to {}.",
829+
"Increasing SVD truncation eps to %d.",
824830
new_truncation_eps,
825831
)
826832
varipeps_global_state.ctmrg_effective_truncation_eps = (
@@ -1030,7 +1036,17 @@ def calc_ctmrg_env_rev(
10301036
)
10311037

10321038
varipeps_global_state.ctmrg_effective_truncation_eps = None
1033-
debug_print("Custom VJP: Converged: {}, Steps: {}", converged, end_count)
1039+
1040+
if not converged and logger.isEnabledFor(logging.WARNING):
1041+
logger.warning(
1042+
"Custom VJP: ❌ did not converge, took %.2f seconds. (Steps: %d)",
1043+
time.perf_counter() - t0, end_count
1044+
)
1045+
elif logger.isEnabledFor(logging.INFO):
1046+
logger.info(
1047+
"Custom VJP: ✅ converged, took %.2f seconds. (Steps: %d)",
1048+
time.perf_counter() - t0, end_count
1049+
)
10341050
if end_count == varipeps_config.ad_custom_max_steps and not converged:
10351051
raise CTMRGGradientNotConvergedError
10361052

varipeps/optimization/optimizer.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,14 +1016,15 @@ def random_noise(a):
10161016

10171017
count += 1
10181018

1019+
step_str = f"{float(linesearch_step):0.8f}" if linesearch_step is not None else "None"
10191020
logger.info(
1020-
"📉 Step %d | Energy: %0.10f | Retries: %d | Conv: %0.8f | Line search step: %s | Max. trunc. err.: %0.8g",
1021-
count,
1022-
working_value,
1023-
random_noise_retries,
1024-
conv,
1025-
f"{float(linesearch_step):0.8f}" if linesearch_step is not None else "None",
1026-
max_trunc_error,
1021+
"📉 Step %d | Energy: %.8f | Retries: %d | Conv: %.3e | Line search step: %s | Max. trunc. err.: %.3e",
1022+
int(count),
1023+
float(working_value),
1024+
int(random_noise_retries),
1025+
float(conv),
1026+
step_str,
1027+
float(max_trunc_error),
10271028
)
10281029

10291030
if count % varipeps_config.optimizer_autosave_step_count == 0:

0 commit comments

Comments
 (0)