Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/lbfgsb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,15 @@ function SciMLBase.__solve(cache::OptimizationCache{
cache.f.cons(cons_tmp, cache.u0)
ρ = max(1e-6, min(10, 2 * (abs(cache.f(cache.u0, cache.p))) / norm(cons_tmp)))

iter_count = Ref(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a simple integer not enough? 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would need to box it anyways

_loss = function (θ)
x = cache.f(θ, cache.p)
iter_count[] += 1
cons_tmp .= zero(eltype(θ))
cache.f.cons(cons_tmp, θ)
cons_tmp[eq_inds] .= cons_tmp[eq_inds] - cache.lcons[eq_inds]
cons_tmp[ineq_inds] .= cons_tmp[ineq_inds] .- cache.ucons[ineq_inds]
opt_state = Optimization.OptimizationState(u = θ, objective = x[1], p = cache.p)
opt_state = Optimization.OptimizationState(u = θ, objective = x[1], p = cache.p, iter = iter_count[])
if cache.callback(opt_state, x...)
error("Optimization halted by callback.")
end
Expand Down Expand Up @@ -206,10 +208,11 @@ function SciMLBase.__solve(cache::OptimizationCache{
cache, cache.opt, res[2], cache.f(res[2], cache.p)[1],
stats = stats, retcode = opt_ret)
else
iter_count = Ref(0)
_loss = function (θ)
x = cache.f(θ, cache.p)

opt_state = Optimization.OptimizationState(u = θ, objective = x[1], p = cache.p)
iter_count[] += 1
opt_state = Optimization.OptimizationState(u = θ, objective = x[1], p = cache.p, iter = iter_count[])
if cache.callback(opt_state, x...)
error("Optimization halted by callback.")
end
Expand Down
Loading