Skip to content

Commit

Permalink
Merge pull request #789 from SciML/optbasev2
Browse files Browse the repository at this point in the history
[WIP] Updates for OptimizationBase v2
  • Loading branch information
Vaibhavdixit02 committed Sep 17, 2024
2 parents 3271e64 + ceb503a commit 4c989c1
Show file tree
Hide file tree
Showing 48 changed files with 721 additions and 1,321 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
- OptimizationBBO
- OptimizationCMAEvolutionStrategy
- OptimizationEvolutionary
- OptimizationFlux
- OptimizationGCMAES
- OptimizationManopt
- OptimizationMetaheuristics
Expand Down Expand Up @@ -62,7 +61,7 @@ jobs:
GROUP: ${{ matrix.group }}
- uses: julia-actions/julia-processcoverage@v1
with:
directories: src,lib/OptimizationBBO/src,lib/OptimizationCMAEvolutionStrategy/src,lib/OptimizationEvolutionary/src,lib/OptimizationFlux/src,lib/OptimizationGCMAES/src,lib/OptimizationMOI/src,lib/OptimizationMetaheuristics/src,lib/OptimizationMultistartOptimization/src,lib/OptimizationNLopt/src,lib/OptimizationNOMAD/src,lib/OptimizationOptimJL/src,lib/OptimizationOptimisers/src,lib/OptimizationPolyalgorithms/src,lib/OptimizationQuadDIRECT/src,lib/OptimizationSpeedMapping/src
directories: src,lib/OptimizationBBO/src,lib/OptimizationCMAEvolutionStrategy/src,lib/OptimizationEvolutionary/src,lib/OptimizationGCMAES/src,lib/OptimizationManopt/src,lib/OptimizationMOI/src,lib/OptimizationMetaheuristics/src,lib/OptimizationMultistartOptimization/src,lib/OptimizationNLopt/src,lib/OptimizationNOMAD/src,lib/OptimizationOptimJL/src,lib/OptimizationOptimisers/src,lib/OptimizationPolyalgorithms/src,lib/OptimizationQuadDIRECT/src,lib/OptimizationSpeedMapping/src
- uses: codecov/codecov-action@v4
with:
file: lcov.info
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ LBFGSB = "5be7bae1-8223-5378-bac3-9e7378a2f6e6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54"
OptimizationBase = "bca83a33-5cc9-4baa-983d-23429ab6bcbb"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
ProgressLogging = "33c8b6b6-d38a-422a-b730-caa89a2f386c"
Expand All @@ -28,7 +29,8 @@ LBFGSB = "0.4.1"
LinearAlgebra = "1.10"
Logging = "1.10"
LoggingExtras = "0.4, 1"
OptimizationBase = "1.3.3"
MLUtils = "0.4.4"
OptimizationBase = "2.0.3"
Printf = "1.10"
ProgressLogging = "0.1"
Reexport = "1.2"
Expand Down
11 changes: 0 additions & 11 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,48 +182,37 @@ to add the specific wrapper packages.
url = {https://doi.org/10.5281/zenodo.7738525},
year = 2023}
```

## Reproducibility

```@raw html
<details><summary>The documentation of this SciML package was built using these direct dependencies,</summary>
```

```@example
using Pkg # hide
Pkg.status() # hide
```

```@raw html
</details>
```

```@raw html
<details><summary>and using this machine and Julia version.</summary>
```

```@example
using InteractiveUtils # hide
versioninfo() # hide
```

```@raw html
</details>
```

```@raw html
<details><summary>A more complete overview of all dependencies and their versions is also provided.</summary>
```

```@example
using Pkg # hide
Pkg.status(; mode = PKGMODE_MANIFEST) # hide
```

```@raw html
</details>
```

```@eval
using TOML
using Markdown
Expand Down
40 changes: 5 additions & 35 deletions lib/OptimizationBBO/src/OptimizationBBO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ function SciMLBase.__solve(cache::Optimization.OptimizationCache{
}
local x, cur, state

if cache.data != Optimization.DEFAULT_DATA
maxiters = length(cache.data)
end

cur, state = iterate(cache.data)

function _cb(trace)
if cache.callback === Optimization.DEFAULT_CALLBACK
cb_call = false
Expand All @@ -138,9 +132,6 @@ function SciMLBase.__solve(cache::Optimization.OptimizationCache{
BlackBoxOptim.shutdown_optimizer!(trace) #doesn't work
end

if cache.data !== Optimization.DEFAULT_DATA
cur, state = iterate(cache.data, state)
end
cb_call
end

Expand All @@ -149,37 +140,16 @@ function SciMLBase.__solve(cache::Optimization.OptimizationCache{

_loss = function (θ)
if isa(cache.f, MultiObjectiveOptimizationFunction)
if cache.callback === Optimization.DEFAULT_CALLBACK &&
cache.data === Optimization.DEFAULT_DATA
return cache.f(θ, cache.p)
elseif cache.callback === Optimization.DEFAULT_CALLBACK
return cache.f(θ, cache.p, cur...)
elseif cache.data !== Optimization.DEFAULT_DATA
x = cache.f(θ, cache.p)
return x
else
x = cache.f(θ, cache.p, cur...)
return first(x)
end
x = (cache.f(θ, cache.p),)
return x[1]
else
if cache.callback === Optimization.DEFAULT_CALLBACK &&
cache.data === Optimization.DEFAULT_DATA
return first(cache.f(θ, cache.p))
elseif cache.callback === Optimization.DEFAULT_CALLBACK
return first(cache.f(θ, cache.p, cur...))
elseif cache.data !== Optimization.DEFAULT_DATA
x = cache.f(θ, cache.p)
return first(x)
else
x = cache.f(θ, cache.p, cur...)
return first(x)
end
x = cache.f(θ, cache.p)
return first(x)
end
end

opt_args = __map_optimizer_args(cache, cache.opt;
callback = cache.callback === Optimization.DEFAULT_CALLBACK &&
cache.data === Optimization.DEFAULT_DATA ?
callback = cache.callback === Optimization.DEFAULT_CALLBACK ?
nothing : _cb,
cache.solver_args...,
maxiters = maxiters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ function SciMLBase.__solve(cache::OptimizationCache{
}
local x, cur, state

if cache.data != Optimization.DEFAULT_DATA
maxiters = length(cache.data)
end

cur, state = iterate(cache.data)

function _cb(opt, y, fvals, perm)
curr_u = opt.logger.xbest[end]
opt_state = Optimization.OptimizationState(; iter = length(opt.logger.fmedian),
Expand All @@ -91,15 +85,14 @@ function SciMLBase.__solve(cache::OptimizationCache{
if !(cb_call isa Bool)
error("The callback should return a boolean `halt` for whether to stop the optimization process.")
end
cur, state = iterate(cache.data, state)
cb_call
end

maxiters = Optimization._check_and_convert_maxiters(cache.solver_args.maxiters)
maxtime = Optimization._check_and_convert_maxtime(cache.solver_args.maxtime)

_loss = function (θ)
x = cache.f(θ, cache.p, cur...)
x = cache.f(θ, cache.p)
return first(x)
end

Expand Down
11 changes: 2 additions & 9 deletions lib/OptimizationEvolutionary/src/OptimizationEvolutionary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ function SciMLBase.__solve(cache::OptimizationCache{
}
local x, cur, state

if cache.data != Optimization.DEFAULT_DATA
maxiters = length(cache.data)
end

cur, state = iterate(cache.data)

function _cb(trace)
curr_u = decompose_trace(trace).metadata["curr_u"]
opt_state = Optimization.OptimizationState(;
Expand All @@ -116,7 +110,6 @@ function SciMLBase.__solve(cache::OptimizationCache{
if !(cb_call isa Bool)
error("The callback should return a boolean `halt` for whether to stop the optimization process.")
end
cur, state = iterate(cache.data, state)
cb_call
end

Expand All @@ -127,10 +120,10 @@ function SciMLBase.__solve(cache::OptimizationCache{

_loss = function (θ)
if isa(f, MultiObjectiveOptimizationFunction)
x = f(θ, cache.p, cur...)
x = f(θ, cache.p)
return x
else
x = f(θ, cache.p, cur...)
x = f(θ, cache.p)
return first(x)
end
end
Expand Down
21 changes: 0 additions & 21 deletions lib/OptimizationFlux/LICENSE

This file was deleted.

25 changes: 0 additions & 25 deletions lib/OptimizationFlux/Project.toml

This file was deleted.

115 changes: 0 additions & 115 deletions lib/OptimizationFlux/src/OptimizationFlux.jl

This file was deleted.

Loading

0 comments on commit 4c989c1

Please sign in to comment.