Skip to content

Commit

Permalink
Merge pull request #153 from JuliaControl/debug_log_CI
Browse files Browse the repository at this point in the history
added: show @debug message in CI if debug logging is activated
  • Loading branch information
franckgaga authored Jan 29, 2025
2 parents 35ee483 + 5280bd9 commit cc2a92f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 11 deletions.
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

2 comments on commit cc2a92f

@franckgaga
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

  • added: show @debug messages in github CI is debug logging is activated
  • changed: @debug messages with the getinfo dictionary are never truncated (show_limited=false is no longer necessary)

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/123927

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.3.1 -m "<description of version>" cc2a92fd3a29b4d7811857d1a5ce12532f29a50c
git push origin v1.3.1

Please sign in to comment.