Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/ModelPredictiveControl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ using RecipesBase
using DifferentiationInterface: ADTypes.AbstractADType, AutoForwardDiff
using DifferentiationInterface: AutoSparse, SecondOrder
using DifferentiationInterface: gradient, jacobian, hessian
using DifferentiationInterface: value_and_gradient, value_gradient_and_hessian
using DifferentiationInterface: value_and_gradient, value_and_jacobian
using DifferentiationInterface: value_gradient_and_hessian
using DifferentiationInterface: gradient!, value_and_gradient!, prepare_gradient
using DifferentiationInterface: jacobian!, value_and_jacobian!, prepare_jacobian
using DifferentiationInterface: hessian!, value_gradient_and_hessian!, prepare_hessian
Expand Down
2 changes: 2 additions & 0 deletions src/controller/execute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ are also available:
- `:gc`: custom nonlinear constraints values at the optimum, ``\mathbf{g_c}``
- `:∇J` or *`:nablaJ`* : optimal gradient of the objective function, ``\mathbf{\nabla} J``
- `:∇²J` or *`:nabla2J`* : optimal Hessian of the objective function, ``\mathbf{\nabla^2}J``
- `:g` : optimal nonlinear inequality constraint values, ``\mathbf{g}``
- `:∇g` or *`:nablag`* : optimal Jacobian of the inequality constraint, ``\mathbf{\nabla g}``
- `:∇²ℓg` or *`:nabla2lg`* : optimal Hessian of the inequality Lagrangian, ``\mathbf{\nabla^2}\ell_{\mathbf{g}}``
- `:geq` : optimal nonlinear equality constraint values, ``\mathbf{g_{eq}}``
- `:∇geq` or *`:nablageq`* : optimal Jacobian of the equality constraint, ``\mathbf{\nabla g_{eq}}``
- `:∇²ℓgeq` or *`:nabla2lgeq`* : optimal Hessian of the equality Lagrangian, ``\mathbf{\nabla^2}\ell_{\mathbf{g_{eq}}}``

Expand Down
10 changes: 6 additions & 4 deletions src/controller/nonlinmpc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,8 @@ end
"""
addinfo!(info, mpc::NonLinMPC) -> info

For [`NonLinMPC`](@ref), add `:sol`, the custom nonlinear objective `:JE`, the custom
constraint `:gc`, and the various derivatives.
For [`NonLinMPC`](@ref), add `:sol`, the custom nonlinear objective `:JE`, the nonlinear
constraint vectors and the various derivatives.
"""
function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
# --- variables specific to NonLinMPC ---
Expand Down Expand Up @@ -585,7 +585,7 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃)
return nothing
end
∇g = jacobian(g!, g, mpc.jacobian, mpc.Z̃, ∇g_cache...)
g, ∇g = value_and_jacobian(g!, g, mpc.jacobian, mpc.Z̃, ∇g_cache...)
if !isnothing(mpc.hessian) && any(old_i_g)
@warn(
"Retrieving optimal Hessian of the Lagrangian is not fully supported yet.\n"*
Expand Down Expand Up @@ -618,7 +618,7 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃)
return nothing
end
∇geq = jacobian(geq!, geq, mpc.jacobian, mpc.Z̃, geq_cache...)
geq, ∇geq = value_and_jacobian(geq!, geq, mpc.jacobian, mpc.Z̃, geq_cache...)
if !isnothing(mpc.hessian) && con.neq > 0
@warn(
"Retrieving optimal Hessian of the Lagrangian is not fully supported yet.\n"*
Expand All @@ -642,8 +642,10 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
end
info[:∇J] = ∇J
info[:∇²J] = ∇²J
info[:g] = g
info[:∇g] = ∇g
info[:∇²ℓg] = ∇²ℓg
info[:geq] = geq
info[:∇geq] = ∇geq
info[:∇²ℓgeq] = ∇²ℓgeq
# --- non-Unicode fields ---
Expand Down
8 changes: 4 additions & 4 deletions src/estimator/mhe/execute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ following fields:
- `:D` : measured disturbances over ``N_k``, ``\mathbf{D}``
- `:sol` : solution summary of the optimizer for printing

For [`NonLinModel`](@ref), it also includes the following derivative fields:
For [`NonLinModel`](@ref), it also includes the following fields:

- `:JE`: economic cost value at the optimum, ``J_E``
- `:gc`: custom nonlinear constraints values at the optimum, ``\mathbf{g_c}``
- `:∇J` or *`:nablaJ`* : optimal gradient of the objective function, ``\mathbf{\nabla} J``
- `:∇²J` or *`:nabla2J`* : optimal Hessian of the objective function, ``\mathbf{\nabla^2}J``
- `:g` : optimal nonlinear inequality constraint values, ``\mathbf{g}``
- `:∇g` or *`:nablag`* : optimal Jacobian of the inequality constraint, ``\mathbf{\nabla g}``
- `:∇²ℓg` or *`:nabla2lg`* : optimal Hessian of the inequality Lagrangian, ``\mathbf{\nabla^2}\ell_{\mathbf{g}}``

Expand Down Expand Up @@ -220,7 +219,7 @@ function addinfo!(
update_prediction!(V̂, X̂0, û0, k0, ŷ0, g, estim, Z̃)
return nothing
end
∇g = jacobian(g!, g, estim.jacobian, estim.Z̃, ∇g_cache...)
g, ∇g = value_and_jacobian(g!, g, estim.jacobian, estim.Z̃, ∇g_cache...)
if !isnothing(estim.hessian) && any(old_i_g)
@warn(
"Retrieving optimal Hessian of the Lagrangian is not fully supported yet.\n"*
Expand All @@ -241,6 +240,7 @@ function addinfo!(
estim.con.i_g .= old_i_g # restore original finite/infinite constraint indices
info[:∇J] = ∇J
info[:∇²J] = ∇²J
info[:g] = g
info[:∇g] = ∇g
info[:∇²ℓg] = ∇²ℓg
# --- non-Unicode fields ---
Expand Down