From c84d3b56f65463d50e0b74ddf4db708ee534f9c3 Mon Sep 17 00:00:00 2001 From: Miles Date: Thu, 26 Sep 2024 10:55:10 -0400 Subject: [PATCH] Improve printer code style --- src/solvers/defaults.jl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/solvers/defaults.jl b/src/solvers/defaults.jl index f9896ea1..09c2ae2f 100644 --- a/src/solvers/defaults.jl +++ b/src/solvers/defaults.jl @@ -1,4 +1,4 @@ -using Printf: @printf +using Printf: @printf, @sprintf using ITensorMPS: maxlinkdim default_outputlevel() = 0 default_nsites() = 2 @@ -7,6 +7,10 @@ default_extracter() = default_extracter default_inserter() = default_inserter default_checkdone() = (; kws...) -> false default_transform_operator() = nothing + +format(x) = @sprintf("%s", x) +format(x::AbstractFloat) = @sprintf("%.1E", x) + function default_region_printer(; inserter_kwargs, outputlevel, @@ -21,9 +25,11 @@ function default_region_printer(; region = first(sweep_plan[which_region_update]) @printf("Sweep %d, region=%s \n", which_sweep, region) print(" Truncated using") - haskey(inserter_kwargs, :cutoff) && @printf(" cutoff=%.1E", inserter_kwargs.cutoff) - haskey(inserter_kwargs, :maxdim) && @printf(" maxdim=%d", inserter_kwargs.maxdim) - haskey(inserter_kwargs, :mindim) && @printf(" mindim=%d", inserter_kwargs.mindim) + for key in [:cutoff, :maxdim, :mindim] + if haskey(inserter_kwargs, key) + print(" ", key, "=", format(inserter_kwargs[key])) + end + end println() if spec != nothing @printf(