Repository navigation
added: ExplicitMPC now supports AD with ForwardDiff.jl - #524
Conversation
verif_obsv=true keyword argument to all LinModel state observersExplicitMPC now support automatic differentiation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #524 +/- ##
==========================================
+ Coverage 97.25% 97.29% +0.03%
==========================================
Files 28 28
Lines 7077 7089 +12
==========================================
+ Hits 6883 6897 +14
+ Misses 194 192 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
It seems to crash on `ControlSystems.jl` side, but it's clean in this repo.
|
Now it's possible to autodiff this MRE with using ModelPredictiveControl, ForwardDiff
using Logging # new line
const ERROR_ONLY = ConsoleLogger(stderr, Logging.Error) # new line
A = [0.9 0.08; -0.15 0.75]
Bu = reshape([0.005, 0.09], 2, 1)
C = [1.0 0.0]
# The first move of an ExplicitMPC as a function of its input weight
function first_move(Nwt)
T = typeof(Nwt)
model = LinModel{T}(A, Bu, C, 0, 0, 0.1)
estim = KalmanFilter(model; nint_ym=0, verify_obsv=false) # added: verify_obsv=false
mpc = ExplicitMPC(estim; Hp=20, Hc=2)
preparestate!(mpc, [0.0])
return moveinput!(mpc, [1.0])[1]
end
@show first_move(0.5)
@show ForwardDiff.derivative(first_move, 0.5)
with_logger(ERROR_ONLY) do
@time ForwardDiff.derivative(first_move, 0.5)
endDoes it seems to fit your needs? |
ExplicitMPC now support automatic differentiationExplicitMPC now supports automatic differentiation
It will never check observability for this `StateEstimator`, since the estimation job is delegated externally.
ExplicitMPC now supports automatic differentiationExplicitMPC now supports automatic differentiation with ForwardDiff.jl
ExplicitMPC now supports automatic differentiation with ForwardDiff.jlExplicitMPC now supports AD with ForwardDiff.jl
|
@PTWaade I will merge this PR, release an update and keep the issue open to remind me to check for the other autodiff engines. |
|
By the way the default using ModelPredictiveControl, ForwardDiff
using ImplicitDifferentiation, ComponentArrays # needed to support AD through `kalman`
using Logging
const ERROR_ONLY = ConsoleLogger(stderr, Logging.Error)
A = [0.9 0.08; -0.15 0.75]
Bu = reshape([0.005, 0.09], 2, 1)
C = [1.0 0.0]
# The first move of an ExplicitMPC as a function of its input weight
function first_move(Nwt)
T = typeof(Nwt)
model = LinModel{T}(A, Bu, C, 0, 0, 0.1)
mpc = ExplicitMPC(model; Hp=20, Hc=2, nint_ym=0, verify_obsv=false)
preparestate!(mpc, [0.0])
return moveinput!(mpc, [1.0])[1]
end
@show first_move(0.5)
@show ForwardDiff.derivative(first_move, 0.5)
with_logger(ERROR_ONLY) do
@time ForwardDiff.derivative(first_move, 0.5)
end |
Bugfix for #523. I only tested it with
ForwardDiff.jl, for now.I added a
verify_obsv=truekeyword argument to allLinModelstate observers, that is:SteadyKalmanFilterKalmanFilterLuenbergerThe failed checkups for the Hessian condition number$\mathrm{cond}(\mathbf{\tilde{H}})$ and the prediction horizon $H_p$ will still emit a
@warn, but it can be silenced locally with: