You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the OptimizationFunction{false} iip argument is specified, solve() breaks with AutoForwardDiff(), as the cost function is seemingly invoked in some kind of in-place form rather than with the parameter value.
Expected behavior
Either solve() to run successfully (as it does if iip isn't set to false), or a clear error message suggesting to avoid iip=false to appear.
Minimal Reproducible Example 👇
Without MRE, we would only be able to help you to a limited extent, and attention to the issue would be limited. to know more about MRE refer to wikipedia and stackoverflow.
using StaticArrays
using Optimization
using OptimizationOptimJL
using ForwardDiff
struct Params
foo::Float64endfunctioncost(u::StaticVector{3}, params::Params)
sum(u.^2) + params.foo
end
optprob =OptimizationProblem(
OptimizationFunction(cost, AutoForwardDiff()),
@MVector([1.0, 1.0, 1.0]),
Params(42.0),
lb=SA[0.0, 0.0, 0.0],
ub=SA[2π, 2π, 2π]
)
sol = Optimization.solve(optprob, LBFGS())
The package versions are the latest Git versions at the time of writing, DifferentiationInterface@9a524d3681aceece0f01955ddf171d2de7e0e113, OptimizationBase@2ffab7e93197c1fc8d9ed6a39857e301a71a474e, Optimization@06ed20e1466376da941b31bfdc1493fb2393eb4f, SciMLBase@f3f4442a4de093ab22fb8c6efb8fe0b307f682fe.
A similar issue occurs on the latest releases.
Output of using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
Julia Version 1.10.5
Commit 6f3fdf7b362 (2024-08-2714:19 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: macOS (arm64-apple-darwin22.4.0)
CPU:10× Apple M1 Max
WORD_SIZE:64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads:10 default, 0 interactive, 5 GC (on 8 virtual cores)
Environment:
JULIA_NUM_THREADS =10
JULIA_EDITOR = code
Additional context
This occurred while I was converting a problem from NonlinearSolve.jl, where the function giving the system of equations was actually out-of-place in a meaningful way, to an Optimization.jl optimisation problem, where the objective is a scalar value (the sum of squares of the previous equations). As a user, it is hard to see what iip = false would even mean in this context (I gather it changes the behaviour for the internal gradients, etc.), but nevertheless, things shouldn't randomly break if it is specified.
The text was updated successfully, but these errors were encountered:
Describe the bug 🐞
If the
OptimizationFunction{false}
iip argument is specified,solve()
breaks withAutoForwardDiff()
, as the cost function is seemingly invoked in some kind of in-place form rather than with the parameter value.Expected behavior
Either
solve()
to run successfully (as it does ifiip
isn't set to false), or a clear error message suggesting to avoidiip=false
to appear.Minimal Reproducible Example 👇
Without MRE, we would only be able to help you to a limited extent, and attention to the issue would be limited. to know more about MRE refer to wikipedia and stackoverflow.
Error & Stacktrace⚠️
Environment (please complete the following information):
using Pkg; Pkg.status()
The package versions are the latest Git versions at the time of writing, DifferentiationInterface@9a524d3681aceece0f01955ddf171d2de7e0e113, OptimizationBase@2ffab7e93197c1fc8d9ed6a39857e301a71a474e, Optimization@06ed20e1466376da941b31bfdc1493fb2393eb4f, SciMLBase@f3f4442a4de093ab22fb8c6efb8fe0b307f682fe.
A similar issue occurs on the latest releases.
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
Additional context
This occurred while I was converting a problem from NonlinearSolve.jl, where the function giving the system of equations was actually out-of-place in a meaningful way, to an Optimization.jl optimisation problem, where the objective is a scalar value (the sum of squares of the previous equations). As a user, it is hard to see what
iip = false
would even mean in this context (I gather it changes the behaviour for the internal gradients, etc.), but nevertheless, things shouldn't randomly break if it is specified.The text was updated successfully, but these errors were encountered: