use external logging

This commit is contained in:
kalmarek 2018-08-20 02:54:50 +02:00
parent 000069961b
commit 57e9e3c404
2 changed files with 88 additions and 20 deletions

58
logging.jl Normal file
View File

@ -0,0 +1,58 @@
using Memento
function setup_logging(filename::String, handlername::Symbol)
isdir(dirname(filename)) || mkdir(dirname(filename))
logger = Memento.config!("info", fmt="{date}| {msg}")
handler = DefaultHandler(filename, DefaultFormatter("{date}| {msg}"))
logger.handlers[String(handlername)] = handler
return logger
end
macro logtime(logger, ex)
quote
local stats = Base.gc_num()
local elapsedtime = Base.time_ns()
local val = $(esc(ex))
elapsedtime = Base.time_ns() - elapsedtime
local diff = Base.GC_Diff(Base.gc_num(), stats)
local ts = time_string(elapsedtime,
diff.allocd,
diff.total_time,
Base.gc_alloc_count(diff)
)
$(esc(info))($(esc(logger)), ts)
val
end
end
function time_string(elapsedtime, bytes, gctime, allocs)
str = @sprintf("%10.6f seconds", elapsedtime/1e9)
if bytes != 0 || allocs != 0
bytes, mb = Base.prettyprint_getunits(bytes, length(Base._mem_units), Int64(1024))
allocs, ma = Base.prettyprint_getunits(allocs, length(Base._cnt_units), Int64(1000))
if ma == 1
str*= @sprintf(" (%d%s allocation%s: ", allocs, Base._cnt_units[ma], allocs==1 ? "" : "s")
else
str*= @sprintf(" (%.2f%s allocations: ", allocs, Base._cnt_units[ma])
end
if mb == 1
str*= @sprintf("%d %s%s", bytes, Base._mem_units[mb], bytes==1 ? "" : "s")
else
str*= @sprintf("%.3f %s", bytes, Base._mem_units[mb])
end
if gctime > 0
str*= @sprintf(", %.2f%% gc time", 100*gctime/elapsedtime)
end
str*=")"
elseif gctime > 0
str*= @sprintf(", %.2f%% gc time", 100*gctime/elapsedtime)
end
return str
end
import Base: info, @time
Base.info(x) = info(getlogger(), x)
macro time(x)
return :(@logtime(getlogger(Main), $(esc(x))))
end

50
main.jl
View File

@ -1,3 +1,5 @@
include("logging.jl")
using AbstractAlgebra using AbstractAlgebra
using Nemo using Nemo
using PropertyT using PropertyT
@ -14,16 +16,16 @@ using PropertyTGroups
struct Symmetrize end struct Symmetrize end
struct Standard end struct Standard end
function summarize(logger, groupdir, iterations, tol, upper_bound, radius, G, S) function summarize(groupdir, iterations, tol, upper_bound, radius, G, S)
info(logger, "Group: $groupdir") info("Group: $groupdir")
info(logger, "Iterations: $iterations") info("Iterations: $iterations")
info(logger, "Precision: $tol") info("Precision: $tol")
info(logger, "Upper bound: $upper_bound") info("Upper bound: $upper_bound")
info(logger, "Radius: $radius") info("Radius: $radius")
info(logger, "Threads: $(Threads.nthreads())") info("Threads: $(Threads.nthreads())")
info(logger, "Workers: $(workers())") info("Workers: $(workers())")
info(logger, string(G)) info(string(G))
info(logger, "with generating set of size $(length(S))") info("with generating set of size $(length(S))")
end end
function params(Gr::SymmetrizedGroup) function params(Gr::SymmetrizedGroup)
@ -47,23 +49,31 @@ end
scs_solver(tol, iterations) = SCSSolver(eps=tol, max_iters=iterations, linearsolver=SCS.Direct, alpha=1.95, acceleration_lookback=1) scs_solver(tol, iterations) = SCSSolver(eps=tol, max_iters=iterations, linearsolver=SCS.Direct, alpha=1.95, acceleration_lookback=1)
main(G::SymmetrizedGroup) = main(Symmetrize, G)
function main(::Type{Symmetrize}, Gr::SymmetrizedGroup)
radius, tol, iterations, upper_bound, warm, N = params(Gr)
groupdir = "$(PropertyTGroups.name(Gr))_r$radius" function main(Gr::PropertyTGroup)
r = Gr.args["radius"]
ub = Gr.args["upper-bound"]
groupdir = "$(PropertyTGroups.name(Gr))_r$r"
isdir(groupdir) || mkdir(groupdir) isdir(groupdir) || mkdir(groupdir)
logger = PropertyT.setup_logging(joinpath(groupdir, "$(upper_bound)"), :fulllog) logfile = PropertyT.filename(joinpath(groupdir, string(ub)), :fulllog)
logger=setup_logging(logfile, :fulllog)
if Gr.args["nosymmetry"]
return main(Naive, Gr, dir=groupdir)
else
return main(Symmetrize, Gr, dir=groupdir)
end
end
G = PropertyTGroups.group(Gr) G = PropertyTGroups.group(Gr)
S = PropertyTGroups.generatingset(Gr) S = PropertyTGroups.generatingset(Gr)
summarize(logger, groupdir, iterations, tol, upper_bound, radius, G, S) summarize(dir, iterations, tol, upper_bound, radius, G, S)
autS = PropertyTGroups.autS(Gr) autS = PropertyTGroups.autS(Gr)
info(logger, "Symmetrising with $(autS)") info("Symmetrising with $(autS)")
solver = scs_solver(tol, iterations) solver = scs_solver(tol, iterations)
@ -76,8 +86,8 @@ function main(::Type{Symmetrize}, Gr::SymmetrizedGroup)
# solver = SDPA.SDPASolver(epsilonStar=tol, epsilonDash=tol) # solver = SDPA.SDPASolver(epsilonStar=tol, epsilonDash=tol)
sett = Settings(groupdir, N, G, S, autS, sett = Settings(dir, N, G, S, autS,
radius, solver, upper_bound, tol, warm, logger) radius, solver, upper_bound, tol, warm)
return PropertyT.check_property_T(sett) return PropertyT.check_property_T(sett)
end end
@ -92,7 +102,7 @@ function main(::Type{Standard}, Gr::SymmetrizedGroup)
G = PropertyTGroups.group(Gr) G = PropertyTGroups.group(Gr)
S = PropertyTGroups.generatingset(Gr) S = PropertyTGroups.generatingset(Gr)
summarize(logger, groupdir, iterations, tol, upper_bound, radius, G, S) summarize(dir, iterations, tol, upper_bound, radius, G, S)
solver = scs_solver(tol, iterations) solver = scs_solver(tol, iterations)