Skip to content

Commit 1098b55

Browse files
Merge pull request #1003 from AayushSabharwal/as/fix-tests
[WIP] fix: fix tests
2 parents 07d369e + 7d5fcab commit 1098b55

File tree

14 files changed

+69
-67
lines changed

14 files changed

+69
-67
lines changed

Project.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Logging = "1.10"
4242
LoggingExtras = "0.4, 1"
4343
Lux = "1.12.4"
4444
MLUtils = "0.4"
45-
ModelingToolkit = "10"
45+
ModelingToolkit = "10.23"
4646
Mooncake = "0.4.138"
4747
Optim = ">= 1.4.1"
4848
OptimizationBase = "2"
@@ -57,10 +57,9 @@ Random = "1.10"
5757
Reexport = "1.2"
5858
ReverseDiff = "1"
5959
SafeTestsets = "0.1"
60-
SciMLBase = "2.82"
60+
SciMLBase = "2.104"
6161
SciMLSensitivity = "7"
6262
SparseArrays = "1.10"
63-
SparseDiffTools = "2"
6463
Symbolics = "6"
6564
TerminalLoggers = "0.1"
6665
Test = "1.10"
@@ -96,7 +95,6 @@ ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
9695
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
9796
SciMLSensitivity = "1ed8b502-d754-442c-8d5d-10ac956f44a1"
9897
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
99-
SparseDiffTools = "47a9eef4-7e08-11e9-0b38-333d64bd3804"
10098
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
10199
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
102100
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
@@ -106,5 +104,5 @@ Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
106104
[targets]
107105
test = ["Aqua", "BenchmarkTools", "Boltz", "ComponentArrays", "DiffEqFlux", "Enzyme", "FiniteDiff", "Flux", "ForwardDiff",
108106
"Ipopt", "IterTools", "Lux", "MLUtils", "ModelingToolkit", "Optim", "OptimizationMOI", "OptimizationOptimJL", "OptimizationOptimisers",
109-
"OrdinaryDiffEqTsit5", "Pkg", "Random", "ReverseDiff", "SafeTestsets", "SciMLSensitivity", "SparseArrays", "SparseDiffTools",
107+
"OrdinaryDiffEqTsit5", "Pkg", "Random", "ReverseDiff", "SafeTestsets", "SciMLSensitivity", "SparseArrays",
110108
"Symbolics", "Test", "Tracker", "Zygote", "Mooncake"]

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Lux = "1"
6060
MLUtils = "0.4.4"
6161
Manifolds = "0.9"
6262
Manopt = "0.4"
63-
ModelingToolkit = "10"
63+
ModelingToolkit = "10.23"
6464
NLPModels = "0.21"
6565
NLPModelsTest = "0.10"
6666
NLopt = "0.6, 1"

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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/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

lib/OptimizationBase/src/function.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ function OptimizationBase.instantiate_function(
5656
cons_vjp = f.cons_vjp === nothing ? nothing : (res, x) -> f.cons_vjp(res, x, p)
5757
cons_h = f.cons_h === nothing ? nothing : (res, x) -> f.cons_h(res, x, p)
5858
hess_prototype = f.hess_prototype === nothing ? nothing :
59-
convert.(eltype(x), f.hess_prototype)
59+
similar(f.hess_prototype, eltype(x))
6060
cons_jac_prototype = f.cons_jac_prototype === nothing ? nothing :
61-
convert.(eltype(x), f.cons_jac_prototype)
61+
similar(f.cons_jac_prototype, eltype(x))
6262
cons_hess_prototype = f.cons_hess_prototype === nothing ? nothing :
63-
[convert.(eltype(x), f.cons_hess_prototype[i])
63+
[similar(f.cons_hess_prototype[i], eltype(x))
6464
for i in 1:num_cons]
6565
expr = symbolify(f.expr)
6666
cons_expr = symbolify.(f.cons_expr)
@@ -90,11 +90,11 @@ function OptimizationBase.instantiate_function(
9090
cons_vjp = f.cons_vjp === nothing ? nothing : (res, x) -> f.cons_vjp(res, x, cache.p)
9191
cons_h = f.cons_h === nothing ? nothing : (res, x) -> f.cons_h(res, x, cache.p)
9292
hess_prototype = f.hess_prototype === nothing ? nothing :
93-
convert.(eltype(cache.u0), f.hess_prototype)
93+
similar(f.hess_prototype, eltype(cache.u0))
9494
cons_jac_prototype = f.cons_jac_prototype === nothing ? nothing :
95-
convert.(eltype(cache.u0), f.cons_jac_prototype)
95+
similar(f.cons_jac_prototype, eltype(cache.u0))
9696
cons_hess_prototype = f.cons_hess_prototype === nothing ? nothing :
97-
[convert.(eltype(cache.u0), f.cons_hess_prototype[i])
97+
[similar(f.cons_hess_prototype[i], eltype(cache.u0))
9898
for i in 1:num_cons]
9999
expr = symbolify(f.expr)
100100
cons_expr = symbolify.(f.cons_expr)
@@ -196,11 +196,11 @@ function OptimizationBase.instantiate_function(
196196
end
197197
end
198198
hess_prototype = f.hess_prototype === nothing ? nothing :
199-
convert.(eltype(x), f.hess_prototype)
199+
similar(f.hess_prototype, eltype(x))
200200
cons_jac_prototype = f.cons_jac_prototype === nothing ? nothing :
201-
convert.(eltype(x), f.cons_jac_prototype)
201+
similar(f.cons_jac_prototype, eltype(x))
202202
cons_hess_prototype = f.cons_hess_prototype === nothing ? nothing :
203-
[convert.(eltype(x), f.cons_hess_prototype[i])
203+
[similar(f.cons_hess_prototype[i], eltype(x))
204204
for i in 1:num_cons]
205205
expr = symbolify(f.expr)
206206
cons_expr = symbolify.(f.cons_expr)

lib/OptimizationIpopt/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
1414
[compat]
1515
Ipopt = "1.10.3"
1616
LinearAlgebra = "1.10.0"
17-
ModelingToolkit = "10.20"
17+
ModelingToolkit = "10.23"
1818
Optimization = "4.3.0"
1919
SciMLBase = "2.90.0"
2020
SparseArrays = "1.10.0"

lib/OptimizationIpopt/src/cache.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ function IpoptCache(prob, opt;
9494
J = if isnothing(f.cons_jac_prototype)
9595
zeros(T, num_cons, n)
9696
else
97-
convert.(T, f.cons_jac_prototype)
97+
similar(f.cons_jac_prototype, T)
9898
end
9999
lagh = !isnothing(f.lag_hess_prototype)
100100
H = if lagh # lag hessian takes precedence
101-
convert.(T, f.lag_hess_prototype)
101+
similar(f.lag_hess_prototype, T)
102102
elseif !isnothing(f.hess_prototype)
103-
convert.(T, f.hess_prototype)
103+
similar(f.hess_prototype, T)
104104
else
105105
zeros(T, n, n)
106106
end
@@ -109,7 +109,7 @@ function IpoptCache(prob, opt;
109109
elseif isnothing(f.cons_hess_prototype)
110110
Matrix{T}[zeros(T, n, n) for i in 1:num_cons]
111111
else
112-
[convert.(T, f.cons_hess_prototype[i]) for i in 1:num_cons]
112+
[similar(f.cons_hess_prototype[i], T) for i in 1:num_cons]
113113
end
114114
lcons = prob.lcons === nothing ? fill(T(-Inf), num_cons) : prob.lcons
115115
ucons = prob.ucons === nothing ? fill(T(Inf), num_cons) : prob.ucons

lib/OptimizationMOI/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Ipopt_jll = "300.1400"
2222
Juniper = "0.9"
2323
LinearAlgebra = "1"
2424
MathOptInterface = "1"
25-
ModelingToolkit = "10"
25+
ModelingToolkit = "10.23"
2626
NLopt = "1"
2727
Optimization = "4.4"
2828
Reexport = "1.2"
@@ -31,7 +31,7 @@ SparseArrays = "1.6"
3131
SymbolicIndexingInterface = "0.3"
3232
Symbolics = "6"
3333
Test = "1.6"
34-
Zygote = "0.6"
34+
Zygote = "0.6, 0.7"
3535
julia = "1.10"
3636

3737
[extras]

lib/OptimizationMOI/src/nlp.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ function MOIOptimizationNLPCache(prob::OptimizationProblem,
123123
end
124124
T = eltype(prob.u0)
125125
n = length(prob.u0)
126-
127126
J = if isnothing(f.cons_jac_prototype)
128127
zeros(T, num_cons, n)
129128
else
130-
convert.(T, f.cons_jac_prototype)
129+
similar(f.cons_jac_prototype, T)
131130
end
132131
lagh = !isnothing(f.lag_hess_prototype)
132+
133133
H = if lagh # lag hessian takes precedence
134-
convert.(T, f.lag_hess_prototype)
134+
similar(f.lag_hess_prototype, T)
135135
elseif !isnothing(f.hess_prototype)
136-
convert.(T, f.hess_prototype)
136+
similar(f.hess_prototype, T)
137137
else
138138
zeros(T, n, n)
139139
end
@@ -142,7 +142,7 @@ function MOIOptimizationNLPCache(prob::OptimizationProblem,
142142
elseif isnothing(f.cons_hess_prototype)
143143
Matrix{T}[zeros(T, n, n) for i in 1:num_cons]
144144
else
145-
[convert.(T, f.cons_hess_prototype[i]) for i in 1:num_cons]
145+
[similar(f.cons_hess_prototype[i], T) for i in 1:num_cons]
146146
end
147147
lcons = prob.lcons === nothing ? fill(T(-Inf), num_cons) : prob.lcons
148148
ucons = prob.ucons === nothing ? fill(T(Inf), num_cons) : prob.ucons

0 commit comments

Comments
 (0)