Skip to content

Commit 84f6688

Browse files
authored
Merge pull request #152 from JuliaControl/debug_moreinfo
added: call `getinfo` when debug logging is activated and not solved
2 parents 3ed42e4 + 371a150 commit 84f6688

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

src/controller/execute.jl

+17-7
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ julia> round.(getinfo(mpc)[:Ŷ], digits=3)
114114
function getinfo(mpc::PredictiveController{NT}) where NT<:Real
115115
model = mpc.estim.model
116116
nŶe, nUe = (mpc.Hp+1)*model.ny, (mpc.Hp+1)*model.nu
117-
info = Dict{Symbol, Union{JuMP._SolutionSummary, Vector{NT}, NT}}()
117+
info = Dict{Symbol, Any}()
118118
Ŷ0, u0, û0 = similar(mpc.Yop), similar(model.uop), similar(model.uop)
119119
Ŷs = similar(mpc.Yop)
120120
x̂0, x̂0next = similar(mpc.estim.x̂0), similar(mpc.estim.x̂0)
@@ -491,7 +491,8 @@ If supported by `mpc.optim`, it warm-starts the solver at:
491491
where ``\mathbf{Δu}_{k-1}(k+j)`` is the input increment for time ``k+j`` computed at the
492492
last control period ``k-1``. It then calls `JuMP.optimize!(mpc.optim)` and extract the
493493
solution. A failed optimization prints an `@error` log in the REPL and returns the
494-
warm-start value.
494+
warm-start value. A failed optimization also prints [`getinfo`](@ref) results in
495+
the debug log [if activated](https://docs.julialang.org/en/v1/stdlib/Logging/#Example:-Enable-debug-level-messages).
495496
"""
496497
function optim_objective!(mpc::PredictiveController{NT}) where {NT<:Real}
497498
model, optim = mpc.estim.model, mpc.optim
@@ -518,13 +519,22 @@ function optim_objective!(mpc::PredictiveController{NT}) where {NT<:Real}
518519
if !issolved(optim)
519520
status = JuMP.termination_status(optim)
520521
if iserror(optim)
521-
@error("MPC terminated without solution: returning last solution shifted",
522-
status)
522+
@error(
523+
"MPC terminated without solution: estimation in open-loop "*
524+
"(more info in debug log)",
525+
status
526+
)
523527
else
524-
@warn("MPC termination status not OPTIMAL or LOCALLY_SOLVED: keeping "*
525-
"solution anyway", status)
528+
@warn(
529+
"MPC termination status not OPTIMAL or LOCALLY_SOLVED: keeping solution "*
530+
"anyway (more info in debug log)",
531+
status
532+
)
526533
end
527-
@debug JuMP.solution_summary(optim, verbose=true)
534+
@debug(
535+
"calling getinfo (use logger with show_limited=false if values are truncated)",
536+
getinfo(mpc)
537+
)
528538
end
529539
if iserror(optim)
530540
mpc.ΔŨ .= ΔŨ0

src/estimator/mhe/execute.jl

+17-8
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ function getinfo(estim::MovingHorizonEstimator{NT}) where NT<:Real
108108
nu, ny, nd = model.nu, model.ny, model.nd
109109
nx̂, nym, nŵ, nϵ = estim.nx̂, estim.nym, estim.nx̂, estim.
110110
nx̃ =+ nx̂
111-
MyTypes = Union{JuMP._SolutionSummary, Hermitian{NT, Matrix{NT}}, Vector{NT}, NT}
112-
info = Dict{Symbol, MyTypes}()
111+
info = Dict{Symbol, Any}()
113112
V̂, X̂0 = similar(estim.Y0m[1:nym*Nk]), similar(estim.X̂0[1:nx̂*Nk])
114113
û0, ŷ0 = similar(model.uop), similar(model.yop)
115114
V̂, X̂0 = predict!(V̂, X̂0, û0, ŷ0, estim, model, estim.Z̃)
@@ -370,7 +369,8 @@ If supported by `estim.optim`, it warm-starts the solver at:
370369
where ``\mathbf{ŵ}_{k-1}(k-j)`` is the input increment for time ``k-j`` computed at the
371370
last time step ``k-1``. It then calls `JuMP.optimize!(estim.optim)` and extract the
372371
solution. A failed optimization prints an `@error` log in the REPL and returns the
373-
warm-start value.
372+
warm-start value. A failed optimization also prints [`getinfo`](@ref) results in
373+
the debug log [if activated](https://docs.julialang.org/en/v1/stdlib/Logging/#Example:-Enable-debug-level-messages).
374374
"""
375375
function optim_objective!(estim::MovingHorizonEstimator{NT}) where NT<:Real
376376
model, optim = estim.model, estim.optim
@@ -406,13 +406,22 @@ function optim_objective!(estim::MovingHorizonEstimator{NT}) where NT<:Real
406406
if !issolved(optim)
407407
status = JuMP.termination_status(optim)
408408
if iserror(optim)
409-
@error("MHE terminated without solution: estimation in open-loop",
410-
status)
409+
@error(
410+
"MHE terminated without solution: estimation in open-loop "*
411+
"(more info in debug log)",
412+
status
413+
)
411414
else
412-
@warn("MHE termination status not OPTIMAL or LOCALLY_SOLVED: keeping "*
413-
"solution anyway", status)
415+
@warn(
416+
"MHE termination status not OPTIMAL or LOCALLY_SOLVED: keeping solution "*
417+
"anyway (more info in debug log)",
418+
status
419+
)
414420
end
415-
@debug JuMP.solution_summary(optim, verbose=true)
421+
@debug(
422+
"calling getinfo (use logger with show_limited=false if values are truncated)",
423+
getinfo(estim)
424+
)
416425
end
417426
if iserror(optim)
418427
estim.Z̃ .= Z̃_0

0 commit comments

Comments
 (0)