diff --git a/src/seemps/analysis/cross/cross.py b/src/seemps/analysis/cross/cross.py index 397867d..db12ab5 100644 --- a/src/seemps/analysis/cross/cross.py +++ b/src/seemps/analysis/cross/cross.py @@ -5,7 +5,7 @@ import dataclasses from ...typing import VectorLike -from ...tools import DEBUG, log +from ...tools import make_logger from ...state import MPS, random_mps from ..mesh import Mesh, mps_to_mesh_matrix from ..sampling import random_mps_indices, evaluate_mps @@ -268,8 +268,8 @@ def cross_interpolation( cross = Cross(state, I_g, func, mesh, T) # Optimize Cross until convergence - if DEBUG: - log(f"Initial TT-Cross state: maxbond = {cross.maxbond:3d}") + logger = make_logger() + logger(f"Initial TT-Cross state: maxbond = {cross.maxbond:3d}") for i in range(cross_strategy.maxiter): start_time = perf_counter() sweep(cross, cross_strategy, ltr=True) @@ -280,14 +280,13 @@ def cross_interpolation( error = cross_strategy.error(cross) variation = cross_strategy.variation(cross) - if DEBUG: - log( - f"Results after TT-Cross sweep {1+i:3d}: error={error:.15e}, " - f"variation={variation:.15e}, " - f"maxbond={cross.maxbond:3d}, " - f"time = {time:5f}, " - f"evals = {cross.evals:8d}" - ) + logger( + f"Results after TT-Cross sweep {1+i:3d}: error={error:.15e}, " + f"variation={variation:.15e}, " + f"maxbond={cross.maxbond:3d}, " + f"time = {time:5f}, " + f"evals = {cross.evals:8d}" + ) converged, message = cross_strategy.converged(cross, error, variation) if converged: @@ -296,7 +295,7 @@ def cross_interpolation( if callback is not None: callback(cross) - log(message) + logger("TT-Cross finished with message:\n{message}") return CrossResults( state=cross.state, error=error, diff --git a/src/seemps/optimization/power.py b/src/seemps/optimization/power.py index 2b8dd4a..9c4aa55 100644 --- a/src/seemps/optimization/power.py +++ b/src/seemps/optimization/power.py @@ -2,7 +2,7 @@ from typing import Callable, Union, Optional, Any import dataclasses import numpy as np -from .. import tools +from ..tools import make_logger from ..state import MPS, CanonicalMPS, Strategy, random_mps from ..truncate import simplify from ..mpo import MPO, MPOList, MPOSum @@ -83,7 +83,8 @@ def power_method( # in itself. results.steps = [] last_energy = np.Inf - tools.log(f"power_method() invoked with {maxiter} iterations") + logger = make_logger() + logger(f"power_method() invoked with {maxiter} iterations") total_steps = 0 def cgs_callback(state, residual): @@ -100,7 +101,7 @@ def cgs_callback(state, residual): results.trajectory.append(energy) results.variances.append(variance) results.steps.append(total_steps) - tools.log(f"step = {step:5d}, energy = {energy}, variance = {variance}") + logger(f"step = {step:5d}, energy = {energy}, variance = {variance}") if callback is not None: callback(state, results) energy_change = energy - last_energy @@ -139,5 +140,6 @@ def cgs_callback(state, residual): else: state = simplify(H_v, strategy=strategy) total_steps += 1 - tools.log(f"power_method() finished with results\n{results}") + logger(f"power_method() finished with results\n{results}") + logger.close() return results