@@ -42,28 +42,28 @@ function solve_problem(prob::GeoOptProblem, solver::Optim.AbstractOptimizer, cvg
4242 end
4343
4444 geoopt_state = prob. geoopt_state
45- inner_callback = function (ts )
45+ inner_callback = function (optim_state )
4646 cache_evaluations = geoopt_state. cache_evaluations
47-
48- geoopt_state. n_iter = ts . iteration
47+ n_iter = optim_state . pseudo_iteration
48+ geoopt_state. n_iter = n_iter
4949 if isempty (cache_evaluations)
5050 # Find out if we already added the current state (if optim cannot
5151 # make progress it keeps printing iterations, but does not run further
5252 # function evaluations ... in this case we have no new forces and virials).
5353 # Also it sometimes does an extra call to the callback even though
5454 # convergence has already been flagged.
55- tol = 10 eps (typeof (ts . value ))
56- is_match = abs (austrip (geoopt_state. history_energy[end ]) - ts . value ) < tol
55+ tol = 10 eps (typeof (optim_state . f_x ))
56+ is_match = abs (austrip (geoopt_state. history_energy[end ]) - optim_state . f_x ) < tol
5757 if ! geoopt_state. converged && ! is_match
58- @warn " Discarding optimisation step of iteration $(ts . iteration ) "
58+ @warn " Discarding optimisation step of iteration $(n_iter ) "
5959 end
6060 else
6161 # Find position in the cache matching Optim's current state
6262 i_match = findlast (cache_evaluations) do eval
63- isnothing (eval. gradnorm ) && return false
64- tol = 10 eps (typeof (ts . value ))
65- ( abs (eval. objective - ts . value) < tol
66- && abs ( eval. gradnorm - ts . g_norm ) < tol)
63+ isnothing (eval. grad ) && return false
64+ tol = 10 eps (typeof (optim_state . f_x ))
65+ ( abs (eval. objective - optim_state . f_x) < tol
66+ && maximum (abs, eval. grad - optim_state . g_x ) < tol)
6767 end
6868 i_match = @something i_match length (cache_evaluations)
6969
@@ -82,7 +82,7 @@ function solve_problem(prob::GeoOptProblem, solver::Optim.AbstractOptimizer, cvg
8282 end
8383
8484 # Callback and possible abortion
85- halt = callback (ts , geoopt_state)
85+ halt = callback (optim_state , geoopt_state)
8686 halt && return true
8787
8888 geoopt_state. converged
@@ -95,8 +95,8 @@ function solve_problem(prob::GeoOptProblem, solver::Optim.AbstractOptimizer, cvg
9595 allow_f_increases= true ,
9696 successive_f_tol= 2 ,
9797 callback= inner_callback,
98- x_abstol= - 1 , f_abstol= - 1 , g_tol= 10 eps (T),
99- x_reltol= - 1 , f_reltol= - 1 ,
98+ x_abstol= NaN , f_abstol= NaN , g_tol= 10 eps (T),
99+ x_reltol= NaN , f_reltol= NaN ,
100100 iterations= maxiters,
101101 time_limit= maxtime,
102102 kwargs...
108108
109109function solve_problem (prob, solver:: Optim.ZerothOrderOptimizer , cvg;
110110 callback, maxiters, maxtime, kwargs... )
111- # TODO Supporting this needs more fiddeling with the callbacks and convergence checks
111+ # TODO : Supporting this needs more fiddeling with the callbacks and convergence checks
112+ # and it's generally not very useful as forces / stresses are usually available
112113 throw (ArgumentError (" Zeroth-order optimizers are currently not supported." ))
113114end
0 commit comments