From 8b59d529fbb65b7cd4b07103f7150d4e85d446a7 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Sun, 26 Jan 2025 16:15:47 -0500 Subject: [PATCH 1/9] added: show @debug message in CI if debug logging is activated --- .github/workflows/CI.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 82bc6d704..3c36e3867 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -39,4 +39,7 @@ jobs: - uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} - fail_ci_if_error: false + fail_ci_if_error: false + - name: Set JULIA_DEBUG environment variable + if: ${{ runner.debug == '1' }} + run: echo "JULIA_DEBUG=all" >> $GITHUB_ENV \ No newline at end of file From d71e0f05456731854d90201349d0892ef0b56551 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Sun, 26 Jan 2025 16:40:30 -0500 Subject: [PATCH 2/9] testing export --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 3c36e3867..fbae5d328 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -42,4 +42,4 @@ jobs: fail_ci_if_error: false - name: Set JULIA_DEBUG environment variable if: ${{ runner.debug == '1' }} - run: echo "JULIA_DEBUG=all" >> $GITHUB_ENV \ No newline at end of file + run: export JULIA_DEBUG="all" \ No newline at end of file From dc6f5f3cc4007b534bbcded7c9a748141c730b77 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Sun, 26 Jan 2025 17:01:43 -0500 Subject: [PATCH 3/9] first step --- .github/workflows/CI.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index fbae5d328..b1f4a0dc0 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=all" >> $GITHUB_ENV - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: @@ -39,7 +42,4 @@ jobs: - uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} - fail_ci_if_error: false - - name: Set JULIA_DEBUG environment variable - if: ${{ runner.debug == '1' }} - run: export JULIA_DEBUG="all" \ No newline at end of file + fail_ci_if_error: false \ No newline at end of file From 9b18425714ff60940754f0a6828814dd5ba068a6 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Sun, 26 Jan 2025 18:09:33 -0500 Subject: [PATCH 4/9] debug logging only for `ModelPredictiveControl` package --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index b1f4a0dc0..0a13f11b7 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -29,7 +29,7 @@ jobs: steps: - name: Set JULIA_DEBUG environment variable if: ${{ runner.debug == '1' }} - run: echo "JULIA_DEBUG=all" >> $GITHUB_ENV + run: echo "JULIA_DEBUG=ModelPredictiveControl" >> $GITHUB_ENV - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: From c8f9eb117df918eedfffef309626396a96713590 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Tue, 28 Jan 2025 18:21:10 -0500 Subject: [PATCH 5/9] added: `info2debugstr` to force no truncation in `@debug` --- src/controller/execute.jl | 5 +---- src/estimator/mhe/execute.jl | 5 +---- src/general.jl | 9 +++++++++ 3 files changed, 11 insertions(+), 8 deletions(-) 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..3004d1ecc 100644 --- a/src/general.jl +++ b/src/general.jl @@ -25,6 +25,15 @@ 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 + mystr *= " :$key => $value\n" + 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 From c5f6145c9a9940f2ce9e40a3cbe007b17061e2e0 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Tue, 28 Jan 2025 18:32:12 -0500 Subject: [PATCH 6/9] bump --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From ebb1be090b1cbbffa6b46e3fc3de8b3a1827e4cf Mon Sep 17 00:00:00 2001 From: franckgaga Date: Tue, 28 Jan 2025 19:19:36 -0500 Subject: [PATCH 7/9] added: disable debug logging for doctests --- test/runtests.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 57954b230..fd8e8ef94 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 = 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; From f544093be9a1aac0b8d8a5cbfd10aa022541fce6 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Tue, 28 Jan 2025 19:27:26 -0500 Subject: [PATCH 8/9] test: call `info2debugstr` function for coverage --- test/test_predictive_control.jl | 3 +++ test/test_state_estim.jl | 1 + 2 files changed, 4 insertions(+) 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 From 5280bd950fb6c8d92a09e6c39ba47fcdb24e4185 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Tue, 28 Jan 2025 20:41:25 -0500 Subject: [PATCH 9/9] debug: use `get` for `runtests.jl` --- src/general.jl | 6 ++++++ test/runtests.jl | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/general.jl b/src/general.jl index 3004d1ecc..19a748638 100644 --- a/src/general.jl +++ b/src/general.jl @@ -29,8 +29,14 @@ end 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 diff --git a/test/runtests.jl b/test/runtests.jl index fd8e8ef94..ac55e1346 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -15,7 +15,7 @@ include("test_state_estim.jl") include("test_predictive_control.jl") include("test_plot_sim.jl") -old_debug_level = ENV["JULIA_DEBUG"] +old_debug_level = get(ENV, "JULIA_DEBUG", "") DocMeta.setdocmeta!( ModelPredictiveControl, :DocTestSetup,