@@ -1241,9 +1241,9 @@ end
12411241end
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+
13911394end
13921395
13931396@testitem " MHE estim. & getinfo (NonLinModel, MS)" setup= [SetupMPCtests] begin
0 commit comments