Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differentiable control design #791

Open
baggepinnen opened this issue Jan 4, 2023 · 1 comment
Open

Differentiable control design #791

baggepinnen opened this issue Jan 4, 2023 · 1 comment

Comments

@baggepinnen
Copy link
Member

baggepinnen commented Jan 4, 2023

A number of functions in this package and in RobustAndOptimalControl.jl fail when trying to compute gradients through them using ForwardDiff or Zygote. This issue tries to summarize the current status

Problematic functions

Function AD package Comment
c2d ForwardDiff :zoh requires exp!(::Matrix{Dual}). ForwardDiffChainRules buggy, but manual implementation possible. #844
feedback Zygote try/catch and @warn
are All Handled through ImplicitDiff #844
hinfnorm ForwardDiff Non-smooth. Works for Zygote. See tests for comments and comment. ForwardDiff in #844 but not for MIMO
svd/qr/schur ForwardDiff DifferentiableFactorizations.jl may be helpful
hessenberg ForwardDiff, ReverseDiff GenericLinearAlgebra.Hessenberg has different fieldnames from LinearAlgebra.Hessenberg

c2d example failing

foo(x) = sum(exp(reshape(x, 2, 2)))
v = randn(4)
using ForwardDiff
ForwardDiff.gradient(foo, v)

ERROR: MethodError: no method matching exp(::Matrix{ForwardDiff.Dual...

Related issues:

@baggepinnen
Copy link
Member Author

With in-place exp!

using ForwardDiff
using ForwardDiffChainRules
@ForwardDiff_frule LinearAlgebra.exp!(x1::AbstractMatrix{<:ForwardDiff.Dual})
foo(x) = sum(LinearAlgebra.exp!(reshape(x, 2, 2)))
v = randn(4)
ForwardDiff.gradient(foo, v)
julia> ForwardDiff.gradient(foo, v)
4-element Vector{Float64}:
 1.1002741981700268
 1.0554893997879182
 0.7951393746830535
 0.7605002893053368

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant