Skip to content

Commit

Permalink
Removed last uses of tools.log
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjosegarciaripoll committed May 5, 2024
1 parent 81dc572 commit 61f48a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
23 changes: 11 additions & 12 deletions src/seemps/analysis/cross/cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions src/seemps/optimization/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 61f48a9

Please sign in to comment.