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

Static arrays + autodiff #14

Open
aplavin opened this issue Feb 27, 2023 · 2 comments
Open

Static arrays + autodiff #14

aplavin opened this issue Feb 27, 2023 · 2 comments

Comments

@aplavin
Copy link

aplavin commented Feb 27, 2023

I tried using static vectors for parameters, which works nicely. But not when combined with autodiff:

julia> using Optimization, OptimizationOptimJL, StaticArrays, ForwardDiff

# don't specify inplace/outofplace:

julia> of = OptimizationFunction((x, p) -> sum(x), Optimization.AutoForwardDiff())
julia> prob = OptimizationProblem(of, SVector(0., 0.), nothing)
julia> solve(prob, Optim.GradientDescent())
ERROR: setindex!(::SVector{2, Float64}, value, ::Int) is not defined.

# specify out of place:

julia> of = OptimizationFunction{false}((x, p) -> sum(x), Optimization.AutoForwardDiff())
julia> prob = OptimizationProblem(of, SVector(0., 0.), nothing)
julia> solve(prob, Optim.GradientDescent())
ERROR: Use OptimizationFunction to pass the derivatives or automatically generate them with one of the autodiff backends

Is this expected?

@ChrisRackauckas
Copy link
Member

The ForwardDiff support for StaticArrays need to avoid the mutable DiffResults that we currently have it setup with. So I guess it's expected in that, now that you have mentioned it in an issue, I can see why it fails. Though I think it was just untested before. Not hard to fix though, but needs the effort.

@Vaibhavdixit02 Vaibhavdixit02 transferred this issue from SciML/Optimization.jl Feb 23, 2024
@gdalle
Copy link
Contributor

gdalle commented Mar 22, 2024

Beware that static arrays don't play nice with DiffResults sometimes:

JuliaDiff/DiffResults.jl#26

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

Successfully merging a pull request may close this issue.

3 participants