SciML / SciML/Optimization.jl

Error with LBFGS() with using adjoint on 3D arrays

Open
#673 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

3D optimization with LBFGS fails. 2D arrays work because adjoint is probably defined.

# ╔═╡ 350d641c-ae24-11ee-018a-b331fe41f5b3
using Optimization, OptimizationOptimisers, OptimizationOptimJL, Zygote

# ╔═╡ 4c272f03-4aae-4788-99bd-88e8bb3a8eea
f(x, p) = sum(abs2, x)

# ╔═╡ eba0efac-2874-4031-97fc-3256ad103bd6
init0 = ones((10, 10, 10))

# ╔═╡ f0afb848-f40f-4999-86cc-50f63f7b553d
opt_fun = OptimizationFunction(f, AutoZygote())

# ╔═╡ c3171aae-9822-4add-a2ec-d1e749158684
problem = OptimizationProblem(opt_fun, init0);

# ╔═╡ d5d19f34-3100-43a3-8d35-6aae4bf1b171
res = solve(problem, OptimizationOptimJL.LBFGS(), maxiters=20)

results in:

adjoint not defined for Array{Float64, 3}. Consider using `permutedims` for higher-dimensional arrays.

    error(::String)@error.jl:35
    adjoint(::Array{Float64, 3})@transpose.jl:3
    alloc_H(::Array{Float64, 3}, ::Float64)@abstract.jl:25
    __solve(::Optimization.OptimizationCache{SciMLBase.OptimizationFunction{true, ADTypes.AutoZygote, typeof(Main.var"workspace#9".f), OptimizationZygoteExt.var"#38#56"{OptimizationZygoteExt.var"#37#55"{SciMLBase.OptimizationFunction{true, ADTypes.AutoZygote, typeof(Main.var"workspace#9".f), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Optimization.ReInitCache{Array{Float64, 3}, SciMLBase.NullParameters}}}, OptimizationZygoteExt.var"#41#59"{OptimizationZygoteExt.var"#37#55"{SciMLBase.OptimizationFunction{true, ADTypes.AutoZygote, typeof(Main.var"workspace#9".f), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Optimization.ReInitCache{Array{Float64, 3}, SciMLBase.NullParameters}}}, OptimizationZygoteExt.var"#45#63", Nothing, OptimizationZygoteExt.var"#49#67"{SciMLBase.OptimizationFunction{true, ADTypes.AutoZygote, typeof(Main.var"workspace#9".f), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Optimization.ReInitCache{Array{Float64, 3}, SciMLBase.NullParameters}}, OptimizationZygoteExt.var"#53#71"{SciMLBase.OptimizationFunction{true, ADTypes.AutoZygote, typeof(Main.var"workspace#9".f), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Optimization.ReInitCache{Array{Float64, 3}, SciMLBase.NullParameters}}, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Optimization.ReInitCache{Array{Float64, 3}, SciMLBase.NullParameters}, Nothing, Nothing, Nothing, Nothing, Nothing, Optim.LBFGS{Nothing, LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"}, Base.Iterators.Cycle{Tuple{Optimization.NullData}}, Bool, OptimizationOptimJL.var"#4#6"})@OptimizationOptimJL.jl:191
    solve!(::Optimization.OptimizationCache{SciMLBase.OptimizationFunction{true, ADTypes.AutoZygote, typeof(Main.var"workspace#9".f), OptimizationZygoteExt.var"#38#56"{OptimizationZygoteExt.var"#37#55"{SciMLBase.OptimizationFunction{true, ADTypes.AutoZygote, typeof(Main.var"workspace#9".f), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Optimization.ReInitCache{Array{Float64, 3}, SciMLBase.NullParameters}}}, OptimizationZygoteExt.var"#41#59"{OptimizationZygoteExt.var"#37#55"{SciMLBase.OptimizationFunction{true, ADTypes.AutoZygote, typeof(Main.var"workspace#9".f), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Optimization.ReInitCache{Array{Float64, 3}, SciMLBase.NullParameters}}}, OptimizationZygoteExt.var"#45#63", Nothing, OptimizationZygoteExt.var"#49#67"{SciMLBase.OptimizationFunction{true, ADTypes.AutoZygote, typeof(Main.var"workspace#9".f), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Optimization.ReInitCache{Array{Float64, 3}, SciMLBase.NullParameters}}, OptimizationZygoteExt.var"#53#71"{SciMLBase.OptimizationFunction{true, ADTypes.AutoZygote, typeof(Main.var"workspace#9".f), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Optimization.ReInitCache{Array{Float64, 3}, SciMLBase.NullParameters}}, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Optimization.ReInitCache{Array{Float64, 3}, SciMLBase.NullParameters}, Nothing, Nothing, Nothing, Nothing, Nothing, Optim.LBFGS{Nothing, LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"}, Base.Iterators.Cycle{Tuple{Optimization.NullData}}, Bool, OptimizationOptimJL.var"#4#6"})@solve.jl:177
    var"#solve#599"(::Base.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:maxiters,), Tuple{Int64}}}, ::typeof(CommonSolve.solve), ::SciMLBase.OptimizationProblem{true, SciMLBase.OptimizationFunction{true, ADTypes.AutoZygote, typeof(Main.var"workspace#9".f), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Array{Float64, 3}, SciMLBase.NullParameters, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, ::Optim.LBFGS{Nothing, LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"})@solve.jl:94
    top-level scope@[Local: 1](http://localhost:1234/edit?id=350d6414-ae24-11ee-39ce-75009143ebb4#)[inlined]
status `/tmp/jl_is47EO/Project.toml`
⌅ [7f7a1694] Optimization v3.20.2
⌅ [36348300] OptimizationOptimJL v0.1.14
⌅ [42dfb2eb] OptimizationOptimisers v0.1.6
  [e88e6eb3] Zygote v0.6.68
  [44cfe95a] Pkg v1.9.2
Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated`


Julia Version 1.9.4
Commit 8e5136fa297 (2023-11-14 08:46 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 24 × AMD Ryzen 9 5900X 12-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, znver3)
  Threads: 24 on 24 virtual cores
Environment:
  JULIA_NUM_THREADS = 24
  JULIA_DEPOT_PATH = /home/felix/.julia:/home/felix/.julia/juliaup/julia-1.9.4+0.x64.linux.gnu/local/share/julia:/home/felix/.julia/juliaup/julia-1.9.4+0.x64.linux.gnu/share/julia
  JULIA_PROJECT = /home/felix/.julia/dev/SwissVAMyKnife.jl/Project.toml
  JULIA_LOAD_PATH = @:@v#.#:@stdlib
  JULIA_REVISE_WORKER_ONLY = 1

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

Start by running the Julia reproducer with Optimization, OptimizationOptimJL, OptimizationOptimisers, and Zygote, then inspect the stack frames at OptimizationOptimJL.jl:191, solve.jl:177, and abstract.jl:25. Compare the 3D failure with the stated working 2D case; done means LBFGS completes for the 3D array without the adjoint error and has regression coverage.

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.