Skip to content

Commit 752ee6e

Browse files
authored
Merge pull request #503 from JuliaControl/precompile_hessian
added: `hessian=true` in precompilation and CI tweaks
2 parents 34a1f13 + f7b774e commit 752ee6e

3 files changed

Lines changed: 19 additions & 16 deletions

File tree

‎.github/workflows/juliaci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
julia-ci:
1616
uses: franckgaga/testitem-workflow/.github/workflows/juliaci.yml@patch-1
1717
with:
18-
memory-threshold: 0.9 # try to avoid OOM error on ubuntu and Julia 1.10
1918
include-windows-x86: false # not worth it, windows 32bit is too uncommon
2019
include-macos-x64: false # most mac are aarch64 nowadays
2120
include-macos-aarch64: false # would like to include it, but too unreliable for now
21+
include-linux-x86: false # would like to include it, but too unreliable for now
2222
permissions: write-all
2323
secrets:
2424
codecov_token: ${{ secrets.CODECOV_TOKEN }}

‎src/precompile.jl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ R̂y = repeat([55; 30], 3)
9898
daemodel = NonLinModelDAE(fq_dae!, h_dae!, 100.0, 1, 1, 1, 1; transcription)
9999
sim!(daemodel, 2, [10])
100100

101-
mhe_dae = MovingHorizonEstimator(daemodel, He=2, direct=false)
101+
mhe_dae = MovingHorizonEstimator(daemodel, He=2, direct=false, hessian=true)
102102
setconstraint!(mhe_dae, x̂min=[-50, 50], x̂max=[50, 50])
103-
nmpc_dae = NonLinMPC(mhe_dae, Hp=3)
103+
nmpc_dae = NonLinMPC(mhe_dae, Hp=3, hessian=true)
104104
setconstraint!(nmpc_dae, ymin=[-50], ymax=[50])
105105
preparestate!(nmpc_dae, [5])
106106
moveinput!(nmpc_dae, [0.1])

‎test/2_test_state_estim.jl‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,9 +1241,9 @@ end
12411241
end
12421242

12431243
@testitem "MHE estim. & getinfo (NonLinModel, SS)" setup=[SetupMPCtests] begin
1244-
using .SetupMPCtests, ControlSystemsBase, LinearAlgebra, ForwardDiff
1244+
using .SetupMPCtests, ControlSystemsBase, LinearAlgebra
12451245
using JuMP, Ipopt, DifferentiationInterface, SparseMatrixColorings, SparseConnectivityTracer
1246-
import ForwardDiff
1246+
import FiniteDiff
12471247

12481248
linmodel = LinModel(sys,Ts,i_u=[1,2], i_d=[3])
12491249
linmodel = setop!(linmodel, uop=[10,50], yop=[50,30], dop=[5])
@@ -1341,7 +1341,10 @@ end
13411341
@test evaloutput(mhe5, [5]) ≈ mhe5([5]) ≈ [50, 30]
13421342
info = getinfo(mhe5)
13431343
@test info[:x̂] ≈ x̂ atol=1e-9
1344-
@test info[:Ŷ][end-1:end] ≈ [50, 30] atol=1e-9
1344+
@test info[:Ŷ][end-1:end] ≈ [50, 30] atol=1e-9
1345+
1346+
@test_nowarn ModelPredictiveControl.info2debugstr(info)
1347+
@test_throws ErrorException setstate!(mhe1, [1,2,3,4,5,6], diagm(.1:.1:.6))
13451348

13461349
# coverage of the branch with error termination status (with an infeasible problem):
13471350
mhe_infeas = MovingHorizonEstimator(nonlinmodel, He=1, Cwt=Inf)
@@ -1352,21 +1355,20 @@ end
13521355
preparestate!(mhe_infeas, [0, 0], [0])
13531356
)
13541357

1355-
@test_nowarn ModelPredictiveControl.info2debugstr(info)
1356-
@test_throws ErrorException setstate!(mhe1, [1,2,3,4,5,6], diagm(.1:.1:.6))
1357-
1358-
hessian = AutoSparse(
1359-
AutoForwardDiff();
1360-
sparsity_detector=TracerSparsityDetector(),
1361-
coloring_algorithm=GreedyColoringAlgorithm(),
1362-
)
1358+
gradient, jacobian, hessian = AutoFiniteDiff(), AutoFiniteDiff(), AutoFiniteDiff()
13631359

1364-
mhe8 = MovingHorizonEstimator(nonlinmodel; He=2, hessian)
1360+
mhe8 = MovingHorizonEstimator(nonlinmodel; He=2, gradient, jacobian, hessian)
1361+
@test mhe8.gradient isa AutoFiniteDiff
1362+
@test mhe8.jacobian isa AutoFiniteDiff
1363+
@test mhe8.hessian isa AutoFiniteDiff
1364+
x̂ = preparestate!(mhe8, [50, 30], [5])
1365+
@test x̂ ≈ zeros(6) atol=1e-6
1366+
updatestate!(mhe8, [10, 50], [50, 30], [5])
13651367
@test_logs(
13661368
(:warn, "NaN values in the MHE measurements ym: ignoring them in the objective"),
13671369
preparestate!(mhe8, [50, NaN], [5])
13681370
)
1369-
@test mhe8.x̂0 ≈ zeros(6) atol=1e-9
1371+
@test mhe8.x̂0 ≈ zeros(6) atol=1e-6
13701372

13711373
function f!(ẋ, x, u, d, p)
13721374
ẋ[] = -p[] * (x[] - 0.2 * u[] - 0.2 * d[])
@@ -1388,6 +1390,7 @@ end
13881390
@test mhe_foh([0.0]) ≈ [1.5]
13891391
info = getinfo(mhe_foh)
13901392
@test info[:x̂] ≈ x̂
1393+
13911394
end
13921395

13931396
@testitem "MHE estim. & getinfo (NonLinModel, MS)" setup=[SetupMPCtests] begin

0 commit comments

Comments
 (0)