Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added: show @debug message in CI if debug logging is activated #153

Merged
merged 9 commits into from
Jan 29, 2025
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
5 changes: 4 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
arch:
- x64
steps:
- name: Set JULIA_DEBUG environment variable
if: ${{ runner.debug == '1' }}
run: echo "JULIA_DEBUG=ModelPredictiveControl" >> $GITHUB_ENV
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
Expand All @@ -39,4 +42,4 @@ jobs:
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
fail_ci_if_error: false
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ModelPredictiveControl"
uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c"
authors = ["Francis Gagnon"]
version = "1.3.0"
version = "1.3.1"

[deps]
ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e"
Expand Down
5 changes: 1 addition & 4 deletions src/controller/execute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,7 @@ function optim_objective!(mpc::PredictiveController{NT}) where {NT<:Real}
status
)
end
@debug(
"calling getinfo (use logger with show_limited=false if values are truncated)",
getinfo(mpc)
)
@debug info2debugstr(getinfo(mpc))
end
if iserror(optim)
mpc.ΔŨ .= ΔŨ0
Expand Down
5 changes: 1 addition & 4 deletions src/estimator/mhe/execute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,7 @@ function optim_objective!(estim::MovingHorizonEstimator{NT}) where NT<:Real
status
)
end
@debug(
"calling getinfo (use logger with show_limited=false if values are truncated)",
getinfo(estim)
)
@debug info2debugstr(getinfo(estim))
end
if iserror(optim)
estim.Z̃ .= Z̃_0
Expand Down
15 changes: 15 additions & 0 deletions src/general.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ function iserror(optim::JuMP.GenericModel)
return any(errstatus->isequal(status, errstatus), ERROR_STATUSES)
end

"Convert getinfo dictionary to a debug string (without any truncation)."
function info2debugstr(info)
mystr = "Content of getinfo dictionary:\n"
for (key, value) in info
(key == :sol) && continue
mystr *= " :$key => $value\n"
end
if haskey(info, :sol)
split_sol = split(string(info[:sol]), "\n")
solstr = join((lpad(line, length(line) + 2) for line in split_sol), "\n", "")
mystr *= " :sol => \n"*solstr
end
return mystr
end

"Evaluate the quadratic programming objective function `0.5x'*H*x + q'*x` at `x`."
obj_quadprog(x, H, q) = 0.5*dot(x, H, x) + q'*x # dot(x, H, x) is faster than x'*H*x

Expand Down
7 changes: 6 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ include("test_state_estim.jl")
include("test_predictive_control.jl")
include("test_plot_sim.jl")

old_debug_level = get(ENV, "JULIA_DEBUG", "")
DocMeta.setdocmeta!(
ModelPredictiveControl,
:DocTestSetup,
:(using ModelPredictiveControl, ControlSystemsBase);
:(
using ModelPredictiveControl, ControlSystemsBase;
ENV["JULIA_DEBUG"] = ""; # temporarily disable @debug logging for the doctests
);
recursive=true,
warn=false
)
doctest(ModelPredictiveControl, testset="DocTest")
ENV["JULIA_DEBUG"] = old_debug_level

end;

Expand Down
3 changes: 3 additions & 0 deletions test/test_predictive_control.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ end
mpc4 = LinMPC(model2)
preparestate!(mpc4, [0])
moveinput!(mpc4, [0]) ≈ [0.0]
@test_nowarn ModelPredictiveControl.info2debugstr(info)

@test_throws DimensionMismatch moveinput!(mpc1, [0,0,0])
@test_throws DimensionMismatch moveinput!(mpc1, [0], [0,0])
Expand Down Expand Up @@ -407,6 +408,7 @@ end
mpc4 = ExplicitMPC(model2)
preparestate!(mpc4, [0])
moveinput!(mpc4, [0]) ≈ [0.0]
@test_nowarn ModelPredictiveControl.info2debugstr(info)
end


Expand Down Expand Up @@ -633,6 +635,7 @@ end
nonlinmodel2.h!(y, Float32[0,0], Float32[0], Float32[])
preparestate!(nmpc7, [0], [0])
@test moveinput!(nmpc7, [0], [0]) ≈ [0.0]
@test_nowarn ModelPredictiveControl.info2debugstr(info)
end

@testset "NonLinMPC step disturbance rejection" begin
Expand Down
1 change: 1 addition & 0 deletions test/test_state_estim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ end
info = getinfo(mhe5)
@test info[:x̂] ≈ x̂ atol=1e-9
@test info[:Ŷ][end-1:end] ≈ [50, 30] atol=1e-9
@test_nowarn ModelPredictiveControl.info2debugstr(info)
end

@testset "MovingHorizonEstimator fallbacks for arrival covariance estimation" begin
Expand Down
Loading