SciML / Optimization.jl

Mathematical Optimization in Julia. Local, global, gradient-based and derivative-free. Linear, Quadratic, Convex, Mixed-Integer, and Nonlinear Optimization in one simple, fast, and differentiable interface.
https://docs.sciml.ai/Optimization/stable/
MIT License
711 stars 79 forks source link

Error with AutoZygote in OptimizationFunction after Julia version upgrade to 1.9.2 #571

Closed sarkispa closed 1 year ago

sarkispa commented 1 year ago

I was trying to run an optimization script after moving from julia 1.6 to the current release (1.9.2) and stumbled upon an error while using AutoZygote. I can't run the following example from the documentation:


using Zygote
using Optimization
rosenbrock(u, p) = (p[1] - u[1])^2 + p[2] * (u[2] - u[1]^2)^2
u0 = zeros(2)
p = [1.0, 100.0]

optf = OptimizationFunction(rosenbrock, AutoZygote)

I get the following error message:

ERROR: MethodError: no method matching (OptimizationFunction{true})(::typeof(rosenbrock), ::Type{AutoZygote})

Closest candidates are:
  (OptimizationFunction{iip})(::Any) where iip
   @ SciMLBase C:\Users\paolo\.julia\packages\SciMLBase\QqtZA\src\scimlfunctions.jl:3583
  (OptimizationFunction{iip})(::Any, ::SciMLBase.AbstractADType; grad, hess, hv, cons, cons_j, cons_h, lag_h, hess_prototype, cons_jac_prototype, cons_hess_prototype, lag_hess_prototype, syms, paramsyms, observed, hess_colorvec, cons_jac_colorvec, cons_hess_colorvec, lag_hess_colorvec, expr, cons_expr, sys) where iip
   @ SciMLBase C:\Users\paolo\.julia\packages\SciMLBase\QqtZA\src\scimlfunctions.jl:3583

Stacktrace:
 [1] OptimizationFunction(::Function, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ SciMLBase C:\Users\paolo\.julia\packages\SciMLBase\QqtZA\src\scimlfunctions.jl:3581
 [2] OptimizationFunction(::Function, ::Vararg{Any})
   @ SciMLBase C:\Users\paolo\.julia\packages\SciMLBase\QqtZA\src\scimlfunctions.jl:3581
 [3] top-level scope
   @ c:\Users\paolo\Dropbox\Experiments-CMS\temp_scripts\build\JuMP-models\estimateCMSonCarsData-insample.jl:146

I looked around in the issues and could find related issue #546 but I did not understand what the local fix was (also version is different).

My version info:

julia> versioninfo()
Julia Version 1.9.2
Commit e4ee485e90 (2023-07-05 09:39 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 12 × 12th Gen Intel(R) Core(TM) i7-1255U
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, alderlake)
  Threads: 1 on 12 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS =
pkg> st Optimization
Status `C:\Users\paolo\Dropbox\Experiments-CMS\Project.toml`
  [7f7a1694] Optimization v3.15.2
pkg> st Zygote
Status `C:\Users\paolo\Dropbox\Experiments-CMS\Project.toml`
  [e88e6eb3] Zygote v0.6.62
Vaibhavdixit02 commented 1 year ago

There's probably some outdated dependencies in your environment, can you ]up and try

sarkispa commented 1 year ago

Sure, here was the status of ADTypes:

pkg> st -m ADTypes
Status `C:\Users\paolo\Dropbox\Experiments-CMS\Manifest.toml`
  [47edcb42] ADTypes v0.1.6

I also updated all packages following what you said but only Distributions was to be updated. This still led to warnings which might be linked?:

pkg> up
    Updating registry at `C:\Users\paolo\.julia\registries\General`
    Updating git-repo `https://github.com/JuliaRegistries/General.git`
   Installed Distributions ─ v0.25.100
    Updating `C:\Users\paolo\Dropbox\Experiments-CMS\Project.toml`
  [31c24e10] ↑ Distributions v0.25.99 ⇒ v0.25.100
    Updating `C:\Users\paolo\Dropbox\Experiments-CMS\Manifest.toml`
  [31c24e10] ↑ Distributions v0.25.99 ⇒ v0.25.100
Precompiling project...
  55 dependencies successfully precompiled in 250 seconds. 612 already precompiled.
  3 dependencies had warnings during precompilation:
┌ Symbolics [0c5d862f-8b57-4792-8d23-62f2024744c7]
│  WARNING: Method definition isapprox(IntervalSets.AbstractInterval{T} where T, IntervalSets.AbstractInterval{T} where T) in module IntervalSets at C:\Users\paolo\.julia\packages\IntervalSets\6RTOk\src\IntervalSets.jl:144 overwritten in module DomainSets at C:\Users\paolo\.julia\packages\DomainSets\aafhp\src\domains\interval.jl:52.
│    ** incremental compilation may be fatally broken for this module **
└  
┌ ModelingToolkit [961ee093-0014-501f-94e3-6117800e7a78]
│  WARNING: Method definition isapprox(IntervalSets.AbstractInterval{T} where T, IntervalSets.AbstractInterval{T} where T) in module IntervalSets at C:\Users\paolo\.julia\packages\IntervalSets\6RTOk\src\IntervalSets.jl:144 overwritten in module DomainSets at C:\Users\paolo\.julia\packages\DomainSets\aafhp\src\domains\interval.jl:52.
│    ** incremental compilation may be fatally broken for this module **
└
┌ OptimizationMTKExt [25f2e3d8-7e69-51be-9405-bb8b65e6479a]
│  WARNING: Method definition isapprox(IntervalSets.AbstractInterval{T} where T, IntervalSets.AbstractInterval{T} where T) in module IntervalSets at C:\Users\paolo\.julia\packages\IntervalSets\6RTOk\src\IntervalSets.jl:144 overwritten in module DomainSets at C:\Users\paolo\.julia\packages\DomainSets\aafhp\src\domains\interval.jl:52.
│    ** incremental compilation may be fatally broken for this module **
└

The error described above remains.

sarkispa commented 1 year ago

Ok I fixed it by cleaning my environment thoroughly and removing packages that I was not using. Then updating all packages, resolving and precompiling. Seems to work fine. Sorry for the bother, closing the issue now.

Vaibhavdixit02 commented 1 year ago

No worries 👍