JuliaNLSolvers / Optim.jl

Optimization functions for Julia
Other
1.1k stars 214 forks source link

Add progress meter #1079

Closed roflmaostc closed 1 month ago

roflmaostc commented 5 months ago

Hi,

is there an option to include a progressbar for the optimization? Something like: https://julialogging.github.io/reference/progresslogging/#ProgressLogging.jl

Best,

Felix

roflmaostc commented 1 month ago

Now I use this:

const start_time = Ref(zeros(1))
const last_time = Ref(zeros(1))
function log_time(x)
   if x[end].iteration == 0
       start_time[] .= time()
       last_time[] .= time()
   end 
   @info "Iteration:\t$(x[end].iteration),\t total time:\t$(round(time()-start_time[][1], digits=2))s,\ttime since last iteration:\t$(round(time()-last_time[][1],  digits=2))s"

   last_time[] .= time()
   return false
end

@time patterns_vial, printed_intensity_vial, optim_res_vial = optimize_patterns(togoc(target), geometry_vial, 
GradientBased(optimizer=Optim.LBFGS(), 
options=Optim.Options(iterations=5, store_trace=true, 
                                           callback=SwissVAMyKnife.log_time)), loss)

Resulting in:


Iteration:  0,   total time:    0.0s,   time since last iteration:  0.0s

Iteration:  1,   total time:    0.91s,  time since last iteration:  0.91s

Iteration:  2,   total time:    1.64s,  time since last iteration:  0.73s

Iteration:  3,   total time:    2.38s,  time since last iteration:  0.73s

Iteration:  4,   total time:    3.12s,  time since last iteration:  0.74s

Iteration:  5,   total time:    3.85s,  time since last iteration:  0.74s
``