Skip to content

Commit 749fbcf

Browse files
authored
Merge pull request #277 from JuliaControl/mhe_hessian
added: `hessian` keyword argument for `MovingHorizonEstimator`
2 parents 23aed06 + 4ea61b7 commit 749fbcf

File tree

11 files changed

+429
-263
lines changed

11 files changed

+429
-263
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ModelPredictiveControl"
22
uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c"
3-
version = "1.12.0"
3+
version = "1.13.0"
44
authors = ["Francis Gagnon"]
55

66
[deps]

benchmark/2_bench_state_estim.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,13 @@ mhe_pendulum_ipopt_curr = setconstraint!(mhe_pendulum_ipopt_curr; v̂min, v̂max
305305
JuMP.unset_time_limit_sec(mhe_pendulum_ipopt_curr.optim)
306306
JuMP.set_attribute(mhe_pendulum_ipopt_curr.optim, "tol", 1e-7)
307307

308+
hessian = true
309+
mhe_pendulum_ipopt_currh = MovingHorizonEstimator(
310+
model; He, σQ, σR, nint_u, σQint_u, optim, direct, hessian
311+
)
312+
mhe_pendulum_ipopt_currh = setconstraint!(mhe_pendulum_ipopt_currh; v̂min, v̂max)
313+
JuMP.unset_time_limit_sec(mhe_pendulum_ipopt_currh.optim)
314+
308315
optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
309316
direct = false
310317
mhe_pendulum_ipopt_pred = MovingHorizonEstimator(
@@ -314,6 +321,14 @@ mhe_pendulum_ipopt_pred = setconstraint!(mhe_pendulum_ipopt_pred; v̂min, v̂max
314321
JuMP.unset_time_limit_sec(mhe_pendulum_ipopt_pred.optim)
315322
JuMP.set_attribute(mhe_pendulum_ipopt_pred.optim, "tol", 1e-7)
316323

324+
hessian = true
325+
mhe_pendulum_ipopt_predh = MovingHorizonEstimator(
326+
model; He, σQ, σR, nint_u, σQint_u, optim, direct, hessian
327+
)
328+
mhe_pendulum_ipopt_predh = setconstraint!(mhe_pendulum_ipopt_predh; v̂min, v̂max)
329+
JuMP.unset_time_limit_sec(mhe_pendulum_ipopt_predh.optim)
330+
JuMP.set_attribute(mhe_pendulum_ipopt_predh.optim, "tol", 1e-7)
331+
317332
optim = JuMP.Model(MadNLP.Optimizer, add_bridges=false)
318333
direct = true
319334
mhe_pendulum_madnlp_curr = MovingHorizonEstimator(
@@ -338,11 +353,21 @@ CASE_ESTIM["Pendulum"]["MovingHorizonEstimator"]["Ipopt"]["Current form"] =
338353
sim!($mhe_pendulum_ipopt_curr, $N, $u; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
339354
samples=samples, evals=evals, seconds=seconds
340355
)
356+
CASE_ESTIM["Pendulum"]["MovingHorizonEstimator"]["Ipopt"]["Current form (Hessian)"] =
357+
@benchmarkable(
358+
sim!($mhe_pendulum_ipopt_currh, $N, $u; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
359+
samples=samples, evals=evals, seconds=seconds
360+
)
341361
CASE_ESTIM["Pendulum"]["MovingHorizonEstimator"]["Ipopt"]["Prediction form"] =
342362
@benchmarkable(
343363
sim!($mhe_pendulum_ipopt_pred, $N, $u; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
344364
samples=samples, evals=evals, seconds=seconds
345365
)
366+
CASE_ESTIM["Pendulum"]["MovingHorizonEstimator"]["Ipopt"]["Prediction form (Hessian)"] =
367+
@benchmarkable(
368+
sim!($mhe_pendulum_ipopt_predh, $N, $u; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
369+
samples=samples, evals=evals, seconds=seconds
370+
)
346371
CASE_ESTIM["Pendulum"]["MovingHorizonEstimator"]["MadNLP"]["Current form"] =
347372
@benchmarkable(
348373
sim!($mhe_pendulum_madnlp_curr, $N, $u; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),

benchmark/3_bench_predictive_control.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,13 @@ optim = JuMP.Model(MadNLP.Optimizer, add_bridges=false)
318318
transcription = SingleShooting()
319319
nmpc_madnlp_ss = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription)
320320
nmpc_madnlp_ss = setconstraint!(nmpc_madnlp_ss; umin, umax)
321-
JuMP.unset_time_limit_sec(nmpc_madnlp_ss.optim)
321+
JuMP.unset_time_limit_sec(nmpc_madnlp_ss.optim)
322+
323+
optim = JuMP.Model(()->UnoSolver.Optimizer(preset="filtersqp"), add_bridges=false)
324+
transcription, hessian, oracle = MultipleShooting(), true, true
325+
nmpc_uno_ms_hess = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription, hessian, oracle)
326+
nmpc_uno_ms_hess = setconstraint!(nmpc_uno_ms_hess; umin, umax)
327+
JuMP.unset_time_limit_sec(nmpc_uno_ms_hess.optim)
322328

323329
# TODO: does not work well with MadNLP and MultipleShooting or TrapezoidalCollocation,
324330
# figure out why. Current theory:
@@ -375,6 +381,11 @@ CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["MadNLP"]["SingleShooting"] =
375381
sim!($nmpc_madnlp_ss, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
376382
samples=samples, evals=evals, seconds=seconds
377383
)
384+
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Uno"]["MultipleShooting (Hessian)"] =
385+
@benchmarkable(
386+
sim!($nmpc_uno_ms_hess, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
387+
samples=samples, evals=evals, seconds=seconds
388+
)
378389

379390
# ----------------- Case study: Pendulum economic --------------------------------
380391
model2, p = pendulum_model2, pendulum_p2

benchmark/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1313
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1414
SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5"
1515
SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35"
16+
UnoSolver = "1baa60ac-02f7-4b39-a7a8-2f4f58486b05"

benchmark/benchmarks.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using BenchmarkTools
22
using ModelPredictiveControl, ControlSystemsBase, LinearAlgebra
3-
using JuMP, OSQP, DAQP, Ipopt, MadNLP
3+
using JuMP, OSQP, DAQP, Ipopt, MadNLP, UnoSolver
44

55
const SUITE = BenchmarkGroup(["ModelPredictiveControl"])
66

docs/src/internals/state_estim.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ ModelPredictiveControl.relaxX̂
1818
ModelPredictiveControl.relaxŴ
1919
ModelPredictiveControl.relaxV̂
2020
ModelPredictiveControl.init_matconstraint_mhe
21-
ModelPredictiveControl.get_nonlinops(::MovingHorizonEstimator, ::ModelPredictiveControl.GenericModel)
21+
ModelPredictiveControl.get_nonlinobj_op(::MovingHorizonEstimator, ::ModelPredictiveControl.GenericModel)
22+
ModelPredictiveControl.get_nonlincon_oracle(::MovingHorizonEstimator, ::ModelPredictiveControl.GenericModel)
2223
```
2324

2425
## Augmented Model

0 commit comments

Comments
 (0)