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
719 stars 80 forks source link

Optimisers basic usecase #653

Closed isentropic closed 7 months ago

isentropic commented 9 months ago
using Optimization
using OptimizationOptimisers
using Zygote

rosenbrock(x, p) = (p[1] - x[1])^2 + p[2] * (x[2] - x[1]^2)^2
x0 = zeros(2)
p = [1.0, 100.0]
solve(OptimizationProblem(OptimizationFunction(rosenbrock, Optimization.AutoZygote()), x0, p), OptimizationOptimisers.Descent())

errors with

ERROR: MethodError: no method matching take(::Base.Iterators.Cycle{Tuple{Optimization.NullData}}, ::Nothing)

Closest candidates are:
  take(::Any, ::Integer)
   @ Base iterators.jl:741

Stacktrace:
 [1] __solve(cache::OptimizationCache{…})
   @ OptimizationOptimisers ~/.julia/packages/OptimizationOptimisers/hZdKg/src/OptimizationOptimisers.jl:49
 [2] solve!(cache::OptimizationCache{…})
   @ SciMLBase ~/.julia/packages/SciMLBase/cL99i/src/solve.jl:177
 [3] solve(::OptimizationProblem{…}, ::Optimisers.Descent{…}; kwargs::@Kwargs{})
   @ SciMLBase ~/.julia/packages/SciMLBase/cL99i/src/solve.jl:94
 [4] solve(::OptimizationProblem{…}, ::Optimisers.Descent{…})
   @ SciMLBase ~/.julia/packages/SciMLBase/cL99i/src/solve.jl:91
 [5] top-level scope

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):

julia> using Pkg; Pkg.status()
Status `~/Projects/panama-convolution/panama/scripts/Project.toml`
  [587475ba] Flux v0.14.7
  [eb30cadb] MLDatasets v0.7.14
  [f1d291b0] MLUtils v0.4.3
  [429524aa] Optim v1.7.8
  [7f7a1694] Optimization v3.20.2
  [42dfb2eb] OptimizationOptimisers v0.1.6
  [2913bbd2] StatsBase v0.34.2
  [bc48ee85] Tullio v0.3.7
  [e88e6eb3] Zygote v0.6.68
  [37e2e46d] LinearAlgebra
julia> Pkg.status(; mode = PKGMODE_MANIFEST)
Status `~/Projects/panama-convolution/panama/scripts/Manifest.toml`
  [47edcb42] ADTypes v0.2.6
  [621f4979] AbstractFFTs v1.5.0
  [1520ce14] AbstractTrees v0.4.4
⌅ [79e6a3ab] Adapt v3.7.2
  [dce04be8] ArgCheck v2.3.0
  [4fba245c] ArrayInterface v7.7.0
  [a9b6321e] Atomix v0.1.0
  [a963bdd2] AtomsBase v0.3.5
  [ab4f0b2a] BFloat16s v0.4.2
  [198e06fe] BangBang v0.3.39
  [9718e550] Baselet v0.1.1
  [d1d4a3ce] BitFlags v0.1.8
  [e1450e63] BufferedStreams v1.2.1
  [fa961155] CEnum v0.5.0
  [336ed68f] CSV v0.10.11
  [082447d4] ChainRules v1.58.1
  [d360d2e6] ChainRulesCore v1.19.0
  [46823bd8] Chemfiles v0.10.41
  [944b1d66] CodecZlib v0.7.3
  [35d6a980] ColorSchemes v3.24.0
  [3da002f7] ColorTypes v0.11.4
  [c3611d14] ColorVectorSpace v0.10.0
  [5ae59095] Colors v0.12.10
  [38540f10] CommonSolve v0.2.4
  [bbf7d656] CommonSubexpressions v0.3.0
  [34da2185] Compat v4.10.1
  [a33af91c] CompositionsBase v0.1.2
  [f0e56b4a] ConcurrentUtilities v2.3.0
  [88cd18e8] ConsoleProgressMonitor v0.1.2
  [187b0558] ConstructionBase v1.5.4
  [6add18c4] ContextVariablesX v0.1.3
  [a8cc5b0e] Crayons v4.1.1
  [9a962f9c] DataAPI v1.15.0
  [124859b0] DataDeps v0.7.11
  [a93c6f00] DataFrames v1.6.1
  [864edb3b] DataStructures v0.18.15
  [e2d170a0] DataValueInterfaces v1.0.0
  [244e2a9f] DefineSingletons v0.1.2
  [8bb1440f] DelimitedFiles v1.9.1
  [163ba53b] DiffResults v1.1.0
  [b552c78f] DiffRules v1.15.1
  [ffbed154] DocStringExtensions v0.9.3
  [4e289a0a] EnumX v1.0.4
  [460bff9d] ExceptionUnwrapping v0.1.9
  [e2ba6199] ExprTools v0.1.10
  [cc61a311] FLoops v0.2.1
  [b9860ae5] FLoopsBase v0.1.1
  [5789e2e9] FileIO v1.16.1
  [48062228] FilePathsBase v0.9.21
  [1a297f60] FillArrays v1.9.3
  [6a86dc24] FiniteDiff v2.21.1
  [53c48c17] FixedPointNumbers v0.8.4
  [587475ba] Flux v0.14.7
  [f6369f11] ForwardDiff v0.10.36
  [069b7b12] FunctionWrappers v1.1.3
  [77dc65aa] FunctionWrappersWrappers v0.1.3
  [d9f16b24] Functors v0.4.5
⌃ [0c68f7d7] GPUArrays v9.1.0
⌅ [46192b85] GPUArraysCore v0.1.5
  [92fee26a] GZip v0.6.2
  [c27321d9] Glob v1.3.1
  [f67ccb44] HDF5 v0.17.1
  [cd3eb016] HTTP v1.10.1
  [7869d1d1] IRTools v0.4.11
  [c817782e] ImageBase v0.1.7
  [a09fc81d] ImageCore v0.10.1
  [4e3cecfd] ImageShow v0.3.8
  [22cec73e] InitialValues v0.3.1
  [842dd82b] InlineStrings v1.4.0
  [7d512f48] InternedStrings v0.7.0
  [41ab1584] InvertedIndices v1.3.0
  [92d709cd] IrrationalConstants v0.2.2
  [82899510] IteratorInterfaceExtensions v1.0.0
  [033835bb] JLD2 v0.4.40
  [692b3bcd] JLLWrappers v1.5.0
  [0f8b85d8] JSON3 v1.14.0
  [b14d175d] JuliaVariables v0.2.4
  [63c18a36] KernelAbstractions v0.9.15
  [929cbde3] LLVM v6.4.1
  [b964fa9f] LaTeXStrings v1.3.1
  [50d2b5c4] Lazy v0.15.1
  [8cdb02fc] LazyModules v0.3.1
  [1d6d02ad] LeftChildRightSiblingTrees v0.2.0
  [d3d80556] LineSearches v7.2.0
  [2ab3a3ac] LogExpFunctions v0.3.26
  [e6f89c97] LoggingExtras v1.0.3
  [23992714] MAT v0.10.6
  [eb30cadb] MLDatasets v0.7.14
  [d8e11817] MLStyle v0.4.17
  [f1d291b0] MLUtils v0.4.3
  [3da0fdf6] MPIPreferences v0.1.10
  [1914dd2f] MacroTools v0.5.12
  [dbb5928d] MappedArrays v0.4.2
  [739be429] MbedTLS v1.1.9
  [128add7d] MicroCollections v0.1.4
  [e1d29d7a] Missings v1.1.0
  [e94cdb99] MosaicViews v0.3.4
  [d41bc354] NLSolversBase v7.8.3
  [872c559c] NNlib v0.9.9
  [15e1cf62] NPZ v0.4.3
  [77ba4419] NaNMath v1.0.2
  [71a1bf82] NameResolution v0.1.5
  [6fe1bfb0] OffsetArrays v1.13.0
  [0b1bfda6] OneHotArrays v0.2.4
  [4d8831e6] OpenSSL v1.4.1
  [429524aa] Optim v1.7.8
  [3bd65402] Optimisers v0.3.1
  [7f7a1694] Optimization v3.20.2
  [42dfb2eb] OptimizationOptimisers v0.1.6
  [bac558e1] OrderedCollections v1.6.3
  [5432bcbf] PaddedViews v0.5.12
  [d96e819e] Parameters v0.12.3
  [69de0a69] Parsers v2.8.1
  [7b2266bf] PeriodicTable v1.1.4
  [fbb45041] Pickle v0.3.3
  [2dfb63ee] PooledArrays v1.4.3
  [85a6dd25] PositiveFactorizations v0.2.4
  [aea7be01] PrecompileTools v1.2.0
  [21216c6a] Preferences v1.4.1
  [8162dcfd] PrettyPrint v0.2.0
  [08abe8d2] PrettyTables v2.3.1
  [33c8b6b6] ProgressLogging v0.1.4
  [92933f4c] ProgressMeter v1.9.0
  [c1ae055f] RealDot v0.1.0
  [3cdcf5f2] RecipesBase v1.3.4
  [731186ca] RecursiveArrayTools v3.3.0
  [189a3867] Reexport v1.2.2
  [ae029012] Requires v1.3.0
  [7e49a35a] RuntimeGeneratedFunctions v0.5.12
  [0bca4576] SciMLBase v2.12.1
  [c0aeaf25] SciMLOperators v0.3.7
  [91c51154] SentinelArrays v1.4.1
  [efcf1570] Setfield v1.1.1
  [605ecd9f] ShowCases v0.1.0
  [777ac1f9] SimpleBufferStream v1.1.0
  [699a6c99] SimpleTraits v0.9.4
⌃ [a2af1166] SortingAlgorithms v1.2.0
  [dc90abb0] SparseInverseSubset v0.1.2
  [276daf66] SpecialFunctions v2.3.1
  [171d559e] SplittablesBase v0.1.15
  [cae243ae] StackViews v0.1.1
  [90137ffa] StaticArrays v1.8.1
  [1e83bf80] StaticArraysCore v1.4.2
  [82ae8749] StatsAPI v1.7.0
  [2913bbd2] StatsBase v0.34.2
⌅ [5e0ebb24] Strided v1.2.3
  [69024149] StringEncodings v0.3.7
  [892a3eda] StringManipulation v0.3.4
  [09ab397b] StructArrays v0.6.16
  [856f2bd8] StructTypes v1.10.0
  [2efcf032] SymbolicIndexingInterface v0.3.1
  [3783bdb8] TableTraits v1.0.1
  [bd369af6] Tables v1.11.1
  [62fd8b95] TensorCore v0.1.1
  [5d786b92] TerminalLoggers v0.1.7
  [3bb67fe8] TranscodingStreams v0.10.2
  [28d57a85] Transducers v0.4.79
  [410a4b4d] Tricks v0.1.8
  [781d530d] TruncatedStacktraces v1.4.0
  [bc48ee85] Tullio v0.3.7
  [9d95972d] TupleTools v1.4.3
  [5c2747f8] URIs v1.5.1
  [3a884ed6] UnPack v1.0.2
  [1986cc42] Unitful v1.19.0
  [a7773ee8] UnitfulAtomic v1.0.0
  [013be700] UnsafeAtomics v0.2.1
  [d80eeb9a] UnsafeAtomicsLLVM v0.1.3
  [ea10d353] WeakRefStrings v1.4.2
  [76eceee3] WorkerUtilities v1.6.1
  [a5390f91] ZipFile v0.10.1
  [e88e6eb3] Zygote v0.6.68
  [700de1a5] ZygoteRules v0.2.4
  [78a364fa] Chemfiles_jll v0.10.4+0
  [0234f1f7] HDF5_jll v1.14.2+1
  [e33a78d0] Hwloc_jll v2.10.0+0
  [dad2f222] LLVMExtra_jll v0.0.27+1
  [1d63c593] LLVMOpenMP_jll v15.0.7+0
  [94ce4f54] Libiconv_jll v1.17.0+0
  [7cb0a576] MPICH_jll v4.1.2+1
  [f1f71cc9] MPItrampoline_jll v5.3.1+1
  [9237b28f] MicrosoftMPI_jll v10.1.4+1
  [fe0851c0] OpenMPI_jll v5.0.1+0
  [458c3c95] OpenSSL_jll v3.0.12+0
  [efe28fd5] OpenSpecFun_jll v0.5.5+0
  [32165bc3] PMIx_jll v4.2.7+0
  [477f73a3] libaec_jll v1.0.6+1
  [1080aeaf] libevent_jll v2.1.13+1
  [eb928a42] prrte_jll v3.0.2+0
  [0dad84c5] ArgTools v1.1.1
  [56f22d72] Artifacts
  [2a0f44e3] Base64
  [ade2ca70] Dates
  [8ba89e20] Distributed
  [f43a241f] Downloads v1.6.0
  [7b1f6079] FileWatching
  [9fa8497b] Future
  [b77e0a4c] InteractiveUtils
  [4af54fe1] LazyArtifacts
  [b27032c2] LibCURL v0.6.4
  [76f85450] LibGit2
  [8f399da3] Libdl
  [37e2e46d] LinearAlgebra
  [56ddb016] Logging
  [d6f4376e] Markdown
  [a63ad114] Mmap
  [ca575930] NetworkOptions v1.2.0
  [44cfe95a] Pkg v1.10.0
  [de0858da] Printf
  [3fa0cd96] REPL
  [9a3f8284] Random
  [ea8e919c] SHA v0.7.0
  [9e88b42a] Serialization
  [6462fe0b] Sockets
  [2f01184e] SparseArrays v1.10.0
  [10745b16] Statistics v1.10.0
  [4607b0f0] SuiteSparse
  [fa267f1f] TOML v1.0.3
  [a4e569a6] Tar v1.10.0
  [8dfed614] Test
  [cf7118a7] UUIDs
  [4ec0a83e] Unicode
  [e66e0078] CompilerSupportLibraries_jll v1.0.5+1
  [deac9b47] LibCURL_jll v8.4.0+0
  [e37daf67] LibGit2_jll v1.6.4+0
  [29816b5a] LibSSH2_jll v1.11.0+1
  [c8ffd9c3] MbedTLS_jll v2.28.2+1
  [14a3606d] MozillaCACerts_jll v2023.1.10
  [4536629a] OpenBLAS_jll v0.3.23+2
  [05823500] OpenLibm_jll v0.8.1+2
  [bea87d4a] SuiteSparse_jll v7.2.1+1
  [83775a58] Zlib_jll v1.2.13+1
  [8e850b90] libblastrampoline_jll v5.8.0+1
  [8e850ede] nghttp2_jll v1.52.0+1
  [3f19e933] p7zip_jll v17.4.0+2
julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 10 × Apple M1 Pro
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
  Threads: 1 on 8 virtual cores
Vaibhavdixit02 commented 9 months ago

You are missing the maxiters to solve call which is required for the Optimisers.jl solvers. This point is not explicitly mentioned in the docs so will add that.

ChrisRackauckas commented 9 months ago

And we should throw a better error. I thought the higher level did have a better error here? Did something mess up with some traits?