Skip to content

Commit e08b458

Browse files
Merge pull request #240 from SciML/automtkoptfun
Use `NonlinearSystem` (via mtk-ize on `NonlinearProblem`) for constraint
2 parents b1eacc1 + 113a7c8 commit e08b458

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/function/mtk.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function instantiate_function(f, x, ::AutoModelingToolkit, p, num_cons=0)
3232
cons = nothing
3333
else
3434
cons = (θ) -> f.cons(θ, p)
35-
cons_sys = ModelingToolkit.modelingtoolkitize(OptimizationProblem(f.cons, x, p); checks=false)
35+
cons_sys = ModelingToolkit.modelingtoolkitize(NonlinearProblem(f.cons, x, p))
3636
end
3737

3838
if f.cons !== nothing && f.cons_j === nothing
@@ -46,11 +46,8 @@ function instantiate_function(f, x, ::AutoModelingToolkit, p, num_cons=0)
4646

4747
if f.cons !== nothing && f.cons_h === nothing
4848
cons_h = function (res, θ)
49-
for i in 1:num_cons
50-
cons_sys_i = ModelingToolkit.modelingtoolkitize(OptimizationProblem((args...) -> f.cons(args...)[i], x, p); checks=false)
51-
cons_hess_oop, cons_hess_iip = ModelingToolkit.generate_hessian(cons_sys_i, expression=Val{false})
52-
cons_hess_iip(res[i], θ, p)
53-
end
49+
cons_hess_oop, cons_hess_iip = ModelingToolkit.generate_hessian(cons_sys, expression=Val{false})
50+
cons_hess_iip(res, θ, p)
5451
end
5552
else
5653
cons_h = f.cons_h

test/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ FiniteDiff = ">= 2.8.1"
2222
Flux = ">= 0.12.6"
2323
ForwardDiff = ">= 0.10.19"
2424
IterTools = ">= 1.3.0"
25-
ModelingToolkit = ">= 6.4.7"
25+
ModelingToolkit = ">= 8.11.0"
2626
Optim = ">= 1.4.1"
2727
OrdinaryDiffEq = ">= 5"
2828
ReverseDiff = ">= 1.9.0"

0 commit comments

Comments
 (0)