SciML / SciML/Optimization.jl

Static arrays + autodiff

Open
#978 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
839
Forks
100
Avg merge
20h 43m
Merged PRs (30d)
38

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce both Julia examples from the issue using Optimization, OptimizationOptimJL, StaticArrays, and ForwardDiff. Trace how OptimizationFunction and Optim.GradientDescent handle SVector inputs and autodiff, then inspect existing tests for static or out-of-place objectives. Done means the supported behavior is verified and covered, or the limitation is clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.