diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 82bc6d704..0a13f11b7 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -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: @@ -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 \ No newline at end of file diff --git a/Project.toml b/Project.toml index c23223b59..2d467c9fc 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/controller/execute.jl b/src/controller/execute.jl index 51a366029..a93ff59dd 100644 --- a/src/controller/execute.jl +++ b/src/controller/execute.jl @@ -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 diff --git a/src/estimator/mhe/execute.jl b/src/estimator/mhe/execute.jl index 5dcb89692..5ec313bef 100644 --- a/src/estimator/mhe/execute.jl +++ b/src/estimator/mhe/execute.jl @@ -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 diff --git a/src/general.jl b/src/general.jl index 1e512b62d..19a748638 100644 --- a/src/general.jl +++ b/src/general.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 57954b230..ac55e1346 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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; diff --git a/test/test_predictive_control.jl b/test/test_predictive_control.jl index ee0ae637a..278082370 100644 --- a/test/test_predictive_control.jl +++ b/test/test_predictive_control.jl @@ -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]) @@ -407,6 +408,7 @@ end mpc4 = ExplicitMPC(model2) preparestate!(mpc4, [0]) moveinput!(mpc4, [0]) ≈ [0.0] + @test_nowarn ModelPredictiveControl.info2debugstr(info) end @@ -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 diff --git a/test/test_state_estim.jl b/test/test_state_estim.jl index 6a4ce0166..28c117b32 100644 --- a/test/test_state_estim.jl +++ b/test/test_state_estim.jl @@ -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