@@ -116,13 +116,15 @@ function SciMLBase.__solve(cache::OptimizationCache{
116
116
cache. f. cons (cons_tmp, cache. u0)
117
117
ρ = max (1e-6 , min (10 , 2 * (abs (cache. f (cache. u0, cache. p))) / norm (cons_tmp)))
118
118
119
+ iter_count = Ref (0 )
119
120
_loss = function (θ)
120
121
x = cache. f (θ, cache. p)
122
+ iter_count[] += 1
121
123
cons_tmp .= zero (eltype (θ))
122
124
cache. f. cons (cons_tmp, θ)
123
125
cons_tmp[eq_inds] .= cons_tmp[eq_inds] - cache. lcons[eq_inds]
124
126
cons_tmp[ineq_inds] .= cons_tmp[ineq_inds] .- cache. ucons[ineq_inds]
125
- opt_state = Optimization. OptimizationState (u = θ, objective = x[1 ], p = cache. p)
127
+ opt_state = Optimization. OptimizationState (u = θ, objective = x[1 ], p = cache. p, iter = iter_count[] )
126
128
if cache. callback (opt_state, x... )
127
129
error (" Optimization halted by callback." )
128
130
end
@@ -206,10 +208,11 @@ function SciMLBase.__solve(cache::OptimizationCache{
206
208
cache, cache. opt, res[2 ], cache. f (res[2 ], cache. p)[1 ],
207
209
stats = stats, retcode = opt_ret)
208
210
else
211
+ iter_count = Ref (0 )
209
212
_loss = function (θ)
210
213
x = cache. f (θ, cache. p)
211
-
212
- opt_state = Optimization. OptimizationState (u = θ, objective = x[1 ], p = cache. p)
214
+ iter_count[] += 1
215
+ opt_state = Optimization. OptimizationState (u = θ, objective = x[1 ], p = cache. p, iter = iter_count[] )
213
216
if cache. callback (opt_state, x... )
214
217
error (" Optimization halted by callback." )
215
218
end
0 commit comments