Skip to content

Commit 28139ef

Browse files
committed
bench: OrthogonalCollocation on pendulum
Also called `GC.gc()` in `setup` function to try to avoid OOM.
1 parent 8eefb3c commit 28139ef

1 file changed

Lines changed: 94 additions & 44 deletions

File tree

benchmark/3_bench_predictive_control.jl

Lines changed: 94 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,8 @@ optim = JuMP.Model(DAQP.Optimizer, add_bridges=false)
268268
transcription = SingleShooting()
269269
mpc_d_daqp_ss = setconstraint!(LinMPC(model_d; optim, transcription), ymin=[45, -Inf])
270270

271-
# # Skip DAQP with MultipleShooting, it is not designed for sparse Hessians. Kind of works
272-
# # with "eps_prox" configured to 1e-6, but not worth it.
273-
# optim = JuMP.Model(DAQP.Optimizer, add_bridges=false)
274-
# transcription = MultipleShooting()
275-
# mpc_d_daqp_ms = setconstraint!(LinMPC(model_d; optim, transcription), ymin=[45, -Inf])
276-
# JuMP.set_attribute(mpc_d_daqp_ms.optim, "eps_prox", 1e-6)
271+
# Skip DAQP with MultipleShooting, it is not designed for sparse Hessians. Kind of works
272+
# with "eps_prox" configured to 1e-6, but not worth it.
277273

278274
optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
279275
transcription = SingleShooting()
@@ -367,20 +363,32 @@ nmpc_ipopt_tct = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription)
367363
nmpc_ipopt_tct = setconstraint!(nmpc_ipopt_tct; umin, umax)
368364
JuMP.unset_time_limit_sec(nmpc_ipopt_tct.optim)
369365

366+
optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
367+
transcription = OrthogonalCollocation()
368+
nmpc_ipopt_oc = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription)
369+
nmpc_ipopt_oc = setconstraint!(nmpc_ipopt_oc; umin, umax)
370+
JuMP.unset_time_limit_sec(nmpc_ipopt_oc.optim)
371+
372+
optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
373+
transcription, hessian = OrthogonalCollocation(), true
374+
nmpc_ipopt_oc_hess = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription, hessian)
375+
nmpc_ipopt_oc_hess = setconstraint!(nmpc_ipopt_oc_hess; umin, umax)
376+
JuMP.unset_time_limit_sec(nmpc_ipopt_oc_hess.optim)
377+
378+
# skip MadNLP.jl with hessian=false, their LBFGS does not work well
379+
370380
optim = JuMP.Model(MadNLP.Optimizer, add_bridges=false)
371-
transcription = SingleShooting()
372-
nmpc_madnlp_ss = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription)
373-
nmpc_madnlp_ss = setconstraint!(nmpc_madnlp_ss; umin, umax)
374-
JuMP.unset_time_limit_sec(nmpc_madnlp_ss.optim)
381+
transcription, hessian = SingleShooting(), true
382+
nmpc_madnlp_ss_hess = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription, hessian)
383+
nmpc_madnlp_ss_hess = setconstraint!(nmpc_madnlp_ss_hess; umin, umax)
384+
JuMP.unset_time_limit_sec(nmpc_madnlp_ss_hess.optim)
375385

376386
optim = JuMP.Model(()->UnoSolver.Optimizer(preset="filtersqp"), add_bridges=false)
377387
transcription, hessian = MultipleShooting(), true
378388
nmpc_uno_ms_hess = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription, hessian)
379389
nmpc_uno_ms_hess = setconstraint!(nmpc_uno_ms_hess; umin, umax)
380390
JuMP.unset_time_limit_sec(nmpc_uno_ms_hess.optim)
381391

382-
# skip MadNLP.jl with MultipleShooting and hessian=false, their LBFGS does not work well
383-
384392
optim = JuMP.Model(MadNLP.Optimizer)
385393
transcription, hessian = MultipleShooting(), true
386394
nmpc_madnlp_ms_hess = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription, hessian)
@@ -391,58 +399,69 @@ samples, evals, seconds = 100, 1, 15*60
391399
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["SingleShooting"] =
392400
@benchmarkable(
393401
sim!($nmpc_ipopt_ss, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
394-
samples=samples, evals=evals, seconds=seconds
402+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
395403
)
396404
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["SingleShooting (Hessian)"] =
397405
@benchmarkable(
398406
sim!($nmpc_ipopt_ss_hess, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
399-
samples=samples, evals=evals, seconds=seconds
407+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
400408
)
401409
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["MultipleShooting"] =
402410
@benchmarkable(
403411
sim!($nmpc_ipopt_ms, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
404-
samples=samples, evals=evals, seconds=seconds
412+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
405413
)
406414
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["MultipleShooting (Hessian)"] =
407415
@benchmarkable(
408416
sim!($nmpc_ipopt_ms_hess, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
409-
samples=samples, evals=evals, seconds=seconds
417+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
410418
)
411419
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["MultipleShooting (threaded)"] =
412420
@benchmarkable(
413421
sim!($nmpc_ipopt_mst, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
414-
samples=samples, evals=evals, seconds=seconds
422+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
415423
)
416424
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["TrapezoidalCollocation"] =
417425
@benchmarkable(
418426
sim!($nmpc_ipopt_tc, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
419-
samples=samples, evals=evals, seconds=seconds
427+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
420428
)
421429
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["TrapezoidalCollocation (Hessian)"] =
422430
@benchmarkable(
423431
sim!($nmpc_ipopt_tc_hess, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
424-
samples=samples, evals=evals, seconds=seconds
432+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
425433
)
426434
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["TrapezoidalCollocation (threaded)"] =
427435
@benchmarkable(
428436
sim!($nmpc_ipopt_tct, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
429-
samples=samples, evals=evals, seconds=seconds
437+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
430438
)
431-
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["MadNLP"]["SingleShooting"] =
439+
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["OrthogonalCollocation"] =
440+
@benchmarkable(
441+
sim!($nmpc_ipopt_oc, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
442+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
443+
)
444+
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["OrthogonalCollocation (Hessian)"] =
445+
@benchmarkable(
446+
sim!($nmpc_ipopt_oc_hess, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
447+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
448+
)
449+
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["MadNLP"]["SingleShooting (Hessian)"] =
432450
@benchmarkable(
433451
sim!($nmpc_madnlp_ss, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
434-
samples=samples, evals=evals, seconds=seconds
452+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
435453
)
436454
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["MadNLP"]["MultipleShooting (Hessian)"] =
437455
@benchmarkable(
438456
sim!($nmpc_madnlp_ms_hess, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
439-
samples=samples, evals=evals, seconds=seconds
457+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
440458
)
441459
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Uno"]["MultipleShooting (Hessian)"] =
442460
@benchmarkable(
443461
sim!($nmpc_uno_ms_hess, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
444-
samples=samples, evals=evals, seconds=seconds
445-
)
462+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
463+
)
464+
446465

447466
# ----------------- Case study: Pendulum economic --------------------------------
448467
model2, p = pendulum_model2, pendulum_p2
@@ -493,49 +512,80 @@ empc_ipopt_tc_hess = NonLinMPC(estim2; Hp, Hc, Nwt, Mwt=Mwt2, Cwt, JE, Ewt, opti
493512
empc_ipopt_tc_hess = setconstraint!(empc_ipopt_tc_hess; umin, umax)
494513
JuMP.unset_time_limit_sec(empc_ipopt_tc_hess.optim)
495514

515+
optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
516+
transcription = OrthogonalCollocation()
517+
empc_ipopt_oc = NonLinMPC(estim2; Hp, Hc, Nwt, Mwt=Mwt2, Cwt, JE, Ewt, optim, transcription, p)
518+
empc_ipopt_oc = setconstraint!(empc_ipopt_oc; umin, umax)
519+
JuMP.unset_time_limit_sec(empc_ipopt_oc.optim)
520+
521+
optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
522+
transcription, hessian = OrthogonalCollocation(), true
523+
empc_ipopt_oc_hess = NonLinMPC(estim2; Hp, Hc, Nwt, Mwt=Mwt2, Cwt, JE, Ewt, optim, transcription, p)
524+
empc_ipopt_oc_hess = setconstraint!(empc_ipopt_oc_hess; umin, umax)
525+
JuMP.unset_time_limit_sec(empc_ipopt_oc_hess.optim)
526+
496527
optim = JuMP.Model(MadNLP.Optimizer, add_bridges=false)
497-
transcription = SingleShooting()
498-
empc_madnlp_ss = NonLinMPC(estim2; Hp, Hc, Nwt, Mwt=Mwt2, Cwt, JE, Ewt, optim, transcription, p)
499-
empc_madnlp_ss = setconstraint!(empc_madnlp_ss; umin, umax)
500-
JuMP.unset_time_limit_sec(empc_madnlp_ss.optim)
528+
transcription, hessian = SingleShooting(), true
529+
empc_madnlp_ss_hess = NonLinMPC(estim2; Hp, Hc, Nwt, Mwt=Mwt2, Cwt, JE, Ewt, optim, transcription, hessian, p)
530+
empc_madnlp_ss_hess = setconstraint!(empc_madnlp_ss_hess; umin, umax)
531+
JuMP.unset_time_limit_sec(empc_madnlp_ss_hess.optim)
501532

502-
# TODO: test EMPC with MadNLP and MultipleShooting and TrapezoidalCollocation, see comment above.
533+
optim = JuMP.Model(()->UnoSolver.Optimizer(preset="filtersqp"), add_bridges=false)
534+
transcription, hessian = MultipleShooting(), true
535+
empc_uno_ss_hess = NonLinMPC(estim2; Hp, Hc, Nwt, Mwt=Mwt2, Cwt, JE, Ewt, optim, transcription, hessian, p)
536+
empc_uno_ss_hess = setconstraint!(empc_uno_ss_hess; umin, umax)
537+
JuMP.unset_time_limit_sec(empc_uno_ss_hess.optim)
503538

504539
samples, evals, seconds = 100, 1, 15*60
505540
CASE_MPC["Pendulum"]["NonLinMPC"]["Economic"]["Ipopt"]["SingleShooting"] =
506541
@benchmarkable(
507542
sim!($empc_ipopt_ss, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
508-
samples=samples, evals=evals, seconds=seconds
543+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
509544
)
510545
CASE_MPC["Pendulum"]["NonLinMPC"]["Economic"]["Ipopt"]["SingleShooting (Hessian)"] =
511546
@benchmarkable(
512547
sim!($empc_ipopt_ss_hess, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
513-
samples=samples, evals=evals, seconds=seconds
548+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
514549
)
515550
CASE_MPC["Pendulum"]["NonLinMPC"]["Economic"]["Ipopt"]["MultipleShooting"] =
516551
@benchmarkable(
517552
sim!($empc_ipopt_ms, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
518-
samples=samples, evals=evals, seconds=seconds
553+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
519554
)
520555
CASE_MPC["Pendulum"]["NonLinMPC"]["Economic"]["Ipopt"]["MultipleShooting (Hessian)"] =
521556
@benchmarkable(
522557
sim!($empc_ipopt_ms_hess, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
523-
samples=samples, evals=evals, seconds=seconds
558+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
524559
)
525560
CASE_MPC["Pendulum"]["NonLinMPC"]["Economic"]["Ipopt"]["TrapezoidalCollocation"] =
526561
@benchmarkable(
527562
sim!($empc_ipopt_tc, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
528-
samples=samples, evals=evals, seconds=seconds
563+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
529564
)
530565
CASE_MPC["Pendulum"]["NonLinMPC"]["Economic"]["Ipopt"]["TrapezoidalCollocation (Hessian)"] =
531566
@benchmarkable(
532567
sim!($empc_ipopt_tc_hess, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
533-
samples=samples, evals=evals, seconds=seconds
568+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
534569
)
535-
CASE_MPC["Pendulum"]["NonLinMPC"]["Economic"]["MadNLP"]["SingleShooting"] =
570+
CASE_MPC["Pendulum"]["NonLinMPC"]["Economic"]["Ipopt"]["OrthogonalCollocation"] =
536571
@benchmarkable(
537-
sim!($empc_madnlp_ss, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
538-
samples=samples, evals=evals, seconds=seconds
572+
sim!($empc_ipopt_oc, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
573+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
574+
)
575+
CASE_MPC["Pendulum"]["NonLinMPC"]["Economic"]["Ipopt"]["OrthogonalCollocation (Hessian)"] =
576+
@benchmarkable(
577+
sim!($empc_ipopt_oc_hess, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
578+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
579+
)
580+
CASE_MPC["Pendulum"]["NonLinMPC"]["Economic"]["MadNLP"]["SingleShooting (Hessian)"] =
581+
@benchmarkable(
582+
sim!($empc_madnlp_ss_hess, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
583+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
584+
)
585+
CASE_MPC["Pendulum"]["NonLinMPC"]["Economic"]["Uno"]["MultipleShooting (Hessian)"] =
586+
@benchmarkable(
587+
sim!($empc_uno_ss_hess, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
588+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
539589
)
540590

541591
# -------------- Case study: Pendulum custom constraints --------------------------
@@ -598,27 +648,27 @@ samples, evals, seconds = 100, 1, 15*60
598648
CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["SingleShooting"] =
599649
@benchmarkable(
600650
sim!($nmpc2_ipopt_ss, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
601-
samples=samples, evals=evals, seconds=seconds
651+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
602652
)
603653
CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["MultipleShooting"] =
604654
@benchmarkable(
605655
sim!($nmpc2_ipopt_ms, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
606-
samples=samples, evals=evals, seconds=seconds
656+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
607657
)
608658
CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["MultipleShooting (Hessian)"] =
609659
@benchmarkable(
610660
sim!($nmpc2_ipopt_ms_hess, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
611-
samples=samples, evals=evals, seconds=seconds
661+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
612662
)
613663
CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["TrapezoidalCollocation"] =
614664
@benchmarkable(
615665
sim!($nmpc2_ipopt_tc, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
616-
samples=samples, evals=evals, seconds=seconds
666+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
617667
)
618668
CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["TrapezoidalCollocation (Hessian)"] =
619669
@benchmarkable(
620670
sim!($nmpc2_ipopt_tc_hess, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
621-
samples=samples, evals=evals, seconds=seconds
671+
samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
622672
)
623673

624674
# ----------------- Case study: Pendulum successive linearization -------------------------

0 commit comments

Comments
 (0)