Skip to content

Commit 561d9e2

Browse files
authored
Merge branch 'master' into kellertuer/properManopt
2 parents ec2183b + 2f96f18 commit 561d9e2

File tree

38 files changed

+160
-191
lines changed

38 files changed

+160
-191
lines changed

Project.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Optimization"
22
uuid = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
3-
version = "4.7.0"
3+
version = "4.8.0"
44

55
[deps]
66
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
@@ -20,6 +20,9 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
2020
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2121
TerminalLoggers = "5d786b92-1e48-4d6f-9151-6b4477ca9bed"
2222

23+
[sources]
24+
OptimizationBase = {path = "lib/OptimizationBase"}
25+
2326
[compat]
2427
ADTypes = "1.2"
2528
Aqua = "0.8"
@@ -42,7 +45,7 @@ Logging = "1.10"
4245
LoggingExtras = "0.4, 1"
4346
Lux = "1.12.4"
4447
MLUtils = "0.4"
45-
ModelingToolkit = "10"
48+
ModelingToolkit = "10.23"
4649
Mooncake = "0.4.138"
4750
Optim = ">= 1.4.1"
4851
OptimizationBase = "2"
@@ -57,10 +60,9 @@ Random = "1.10"
5760
Reexport = "1.2"
5861
ReverseDiff = "1"
5962
SafeTestsets = "0.1"
60-
SciMLBase = "2.82"
63+
SciMLBase = "2.104"
6164
SciMLSensitivity = "7"
6265
SparseArrays = "1.10"
63-
SparseDiffTools = "2"
6466
Symbolics = "6"
6567
TerminalLoggers = "0.1"
6668
Test = "1.10"
@@ -96,7 +98,6 @@ ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
9698
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
9799
SciMLSensitivity = "1ed8b502-d754-442c-8d5d-10ac956f44a1"
98100
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
99-
SparseDiffTools = "47a9eef4-7e08-11e9-0b38-333d64bd3804"
100101
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
101102
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
102103
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
@@ -106,5 +107,5 @@ Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
106107
[targets]
107108
test = ["Aqua", "BenchmarkTools", "Boltz", "ComponentArrays", "DiffEqFlux", "Enzyme", "FiniteDiff", "Flux", "ForwardDiff",
108109
"Ipopt", "IterTools", "Lux", "MLUtils", "ModelingToolkit", "Optim", "OptimizationMOI", "OptimizationOptimJL", "OptimizationOptimisers",
109-
"OrdinaryDiffEqTsit5", "Pkg", "Random", "ReverseDiff", "SafeTestsets", "SciMLSensitivity", "SparseArrays", "SparseDiffTools",
110+
"OrdinaryDiffEqTsit5", "Pkg", "Random", "ReverseDiff", "SafeTestsets", "SciMLSensitivity", "SparseArrays",
110111
"Symbolics", "Test", "Tracker", "Zygote", "Mooncake"]

docs/Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
2+
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
23
AmplNLWriter = "7c4d4715-977e-5154-bfe0-e096adeac482"
34
ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
45
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
@@ -60,7 +61,7 @@ Lux = "1"
6061
MLUtils = "0.4.4"
6162
Manifolds = "0.10"
6263
Manopt = "0.5"
63-
ModelingToolkit = "10"
64+
ModelingToolkit = "10.23"
6465
NLPModels = "0.21"
6566
NLPModelsTest = "0.10"
6667
NLopt = "0.6, 1"

docs/make.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Documenter, Optimization
22
using FiniteDiff, ForwardDiff, ModelingToolkit, ReverseDiff, Tracker, Zygote
3+
using ADTypes
34

45
cp("./docs/Manifest.toml", "./docs/src/assets/Manifest.toml", force = true)
56
cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true)
@@ -9,9 +10,9 @@ include("pages.jl")
910
makedocs(sitename = "Optimization.jl",
1011
authors = "Chris Rackauckas, Vaibhav Kumar Dixit et al.",
1112
modules = [Optimization, Optimization.SciMLBase, Optimization.OptimizationBase,
12-
FiniteDiff, ForwardDiff, ModelingToolkit, ReverseDiff, Tracker, Zygote],
13+
FiniteDiff, ForwardDiff, ModelingToolkit, ReverseDiff, Tracker, Zygote, ADTypes],
1314
clean = true, doctest = false, linkcheck = true,
14-
warnonly = [:missing_docs],
15+
warnonly = [:missing_docs, :cross_references],
1516
format = Documenter.HTML(assets = ["assets/favicon.ico"],
1617
canonical = "https://docs.sciml.ai/Optimization/stable/"),
1718
pages = pages)

docs/src/API/ad.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ OptimizationBase.AutoZygote
2323
OptimizationBase.AutoTracker
2424
OptimizationBase.AutoModelingToolkit
2525
OptimizationBase.AutoEnzyme
26-
OptimizationBase.AutoMooncake
26+
ADTypes.AutoMooncake
2727
```

docs/src/optimization_packages/optimization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ There are some solvers that are available in the Optimization.jl package directl
99
This can also handle arbitrary non-linear constraints through a Augmented Lagrangian method with bounds constraints described in 17.4 of Numerical Optimization by Nocedal and Wright. Thus serving as a general-purpose nonlinear optimization solver available directly in Optimization.jl.
1010

1111
```@docs
12-
Sophia
12+
Optimization.Sophia
1313
```
1414

1515
## Examples

lib/OptimizationBBO/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "OptimizationBBO"
22
uuid = "3e6eede4-6085-4f62-9a71-46d9bc1eb92b"
33
authors = ["Vaibhav Dixit <[email protected]> and contributors"]
4-
version = "0.4.2"
4+
version = "0.4.3"
55

66
[deps]
77
BlackBoxOptim = "a134a8b2-14d6-55f6-9291-3336d3ab0209"

lib/OptimizationBBO/src/OptimizationBBO.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module OptimizationBBO
22

33
using Reexport
44
import Optimization
5+
import Optimization: OptimizationBase
56
import BlackBoxOptim, Optimization.SciMLBase
67
import Optimization.SciMLBase: MultiObjectiveOptimizationFunction
78

lib/OptimizationBase/Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "OptimizationBase"
22
uuid = "bca83a33-5cc9-4baa-983d-23429ab6bcbb"
33
authors = ["Vaibhav Dixit <[email protected]> and contributors"]
4-
version = "2.11.0"
4+
version = "2.12.0"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
@@ -51,11 +51,11 @@ ForwardDiff = "0.10.26, 1"
5151
LinearAlgebra = "1.9, 1.10"
5252
MLDataDevices = "1"
5353
MLUtils = "0.4"
54-
ModelingToolkit = "9, 10"
54+
ModelingToolkit = "10.23"
5555
PDMats = "0.11"
5656
Reexport = "1.2"
5757
ReverseDiff = "1.14"
58-
SciMLBase = "2"
58+
SciMLBase = "2.104"
5959
SparseConnectivityTracer = "0.6, 1"
6060
SparseMatrixColorings = "0.4"
6161
SymbolicAnalysis = "0.3"

lib/OptimizationBase/ext/OptimizationEnzymeExt.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ function inner_grad(mode::Mode, θ, bθ, f, p) where {Mode}
2828
return nothing
2929
end
3030

31-
function hv_f2_alloc(mode::Mode, x, f, p) where {Mode}
32-
dx = Enzyme.make_zero(x)
31+
function hv_f2_alloc(mode::Mode, xdup, f, p) where {Mode}
3332
Enzyme.autodiff(mode,
3433
Const(firstapply),
3534
Active,
3635
Const(f),
37-
Enzyme.Duplicated(x, dx),
36+
xdup,
3837
Const(p)
3938
)
40-
return dx
39+
return xdup
4140
end
4241

4342
function inner_cons(x, fcons::Function, p::Union{SciMLBase.NullParameters, Nothing},
@@ -200,10 +199,12 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{true}, x,
200199

201200
if hv == true && f.hv === nothing
202201
function hv!(H, θ, v, p = p)
202+
x = Duplicated(θ, v)
203+
dx = Enzyme.make_zero(x)
203204
H .= Enzyme.autodiff(
204-
fmode, hv_f2_alloc, Const(rmode), Duplicated(θ, v),
205+
fmode, hv_f2_alloc, Const(rmode), Duplicated(x,dx),
205206
Const(f.f), Const(p)
206-
)[1]
207+
)[1].dval
207208
end
208209
elseif hv == true
209210
hv! = (H, θ, v, p = p) -> f.hv(H, θ, v, p)
@@ -553,10 +554,12 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{false}, x
553554

554555
if hv == true && f.hv === nothing
555556
function hv!(θ, v, p = p)
557+
x = Duplicated(θ, v)
558+
dx = Enzyme.make_zero(x)
556559
return Enzyme.autodiff(
557-
fmode, hv_f2_alloc, DuplicatedNoNeed, Const(rmode), Duplicated(θ, v),
560+
fmode, hv_f2_alloc, DuplicatedNoNeed, Const(rmode), Duplicated(x, dx),
558561
Const(_f), Const(f.f), Const(p)
559-
)[1]
562+
)[1].dval
560563
end
561564
elseif hv == true
562565
hv! = (θ, v, p = p) -> f.hv(θ, v, p)

lib/OptimizationBase/ext/OptimizationMTKExt.jl

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,25 @@ function OptimizationBase.instantiate_function(
2121
num_cons))))
2222
#sys = ModelingToolkit.structural_simplify(sys)
2323
# don't need to pass `x` or `p` since they're defaults now
24-
f = OptimizationProblem(sys, nothing; grad = g, hess = h,
24+
mtkprob = OptimizationProblem(sys, nothing; grad = g, hess = h,
2525
sparse = true, cons_j = cons_j, cons_h = cons_h,
26-
cons_sparse = true).f
26+
cons_sparse = true)
27+
f = mtkprob.f
2728

28-
grad = (G, θ, args...) -> f.grad(G, θ, p, args...)
29+
grad = (G, θ, args...) -> f.grad(G, θ, mtkprob.p, args...)
2930

30-
hess = (H, θ, args...) -> f.hess(H, θ, p, args...)
31+
hess = (H, θ, args...) -> f.hess(H, θ, mtkprob.p, args...)
3132

3233
hv = function (H, θ, v, args...)
33-
res = (eltype(θ)).(f.hess_prototype)
34+
res = similar(f.hess_prototype, eltype(θ))
3435
hess(res, θ, args...)
3536
H .= res * v
3637
end
3738

3839
if !isnothing(f.cons)
39-
cons = (res, θ) -> f.cons(res, θ, p)
40-
cons_j = (J, θ) -> f.cons_j(J, θ, p)
41-
cons_h = (res, θ) -> f.cons_h(res, θ, p)
40+
cons = (res, θ) -> f.cons(res, θ, mtkprob.p)
41+
cons_j = (J, θ) -> f.cons_j(J, θ, mtkprob.p)
42+
cons_h = (res, θ) -> f.cons_h(res, θ, mtkprob.p)
4243
else
4344
cons = nothing
4445
cons_j = nothing
@@ -72,24 +73,24 @@ function OptimizationBase.instantiate_function(
7273
num_cons))))
7374
#sys = ModelingToolkit.structural_simplify(sys)
7475
# don't need to pass `x` or `p` since they're defaults now
75-
f = OptimizationProblem(sys, nothing; grad = g, hess = h,
76+
mtkprob = OptimizationProblem(sys, nothing; grad = g, hess = h,
7677
sparse = true, cons_j = cons_j, cons_h = cons_h,
77-
cons_sparse = true).f
78+
cons_sparse = true)
79+
f = mtkprob.f
7880

79-
grad = (G, θ, args...) -> f.grad(G, θ, cache.p, args...)
81+
grad = (G, θ, args...) -> f.grad(G, θ, mtkprob.p, args...)
8082

81-
hess = (H, θ, args...) -> f.hess(H, θ, cache.p, args...)
83+
hess = (H, θ, args...) -> f.hess(H, θ, mtkprob.p, args...)
8284

8385
hv = function (H, θ, v, args...)
84-
res = (eltype(θ)).(f.hess_prototype)
86+
res = similar(f.hess_prototype, eltype(θ))
8587
hess(res, θ, args...)
8688
H .= res * v
8789
end
88-
8990
if !isnothing(f.cons)
90-
cons = (res, θ) -> f.cons(res, θ, cache.p)
91-
cons_j = (J, θ) -> f.cons_j(J, θ, cache.p)
92-
cons_h = (res, θ) -> f.cons_h(res, θ, cache.p)
91+
cons = (res, θ) -> f.cons(res, θ, mtkprob.p)
92+
cons_j = (J, θ) -> f.cons_j(J, θ, mtkprob.p)
93+
cons_h = (res, θ) -> f.cons_h(res, θ, mtkprob.p)
9394
else
9495
cons = nothing
9596
cons_j = nothing
@@ -121,13 +122,14 @@ function OptimizationBase.instantiate_function(
121122
num_cons))))
122123
#sys = ModelingToolkit.structural_simplify(sys)
123124
# don't need to pass `x` or `p` since they're defaults now
124-
f = OptimizationProblem(sys, nothing; grad = g, hess = h,
125+
mtkprob = OptimizationProblem(sys, nothing; grad = g, hess = h,
125126
sparse = false, cons_j = cons_j, cons_h = cons_h,
126-
cons_sparse = false).f
127+
cons_sparse = false)
128+
f = mtkprob.f
127129

128-
grad = (G, θ, args...) -> f.grad(G, θ, p, args...)
130+
grad = (G, θ, args...) -> f.grad(G, θ, mtkprob.p, args...)
129131

130-
hess = (H, θ, args...) -> f.hess(H, θ, p, args...)
132+
hess = (H, θ, args...) -> f.hess(H, θ, mtkprob.p, args...)
131133

132134
hv = function (H, θ, v, args...)
133135
res = ArrayInterface.zeromatrix(θ)
@@ -136,9 +138,9 @@ function OptimizationBase.instantiate_function(
136138
end
137139

138140
if !isnothing(f.cons)
139-
cons = (res, θ) -> f.cons(res, θ, p)
140-
cons_j = (J, θ) -> f.cons_j(J, θ, p)
141-
cons_h = (res, θ) -> f.cons_h(res, θ, p)
141+
cons = (res, θ) -> f.cons(res, θ, mtkprob.p)
142+
cons_j = (J, θ) -> f.cons_j(J, θ, mtkprob.p)
143+
cons_h = (res, θ) -> f.cons_h(res, θ, mtkprob.p)
142144
else
143145
cons = nothing
144146
cons_j = nothing
@@ -172,13 +174,14 @@ function OptimizationBase.instantiate_function(
172174
num_cons))))
173175
#sys = ModelingToolkit.structural_simplify(sys)
174176
# don't need to pass `x` or `p` since they're defaults now
175-
f = OptimizationProblem(sys, nothing; grad = g, hess = h,
177+
mtkprob = OptimizationProblem(sys, nothing; grad = g, hess = h,
176178
sparse = false, cons_j = cons_j, cons_h = cons_h,
177-
cons_sparse = false).f
179+
cons_sparse = false)
180+
f = mtkprob.f
178181

179-
grad = (G, θ, args...) -> f.grad(G, θ, cache.p, args...)
182+
grad = (G, θ, args...) -> f.grad(G, θ, mtkprob.p, args...)
180183

181-
hess = (H, θ, args...) -> f.hess(H, θ, cache.p, args...)
184+
hess = (H, θ, args...) -> f.hess(H, θ, mtkprob.p, args...)
182185

183186
hv = function (H, θ, v, args...)
184187
res = ArrayInterface.zeromatrix(θ)
@@ -187,9 +190,9 @@ function OptimizationBase.instantiate_function(
187190
end
188191

189192
if !isnothing(f.cons)
190-
cons = (res, θ) -> f.cons(res, θ, cache.p)
191-
cons_j = (J, θ) -> f.cons_j(J, θ, cache.p)
192-
cons_h = (res, θ) -> f.cons_h(res, θ, cache.p)
193+
cons = (res, θ) -> f.cons(res, θ, mtkprob.p)
194+
cons_j = (J, θ) -> f.cons_j(J, θ, mtkprob.p)
195+
cons_h = (res, θ) -> f.cons_h(res, θ, mtkprob.p)
193196
else
194197
cons = nothing
195198
cons_j = nothing

0 commit comments

Comments
 (0)