Skip to content

Commit d83acd4

Browse files
committed
bench: new TapezoidalCollocation benchmarks
1 parent ec33fad commit d83acd4

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

benchmark/0_bench_setup.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ linmodel = setop!(LinModel(sys, Ts, i_d=[3]), uop=[10, 50], yop=[50, 30], dop=[5
1616
nonlinmodel = NonLinModel(f_lin!, h_lin!, Ts, 2, 4, 2, 1, p=linmodel, solver=nothing)
1717
nonlinmodel = setop!(nonlinmodel, uop=[10, 50], yop=[50, 30], dop=[5])
1818
u, d, y = [10, 50], [5], [50, 30]
19+
nonlinmodel_c = NonLinModel(
20+
(ẋ,x,u,d,_) -> ẋ .= -0.001x .+ u .+ d ,
21+
(y,x,d,_) -> y .= x .+ 0.001d, 500, 1, 1, 1, 1
22+
)
23+
u_c, d_c, y_c = [1], [0], [0]
1924

2025
G = [ tf(1.90, [18, 1]) tf(1.90, [18, 1]);
2126
tf(-0.74,[8, 1]) tf(0.74, [8, 1]) ]

benchmark/3_bench_predictive_control.jl

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ nmpc_nonlin_ms = NonLinMPC(
5050
nonlinmodel, transcription=MultipleShooting(),
5151
Mwt=[1, 1], Nwt=[0.1, 0.1], Lwt=[0.1, 0.1], Hp=10
5252
)
53+
nmpc_nonlin_tc = NonLinMPC(
54+
nonlinmodel_c, transcription=TrapezoidalCollocation(),
55+
Mwt=[1], Nwt=[0.1], Lwt=[0.1], Hp=10
56+
)
5357

5458
samples, evals, seconds = 10000, 1, 60
5559
UNIT_MPC["NonLinMPC"]["moveinput!"]["LinModel"]["SingleShooting"] =
@@ -76,6 +80,12 @@ UNIT_MPC["NonLinMPC"]["moveinput!"]["NonLinModel"]["MultipleShooting"] =
7680
setup=preparestate!($nmpc_nonlin_ms, $y, $d),
7781
samples=samples, evals=evals, seconds=seconds
7882
)
83+
UNIT_MPC["NonLinMPC"]["moveinput!"]["NonLinModel"]["TrapezoidalCollocation"] =
84+
@benchmarkable(
85+
moveinput!($nmpc_nonlin_tc, $y_c, $d_c),
86+
setup=preparestate!($nmpc_nonlin_ms, $y_c, $d_c),
87+
samples=samples, evals=evals, seconds=seconds
88+
)
7989

8090
## ----------------------------------------------------------------------------------------
8191
## ---------------------- CASE STUDIES ----------------------------------------------------
@@ -255,13 +265,20 @@ nmpc_ipopt_ms = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription)
255265
nmpc_ipopt_ms = setconstraint!(nmpc_ipopt_ms; umin, umax)
256266
JuMP.unset_time_limit_sec(nmpc_ipopt_ms.optim)
257267

268+
optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
269+
transcription = TrapezoidalCollocation()
270+
nmpc_ipopt_tc = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription)
271+
nmpc_ipopt_tc = setconstraint!(nmpc_ipopt_tc; umin, umax)
272+
JuMP.unset_time_limit_sec(nmpc_ipopt_tc.optim)
273+
258274
optim = JuMP.Model(MadNLP.Optimizer, add_bridges=false)
259275
transcription = SingleShooting()
260276
nmpc_madnlp_ss = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription)
261277
nmpc_madnlp_ss = setconstraint!(nmpc_madnlp_ss; umin, umax)
262278
JuMP.unset_time_limit_sec(nmpc_madnlp_ss.optim)
263279

264-
# TODO: does not work well with MadNLP and MultipleShooting, figure out why. Current theory:
280+
# TODO: does not work well with MadNLP and MultipleShooting or TrapezoidalCollocation,
281+
# figure out why. Current theory:
265282
# MadNLP LBFGS approximation is less robust than Ipopt version. Re-test when exact Hessians
266283
# will be supported in ModelPredictiveControl.jl. The following attributes kinda work with
267284
# the MadNLP LBFGS approximation but super slow (~1000 times slower than Ipopt):
@@ -285,6 +302,11 @@ CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["MultipleShooting"] =
285302
sim!($nmpc_ipopt_ms, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0),
286303
samples=samples, evals=evals, seconds=seconds
287304
)
305+
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["TrapezoidalCollocation"] =
306+
@benchmarkable(
307+
sim!($nmpc_ipopt_tc, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0),
308+
samples=samples, evals=evals, seconds=seconds
309+
)
288310
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["MadNLP"]["SingleShooting"] =
289311
@benchmarkable(
290312
sim!($nmpc_madnlp_ss, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0),
@@ -316,13 +338,19 @@ empc_ipopt_ms = NonLinMPC(estim2; Hp, Hc, Nwt, Mwt=Mwt2, Cwt, JE, Ewt, optim, tr
316338
empc_ipopt_ms = setconstraint!(empc_ipopt_ms; umin, umax)
317339
JuMP.unset_time_limit_sec(empc_ipopt_ms.optim)
318340

341+
optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
342+
transcription = TrapezoidalCollocation()
343+
empc_ipopt_tc = NonLinMPC(estim2; Hp, Hc, Nwt, Mwt=Mwt2, Cwt, JE, Ewt, optim, transcription, p)
344+
empc_ipopt_tc = setconstraint!(empc_ipopt_tc; umin, umax)
345+
JuMP.unset_time_limit_sec(empc_ipopt_tc.optim)
346+
319347
optim = JuMP.Model(MadNLP.Optimizer, add_bridges=false)
320348
transcription = SingleShooting()
321349
empc_madnlp_ss = NonLinMPC(estim2; Hp, Hc, Nwt, Mwt=Mwt2, Cwt, JE, Ewt, optim, transcription, p)
322350
empc_madnlp_ss = setconstraint!(empc_madnlp_ss; umin, umax)
323351
JuMP.unset_time_limit_sec(empc_madnlp_ss.optim)
324352

325-
# TODO: test EMPC with MadNLP and MultipleShooting, see comment above.
353+
# TODO: test EMPC with MadNLP and MultipleShooting and TrapezoidalCollocation, see comment above.
326354

327355
samples, evals, seconds = 100, 1, 15*60
328356
CASE_MPC["Pendulum"]["NonLinMPC"]["Economic"]["Ipopt"]["SingleShooting"] =
@@ -335,6 +363,11 @@ CASE_MPC["Pendulum"]["NonLinMPC"]["Economic"]["Ipopt"]["MultipleShooting"] =
335363
sim!($empc_ipopt_ms, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0),
336364
samples=samples, evals=evals, seconds=seconds
337365
)
366+
CASE_MPC["Pendulum"]["NonLinMPC"]["Economic"]["Ipopt"]["TrapezoidalCollocation"] =
367+
@benchmarkable(
368+
sim!($empc_ipopt_tc, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0),
369+
samples=samples, evals=evals, seconds=seconds
370+
)
338371
CASE_MPC["Pendulum"]["NonLinMPC"]["Economic"]["MadNLP"]["SingleShooting"] =
339372
@benchmarkable(
340373
sim!($empc_madnlp_ss, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0),
@@ -373,8 +406,17 @@ nmpc2_ipopt_ms = NonLinMPC(estim2;
373406
nmpc2_ipopt_ms = setconstraint!(nmpc2_ipopt_ms; umin, umax)
374407
JuMP.unset_time_limit_sec(nmpc2_ipopt_ms.optim)
375408

409+
optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
410+
transcription = TrapezoidalCollocation()
411+
nmpc2_ipopt_tc = NonLinMPC(estim2;
412+
Hp, Hc, Nwt=Nwt, Mwt=[0.5, 0], Cwt, gc!, nc, p=Pmax, optim, transcription
413+
)
414+
nmpc2_ipopt_tc = setconstraint!(nmpc2_ipopt_tc; umin, umax)
415+
JuMP.unset_time_limit_sec(nmpc2_ipopt_tc.optim)
416+
376417
# TODO: test custom constraints with MadNLP and SingleShooting, see comment above.
377418
# TODO: test custom constraints with MadNLP and MultipleShooting, see comment above.
419+
# TODO: test custom constraints with MadNLP and TrapezoidalCollocation, see comment above.
378420

379421
samples, evals, seconds = 100, 1, 15*60
380422
CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["SingleShooting"] =
@@ -387,6 +429,11 @@ CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["MultipleShooti
387429
sim!($nmpc2_ipopt_ms, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0),
388430
samples=samples, evals=evals, seconds=seconds
389431
)
432+
CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["TrapezoidalCollocation"] =
433+
@benchmarkable(
434+
sim!($nmpc2_ipopt_tc, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0),
435+
samples=samples, evals=evals, seconds=seconds
436+
)
390437

391438
# ----------------- Case study: Pendulum successive linearization -------------------------
392439
linmodel = linearize(model, x=[0, 0], u=[0])

benchmark/benchmarks.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ SUITE["UNIT TESTS"] = BenchmarkGroup(["allocation-free", "allocations", "singl
88
SUITE["CASE STUDIES"] = BenchmarkGroup(["performance", "speed" ,"integration"])
99

1010
include("0_bench_setup.jl")
11-
include("1_bench_sim_model.jl")
12-
include("2_bench_state_estim.jl")
11+
#include("1_bench_sim_model.jl")
12+
#include("2_bench_state_estim.jl")
1313
include("3_bench_predictive_control.jl")

0 commit comments

Comments
 (0)