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
720 stars 79 forks source link

Issue in running OptimizationFunction #686

Closed lakshaya17 closed 7 months ago

lakshaya17 commented 8 months ago

I am trying to run the example in the README, but I am getting the following error:

MethodError: no method matching (OptimizationFunction{true})(::typeof(rosenbrock), ::AutoForwardDiff{nothing, Nothing})

Some of the types have been truncated in the stacktrace for improved reading. To emit complete information
in the stack trace, evaluate `TruncatedStacktraces.VERBOSE[] = true` and re-run the code.

Closest candidates are:
  (OptimizationFunction{iip})(::Any) where iip at C:\Users\lakshay\.julia\packages\SciMLBase\zXEYU\src\scimlfunctions.jl:3907
  (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 at C:\Users\lakshay\.julia\packages\SciMLBase\zXEYU\src\scimlfunctions.jl:3907

Stacktrace:
 [1] OptimizationFunction(::Function, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ SciMLBase C:\Users\lakshay\.julia\packages\SciMLBase\zXEYU\src\scimlfunctions.jl:3905
 [2] OptimizationFunction(::Function, ::Vararg{Any})
   @ SciMLBase C:\Users\lakshay\.julia\packages\SciMLBase\zXEYU\src\scimlfunctions.jl:3905
 [3] top-level scope
   @ In[15]:2

Particularly I am running this code:

using ForwardDiff
f = OptimizationFunction(rosenbrock, Optimization.AutoForwardDiff())
prob = OptimizationProblem(f, x0, p)
sol = solve(prob, BFGS())

I would be obliged if someone could help me with the same.

Regards

SebastianM-C commented 8 months ago

I ran the code with recent versions of the packages and it works for me? What does ]st -m Optimization SciMLBase show for you.

lakshaya17 commented 8 months ago

⌅ [7f7a1694] Optimization v3.19.3 ⌅ [0bca4576] SciMLBase v1.89.0

SebastianM-C commented 8 months ago

Oh, you have am old SciMLBase (pre v2). @ChrisRackauckas I think that https://github.com/SciML/Optimization.jl/blob/5cb65c83b00e8f0adc00deb7f4678799fdd32188/Project.toml#L53 is not really correct and it should ~drop the 2~ require 2, I tried

Edit: v2 should be required, not dropped, sorry for the confusion.

(jl_8TnPqU) pkg> st
Status `C:\Users\sebastian\AppData\Local\Temp\jl_8TnPqU\Project.toml`
  [f6369f11] ForwardDiff v0.10.36
⌃ [7f7a1694] Optimization v3.19.3
⌃ [0bca4576] SciMLBase v1.89.0
Info Packages marked with ⌃ have new versions available and may be upgradable.

and I can reproduce the error mentioned above:

julia> f = OptimizationFunction(rosenbrock, Optimization.AutoForwardDiff())
ERROR: MethodError: no method matching (OptimizationFunction{true})(::typeof(rosenbrock), ::AutoForwardDiff{nothing, Nothing})

Closest candidates are:
  (OptimizationFunction{iip})(::Any; ...) where iip
   @ SciMLBase C:\Users\sebastian\.julia\packages\SciMLBase\zXEYU\src\scimlfunctions.jl:3907
  (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\sebastian\.julia\packages\SciMLBase\zXEYU\src\scimlfunctions.jl:3907

Stacktrace:
 [1] OptimizationFunction(::Function, ::Vararg{Any}; kwargs::@Kwargs{})
   @ SciMLBase C:\Users\sebastian\.julia\packages\SciMLBase\zXEYU\src\scimlfunctions.jl:3905
 [2] top-level scope
   @ REPL[15]:1

@lakshaya17 You can see what packages are holding back SciMLBase with ]st -m --outdated SciMLBase.

ChrisRackauckas commented 8 months ago

Yes, that should get bumped to require v2. In fact, we need the full downgrade CI here.

Vaibhavdixit02 commented 8 months ago

There is downgrade CI here already.

Tbh I don't get the issue here, how did you end up with those versions @lakshaya17?

is not really correct and it should drop the 2, I tried (jl_8TnPqU) pkg> st Status C:\Users\sebastian\AppData\Local\Temp\jl_8TnPqU\Project.toml [f6369f11] ForwardDiff v0.10.36 ⌃ [7f7a1694] Optimization v3.19.3 ⌃ [0bca4576] SciMLBase v1.89.0 Info Packages marked with ⌃ have new versions available and may be upgradable. and I can reproduce the error mentioned above:

I am probably misunderstanding but doesn't this mean that v2 should be there and should have been used but somehow the OP ended up with <v2 and that led to the error?

lakshaya17 commented 8 months ago

I tried that and updated the Julia version as well. Still no luck. I checked the outdated packages, and they showing me this:

(@v1.10) pkg> status --outdated
Status `C:\Users\lakshay\.julia\environments\v1.10\Project.toml`
⌅ [764a87c0] BoundaryValueDiffEq v4.0.1 (<v5.6.1): DifferentialEquations
⌃ [a6e380b2] ControlSystems v1.10.0 (<v1.10.1)
⌃ [0c46a032] DifferentialEquations v7.10.0 (<v7.12.0)
⌅ [76087f3c] NLopt v0.6.5 (<v1.0.1): OptimizationNLopt
⌃ [7f7a1694] Optimization v3.19.3 (<v3.21.2)
⌃ [fd9f6733] OptimizationMOI v0.1.16 (<v0.3.4)
⌃ [4e6fcdb7] OptimizationNLopt v0.1.8 (<v0.2.0)
⌃ [1dea7af3] OrdinaryDiffEq v6.58.2 (<v6.69.0)
⌅ [0bca4576] SciMLBase v1.98.1 (<v2.21.0): BoundaryValueDiffEq, DiffEqBase, Integrals, ModelingToolkit, StochasticDiffEq
⌃ [1ed8b502] SciMLSensitivity v7.51.0 (<v7.53.0)

With the command:

st -m --outdated SciMLBase

Its giving me this:

[0bca4576] SciMLBase v1.98.1 (<v2.21.0): BoundaryValueDiffEq, DiffEqBase, Integrals, ModelingToolkit, StochasticDiffEq

When I am trying to update these, they are either giving me compatibility issues.

Vaibhavdixit02 commented 8 months ago

Does just ]up give you compatibility issues?

lakshaya17 commented 8 months ago

No. I just ran this:

(@v1.10) pkg> up
    Updating registry at `C:\Users\lakshay\.julia\registries\General.toml`
  No Changes to `C:\Users\lakshay\.julia\environments\v1.10\Project.toml`
  No Changes to `C:\Users\lakshay\.julia\environments\v1.10\Manifest.toml`
Vaibhavdixit02 commented 8 months ago

You should restart the julia session and try this

lakshaya17 commented 8 months ago

@Vaibhavdixit02 I ran that after restarting Julia session only.

SebastianM-C commented 8 months ago

doesn't this mean that v2 should be there and should have been used but somehow the OP ended up with <v2 and that led to the error?

@Vaibhavdixit02 yeah, it should require v2 and OP somehow ended up with <v2, sorry for the confusion.

@lakshaya17 what do you get if you try to explicitly ]add SciMLBase@v2?

lakshaya17 commented 8 months ago

@SebastianM-C I am getting this:

(@v1.10) pkg> add SciMLBase@v2
   Resolving package versions...
ERROR: Unsatisfiable requirements detected for package Integrals [de52edbc]:
 Integrals [de52edbc] log:
 ├─possible versions are: 3.0.0-4.1.0 or uninstalled
 ├─restricted to versions 3.1.0-3 by SciMLExpectations [afe9f18d], leaving only versions: 3.1.0-3.9.0
 │ └─SciMLExpectations [afe9f18d] log:
 │   ├─possible versions are: 2.1.0 or uninstalled
 │   └─SciMLExpectations [afe9f18d] is fixed to version 2.1.0
 └─restricted by compatibility requirements with SciMLBase [0bca4576] to versions: 4.0.0-4.1.0 or uninstalled — no versions left
SebastianM-C commented 8 months ago

It looks like SciMLExpectations is holding back Integrals to a version pre SciMLBase@v2. If you don't need SciMLExpectations in this environment, removing it and updating should hopefully resolve the issue.