Skip to content

Commit cc2a92f

Browse files
authored
Merge pull request #153 from JuliaControl/debug_log_CI
added: show @debug message in CI if debug logging is activated
2 parents 35ee483 + 5280bd9 commit cc2a92f

File tree

8 files changed

+32
-11
lines changed

8 files changed

+32
-11
lines changed

.github/workflows/CI.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ jobs:
2727
arch:
2828
- x64
2929
steps:
30+
- name: Set JULIA_DEBUG environment variable
31+
if: ${{ runner.debug == '1' }}
32+
run: echo "JULIA_DEBUG=ModelPredictiveControl" >> $GITHUB_ENV
3033
- uses: actions/checkout@v2
3134
- uses: julia-actions/setup-julia@v1
3235
with:
@@ -39,4 +42,4 @@ jobs:
3942
- uses: codecov/codecov-action@v4
4043
with:
4144
token: ${{ secrets.CODECOV_TOKEN }}
42-
fail_ci_if_error: false
45+
fail_ci_if_error: false

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ModelPredictiveControl"
22
uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c"
33
authors = ["Francis Gagnon"]
4-
version = "1.3.0"
4+
version = "1.3.1"
55

66
[deps]
77
ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e"

src/controller/execute.jl

+1-4
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,7 @@ function optim_objective!(mpc::PredictiveController{NT}) where {NT<:Real}
531531
status
532532
)
533533
end
534-
@debug(
535-
"calling getinfo (use logger with show_limited=false if values are truncated)",
536-
getinfo(mpc)
537-
)
534+
@debug info2debugstr(getinfo(mpc))
538535
end
539536
if iserror(optim)
540537
mpc.ΔŨ .= ΔŨ0

src/estimator/mhe/execute.jl

+1-4
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,7 @@ function optim_objective!(estim::MovingHorizonEstimator{NT}) where NT<:Real
418418
status
419419
)
420420
end
421-
@debug(
422-
"calling getinfo (use logger with show_limited=false if values are truncated)",
423-
getinfo(estim)
424-
)
421+
@debug info2debugstr(getinfo(estim))
425422
end
426423
if iserror(optim)
427424
estim.Z̃ .= Z̃_0

src/general.jl

+15
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ function iserror(optim::JuMP.GenericModel)
2525
return any(errstatus->isequal(status, errstatus), ERROR_STATUSES)
2626
end
2727

28+
"Convert getinfo dictionary to a debug string (without any truncation)."
29+
function info2debugstr(info)
30+
mystr = "Content of getinfo dictionary:\n"
31+
for (key, value) in info
32+
(key == :sol) && continue
33+
mystr *= " :$key => $value\n"
34+
end
35+
if haskey(info, :sol)
36+
split_sol = split(string(info[:sol]), "\n")
37+
solstr = join((lpad(line, length(line) + 2) for line in split_sol), "\n", "")
38+
mystr *= " :sol => \n"*solstr
39+
end
40+
return mystr
41+
end
42+
2843
"Evaluate the quadratic programming objective function `0.5x'*H*x + q'*x` at `x`."
2944
obj_quadprog(x, H, q) = 0.5*dot(x, H, x) + q'*x # dot(x, H, x) is faster than x'*H*x
3045

test/runtests.jl

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ include("test_state_estim.jl")
1515
include("test_predictive_control.jl")
1616
include("test_plot_sim.jl")
1717

18+
old_debug_level = get(ENV, "JULIA_DEBUG", "")
1819
DocMeta.setdocmeta!(
1920
ModelPredictiveControl,
2021
:DocTestSetup,
21-
:(using ModelPredictiveControl, ControlSystemsBase);
22+
:(
23+
using ModelPredictiveControl, ControlSystemsBase;
24+
ENV["JULIA_DEBUG"] = ""; # temporarily disable @debug logging for the doctests
25+
);
2226
recursive=true,
2327
warn=false
2428
)
2529
doctest(ModelPredictiveControl, testset="DocTest")
30+
ENV["JULIA_DEBUG"] = old_debug_level
2631

2732
end;
2833

test/test_predictive_control.jl

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ end
8282
mpc4 = LinMPC(model2)
8383
preparestate!(mpc4, [0])
8484
moveinput!(mpc4, [0]) [0.0]
85+
@test_nowarn ModelPredictiveControl.info2debugstr(info)
8586

8687
@test_throws DimensionMismatch moveinput!(mpc1, [0,0,0])
8788
@test_throws DimensionMismatch moveinput!(mpc1, [0], [0,0])
@@ -407,6 +408,7 @@ end
407408
mpc4 = ExplicitMPC(model2)
408409
preparestate!(mpc4, [0])
409410
moveinput!(mpc4, [0]) [0.0]
411+
@test_nowarn ModelPredictiveControl.info2debugstr(info)
410412
end
411413

412414

@@ -633,6 +635,7 @@ end
633635
nonlinmodel2.h!(y, Float32[0,0], Float32[0], Float32[])
634636
preparestate!(nmpc7, [0], [0])
635637
@test moveinput!(nmpc7, [0], [0]) [0.0]
638+
@test_nowarn ModelPredictiveControl.info2debugstr(info)
636639
end
637640

638641
@testset "NonLinMPC step disturbance rejection" begin

test/test_state_estim.jl

+1
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ end
973973
info = getinfo(mhe5)
974974
@test info[:x̂] x̂ atol=1e-9
975975
@test info[:Ŷ][end-1:end] [50, 30] atol=1e-9
976+
@test_nowarn ModelPredictiveControl.info2debugstr(info)
976977
end
977978

978979
@testset "MovingHorizonEstimator fallbacks for arrival covariance estimation" begin

0 commit comments

Comments
 (0)