Skip to content

Commit d788a3e

Browse files
fixes to the logger implementation
1 parent 795db9e commit d788a3e

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
@@ -723,11 +723,17 @@ def calc_ctmrg_env(
723723
else:
724724
converged = False
725725
end_count = tmp_count
726-
if logger.isEnabledFor(logging.INFO):
727-
if logger.isEnabledFor(logging.WARNING) and not converged:
728-
logger.warning("CTMRG: ❌ did not converge, took %.2f seconds. (Steps: %d, Smallest SVD Norm: %.3e)", time.perf_counter() - t0, end_count, norm_smallest_S)
729-
else:
730-
logger.info("CTMRG: ✅ converged, took %.2f seconds. (Steps: %d, Smallest SVD Norm: %.3e)", time.perf_counter() - t0, end_count, norm_smallest_S)
726+
727+
if not converged and logger.isEnabledFor(logging.WARNING):
728+
logger.warning(
729+
"CTMRG: ❌ did not converge, took %.2f seconds. (Steps: %d, Smallest SVD Norm: %.3e)",
730+
time.perf_counter() - t0, end_count, norm_smallest_S
731+
)
732+
elif logger.isEnabledFor(logging.INFO):
733+
logger.info(
734+
"CTMRG: ✅ converged, took %.2f seconds. (Steps: %d, Smallest SVD Norm: %.3e)",
735+
time.perf_counter() - t0, end_count, norm_smallest_S
736+
)
731737

732738
if converged and (
733739
working_unitcell[0, 0][0][0].chi > best_chi or best_result is None
@@ -761,7 +767,7 @@ def calc_ctmrg_env(
761767

762768
if logger.isEnabledFor(logging.INFO):
763769
logger.info(
764-
"Increasing chi to {} since smallest SVD Norm was {}.",
770+
"Increasing chi to %d since smallest SVD Norm was %.3e.",
765771
new_chi,
766772
norm_smallest_S,
767773
)
@@ -795,7 +801,7 @@ def calc_ctmrg_env(
795801

796802
if logger.isEnabledFor(logging.INFO):
797803
logger.info(
798-
"Decreasing chi to {} since smallest SVD Norm was {} or routine did not converge.",
804+
"Decreasing chi to %d since smallest SVD Norm was %.3e or routine did not converge.",
799805
new_chi,
800806
norm_smallest_S,
801807
)
@@ -819,7 +825,7 @@ def calc_ctmrg_env(
819825
):
820826
if logger.isEnabledFor(logging.INFO):
821827
logger.info(
822-
"Increasing SVD truncation eps to {}.",
828+
"Increasing SVD truncation eps to %d.",
823829
new_truncation_eps,
824830
)
825831
varipeps_global_state.ctmrg_effective_truncation_eps = (
@@ -1029,7 +1035,17 @@ def calc_ctmrg_env_rev(
10291035
)
10301036

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

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)