From 50a90dffc247c34ac05cc9406b3a51f23b60f3cd Mon Sep 17 00:00:00 2001 From: franckgaga Date: Tue, 8 Oct 2024 10:15:58 -0400 Subject: [PATCH 1/7] added: additional details in the observability error message --- src/estimator/construct.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/estimator/construct.jl b/src/estimator/construct.jl index 326c8c63..4a4916af 100644 --- a/src/estimator/construct.jl +++ b/src/estimator/construct.jl @@ -156,7 +156,9 @@ function augment_model(model::LinModel{NT}, As, Cs_u, Cs_y; verify_obsv=true) wh if verify_obsv && !ControlSystemsBase.observability(Â, Ĉ)[:isobservable] error("The augmented model is unobservable. You may try to use 0 integrator on "* "model integrating outputs with nint_ym parameter. Adding integrators at both "* - "inputs (nint_u) and outputs (nint_ym) can also violate observability.") + "inputs (nint_u) and outputs (nint_ym) can also violate observability. If the "* + "model is still unobservable without any integrators, you may need to call "* + "sminreal or minreal on your system.") end x̂op, f̂op = [model.xop; zeros(nxs)], [model.fop; zeros(nxs)] return Â, B̂u, Ĉ, B̂d, D̂d, x̂op, f̂op From 688b28fbeb971f020352ccc2267e98e96cfcc8cf Mon Sep 17 00:00:00 2001 From: franckgaga Date: Tue, 8 Oct 2024 12:50:32 -0400 Subject: [PATCH 2/7] CI: tests on `lts` an `release` versions, build doc on `release` --- .github/workflows/CI.yml | 4 ++-- .github/workflows/documentation.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 37ab810e..35efbb1e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -19,8 +19,8 @@ jobs: fail-fast: false matrix: version: - - '1.6' - - '1' + - 'release' + - 'lts' - 'nightly' os: - ubuntu-latest diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 404de46f..c97d5be0 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: - version: '1' + version: 'release' - name: Install dependencies run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' - name: Build and deploy From 1eae9cc1e698090f2318b3fe3270c2be8f28e63b Mon Sep 17 00:00:00 2001 From: franckgaga Date: Tue, 8 Oct 2024 12:53:12 -0400 Subject: [PATCH 3/7] debug: replace `release` tag with `1` --- .github/workflows/CI.yml | 2 +- .github/workflows/documentation.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 35efbb1e..e280f17c 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -19,7 +19,7 @@ jobs: fail-fast: false matrix: version: - - 'release' + - '1' - 'lts' - 'nightly' os: diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index c97d5be0..404de46f 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: - version: 'release' + version: '1' - name: Install dependencies run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' - name: Build and deploy From b22a18bef063dc6b596797cbff7e0e5a3b5967ee Mon Sep 17 00:00:00 2001 From: franckgaga Date: Tue, 8 Oct 2024 13:08:36 -0400 Subject: [PATCH 4/7] changed `lts` to `1.10` --- .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 e280f17c..82bc6d70 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -20,7 +20,7 @@ jobs: matrix: version: - '1' - - 'lts' + - '1.10' - 'nightly' os: - ubuntu-latest From 2cb763f625d55dce89a3026aab0f0a6a2f6f5426 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Tue, 8 Oct 2024 16:36:41 -0400 Subject: [PATCH 5/7] remove code related to julia 1.6 compatibility --- src/estimator/kalman.jl | 12 ++++++++---- src/model/solver.jl | 12 +++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/estimator/kalman.jl b/src/estimator/kalman.jl index 1c40a280..4322131b 100644 --- a/src/estimator/kalman.jl +++ b/src/estimator/kalman.jl @@ -38,11 +38,15 @@ struct SteadyKalmanFilter{NT<:Real, SM<:LinModel} <: StateEstimator{NT} Â, B̂u, Ĉ, B̂d, D̂d, x̂op, f̂op = augment_model(model, As, Cs_u, Cs_y) Ĉm, D̂dm = Ĉ[i_ym, :], D̂d[i_ym, :] validate_kfcov(nym, nx̂, Q̂, R̂) + if ny == nym + R̂_y = R̂ + else + R̂_y = zeros(NT, ny, ny) + R̂_y[i_ym, i_ym] = R̂ + R̂_y = Hermitian(R̂_y, :L) + end K̂ = try - Q̂_kalman = Matrix(Q̂) # Matrix() required for Julia 1.6 - R̂_kalman = zeros(NT, ny, ny) - R̂_kalman[i_ym, i_ym] = R̂ - ControlSystemsBase.kalman(Discrete, Â, Ĉ, Q̂_kalman, R̂_kalman; direct)[:, i_ym] + ControlSystemsBase.kalman(Discrete, Â, Ĉ, Q̂, R̂_y; direct)[:, i_ym] catch my_error if isa(my_error, ErrorException) error("Cannot compute the optimal Kalman gain K̂ for the "* diff --git a/src/model/solver.jl b/src/model/solver.jl index f0b3676f..9ab54a3c 100644 --- a/src/model/solver.jl +++ b/src/model/solver.jl @@ -47,13 +47,11 @@ function get_solver_functions(NT::DataType, solver::RungeKutta, fc!, hc!, Ts, _ k4_cache::DiffCache{Vector{NT}, Vector{NT}} = DiffCache(zeros(NT, nx), Nc) f! = function inner_solver_f!(xnext, x, u, d, p) CT = promote_type(eltype(x), eltype(u), eltype(d)) - # dummy variable for get_tmp, necessary for PreallocationTools + Julia 1.6 : - var::CT = 0 - xcur = get_tmp(xcur_cache, var) - k1 = get_tmp(k1_cache, var) - k2 = get_tmp(k2_cache, var) - k3 = get_tmp(k3_cache, var) - k4 = get_tmp(k4_cache, var) + xcur = get_tmp(xcur_cache, CT) + k1 = get_tmp(k1_cache, CT) + k2 = get_tmp(k2_cache, CT) + k3 = get_tmp(k3_cache, CT) + k4 = get_tmp(k4_cache, CT) xterm = xnext @. xcur = x for i=1:solver.supersample From 2e481ecbe2d6eda800ccf437d08f974240e1bbd2 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Tue, 8 Oct 2024 18:05:46 -0400 Subject: [PATCH 6/7] doc: mtk example now uses the in-place output function (but still crash with same error `BoundsError: attempt to access Float64 at index [2]`) --- docs/src/manual/mtk.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/src/manual/mtk.md b/docs/src/manual/mtk.md index 68df46b1..2d410b9a 100644 --- a/docs/src/manual/mtk.md +++ b/docs/src/manual/mtk.md @@ -76,14 +76,18 @@ function generate_f_h(model, inputs, outputs) end return nothing end - h_ = ModelingToolkit.build_explicit_observed_function(io_sys, outputs; inputs) + return_inplace = true + (_, h_ip) = ModelingToolkit.build_explicit_observed_function( + io_sys, outputs; inputs, return_inplace + ) + println(h_ip) u_nothing = fill(nothing, nu) function h!(y, x, _ , p) - y .= try + try # MTK.jl supports a `u` argument in `h_` function but not this package. We set # `u` as a vector of nothing and `h_` function will presumably throw an # MethodError it this argument is used inside the function - h_(x, u_nothing, p, nothing) + h_ip(y, x, u_nothing, p, nothing) catch err if err isa MethodError error("NonLinModel only support strictly proper systems (no manipulated "* From 80097526744ea2c84913aa8be0f9ee04234c6c29 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Wed, 9 Oct 2024 09:47:24 -0400 Subject: [PATCH 7/7] restrict MTK.jl to v.9.41 in doc building --- docs/Project.toml | 2 +- docs/src/manual/mtk.md | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/Project.toml b/docs/Project.toml index 2f94ea2f..7aa68c8f 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -16,4 +16,4 @@ JuMP = "1" LinearAlgebra = "1.6" Logging = "1.6" Plots = "1" -ModelingToolkit = "9" +ModelingToolkit = "~9.41" diff --git a/docs/src/manual/mtk.md b/docs/src/manual/mtk.md index 2d410b9a..76c44cea 100644 --- a/docs/src/manual/mtk.md +++ b/docs/src/manual/mtk.md @@ -22,6 +22,9 @@ the last section. as a basic starting template to combine both packages. There is no guarantee that it will work for all corner cases. +!!! compat + The example only work with `ModelingToolkit.jl` v9.41 releases. + We first construct and instantiate the pendulum model: ```@example 1