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

OptimizationFunction cannot return multiple values #839

Open
vpuri3 opened this issue Oct 3, 2024 · 1 comment
Open

OptimizationFunction cannot return multiple values #839

vpuri3 opened this issue Oct 3, 2024 · 1 comment

Comments

@vpuri3
Copy link
Member

vpuri3 commented Oct 3, 2024

The API used to allow the OptimizationFunction to return multiple objects where the first one needs to be the loss value.

https://github.com/SciML/SciMLBase.jl/blob/master/src/scimlfunctions.jl#L1813-L1815

This MWE shows that all of the outputs of the optimization function are passed down to the AD backend.

julia> using OptimizationOptimJL, Zygote                                                                                                                                                                                                                             
                                                                                                                              
julia> f(x, p) = sum(x), (;)                                                                                                                                                                                                                                 
f (generic function with 1 method)                                                                                            
                                                                                                                                                                                                                                                             
julia> optf = OptimizationFunction(f, AutoZygote())                                                                                                                                                                                                          
                                                                                                                              
julia> optprob = OptimizationProblem(optf, rand(4))                                                                                                                                                                                                          
OptimizationProblem. In-place: true                                                                                           
u0: 4-element Vector{Float64}:                                                                                                                                                                                                                               
 0.7025958336860735                                                                                                           
 0.5420026600629022                                                                                                                                                                                                                                          
 0.6272098967494587
 0.1342462910974671

julia> optsol = solve(optprob, Optim.BFGS())
ERROR: Output should be scalar; gradients are not defined for output (2.0060546815959017, NamedTuple())
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] sensitivity(y::Tuple{Float64, @NamedTuple{}})
    @ Zygote ~/.julia/packages/Zygote/Tt5Gx/src/compiler/interface.jl:114
  [3] gradient(::Function, ::Vector{Float64}, ::Vararg{Any})
    @ Zygote ~/.julia/packages/Zygote/Tt5Gx/src/compiler/interface.jl:148
  [4] gradient
    @ ~/.julia/packages/DifferentiationInterface/QK77S/ext/DifferentiationInterfaceZygoteExt/DifferentiationInterfaceZygoteExt.jl:100 [inlined]
vpuri3 added a commit to vpuri3/NeuralROMs.jl that referenced this issue Oct 3, 2024
@SebastianM-C
Copy link
Contributor

#835 (comment) suggests that this is no longer supported.

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

No branches or pull requests

2 participants