Skip to content

Conversation

franckgaga
Copy link
Member

@franckgaga franckgaga commented Sep 10, 2025

This new feature allows two things:

  1. fixing the arrival covariance of the MHE at the Kalman Filter steady-state value $\mathbf{\hat{P}}(\infty)$. This is common choice in the literature, and its the default behaviour when covestim is a SteadyKalmanFilter. Note that the default covestim for the MHE with a LinModel is still a time-varying KalmanFilter.
  2. with some tweaking, fixing the arrival covariance at an arbitrary value selected by the user, for example:
    using ControlSystemsBase, ModelPredictiveControl, LinearAlgebra
    linmodel = LinModel(tf(2, [10, 1]), 1.0)
    i_ym, nint_u, nint_ym, He = 1:1, [1], 0, 10= diagm([1/2, 1].^2) 
    R̂ = diagm([1].^2)
    covestim = SteadyKalmanFilter(linmodel, i_ym, nint_u, nint_ym, Q̂, R̂)
    P̂_0 = diagm([0.1, 0.1].^2) # user-specified fixed arrival covariance
    setstate!(covestim, zeros(2), P̂_0)
    mhe = MovingHorizonEstimator(linmodel, He, i_ym, nint_u, nint_ym, P̂_0, Q̂, R̂; covestim)
    for i in 1:25
        y = [2.0]
        x̂ = preparestate!(mhe, y)
        u = [0.0]
        println(x̂)
        updatestate!(mhe, u, y)
    end
    The same is also possible with NonLinModel. The user just needs to construct a SteadyKalmanFilter with a dummy LinModel with the same number of estimated state nx̂ than the MHE, and fix the arrival covariance using setstate! as above.

The covestim argument is also now displayed when pretty-printing a MovingHorizonEstimator, in the "arrival covariance" field:

MovingHorizonEstimator estimator with a sample time Ts = 4.0 s:
├ model: LinModel
├ optimizer: OSQP 
├ arrival covariance: SteadyKalmanFilter 
└ dimensions:
  ├ 5 estimation steps He
  ├ 0 slack variable ε (estimation constraints)
  ├ 2 manipulated inputs u (0 integrating states)
  ├ 4 estimated states x̂
  ├ 2 measured outputs ym (0 integrating states)
  ├ 0 unmeasured outputs yu
  └ 1 measured disturbances d

Note that it relies on the new extra=Val(true) arguments in ControlSystemsBase.jl, introduced in v1.18.2. This PR hence bumps the compat entry to ControlSystemsBase = "1.18.2"
edit: Come to think of it, I don't this that's a good idea to bump the compat of ControlSystemsBase.jl just for this niche feature. I now rely on pkgversion(ControlSystemsBase) to pass or not the extra keyword argument to kalman. Do you see any drawback to this workaround @baggepinnen ?

edit 2: Also I notice that the computed steady-state Kalman gain with direct=true is not the same before and after v1.18.2, you corrected a mistake in the formula @baggepinnen ?

@franckgaga franckgaga changed the title added: SteadyKalmanFilter support for covestim in added: SteadyKalmanFilter support for covestim in MovingHorizonEstimator Sep 10, 2025
@franckgaga franckgaga changed the title added: SteadyKalmanFilter support for covestim in MovingHorizonEstimator added: covestim in MovingHorizonEstimator now supports SteadyKalmanFilter Sep 10, 2025
Copy link

github-actions bot commented Sep 10, 2025

Benchmark Results (Julia v1)

Time benchmarks
main e0e7c84... main / e0e7c84...
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/DAQP/SingleShooting 6.96 ± 0.53 ms 6.98 ± 0.51 ms 0.996 ± 0.1
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/Ipopt/MultipleShooting 0.318 ± 0.006 s 0.321 ± 0.0044 s 0.988 ± 0.023
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/Ipopt/SingleShooting 0.231 ± 0.014 s 0.234 ± 0.011 s 0.989 ± 0.076
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/OSQP/MultipleShooting 8.8 ± 0.59 ms 9.38 ± 0.61 ms 0.938 ± 0.087
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/OSQP/SingleShooting 1.46 ± 0.084 ms 1.55 ± 0.082 ms 0.946 ± 0.074
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/DAQP/SingleShooting 6.96 ± 0.66 ms 7.04 ± 0.51 ms 0.988 ± 0.12
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/Ipopt/MultipleShooting 0.279 ± 0.0033 s 0.286 ± 0.002 s 0.975 ± 0.013
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/Ipopt/SingleShooting 0.235 ± 0.0026 s 0.247 ± 0.0019 s 0.951 ± 0.013
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/OSQP/MultipleShooting 5.92 ± 0.42 ms 6.47 ± 0.47 ms 0.915 ± 0.092
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/OSQP/SingleShooting 1.59 ± 0.096 ms 1.68 ± 0.049 ms 0.949 ± 0.063
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/DAQP/SingleShooting 8.28 ± 1.5 ms 8.17 ± 1.4 ms 1.01 ± 0.25
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/Ipopt/MultipleShooting 0.333 ± 0.036 s 0.333 ± 0.033 s 1 ± 0.15
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/Ipopt/SingleShooting 0.157 ± 0.0021 s 0.159 ± 0.0018 s 0.987 ± 0.017
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/OSQP/MultipleShooting 0.112 ± 0.014 s 0.116 ± 0.014 s 0.962 ± 0.17
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/OSQP/SingleShooting 12 ± 1.8 ms 11.8 ± 1.7 ms 1.02 ± 0.21
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/MultipleShooting 1.96 ± 0.027 s 1.95 ± 0.029 s 1.01 ± 0.021
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/SingleShooting 2.11 ± 0.026 s 2.1 ± 0.023 s 1.01 ± 0.016
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/TrapezoidalCollocation 1.93 ± 0.042 s 1.96 ± 0.03 s 0.983 ± 0.026
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/MultipleShooting 0.891 ± 0.018 s 0.909 ± 0.012 s 0.981 ± 0.024
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/SingleShooting 0.511 ± 0.04 s 0.52 ± 0.05 s 0.982 ± 0.12
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/TrapezoidalCollocation 0.859 ± 0.011 s 0.863 ± 0.013 s 0.996 ± 0.02
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/MadNLP/SingleShooting 0.142 ± 0.0046 s 0.143 ± 0.0046 s 0.99 ± 0.045
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/MultipleShooting 0.796 ± 0.013 s 0.817 ± 0.019 s 0.974 ± 0.028
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/SingleShooting 0.501 ± 0.045 s 0.501 ± 0.054 s 1 ± 0.14
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/TrapezoidalCollocation 0.753 ± 0.01 s 0.788 ± 0.011 s 0.955 ± 0.018
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/MadNLP/SingleShooting 0.123 ± 0.0057 s 0.121 ± 0.0053 s 1.01 ± 0.064
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/DAQP/Current form 0.0415 ± 0.006 s 0.0428 ± 0.0062 s 0.971 ± 0.2
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/DAQP/Prediction form 0.0354 ± 0.0031 s 0.0354 ± 0.0044 s 0.999 ± 0.15
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/Ipopt/Current form 0.198 ± 0.03 s 0.196 ± 0.044 s 1.01 ± 0.27
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/Ipopt/Prediction form 0.17 ± 0.034 s 0.172 ± 0.024 s 0.984 ± 0.24
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/OSQP/Current form 0.0369 ± 0.0054 s 0.0366 ± 0.0049 s 1.01 ± 0.2
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/OSQP/Prediction form 27.7 ± 1.9 ms 27.3 ± 2.8 ms 1.01 ± 0.12
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/Ipopt/Current form 14.2 ± 0.17 s 14.7 ± 0.32 s 0.967 ± 0.024
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/Ipopt/Prediction form 4.24 ± 0.075 s 4.39 ± 0.058 s 0.966 ± 0.021
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/MadNLP/Current form 2.09 ± 0.027 s 2.1 ± 0.039 s 0.995 ± 0.022
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/MadNLP/Prediction form 1.21 ± 0.0079 s 1.24 ± 0.025 s 0.979 ± 0.021
UNIT TESTS/PredictiveController/ExplicitMPC/moveinput! 2.58 ± 0.03 μs 2.53 ± 0.021 μs 1.02 ± 0.015
UNIT TESTS/PredictiveController/LinMPC/moveinput!/MultipleShooting 0.108 ± 0.0037 ms 0.119 ± 0.0049 ms 0.911 ± 0.049
UNIT TESTS/PredictiveController/LinMPC/moveinput!/SingleShooting 12.8 ± 0.33 μs 13.9 ± 0.32 μs 0.923 ± 0.032
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/LinModel/MultipleShooting 2.87 ± 0.18 ms 3.04 ± 0.3 ms 0.945 ± 0.11
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/LinModel/SingleShooting 1.95 ± 0.11 ms 1.96 ± 0.11 ms 0.992 ± 0.082
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/MultipleShooting 8.93 ± 0.35 ms 9.35 ± 0.38 ms 0.955 ± 0.054
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/SingleShooting 1.91 ± 0.1 ms 2.02 ± 0.11 ms 0.948 ± 0.071
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/TrapezoidalCollocation 3.74 ± 0.22 ms 3.99 ± 0.24 ms 0.938 ± 0.077
UNIT TESTS/SimModel/LinModel/evaloutput 0.13 ± 0.001 μs 0.13 ± 0.01 μs 1 ± 0.077
UNIT TESTS/SimModel/LinModel/updatestate! 0.211 ± 0.001 μs 0.211 ± 0.011 μs 1 ± 0.052
UNIT TESTS/SimModel/NonLinModel/evaloutput 0.14 ± 0.01 μs 0.14 ± 0.01 μs 1 ± 0.1
UNIT TESTS/SimModel/NonLinModel/linearize! 1.14 ± 0.01 μs 1.15 ± 0.01 μs 0.99 ± 0.012
UNIT TESTS/SimModel/NonLinModel/updatestate! 0.22 ± 0.01 μs 0.21 ± 0.01 μs 1.05 ± 0.069
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/evaloutput/LinModel 0.131 ± 0.01 μs 0.14 ± 0.009 μs 0.936 ± 0.093
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/evaloutput/NonLinModel 0.19 ± 0.001 μs 0.181 ± 0.01 μs 1.05 ± 0.058
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/preparestate!/LinModel 0.04 ± 0 μs 0.04 ± 0 μs 1 ± 0
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/preparestate!/NonLinModel 0.04 ± 0 μs 0.04 ± 0 μs 1 ± 0
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/updatestate!/LinModel 2.92 ± 0.041 μs 2.77 ± 0.03 μs 1.05 ± 0.019
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/updatestate!/NonLinModel 3.46 ± 0.041 μs 3.38 ± 0.031 μs 1.02 ± 0.015
UNIT TESTS/StateEstimator/InternalModel/evaloutput/LinModel 0.12 ± 0.01 μs 0.12 ± 0.001 μs 1 ± 0.084
UNIT TESTS/StateEstimator/InternalModel/evaloutput/NonLinModel 0.12 ± 0.001 μs 0.12 ± 0.01 μs 1 ± 0.084
UNIT TESTS/StateEstimator/InternalModel/preparestate!/LinModel 0.19 ± 0.01 μs 0.19 ± 0.01 μs 1 ± 0.074
UNIT TESTS/StateEstimator/InternalModel/preparestate!/NonLinModel 0.19 ± 0.01 μs 0.19 ± 0.011 μs 1 ± 0.078
UNIT TESTS/StateEstimator/InternalModel/updatestate!/LinModel 0.311 ± 0.001 μs 0.311 ± 0.011 μs 1 ± 0.036
UNIT TESTS/StateEstimator/InternalModel/updatestate!/NonLinModel 0.31 ± 0.01 μs 0.31 ± 0.019 μs 1 ± 0.069
UNIT TESTS/StateEstimator/KalmanFilter/evaloutput 0.14 ± 0.01 μs 0.14 ± 0.001 μs 1 ± 0.072
UNIT TESTS/StateEstimator/KalmanFilter/preparestate! 0.04 ± 0.01 μs 0.05 ± 0.01 μs 0.8 ± 0.26
UNIT TESTS/StateEstimator/KalmanFilter/updatestate! 2.08 ± 0.03 μs 2.1 ± 0.019 μs 0.99 ± 0.017
UNIT TESTS/StateEstimator/Luenberger/evaloutput 0.14 ± 0.01 μs 0.15 ± 0.01 μs 0.933 ± 0.091
UNIT TESTS/StateEstimator/Luenberger/preparestate! 0.2 ± 0.001 μs 0.21 ± 0.001 μs 0.952 ± 0.0066
UNIT TESTS/StateEstimator/Luenberger/updatestate! 0.29 ± 0.01 μs 0.291 ± 0.01 μs 0.997 ± 0.049
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/LinModel/Current form 3.35 ± 4.1 ms 3.55 ± 4.4 ms 0.945 ± 1.7
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/LinModel/Prediction form 0.04 ± 0.009 μs 0.04 ± 0 μs 1 ± 0.23
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/NonLinModel/Current form 0.331 ± 0.02 ms 0.345 ± 0.019 ms 0.959 ± 0.08
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/NonLinModel/Prediction form 0.04 ± 0 μs 0.04 ± 0 μs 1 ± 0
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/LinModel/Current form 6.3 ± 2.4 μs 6.31 ± 2.4 μs 0.998 ± 0.54
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/LinModel/Prediction form 3.16 ± 0.28 ms 3.27 ± 0.49 ms 0.968 ± 0.17
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/NonLinModel/Current form 13.4 ± 0.26 μs 13.3 ± 0.31 μs 1.01 ± 0.031
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/NonLinModel/Prediction form 0.34 ± 0.019 ms 0.357 ± 0.019 ms 0.951 ± 0.074
UNIT TESTS/StateEstimator/SteadyKalmanFilter/evaloutput 0.15 ± 0.011 μs 0.15 ± 0.01 μs 1 ± 0.099
UNIT TESTS/StateEstimator/SteadyKalmanFilter/preparestate! 0.201 ± 0.01 μs 0.211 ± 0.01 μs 0.953 ± 0.065
UNIT TESTS/StateEstimator/SteadyKalmanFilter/updatestate! 0.29 ± 0.01 μs 0.3 ± 0.01 μs 0.967 ± 0.046
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/evaloutput/LinModel 0.141 ± 0.01 μs 0.14 ± 0.01 μs 1.01 ± 0.1
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/evaloutput/NonLinModel 0.191 ± 0.01 μs 0.2 ± 0.01 μs 0.955 ± 0.069
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/preparestate!/LinModel 3.48 ± 0.04 μs 3.41 ± 0.021 μs 1.02 ± 0.013
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/preparestate!/NonLinModel 3.91 ± 0.03 μs 3.91 ± 0.03 μs 1 ± 0.011
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/updatestate!/LinModel 3.39 ± 0.05 μs 3.41 ± 0.07 μs 0.994 ± 0.025
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/updatestate!/NonLinModel 4.9 ± 0.08 μs 4.75 ± 0.06 μs 1.03 ± 0.021
time_to_load 3.8 ± 0.082 s 3.82 ± 0.027 s 0.994 ± 0.022
Memory benchmarks
main e0e7c84... main / e0e7c84...
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/DAQP/SingleShooting 0.0449 M allocs: 1.79 MB 0.0449 M allocs: 1.79 MB 1
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/Ipopt/MultipleShooting 0.183 M allocs: 9.81 MB 0.183 M allocs: 9.81 MB 1
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/Ipopt/SingleShooting 0.0746 M allocs: 2.81 MB 0.0746 M allocs: 2.81 MB 1
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/OSQP/MultipleShooting 0.0758 M allocs: 1.88 MB 0.0758 M allocs: 1.88 MB 1
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/OSQP/SingleShooting 7.85 k allocs: 0.243 MB 7.85 k allocs: 0.243 MB 1
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/DAQP/SingleShooting 0.0448 M allocs: 1.79 MB 0.0448 M allocs: 1.79 MB 1
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/Ipopt/MultipleShooting 0.148 M allocs: 8 MB 0.148 M allocs: 8 MB 1
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/Ipopt/SingleShooting 0.0779 M allocs: 2.88 MB 0.0779 M allocs: 2.88 MB 1
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/OSQP/MultipleShooting 0.0532 M allocs: 1.33 MB 0.0532 M allocs: 1.33 MB 1
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/OSQP/SingleShooting 7.7 k allocs: 0.237 MB 7.7 k allocs: 0.237 MB 1
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/DAQP/SingleShooting 0.102 M allocs: 6.48 MB 0.102 M allocs: 6.48 MB 1
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/Ipopt/MultipleShooting 4.64 M allocs: 0.251 GB 4.64 M allocs: 0.251 GB 1
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/Ipopt/SingleShooting 0.112 M allocs: 6.87 MB 0.112 M allocs: 6.87 MB 1
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/OSQP/MultipleShooting 4.66 M allocs: 0.255 GB 4.66 M allocs: 0.255 GB 1
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/OSQP/SingleShooting 0.114 M allocs: 8.19 MB 0.114 M allocs: 8.19 MB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/MultipleShooting 16.9 M allocs: 0.955 GB 16.9 M allocs: 0.955 GB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/SingleShooting 2.68 M allocs: 0.705 GB 2.68 M allocs: 0.705 GB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/TrapezoidalCollocation 17.7 M allocs: 0.998 GB 17.7 M allocs: 0.998 GB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/MultipleShooting 10 M allocs: 0.574 GB 10 M allocs: 0.574 GB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/SingleShooting 0.111 M allocs: 18.2 MB 0.111 M allocs: 18.2 MB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/TrapezoidalCollocation 10.4 M allocs: 0.59 GB 10.4 M allocs: 0.59 GB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/MadNLP/SingleShooting 0.293 M allocs: 0.0647 GB 0.293 M allocs: 0.0647 GB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/MultipleShooting 7.95 M allocs: 0.458 GB 7.95 M allocs: 0.458 GB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/SingleShooting 0.0889 M allocs: 13.8 MB 0.0889 M allocs: 13.8 MB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/TrapezoidalCollocation 8.09 M allocs: 0.465 GB 8.09 M allocs: 0.465 GB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/MadNLP/SingleShooting 0.253 M allocs: 0.0559 GB 0.253 M allocs: 0.0559 GB 1
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/DAQP/Current form 0.728 M allocs: 0.0876 GB 0.728 M allocs: 0.087 GB 1.01
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/DAQP/Prediction form 0.648 M allocs: 0.0621 GB 0.648 M allocs: 0.0621 GB 1
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/Ipopt/Current form 0.622 M allocs: 0.0833 GB 0.622 M allocs: 0.0833 GB 1
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/Ipopt/Prediction form 0.577 M allocs: 0.0601 GB 0.577 M allocs: 0.0601 GB 1
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/OSQP/Current form 0.595 M allocs: 0.0821 GB 0.595 M allocs: 0.0821 GB 1
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/OSQP/Prediction form 0.55 M allocs: 0.0589 GB 0.55 M allocs: 0.0589 GB 1
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/Ipopt/Current form 0.0884 G allocs: 15.9 GB 0.0884 G allocs: 15.9 GB 1
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/Ipopt/Prediction form 12.9 M allocs: 2.3 GB 12.9 M allocs: 2.3 GB 1
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/MadNLP/Current form 15.1 M allocs: 2.8 GB 15.1 M allocs: 2.8 GB 1
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/MadNLP/Prediction form 8.83 M allocs: 1.63 GB 8.83 M allocs: 1.63 GB 1
UNIT TESTS/PredictiveController/ExplicitMPC/moveinput! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/PredictiveController/LinMPC/moveinput!/MultipleShooting 0.994 k allocs: 24.5 kB 0.994 k allocs: 24.5 kB 1
UNIT TESTS/PredictiveController/LinMPC/moveinput!/SingleShooting 0.088 k allocs: 2.16 kB 0.088 k allocs: 2.16 kB 1
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/LinModel/MultipleShooting 3 k allocs: 0.196 MB 3 k allocs: 0.196 MB 1
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/LinModel/SingleShooting 0.599 k allocs: 0.0556 MB 0.599 k allocs: 0.0556 MB 1
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/MultipleShooting 0.104 M allocs: 7.98 MB 0.104 M allocs: 7.98 MB 1
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/SingleShooting 0.633 k allocs: 0.116 MB 0.633 k allocs: 0.116 MB 1
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/TrapezoidalCollocation 15.7 k allocs: 1.43 MB 15.7 k allocs: 1.43 MB 1
UNIT TESTS/SimModel/LinModel/evaloutput 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/SimModel/LinModel/updatestate! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/SimModel/NonLinModel/evaloutput 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/SimModel/NonLinModel/linearize! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/SimModel/NonLinModel/updatestate! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/evaloutput/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/evaloutput/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/preparestate!/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/preparestate!/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/updatestate!/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/updatestate!/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/InternalModel/evaloutput/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/InternalModel/evaloutput/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/InternalModel/preparestate!/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/InternalModel/preparestate!/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/InternalModel/updatestate!/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/InternalModel/updatestate!/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/KalmanFilter/evaloutput 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/KalmanFilter/preparestate! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/KalmanFilter/updatestate! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/Luenberger/evaloutput 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/Luenberger/preparestate! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/Luenberger/updatestate! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/LinModel/Current form 0.0734 M allocs: 16 MB 0.0734 M allocs: 15.9 MB 1
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/LinModel/Prediction form 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/NonLinModel/Current form 0.996 k allocs: 24.7 kB 0.996 k allocs: 24.7 kB 1
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/NonLinModel/Prediction form 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/LinModel/Current form 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/LinModel/Prediction form 6.7 k allocs: 0.451 MB 6.7 k allocs: 0.451 MB 1
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/NonLinModel/Current form 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/NonLinModel/Prediction form 0.996 k allocs: 24.7 kB 0.996 k allocs: 24.7 kB 1
UNIT TESTS/StateEstimator/SteadyKalmanFilter/evaloutput 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/SteadyKalmanFilter/preparestate! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/SteadyKalmanFilter/updatestate! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/evaloutput/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/evaloutput/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/preparestate!/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/preparestate!/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/updatestate!/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/updatestate!/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
time_to_load 0.159 k allocs: 11.2 kB 0.159 k allocs: 11.2 kB 1

@codecov-commenter
Copy link

codecov-commenter commented Sep 10, 2025

Codecov Report

❌ Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.63%. Comparing base (bc08d73) to head (e0e7c84).

Files with missing lines Patch % Lines
src/estimator/kalman.jl 91.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #248      +/-   ##
==========================================
+ Coverage   98.60%   98.63%   +0.02%     
==========================================
  Files          26       26              
  Lines        4443     4458      +15     
==========================================
+ Hits         4381     4397      +16     
+ Misses         62       61       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@baggepinnen
Copy link
Member

Come to think of it, I don't this that's a good idea to bump the compat of ControlSystemsBase.jl just for this niche feature. I now rely on pkgversion(ControlSystemsBase) to pass or not the extra keyword argument to kalman. Do you see any drawback to this workaround @baggepinnen ?

I wouldn't bother with the additional complexity, for the simple reason that people updating packages in order to get access to a new feature, such as that added in this PR, tend to be on the latest version of most packages and therefore won't need the fix. Explicit version management like this only tends to be warranted when there is a significant user base that lags in their adoption of new package versions for some reason, and these users critically need bugfixes.

Also I notice that the computed steady-state Kalman gain with direct=true is not the same before and after v1.18.2, you corrected a mistake in the formula @baggepinnen ?

Yes, I noticed that the are solver in MatrixEquations returns the covariance matrix for the direct form but the gain matrix for the indirect form. The function kalman will now return the covariance matrix computed by are, but when direct=true recompute the Kalman gain to represent the direct form. Before, the covariance matrix when direct=true had one "directification" too much applied.

You can read the changes to the docstring here
https://github.com/JuliaControl/ControlSystems.jl/pull/994/files#diff-28e18ef7f9690603701c34825ed5b700cadee648b4428b7ea5535353cf863eda

@franckgaga
Copy link
Member Author

Alright, I will revert the pkgversion addition and bump the compat entry. Thanks once more for your time 🙂

@franckgaga franckgaga merged commit 1ed3284 into main Sep 11, 2025
5 checks passed
@franckgaga franckgaga deleted the skf_mhe branch September 11, 2025 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants