Skip to content

Commit 873cfa6

Browse files
committed
replacing with Logging
1 parent 3a493a1 commit 873cfa6

File tree

7 files changed

+21
-46
lines changed

7 files changed

+21
-46
lines changed

Project.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Libxc = "66e17ffc-8502-11e9-23b5-c9248d0eb96d"
2424
LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255"
2525
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
2626
LinearMaps = "7a12625a-238d-50fd-b39a-03d52299707e"
27+
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
2728
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
2829
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
2930
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
@@ -139,16 +140,14 @@ IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
139140
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
140141
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
141142
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
142-
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
143143
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
144144
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
145145
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
146-
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
147146
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
148147
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
149148
Wannier = "2b19380a-1f7e-4d7d-b1b8-8aa60b3321c9"
150149
WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"
151150
wannier90_jll = "c5400fa0-8d08-52c2-913f-1e3f656c1ce9"
152151

153152
[targets]
154-
test = ["Test", "TestItemRunner", "ASEconvert", "Aqua", "AtomsIO", "AtomsIOPython", "CUDA", "CUDA_Runtime_jll", "ComponentArrays", "DoubleFloats", "FiniteDiff", "FiniteDifferences", "GenericLinearAlgebra", "IntervalArithmetic", "JLD2", "JSON3", "KrylovKit", "Logging", "Plots", "QuadGK", "Random", "Suppressor", "Wannier", "WriteVTK", "wannier90_jll"]
153+
test = ["Test", "TestItemRunner", "ASEconvert", "Aqua", "AtomsIO", "AtomsIOPython", "CUDA", "CUDA_Runtime_jll", "ComponentArrays", "DoubleFloats", "FiniteDiff", "FiniteDifferences", "GenericLinearAlgebra", "IntervalArithmetic", "JLD2", "JSON3", "KrylovKit", "Plots", "QuadGK", "Random", "Wannier", "WriteVTK", "wannier90_jll"]

src/DFTK.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export Mat3
2626
export mpi_nprocs
2727
export mpi_master
2828
export setup_threading, disable_threading
29+
include("common/logging.jl")
2930
include("common/timer.jl")
3031
include("common/constants.jl")
3132
include("common/ortho.jl")

src/common/logging.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
using Logging

src/eigen/lobpcg_hyper_impl.jl

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
## TODO it seems there is a lack of orthogonalization immediately after locking, maybe investigate this to save on some choleskys
4040
## TODO debug orthogonalizations when A=I
4141

42-
# TODO Use @debug for this
43-
# vprintln(args...) = println(args...) # Uncomment for output
44-
vprintln(args...) = nothing
45-
4642
using LinearAlgebra
4743
import LinearAlgebra: BlasFloat
4844
import Base: *
@@ -180,7 +176,7 @@ normest(M) = maximum(abs.(diag(M))) + norm(M - Diagonal(diag(M)))
180176
success = true
181177
catch err
182178
@assert isa(err, PosDefException)
183-
vprintln("fail")
179+
@debug "fail"
184180
# see https://arxiv.org/pdf/1809.11085.pdf for a nice analysis
185181
# We are not being very clever here; but this should very rarely happen
186182
# so it should be OK
@@ -220,7 +216,7 @@ normest(M) = maximum(abs.(diag(M))) + norm(M - Diagonal(diag(M)))
220216
# condR = 1/LAPACK.trcon!('I', 'U', 'N', Array(R))
221217
condR = normest(R)*norminvR # in practice this seems to be an OK estimate
222218

223-
vprintln("Ortho(X) success? $success ", eps(real(T))*condR^2, " < $tol")
219+
@debug "Ortho(X) success? $success ", eps(real(T))*condR^2, " < $tol"
224220

225221
# a good a posteriori error is that X'X - I is eps()*κ(R)^2;
226222
# in practice this seems to be sometimes very overconservative
@@ -289,7 +285,7 @@ end
289285
niter > 10 && error("Ortho(X,Y) is failing badly, this should never happen")
290286
niter += 1
291287
end
292-
vprintln("ortho choleskys: ", ninners) # get how many Choleskys are performed
288+
@debug "ortho choleskys: ", ninners # get how many Choleskys are performed
293289

294290
# @assert (norm(BY'X)) < tol
295291
# @assert (norm(X'X-I)) < tol
@@ -400,7 +396,7 @@ end
400396
resid_history[i + nlocked, niter+1] = norm(new_R[:, i])
401397
end
402398
end
403-
vprintln(niter, " ", resid_history[:, niter+1])
399+
@debug niter, " ", resid_history[:, niter+1]
404400

405401
# it is actually a good question of knowing when to
406402
# precondition. Here seems sensible, but it could plausibly be
@@ -418,7 +414,7 @@ end
418414
for i=nlocked+1:M
419415
if resid_history[i, niter+1] < tol
420416
nlocked += 1
421-
vprintln("locked $nlocked")
417+
@debug "locked $nlocked"
422418
else
423419
# We lock in order, assuming that the lowest
424420
# eigenvectors converge first; might be tricky otherwise
@@ -428,8 +424,8 @@ end
428424
end
429425

430426
if display_progress
431-
println("Iter $niter, converged $(nlocked)/$(n_conv_check), resid ",
432-
norm(resid_history[1:n_conv_check, niter+1]))
427+
@info "Iter $niter, converged $(nlocked)/$(n_conv_check), resid " *
428+
"$(norm(resid_history[1:n_conv_check, niter+1]))"
433429
end
434430

435431
if nlocked >= n_conv_check # Converged!

src/scf/scf_callbacks.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ function (cb::ScfDefaultCallback)(info)
6767
label_damp = show_damp ? (" α ", " ----") : ("", "")
6868
label_diag = show_diag ? (" Diag", " ----") : ("", "")
6969
label_time = show_time ? (" Δtime", " ------") : ("", "")
70-
@printf "n Energy log10(ΔE) log10(Δρ)"
71-
println(label_magn[1], label_damp[1], label_diag[1], label_time[1])
72-
@printf "--- --------------- --------- ---------"
73-
println(label_magn[2], label_damp[2], label_diag[2], label_time[2])
70+
@info "n Energy log10(ΔE) log10(Δρ)" *
71+
"$(label_magn[1]) $(label_damp[1]) $(label_diag[1]) $(label_time[1])"
72+
@info "--- --------------- --------- ---------" *
73+
"$(label_magn[2]) $(label_damp[2]) $(label_diag[2]) $(label_time[2])"
7474
end
7575
E = isnothing(info.energies) ? Inf : info.energies.total
7676
magn = sum(spin_density(info.ρout)) * info.basis.dvol
@@ -97,8 +97,8 @@ function (cb::ScfDefaultCallback)(info)
9797
αstr = ""
9898
show_damp && (αstr = isnan(info.α) ? " " : @sprintf " % 4.2f" info.α)
9999

100-
@printf "% 3d %s %s %s" info.n_iter Estr ΔE Δρstr
101-
println(Mstr, αstr, diagstr, tstr)
100+
line = @sprintf "% 3d %s %s %s" info.n_iter Estr ΔE Δρstr
101+
@info line * "$Mstr $αstr $diagstr $tstr"
102102

103103
flush(stdout)
104104
info

src/workarounds/forwarddiff_rules.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function self_consistent_field(basis_dual::PlaneWaveBasis{T};
209209
end
210210

211211
## Implicit differentiation
212-
response.verbose && println("Solving response problem")
212+
response.verbose && @info "Solving response problem"
213213
δresults = ntuple(ForwardDiff.npartials(T)) do α
214214
δHextψ = [ForwardDiff.partials.(δHextψk, α) for δHextψk in Hψ_dual]
215215
solve_ΩplusK_split(scfres, -δHextψ; tol=last(scfres.history_Δρ), response.verbose)

test/runtests_runner.jl

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# This is needed to play nicely with MPI parallelised tests
33
#
44
using TestItemRunner
5-
using Suppressor
65

76
include("runtests_parser.jl")
87
(; base_tag, excluded, included) = parse_test_args()
@@ -31,29 +30,8 @@ function dftk_testfilter(ti)
3130
end
3231
end
3332

34-
function run_tests()
35-
output = @capture_out try
36-
@run_package_tests filter=dftk_testfilter verbose=true
37-
catch err
38-
Base.showerror(stderr, err, Base.catch_backtrace())
39-
end
33+
using Logging
4034

41-
lines = split(output, "\n")
42-
# Print failed tests.
43-
println()
44-
for id in findall(occursin.("Test Failed", lines))
45-
id_context = id
46-
while !isempty(lines[id_context])
47-
println(lines[id_context])
48-
id_context += 1
49-
end
50-
println()
51-
end
52-
# Print the summary.
53-
idx = findfirst(occursin.(r"^Test Summary:", lines))
54-
if !isnothing(idx)
55-
println(join(lines[idx:end], "\n"))
56-
end
35+
with_logger(ConsoleLogger(stdout, LogLevel(1))) do
36+
@run_package_tests filter=dftk_testfilter verbose=true
5737
end
58-
59-
run_tests()

0 commit comments

Comments
 (0)