Skip to content

Conversation

@franckgaga
Copy link
Member

@franckgaga franckgaga commented Aug 23, 2025

I almost finished the TapezoidalCollocation() to handle moderately stiff system. Just need to add some tests and possibly some new benchmarks. Compared to a MultipleShooting transcription on the pendulum example, benchmarks are practically identical as expected, but the closed-loop response are marginally differents. This is also expected since the MultipleShooting uses a RungeKutta(4) to discretize the dynamics, while TrapezoidalCollocation uses a implicit trapezoidal rule.

  • The TapezoidalCollocation only support NonLinModel, since LinModel objects currently include no information about the original continuous-time dynamics, when it's constructed from a constinuous LTI system. I'm not sure it is worth the effort refactoring LinModel objects to support this transcription method, although linear stiff systems do exists (i.e. large gap in the smallest and largest eigenvalues). For such corner cases, there is always the option to construct a NonLinModel with the continuous state-space matrices i.e.: with f(x,u,d,_) = A*x + Bu*u + Bd*d and solver != nothing.
  • The built-in state estimator will still use the stepper defined in model.solver, which is RungeKutta(4) by default. For UKF or EKF, the state update function is only called a couple of times per time step, so it's not super expensive to use fixed-step solver and increase super-sampling if the system is stiff. And I don't think adding a new dependency with a root solver is worth the trouble. Neither calling Ipopt as a root solver. The implicit trapezoidal method is truly interesting inside an optimization problem, otherwise just use a fixed-step solver with super-sampling if necessary.
  • As mentioned in the issue, the stochastic model of the unmeasured disturbances is constructed as linear discrete-time state-space description. Collocation methods want continuous-time dynamics. I chose to handle the deterministic states and the stochastic states separately. The defects on the stochastic states are trivial equality constraints. In other words, the deterministic part is transcribed with TrapezoidalCollocation and the stochastic part is transcribed with MultipleShooting.
  • Right now it assumes piecewise constant manipulated inputs, but I will add linear interpolation soon.

Any comment/concern on these aspects @baggepinnen ?

@codecov-commenter
Copy link

codecov-commenter commented Aug 23, 2025

Codecov Report

❌ Patch coverage is 63.86555% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.66%. Comparing base (9e50689) to head (bf181ac).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/controller/transcription.jl 57.42% 43 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #234      +/-   ##
==========================================
- Coverage   98.68%   97.66%   -1.02%     
==========================================
  Files          26       26              
  Lines        4324     4375      +51     
==========================================
+ Hits         4267     4273       +6     
- Misses         57      102      +45     

☔ 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.

@github-actions
Copy link

github-actions bot commented Aug 23, 2025

Benchmark Results (Julia v1)

Time benchmarks
main bf181ac... main / bf181ac...
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/DAQP/SingleShooting 6.65 ± 0.55 ms 6.62 ± 0.55 ms 1 ± 0.12
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/Ipopt/MultipleShooting 0.315 ± 0.0046 s 0.312 ± 0.0057 s 1.01 ± 0.024
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/Ipopt/SingleShooting 0.226 ± 0.013 s 0.226 ± 0.011 s 1 ± 0.077
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/OSQP/MultipleShooting 8.77 ± 0.54 ms 8.74 ± 0.52 ms 1 ± 0.086
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/OSQP/SingleShooting 1.47 ± 0.076 ms 1.48 ± 0.068 ms 0.994 ± 0.069
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/DAQP/SingleShooting 6.79 ± 0.55 ms 6.87 ± 0.54 ms 0.988 ± 0.11
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/Ipopt/MultipleShooting 0.275 ± 0.0033 s 0.274 ± 0.0029 s 1 ± 0.016
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/Ipopt/SingleShooting 0.231 ± 0.003 s 0.229 ± 0.0018 s 1.01 ± 0.015
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/OSQP/MultipleShooting 6 ± 0.44 ms 5.91 ± 0.42 ms 1.02 ± 0.1
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/OSQP/SingleShooting 1.58 ± 0.068 ms 1.57 ± 0.059 ms 1.01 ± 0.058
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/DAQP/SingleShooting 7.96 ± 0.66 ms 7.98 ± 0.79 ms 0.997 ± 0.13
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/Ipopt/MultipleShooting 0.332 ± 0.0071 s 0.33 ± 0.0055 s 1.01 ± 0.027
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/Ipopt/SingleShooting 0.156 ± 0.0017 s 0.155 ± 0.00093 s 1.01 ± 0.012
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/OSQP/MultipleShooting 0.109 ± 0.0018 s 0.109 ± 0.0025 s 1 ± 0.028
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/OSQP/SingleShooting 11.4 ± 0.89 ms 11.5 ± 0.8 ms 0.991 ± 0.1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/MultipleShooting 1.96 ± 0.056 s 1.9 ± 0.028 s 1.03 ± 0.033
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/SingleShooting 2.09 ± 0.05 s 2.04 ± 0.016 s 1.02 ± 0.026
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/MultipleShooting 0.893 ± 0.0078 s 0.885 ± 0.013 s 1.01 ± 0.017
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/SingleShooting 0.521 ± 0.035 s 0.533 ± 0.054 s 0.977 ± 0.12
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/MadNLP/SingleShooting 0.14 ± 0.0018 s 0.143 ± 0.003 s 0.978 ± 0.024
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/MultipleShooting 0.8 ± 0.035 s 0.818 ± 0.021 s 0.977 ± 0.05
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/SingleShooting 0.51 ± 0.041 s 0.505 ± 0.043 s 1.01 ± 0.12
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/MadNLP/SingleShooting 0.12 ± 0.0035 s 0.118 ± 0.003 s 1.01 ± 0.039
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/DAQP/Current form 0.0408 ± 0.0055 s 0.043 ± 0.006 s 0.949 ± 0.19
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/DAQP/Prediction form 0.0355 ± 0.0021 s 0.0362 ± 0.0025 s 0.979 ± 0.09
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/Ipopt/Current form 0.203 ± 0.02 s 0.2 ± 0.03 s 1.02 ± 0.18
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/Ipopt/Prediction form 0.163 ± 0.048 s 0.165 ± 0.045 s 0.989 ± 0.4
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/OSQP/Current form 0.0363 ± 0.0046 s 0.0376 ± 0.0048 s 0.964 ± 0.17
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/OSQP/Prediction form 27.4 ± 2.3 ms 28.1 ± 2.2 ms 0.972 ± 0.11
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/Ipopt/Current form 14.3 ± 0.48 s 13.9 ± 1 s 1.03 ± 0.083
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/Ipopt/Prediction form 4.37 ± 0.12 s 4.21 ± 0.046 s 1.04 ± 0.03
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/MadNLP/Current form 2.11 ± 0.096 s 2.12 ± 0.03 s 0.996 ± 0.048
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/MadNLP/Prediction form 1.25 ± 0.023 s 1.25 ± 0.0093 s 1 ± 0.02
UNIT TESTS/PredictiveController/ExplicitMPC/moveinput! 2.56 ± 0.03 μs 2.54 ± 0.011 μs 1 ± 0.013
UNIT TESTS/PredictiveController/LinMPC/moveinput!/MultipleShooting 0.109 ± 0.0041 ms 0.108 ± 0.0036 ms 1.01 ± 0.051
UNIT TESTS/PredictiveController/LinMPC/moveinput!/SingleShooting 12.5 ± 0.26 μs 12.6 ± 0.32 μs 0.992 ± 0.033
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/LinModel/MultipleShooting 2.92 ± 0.22 ms 2.9 ± 0.25 ms 1.01 ± 0.12
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/LinModel/SingleShooting 1.91 ± 0.14 ms 1.87 ± 0.16 ms 1.02 ± 0.11
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/MultipleShooting 9.13 ± 0.5 ms 8.92 ± 0.33 ms 1.02 ± 0.068
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/SingleShooting 1.97 ± 0.085 ms 1.93 ± 0.096 ms 1.03 ± 0.068
UNIT TESTS/SimModel/LinModel/evaloutput 0.14 ± 0.01 μs 0.131 ± 0.01 μs 1.07 ± 0.11
UNIT TESTS/SimModel/LinModel/updatestate! 0.23 ± 0.001 μs 0.211 ± 0.01 μs 1.09 ± 0.052
UNIT TESTS/SimModel/NonLinModel/evaloutput 0.14 ± 0.01 μs 0.131 ± 0.01 μs 1.07 ± 0.11
UNIT TESTS/SimModel/NonLinModel/linearize! 1.12 ± 0.019 μs 1.13 ± 0.01 μs 0.991 ± 0.019
UNIT TESTS/SimModel/NonLinModel/updatestate! 0.22 ± 0.01 μs 0.22 ± 0.01 μs 1 ± 0.064
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/evaloutput/LinModel 0.14 ± 0.001 μs 0.14 ± 0.001 μs 1 ± 0.01
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/evaloutput/NonLinModel 0.18 ± 0.001 μs 0.181 ± 0.01 μs 0.994 ± 0.055
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.77 ± 0.031 μs 2.75 ± 0.03 μs 1.01 ± 0.016
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/updatestate!/NonLinModel 3.34 ± 0.039 μs 3.32 ± 0.031 μs 1.01 ± 0.015
UNIT TESTS/StateEstimator/InternalModel/evaloutput/LinModel 0.12 ± 0.009 μs 0.12 ± 0.01 μs 1 ± 0.11
UNIT TESTS/StateEstimator/InternalModel/evaloutput/NonLinModel 0.12 ± 0 μs 0.111 ± 0.01 μs 1.08 ± 0.097
UNIT TESTS/StateEstimator/InternalModel/preparestate!/LinModel 0.19 ± 0.01 μs 0.181 ± 0.01 μs 1.05 ± 0.08
UNIT TESTS/StateEstimator/InternalModel/preparestate!/NonLinModel 0.181 ± 0.01 μs 0.181 ± 0.01 μs 1 ± 0.078
UNIT TESTS/StateEstimator/InternalModel/updatestate!/LinModel 0.311 ± 0.01 μs 0.311 ± 0.011 μs 1 ± 0.048
UNIT TESTS/StateEstimator/InternalModel/updatestate!/NonLinModel 0.31 ± 0.01 μs 0.301 ± 0.01 μs 1.03 ± 0.048
UNIT TESTS/StateEstimator/KalmanFilter/evaloutput 0.14 ± 0.001 μs 0.14 ± 0.009 μs 1 ± 0.065
UNIT TESTS/StateEstimator/KalmanFilter/preparestate! 0.04 ± 0 μs 0.04 ± 0 μs 1 ± 0
UNIT TESTS/StateEstimator/KalmanFilter/updatestate! 2.07 ± 0.03 μs 2.07 ± 0.02 μs 1 ± 0.017
UNIT TESTS/StateEstimator/Luenberger/evaloutput 0.15 ± 0.01 μs 0.14 ± 0.01 μs 1.07 ± 0.1
UNIT TESTS/StateEstimator/Luenberger/preparestate! 0.21 ± 0.01 μs 0.21 ± 0.011 μs 1 ± 0.071
UNIT TESTS/StateEstimator/Luenberger/updatestate! 0.29 ± 0.01 μs 0.281 ± 0.01 μs 1.03 ± 0.051
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/LinModel/Current form 3.6 ± 4.2 ms 3.5 ± 4 ms 1.03 ± 1.7
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/LinModel/Prediction form 0.04 ± 0 μs 0.04 ± 0 μs 1 ± 0
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/NonLinModel/Current form 0.321 ± 0.018 ms 0.325 ± 0.02 ms 0.986 ± 0.082
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/NonLinModel/Prediction form 0.04 ± 0 μs 0.04 ± 0.009 μs 1 ± 0.23
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/LinModel/Current form 6.5 ± 2.2 μs 6.86 ± 2.5 μs 0.947 ± 0.47
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/LinModel/Prediction form 3.25 ± 1.4 ms 3.24 ± 0.68 ms 1 ± 0.47
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/NonLinModel/Current form 13 ± 0.31 μs 12.9 ± 0.3 μs 1.01 ± 0.034
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/NonLinModel/Prediction form 0.341 ± 0.019 ms 0.337 ± 0.02 ms 1.01 ± 0.081
UNIT TESTS/StateEstimator/SteadyKalmanFilter/evaloutput 0.15 ± 0.01 μs 0.15 ± 0.01 μs 1 ± 0.094
UNIT TESTS/StateEstimator/SteadyKalmanFilter/preparestate! 0.221 ± 0.01 μs 0.201 ± 0.01 μs 1.1 ± 0.074
UNIT TESTS/StateEstimator/SteadyKalmanFilter/updatestate! 0.281 ± 0.01 μs 0.29 ± 0.01 μs 0.969 ± 0.048
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/evaloutput/LinModel 0.14 ± 0.01 μs 0.141 ± 0.01 μs 0.993 ± 0.1
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/evaloutput/NonLinModel 0.191 ± 0.011 μs 0.191 ± 0.01 μs 1 ± 0.078
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/preparestate!/LinModel 3.47 ± 0.031 μs 3.39 ± 0.039 μs 1.02 ± 0.015
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/preparestate!/NonLinModel 3.94 ± 0.03 μs 3.9 ± 0.031 μs 1.01 ± 0.011
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/updatestate!/LinModel 3.29 ± 0.081 μs 3.27 ± 0.04 μs 1.01 ± 0.028
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/updatestate!/NonLinModel 4.62 ± 0.06 μs 4.73 ± 0.09 μs 0.977 ± 0.023
time_to_load 3.83 ± 0.039 s 3.79 ± 0.006 s 1.01 ± 0.01
Memory benchmarks
main bf181ac... main / bf181ac...
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.46 MB 0.102 M allocs: 6.46 MB 1
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/Ipopt/MultipleShooting 4.64 M allocs: 0.248 GB 4.64 M allocs: 0.248 GB 1
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/Ipopt/SingleShooting 0.112 M allocs: 6.86 MB 0.112 M allocs: 6.86 MB 1
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/OSQP/MultipleShooting 4.66 M allocs: 0.252 GB 4.66 M allocs: 0.252 GB 1
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/OSQP/SingleShooting 0.113 M allocs: 8.17 MB 0.113 M allocs: 8.17 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/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/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/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.727 M allocs: 0.086 GB 0.727 M allocs: 0.086 GB 1
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.623 M allocs: 0.0855 GB 0.622 M allocs: 0.0833 GB 1.03
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/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

@franckgaga franckgaga changed the title added: simple TrapezoidalMethod() collocation added: simple TrapezoidalCollocation() collocation Aug 27, 2025
@franckgaga franckgaga changed the title added: simple TrapezoidalCollocation() collocation added: simple TrapezoidalCollocation() transcription method Aug 27, 2025
@franckgaga franckgaga linked an issue Aug 28, 2025 that may be closed by this pull request
@franckgaga franckgaga requested a review from baggepinnen August 28, 2025 19:38
@baggepinnen
Copy link
Member

I would not bother with the LinModel, ZoH integration for linear systems using the matrix exponential is exact, stiff or not.

so it's not super expensive to use fixed-step solver and increase super-sampling if the system is stiff. And I don't think adding a new dependency with a root solver is worth the trouble. Neither calling Ipopt as a root solver. The implicit trapezoidal method is truly interesting inside an optimization problem, otherwise just use a fixed-step solver with super-sampling if necessary.

This is missing the capability of implicit methods to handle DAEs, explicit methods like RK4 will not handle those. Even if the implementation right now does not support algebraic equations, it should be possible to support with minor effort. Modeling tools like MTK and modelica-based tools often produces DAEs. Since ManualEstimator exists, the user can always stick their DAE in there and use any DAE integrator from SeeToDee if required.

@franckgaga
Copy link
Member Author

franckgaga commented Aug 29, 2025

Good point! The current design should be non-blocking for DAEs. Users can creates two SimModel:

  1. a NonLinModel with solver=nothing (discrete-time, from the point of view of MPC.jl) that calls a SeeToDee.jl integrator. Its purpose would for plant simulation, but pretty sure that it would also work to construct e.g. an UnscentedKalmanFilter. If not, there is also your version of the UKF that explicitly handle DAEs.
  2. another NonLinModel with default solver option (not important the choice since it will be ignored), and use it in ManualEstimator to construct a NonLinMPC with transcription=TrapezoidalCollocation option.

BTW for my own understanding, about 1. , if we call a stepper that supports DAE, is it sufficient to directly use the nonlinear model in the classic versions of the UKF or EKF ?

@franckgaga franckgaga merged commit ad12293 into main Aug 29, 2025
5 checks passed
@franckgaga franckgaga deleted the trapezoidal branch August 29, 2025 17:56
@baggepinnen
Copy link
Member

BTW for my own understanding, about 1. , if we call a stepper that supports DAE, is it sufficient to directly use the nonlinear model in the classic versions of the UKF or EKF ?

It depends a bit on the nature of the algebraic equations. A UKF can readily use a DAE stepper to propagate the sigma points, but computing the mean of the propagated points may give you a mean point that does not satisfy the algebraic equations. There are multiple different ways in which this can be handled, the simplest of which is to somehow project the mean onto the manifold implied by the algebraic equations.

Similarily, both UKF and EKF may get you a point that doesn't satisfy the equations after the Kalman update x += Ke

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.

Trapezoidal collocation transcription

3 participants