From 5ed6befaca861bee7f8fbe0abc5639bf1f53b76a Mon Sep 17 00:00:00 2001 From: tmigot Date: Thu, 18 Aug 2022 16:09:01 -0400 Subject: [PATCH 1/4] fill-in! with the same jacobian matrix --- src/Stopping/NLPStoppingmod.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Stopping/NLPStoppingmod.jl b/src/Stopping/NLPStoppingmod.jl index 3b5ec319..280f406b 100644 --- a/src/Stopping/NLPStoppingmod.jl +++ b/src/Stopping/NLPStoppingmod.jl @@ -229,7 +229,13 @@ function fill_in!( end if stp.pb.meta.ncon > 0 - gJx = isnothing(Jx) ? jac(stp.pb, x) : Jx + gJx = if !isnothing(Jx) + Jx + elseif typeof(stp.current_state.Jx) <: LinearOperator + jac_op(stp.pb, x) + else # typeof(stp.current_state.Jx) <: SparseArrays.SparseMatrixCSC + jac(stp.pb, x) + end gcx = isnothing(cx) ? cons(stp.pb, x) : cx else gJx = stp.current_state.Jx From a0e58889ade9ccd094b69f1ae1cf4931c433f63b Mon Sep 17 00:00:00 2001 From: tmigot Date: Thu, 18 Aug 2022 16:26:00 -0400 Subject: [PATCH 2/4] add `convert` keyword in `fill_in!` --- src/Stopping/NLPStoppingmod.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Stopping/NLPStoppingmod.jl b/src/Stopping/NLPStoppingmod.jl index 280f406b..8ca55796 100644 --- a/src/Stopping/NLPStoppingmod.jl +++ b/src/Stopping/NLPStoppingmod.jl @@ -217,6 +217,7 @@ function fill_in!( lambda::Union{T, Nothing} = nothing, mu::Union{T, Nothing} = nothing, matrix_info::Bool = true, + convert::Bool = true, kwargs..., ) where {Pb, M, SRC, MStp, LoS, S, T} gfx = isnothing(fx) ? obj(stp.pb, x) : fx @@ -251,7 +252,7 @@ function fill_in!( lb, lc = mu, lambda end - return update!(stp, x = x, fx = gfx, gx = ggx, Hx = gHx, cx = gcx, Jx = gJx, mu = lb, lambda = lc) + return update!(stp, x = x, fx = gfx, gx = ggx, Hx = gHx, cx = gcx, Jx = gJx, mu = lb, lambda = lc, convert = convert) end function fill_in!( @@ -261,6 +262,7 @@ function fill_in!( gx::Union{T, Nothing} = nothing, f₀::Union{T, Nothing} = nothing, g₀::Union{T, Nothing} = nothing, + convert::Bool = true, kwargs..., ) where {Pb, M, SRC, S, T, MStp, LoS} gfx = isnothing(fx) ? obj(stp.pb, x) : fx @@ -268,7 +270,7 @@ function fill_in!( gf₀ = isnothing(f₀) ? obj(stp.pb, 0.0) : f₀ gg₀ = isnothing(g₀) ? grad(stp.pb, 0.0) : g₀ - return update!(stp.current_state, x = x, fx = gfx, gx = ggx, f₀ = gf₀, g₀ = gg₀) + return update!(stp.current_state, x = x, fx = gfx, gx = ggx, f₀ = gf₀, g₀ = gg₀, convert = convert) end """ From 3c390b063719ee67cfbf8a114f737505434cefec Mon Sep 17 00:00:00 2001 From: tmigot Date: Thu, 18 Aug 2022 16:37:05 -0400 Subject: [PATCH 3/4] test show --- src/Stopping/NLPStoppingmod.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Stopping/NLPStoppingmod.jl b/src/Stopping/NLPStoppingmod.jl index 8ca55796..284f7ada 100644 --- a/src/Stopping/NLPStoppingmod.jl +++ b/src/Stopping/NLPStoppingmod.jl @@ -252,6 +252,7 @@ function fill_in!( lb, lc = mu, lambda end + @show x gfx ggx gHx gcx gJx lb lc convert return update!(stp, x = x, fx = gfx, gx = ggx, Hx = gHx, cx = gcx, Jx = gJx, mu = lb, lambda = lc, convert = convert) end From ed66c06623bae73f66413cd9e6540cb9b1213d4b Mon Sep 17 00:00:00 2001 From: tmigot Date: Thu, 18 Aug 2022 17:03:47 -0400 Subject: [PATCH 4/4] fix2 --- src/Stopping/NLPStoppingmod.jl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Stopping/NLPStoppingmod.jl b/src/Stopping/NLPStoppingmod.jl index 284f7ada..b2d69fc3 100644 --- a/src/Stopping/NLPStoppingmod.jl +++ b/src/Stopping/NLPStoppingmod.jl @@ -226,7 +226,7 @@ function fill_in!( if isnothing(Hx) && matrix_info gHx = hess(stp.pb, x).data else - gHx = Hx + gHx = isnothing(Hx) ? zeros(eltype(T), 0, 0) : Hx end if stp.pb.meta.ncon > 0 @@ -246,13 +246,17 @@ function fill_in!( #update the Lagrange multiplier if one of the 2 is asked if (stp.pb.meta.ncon > 0 || has_bounds(stp.pb)) && (isnothing(lambda) || isnothing(mu)) lb, lc = _compute_mutliplier(stp.pb, x, ggx, gcx, gJx; kwargs...) - elseif stp.pb.meta.ncon == 0 && !has_bounds(stp.pb) && isnothing(lambda) - lb, lc = mu, stp.current_state.lambda else - lb, lc = mu, lambda + lb = if isnothing(mu) & has_bounds(stp.pb) + zeros(eltype(T), get_nvar(stp.pb)) + elseif isnothing(mu) & !has_bounds(stp.pb) + zeros(eltype(T), 0) + else + mu + end + lc = isnothing(lambda) ? zeros(eltype(T), get_ncon(stp.pb)) : lambda end - @show x gfx ggx gHx gcx gJx lb lc convert return update!(stp, x = x, fx = gfx, gx = ggx, Hx = gHx, cx = gcx, Jx = gJx, mu = lb, lambda = lc, convert = convert) end