1+ # # ----------------- Runtime benchmarks : CSTR ----------------------------------------
12G = [ tf (1.90 , [18 , 1 ]) tf (1.90 , [18 , 1 ]);
23 tf (- 0.74 ,[8 , 1 ]) tf (0.74 , [8 , 1 ]) ]
34uop, yop = [20 , 20 ], [50 , 30 ]
@@ -20,7 +21,6 @@ function test_mpc(mpc, plant)
2021 return U, Y, Ry
2122end
2223
23- # # ----------------- Runtime benchmarks ---------------------------------------------
2424optim = JuMP. Model (OSQP. Optimizer, add_bridges= false )
2525transcription = SingleShooting ()
2626mpc_osqp_ss = setconstraint! (LinMPC (model; optim, transcription), ymin= [45 , - Inf ])
@@ -38,33 +38,119 @@ mpc_daqp_ss = setconstraint!(LinMPC(model; optim, transcription), ymin=[45, -Inf
3838optim = JuMP. Model (DAQP. Optimizer, add_bridges= false )
3939transcription = MultipleShooting ()
4040mpc_daqp_ms = setconstraint! (LinMPC (model; optim, transcription), ymin= [45 , - Inf ])
41- # needed to solve Hessians with eigenvalues at zero, like in MultipleShooting transcription :
41+ # needed to solve Hessians with eigenvalues at zero, like with MultipleShooting:
4242JuMP. set_attribute (mpc_daqp_ms. optim, " eps_prox" , 1e-6 )
4343
44+ optim = JuMP. Model (optimizer_with_attributes (Ipopt. Optimizer," sb" => " yes" ), add_bridges= false )
45+ transcription = SingleShooting ()
46+ mpc_ipopt_ss = setconstraint! (LinMPC (model; optim, transcription), ymin= [45 , - Inf ])
47+ JuMP. unset_time_limit_sec (mpc_ipopt_ss. optim)
48+
49+ optim = JuMP. Model (optimizer_with_attributes (Ipopt. Optimizer," sb" => " yes" ), add_bridges= false )
50+ transcription = MultipleShooting ()
51+ mpc_ipopt_ms = setconstraint! (LinMPC (model; optim, transcription), ymin= [45 , - Inf ])
52+ JuMP. unset_time_limit_sec (mpc_ipopt_ms. optim)
53+
4454samples, evals = 500 , 1
45- SUITE[ " runtime " ] [" PredictiveController" ][" CSTR" ][" LinMPC" ][" OSQP" ][" SingleShooting" ] =
55+ RUNTIME [" PredictiveController" ][" CSTR" ][" LinMPC" ][" OSQP" ][" SingleShooting" ] =
4656 @benchmarkable (test_mpc ($ mpc_osqp_ss, $ model);
4757 samples= samples, evals= evals
4858)
49- SUITE[ " runtime " ] [" PredictiveController" ][" CSTR" ][" LinMPC" ][" OSQP" ][" MultipleShooting" ] =
59+ RUNTIME [" PredictiveController" ][" CSTR" ][" LinMPC" ][" OSQP" ][" MultipleShooting" ] =
5060 @benchmarkable (test_mpc ($ mpc_osqp_ms, $ model);
5161 samples= samples, evals= evals
5262)
53- SUITE[ " runtime " ] [" PredictiveController" ][" CSTR" ][" LinMPC" ][" DAQP" ][" SingleShooting" ] =
63+ RUNTIME [" PredictiveController" ][" CSTR" ][" LinMPC" ][" DAQP" ][" SingleShooting" ] =
5464 @benchmarkable (test_mpc ($ mpc_daqp_ss, $ model);
5565 samples= samples, evals= evals
5666)
57- SUITE[ " runtime " ] [" PredictiveController" ][" CSTR" ][" LinMPC" ][" DAQP" ][" MultipleShooting" ] =
67+ RUNTIME [" PredictiveController" ][" CSTR" ][" LinMPC" ][" DAQP" ][" MultipleShooting" ] =
5868 @benchmarkable (test_mpc ($ mpc_daqp_ms, $ model);
5969 samples= samples, evals= evals
6070)
71+ RUNTIME[" PredictiveController" ][" CSTR" ][" LinMPC" ][" Ipopt" ][" SingleShooting" ] =
72+ @benchmarkable (test_mpc ($ mpc_ipopt_ss, $ model);
73+ samples= samples, evals= evals
74+ )
75+ RUNTIME[" PredictiveController" ][" CSTR" ][" LinMPC" ][" Ipopt" ][" MultipleShooting" ] =
76+ @benchmarkable (test_mpc ($ mpc_ipopt_ms, $ model);
77+ samples= samples, evals= evals
78+ )
79+
80+ # ----------------- Runtime benchmarks : Pendulum ---------------------------------------
81+ function f! (ẋ, x, u, _ , p)
82+ g, L, K, m = p # [m/s²], [m], [kg/s], [kg]
83+ θ, ω = x[1 ], x[2 ] # [rad], [rad/s]
84+ τ = u[1 ] # [Nm]
85+ ẋ[1 ] = ω
86+ ẋ[2 ] = - g/ L* sin (θ) - K/ m* ω + τ/ m/ L^ 2
87+ end
88+ h! (y, x, _ , _ ) = (y[1 ] = 180 / π* x[1 ]) # [°]
89+ p = [9.8 , 0.4 , 1.2 , 0.3 ]
90+ nu = 1 ; nx = 2 ; ny = 1 ; Ts = 0.1
91+ model = NonLinModel (f!, h!, Ts, nu, nx, ny; p)
92+ σQ = [0.1 , 1.0 ]; σR= [5.0 ]; nint_u= [1 ]; σQint_u= [0.1 ]
93+ estim = UnscentedKalmanFilter (model; σQ, σR, nint_u, σQint_u)
94+ p_plant = copy (p); p_plant[3 ] = 1.25 * p[3 ]
95+ plant = NonLinModel (f!, h!, Ts, nu, nx, ny; p= p_plant)
96+ N = 35 ; u = [0.5 ];
97+
98+ Hp, Hc, Mwt, Nwt, Cwt = 20 , 2 , [0.5 ], [2.5 ], Inf
99+ umin, umax = [- 1.5 ], [+ 1.5 ]
100+ x_0 = [0 , 0 ]; x̂_0 = [0 , 0 , 0 ]; ry = [180 ]
101+
102+ optim = JuMP. Model (optimizer_with_attributes (Ipopt. Optimizer," sb" => " yes" ), add_bridges= false )
103+ transcription = SingleShooting ()
104+ nmpc_ipopt_ss = NonLinMPC (estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription)
105+ nmpc_ipopt_ss = setconstraint! (nmpc_ipopt_ss; umin, umax)
106+ JuMP. unset_time_limit_sec (nmpc_ipopt_ss. optim)
61107
108+ optim = JuMP. Model (optimizer_with_attributes (Ipopt. Optimizer," sb" => " yes" ), add_bridges= false )
109+ transcription = MultipleShooting ()
110+ nmpc_ipopt_ms = NonLinMPC (estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription)
111+ nmpc_ipopt_ms = setconstraint! (nmpc_ipopt_ms; umin, umax)
112+ JuMP. unset_time_limit_sec (nmpc_ipopt_ms. optim)
113+
114+ optim = JuMP. Model (MadNLP. Optimizer, add_bridges= false )
115+ transcription = SingleShooting ()
116+ nmpc_madnlp_ss = NonLinMPC (estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription)
117+ nmpc_madnlp_ss = setconstraint! (nmpc_madnlp_ss; umin, umax)
118+ JuMP. unset_time_limit_sec (nmpc_madnlp_ss. optim)
119+
120+ optim = JuMP. Model (MadNLP. Optimizer, add_bridges= false )
121+ transcription = MultipleShooting ()
122+ nmpc_madnlp_ms = NonLinMPC (estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription)
123+ nmpc_madnlp_ms = setconstraint! (nmpc_madnlp_ms; umin, umax)
124+ JuMP. unset_time_limit_sec (nmpc_madnlp_ms. optim)
125+
126+ samples, evals, seconds = 50 , 1 , 15 * 60
127+ RUNTIME[" PredictiveController" ][" Pendulum" ][" NonLinMPC" ][" Ipopt" ][" SingleShooting" ] =
128+ @benchmarkable (
129+ sim! ($ nmpc_ipopt_ss, $ N, $ ry; plant= $ plant, x_0= $ x_0, x̂_0= $ x̂_0),
130+ samples= samples, evals= evals, seconds= seconds
131+ )
132+ RUNTIME[" PredictiveController" ][" Pendulum" ][" NonLinMPC" ][" Ipopt" ][" MultipleShooting" ] =
133+ @benchmarkable (
134+ sim! ($ nmpc_ipopt_ms, $ N, $ ry; plant= $ plant, x_0= $ x_0, x̂_0= $ x̂_0),
135+ samples= samples, evals= evals, seconds= seconds
136+ )
137+ RUNTIME[" PredictiveController" ][" Pendulum" ][" NonLinMPC" ][" MadNLP" ][" SingleShooting" ] =
138+ @benchmarkable (
139+ sim! ($ nmpc_madnlp_ss, $ N, $ ry; plant= $ plant, x_0= $ x_0, x̂_0= $ x̂_0),
140+ samples= samples, evals= evals, seconds= seconds
141+ )
142+ # TODO : does not work with MadNLP and MultipleShooting, figure out why
143+ # RUNTIME["PredictiveController"]["Pendulum"]["NonLinMPC"]["MadNLP"]["MultipleShooting"] =
144+ # @benchmarkable(
145+ # sim!($nmpc_madnlp_ms, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0),
146+ # samples=samples, evals=evals, seconds=seconds
147+ # )
62148
63149# ---------------------- Allocation benchmarks ------------------------------------------
64150empc = ExplicitMPC (linmodel, Mwt= [1 , 1 ], Nwt= [0.1 , 0.1 ], Lwt= [0.1 , 0.1 ])
65151
66152samples, evals = 1 , 1
67- SUITE[ " allocation " ] [" PredictiveController" ][" ExplicitMPC" ][" moveinput!" ] =
153+ ALLOC [" PredictiveController" ][" ExplicitMPC" ][" moveinput!" ] =
68154 @benchmarkable (
69155 moveinput! ($ empc, $ y, $ d),
70156 setup= preparestate! ($ empc, $ y, $ d),
0 commit comments