Skip to content

Commit e6729fe

Browse files
committed
added: RandomOrder and StableRNGs dep.
This significantly improve the efficiency of `hessian!` for the economic MPC on the pendulum.
1 parent b4ad881 commit e6729fe

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
2020
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2121
SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5"
2222
SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35"
23+
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
2324

2425
[compat]
2526
ControlSystemsBase = "1.18.2"
@@ -42,6 +43,7 @@ RecipesBase = "1"
4243
SparseArrays = "1.10"
4344
SparseConnectivityTracer = "0.6.13, 1"
4445
SparseMatrixColorings = "0.4.14"
46+
StableRNGs = "1.0.4"
4547
TestItemRunner = "1"
4648
TestItems = "1"
4749
julia = "1.10"

src/ModelPredictiveControl.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module ModelPredictiveControl
33
using PrecompileTools
44
using LinearAlgebra, SparseArrays
55
using Random: randn
6+
using StableRNGs: StableRNG
67

78
using RecipesBase
89

@@ -15,7 +16,9 @@ using DifferentiationInterface: Constant, Cache
1516
using SparseConnectivityTracer: TracerSparsityDetector
1617
using SparseMatrixColorings: GreedyColoringAlgorithm, sparsity_pattern
1718
using SparseMatrixColorings: NaturalOrder, LargestFirst, SmallestLast
18-
using SparseMatrixColorings: IncidenceDegree, DynamicLargestFirst
19+
using SparseMatrixColorings: IncidenceDegree, DynamicLargestFirst, RandomOrder
20+
21+
using SparseMatrixColorings: ncolors
1922

2023
import ProgressLogging
2124

src/controller/nonlinmpc.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,8 @@ function get_nonlinobj_op(mpc::NonLinMPC, optim::JuMP.GenericModel{JNT}) where J
662662
∇²J_prep = prepare_hessian(J!, hess, Z̃_J, J_cache...; strict)
663663
∇²J = init_diffmat(JNT, hess, ∇²J_prep, nZ̃, nZ̃)
664664
∇²J_structure = lowertriangle_indices(init_diffstructure(∇²J))
665+
@show ncolors(∇²J_prep)
666+
display(sparsity_pattern(∇²J_prep))
665667
end
666668
update_objective! = if !isnothing(hess)
667669
function (J, ∇J, ∇²J, Z̃_J, Z̃_arg)

src/general.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const ALL_COLORING_ORDERS = (
1313
SmallestLast(),
1414
IncidenceDegree(),
1515
DynamicLargestFirst(),
16+
RandomOrder(StableRNG(0), 0)
1617
)
1718

1819
"Termination status that means 'no solution available'."

0 commit comments

Comments
 (0)