Skip to content

Commit ff2675f

Browse files
committed
debug: do not get duals if isnothing(hessian)
1 parent 7700d45 commit ff2675f

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

src/controller/nonlinmpc.jl

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,6 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
573573
else
574574
∇J, ∇²J = gradient(J!, mpc.gradient, mpc.Z̃, J_cache...), nothing
575575
end
576-
nonlincon = optim[:nonlinconstraint]
577-
nonlinconeq = optim[:nonlinconstrainteq]
578-
λ, λeq = JuMP.dual.(nonlincon), JuMP.dual.(nonlinconeq)
579-
display(λ)
580-
display(λeq)
581-
582576
∇g_cache = (
583577
Cache(ΔŨ), Cache(x̂0end), Cache(Ue), Cache(Ŷe), Cache(U0), Cache(Ŷ0),
584578
Cache(Û0), Cache(K0), Cache(X̂0),
@@ -589,7 +583,6 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
589583
return nothing
590584
end
591585
∇g = jacobian(g!, g, mpc.jacobian, mpc.Z̃, ∇g_cache...)
592-
#=
593586
if !isnothing(mpc.hessian)
594587
function ℓ_g(Z̃, λ, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, geq, g)
595588
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃)
@@ -600,11 +593,13 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
600593
Cache(Û0), Cache(K0), Cache(X̂0),
601594
Cache(gc), Cache(geq), Cache(g)
602595
)
596+
nonlincon = optim[:nonlinconstraint]
597+
λ = JuMP.dual.(nonlincon) # FIXME: does not work for now
598+
λ = ones(NT, ng)
603599
∇²ℓg = hessian(ℓ_g, mpc.hessian, mpc.Z̃, Constant(λ), ∇²g_cache...)
604600
else
605601
∇²ℓg = nothing
606602
end
607-
=# ∇²ℓg = nothing #TODO: delete this line when enabling the above block
608603
geq_cache = (
609604
Cache(ΔŨ), Cache(x̂0end), Cache(Ue), Cache(Ŷe), Cache(U0), Cache(Ŷ0),
610605
Cache(Û0), Cache(K0), Cache(X̂0),
@@ -615,9 +610,23 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
615610
return nothing
616611
end
617612
∇geq = jacobian(geq!, geq, mpc.jacobian, mpc.Z̃, geq_cache...)
618-
∇²ℓgeq = nothing # TODO: implement later
619-
620-
613+
if !isnothing(mpc.hessian)
614+
∇²geq_cache = (
615+
Cache(ΔŨ), Cache(x̂0end), Cache(Ue), Cache(Ŷe), Cache(U0), Cache(Ŷ0),
616+
Cache(Û0), Cache(K0), Cache(X̂0),
617+
Cache(gc), Cache(geq), Cache(g)
618+
)
619+
function ℓ_geq(Z̃, λeq, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, geq, g)
620+
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃)
621+
return dot(λeq, geq)
622+
end
623+
nonlinconeq = optim[:nonlinconstrainteq]
624+
λeq = JuMP.dual.(nonlinconeq) # FIXME: does not work for now
625+
λeq = ones(NT, neq)
626+
∇²ℓgeq = hessian(ℓ_geq, mpc.hessian, mpc.Z̃, Constant(λeq), ∇²geq_cache...)
627+
else
628+
∇²ℓgeq = nothing
629+
end
621630
info[:∇J] = ∇J
622631
info[:∇²J] = ∇²J
623632
info[:∇g] = ∇g

src/estimator/mhe/execute.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,29 +201,25 @@ function addinfo!(
201201
else
202202
∇J, ∇²J = gradient(J!, estim.gradient, estim.Z̃, J_cache...), nothing
203203
end
204-
nonlincon = optim[:nonlinconstraint]
205-
λ = JuMP.dual.(nonlincon)
206-
display(λ)
207-
208204
∇g_cache = (Cache(V̂), Cache(X̂0), Cache(û0), Cache(k0), Cache(ŷ0))
209205
function g!(g, Z̃, V̂, X̂0, û0, k0, ŷ0)
210206
update_prediction!(V̂, X̂0, û0, k0, ŷ0, g, estim, Z̃)
211207
return nothing
212208
end
213209
∇g = jacobian(g!, g, estim.jacobian, estim.Z̃, ∇g_cache...)
214-
#=
215210
if !isnothing(estim.hessian)
211+
∇²g_cache = (Cache(V̂), Cache(X̂0), Cache(û0), Cache(k0), Cache(ŷ0), Cache(g))
216212
function ℓ_g(Z̃, λ, V̂, X̂0, û0, k0, ŷ0, g)
217213
update_prediction!(V̂, X̂0, û0, k0, ŷ0, g, estim, Z̃)
218214
return dot(λ, g)
219215
end
220-
∇²g_cache = (Cache(V̂), Cache(X̂0), Cache(û0), Cache(k0), Cache(ŷ0), Cache(g))
216+
nonlincon = optim[:nonlinconstraint]
217+
λ = JuMP.dual.(nonlincon) # FIXME: does not work for now
218+
λ = ones(NT, ng)
221219
∇²ℓg = hessian(ℓ_g, estim.hessian, estim.Z̃, Constant(λ), ∇²g_cache...)
222220
else
223221
∇²ℓg = nothing
224222
end
225-
=# ∇²ℓg = nothing #TODO: delete this line when enabling the above block
226-
227223
info[:∇J] = ∇J
228224
info[:∇²J] = ∇²J
229225
info[:∇g] = ∇g

0 commit comments

Comments
 (0)