From 7a6923a2c0c2174c357ca39eca61915f842ff555 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Sat, 8 Nov 2025 11:46:57 -0500 Subject: [PATCH] bench: custom constraint tests with `hessian=true` --- benchmark/3_bench_predictive_control.jl | 39 +++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/benchmark/3_bench_predictive_control.jl b/benchmark/3_bench_predictive_control.jl index 59b99ffdf..dc54b5c39 100644 --- a/benchmark/3_bench_predictive_control.jl +++ b/benchmark/3_bench_predictive_control.jl @@ -308,6 +308,12 @@ nmpc_ipopt_tc = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription) nmpc_ipopt_tc = setconstraint!(nmpc_ipopt_tc; umin, umax) JuMP.unset_time_limit_sec(nmpc_ipopt_tc.optim) +optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false) +transcription, hessian = TrapezoidalCollocation(), true +nmpc_ipopt_tc_hess = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription, hessian) +nmpc_ipopt_tc_hess = setconstraint!(nmpc_ipopt_tc_hess; umin, umax) +JuMP.unset_time_limit_sec(nmpc_ipopt_tc_hess.optim) + optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false) transcription = TrapezoidalCollocation(f_threads=true) nmpc_ipopt_tct = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription) @@ -371,6 +377,11 @@ CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["TrapezoidalCollocatio sim!($nmpc_ipopt_tc, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false), samples=samples, evals=evals, seconds=seconds ) +CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["TrapezoidalCollocation (Hessian)"] = + @benchmarkable( + sim!($nmpc_ipopt_tc_hess, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false), + samples=samples, evals=evals, seconds=seconds + ) CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["TrapezoidalCollocation (threaded)"] = @benchmarkable( sim!($nmpc_ipopt_tct, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false), @@ -480,6 +491,14 @@ nmpc2_ipopt_ms = NonLinMPC(estim2; nmpc2_ipopt_ms = setconstraint!(nmpc2_ipopt_ms; umin, umax) JuMP.unset_time_limit_sec(nmpc2_ipopt_ms.optim) +optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false) +transcription, hessian = MultipleShooting(), true +nmpc2_ipopt_ms_hess = NonLinMPC(estim2; + Hp, Hc, Nwt=Nwt, Mwt=[0.5, 0], Cwt, gc!, nc, p=Pmax, optim, transcription, hessian +) +nmpc2_ipopt_ms_hess = setconstraint!(nmpc2_ipopt_ms_hess; umin, umax) +JuMP.unset_time_limit_sec(nmpc2_ipopt_ms_hess.optim) + optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false) transcription = TrapezoidalCollocation() nmpc2_ipopt_tc = NonLinMPC(estim2; @@ -488,9 +507,13 @@ nmpc2_ipopt_tc = NonLinMPC(estim2; nmpc2_ipopt_tc = setconstraint!(nmpc2_ipopt_tc; umin, umax) JuMP.unset_time_limit_sec(nmpc2_ipopt_tc.optim) -# TODO: test custom constraints with MadNLP and SingleShooting, see comment above. -# TODO: test custom constraints with MadNLP and MultipleShooting, see comment above. -# TODO: test custom constraints with MadNLP and TrapezoidalCollocation, see comment above. +optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false) +transcription, hessian = TrapezoidalCollocation(), true +nmpc2_ipopt_tc_hess = NonLinMPC(estim2; + Hp, Hc, Nwt=Nwt, Mwt=[0.5, 0], Cwt, gc!, nc, p=Pmax, optim, transcription, hessian +) +nmpc2_ipopt_tc = setconstraint!(nmpc2_ipopt_tc_hess; umin, umax) +JuMP.unset_time_limit_sec(nmpc2_ipopt_tc_hess.optim) samples, evals, seconds = 100, 1, 15*60 CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["SingleShooting"] = @@ -503,11 +526,21 @@ CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["MultipleShooti sim!($nmpc2_ipopt_ms, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false), samples=samples, evals=evals, seconds=seconds ) +CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["MultipleShooting (Hessian)"] = + @benchmarkable( + sim!($nmpc2_ipopt_ms_hess, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false), + samples=samples, evals=evals, seconds=seconds + ) CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["TrapezoidalCollocation"] = @benchmarkable( sim!($nmpc2_ipopt_tc, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false), samples=samples, evals=evals, seconds=seconds ) +CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["TrapezoidalCollocation (Hessian)"] = + @benchmarkable( + sim!($nmpc2_ipopt_tc_hess, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false), + samples=samples, evals=evals, seconds=seconds + ) # ----------------- Case study: Pendulum successive linearization ------------------------- linmodel = linearize(model, x=[0, 0], u=[0])