Skip to content

Commit 56433fb

Browse files
committed
starting support of sparse Jacobians
1 parent a4ca9b8 commit 56433fb

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1717
ProgressLogging = "33c8b6b6-d38a-422a-b730-caa89a2f386c"
1818
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1919
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
20+
SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5"
21+
SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35"
2022

2123
[compat]
2224
ControlSystemsBase = "1.9"
@@ -32,6 +34,8 @@ PrecompileTools = "1"
3234
ProgressLogging = "0.1"
3335
Random = "1.10"
3436
RecipesBase = "1"
37+
SparseConnectivityTracer = "0.6.13"
38+
SparseMatrixColorings = "0.4.14"
3539
julia = "1.10"
3640

3741
[extras]

src/ModelPredictiveControl.jl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@ using Random: randn
77
using RecipesBase
88
using ProgressLogging
99

10-
11-
1210
using DifferentiationInterface: ADTypes.AbstractADType, AutoForwardDiff, AutoSparse
1311
using DifferentiationInterface: gradient!, jacobian!, prepare_gradient, prepare_jacobian
12+
using SparseConnectivityTracer: TracerSparsityDetector
13+
using SparseMatrixColorings: GreedyColoringAlgorithm
1414

15-
import ForwardDiff
16-
17-
18-
19-
15+
import ForwardDiff #TODO: delete this after `linearize!` and `ExtendedKalmanFilter` are updated
2016

2117
import ControlSystemsBase
2218
import ControlSystemsBase: ss, tf, delay

src/controller/nonlinmpc.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
const DEFAULT_NONLINMPC_TRANSCRIPTION = SingleShooting()
22
const DEFAULT_NONLINMPC_OPTIMIZER = optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes")
3-
const DEFAULT_NONLINMPC_GRADIENT = AutoForwardDiff()
3+
const DEFAULT_NONLINMPC_GRADIENT = AutoForwardDiff()
4+
const DEFAULT_NONLINMPC_JACDENSE = AutoForwardDiff()
5+
const DEFAULT_NONLINMPC_JACSPARSE = AutoSparse(
6+
AutoForwardDiff();
7+
sparsity_detector=TracerSparsityDetector(),
8+
coloring_algorithm=GreedyColoringAlgorithm(),
9+
)
410

511
struct NonLinMPC{
612
NT<:Real,
@@ -375,8 +381,8 @@ function NonLinMPC(
375381
)
376382
end
377383

378-
default_jacobian(::SingleShooting) = AutoForwardDiff()
379-
default_jacobian(::TranscriptionMethod) = AutoForwardDiff()
384+
default_jacobian(::SingleShooting) = DEFAULT_NONLINMPC_JACDENSE
385+
default_jacobian(::TranscriptionMethod) = DEFAULT_NONLINMPC_JACSPARSE
380386

381387
"""
382388
validate_JE(NT, JE) -> nothing

src/estimator/mhe/construct.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,12 +1196,18 @@ function init_predmat_mhe(
11961196
end
11971197

11981198
"""
1199-
init_optimization!(estim::MovingHorizonEstimator, model::SimModel, optim, _ , _ )
1199+
init_optimization!(
1200+
estim::MovingHorizonEstimator, model::SimModel, optim::JuMP.GenericModel, _ , _
1201+
)
12001202
12011203
Init the quadratic optimization of [`MovingHorizonEstimator`](@ref).
12021204
"""
12031205
function init_optimization!(
1204-
estim::MovingHorizonEstimator, ::LinModel, optim::JuMP.GenericModel, _ , _
1206+
estim::MovingHorizonEstimator,
1207+
::LinModel,
1208+
optim::JuMP.GenericModel,
1209+
::AbstractADType,
1210+
::AbstractADType
12051211
)
12061212
nZ̃ = length(estim.Z̃)
12071213
JuMP.num_variables(optim) == 0 || JuMP.empty!(optim)

0 commit comments

Comments
 (0)