Skip to content

Commit cf4fad0

Browse files
committed
refactor(OptimizationIpopt): drop mtkize
1 parent 83991fb commit cf4fad0

File tree

2 files changed

+6
-48
lines changed

2 files changed

+6
-48
lines changed

lib/OptimizationIpopt/src/OptimizationIpopt.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,12 @@ function SciMLBase.__init(prob::OptimizationProblem,
203203
maxtime::Union{Number, Nothing} = nothing,
204204
abstol::Union{Number, Nothing} = nothing,
205205
reltol::Union{Number, Nothing} = nothing,
206-
mtkize = false,
207206
kwargs...)
208207
cache = IpoptCache(prob, opt;
209208
maxiters,
210209
maxtime,
211210
abstol,
212211
reltol,
213-
mtkize,
214212
kwargs...
215213
)
216214
cache.reinit_cache.u0 .= prob.u0

lib/OptimizationIpopt/src/cache.jl

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ function SciMLBase.get_paramsyms(sol::SciMLBase.OptimizationSolution{
7272
end
7373

7474
function IpoptCache(prob, opt;
75-
mtkize,
7675
callback = nothing,
7776
progress = false,
7877
kwargs...)
@@ -115,50 +114,11 @@ function IpoptCache(prob, opt;
115114
lcons = prob.lcons === nothing ? fill(T(-Inf), num_cons) : prob.lcons
116115
ucons = prob.ucons === nothing ? fill(T(Inf), num_cons) : prob.ucons
117116

118-
# if f.sys isa SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing} && mtkize
119-
# try
120-
# sys = MTK.modelingtoolkitize(prob)
121-
# catch err
122-
# throw(ArgumentError("Automatic symbolic expression generation with ModelingToolkit failed with error: $err.
123-
# Try by setting `mtkize = false` instead if the solver doesn't require symbolic expressions."))
124-
# end
125-
# if !isnothing(prob.p) && !(prob.p isa SciMLBase.NullParameters)
126-
# unames = variable_symbols(sys)
127-
# pnames = parameter_symbols(sys)
128-
# us = [unames[i] => prob.u0[i] for i in 1:length(prob.u0)]
129-
# ps = [pnames[i] => prob.p[i] for i in 1:length(prob.p)]
130-
# sysprob = OptimizationProblem(sys, us, ps)
131-
# else
132-
# unames = variable_symbols(sys)
133-
# us = [unames[i] => prob.u0[i] for i in 1:length(prob.u0)]
134-
# sysprob = OptimizationProblem(sys, us)
135-
# end
117+
sys = f.sys isa SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing} ?
118+
nothing : f.sys
119+
obj_expr = f.expr
120+
cons_expr = f.cons_expr
136121

137-
# obj_expr = sysprob.f.expr
138-
# cons_expr = sysprob.f.cons_expr
139-
# else
140-
sys = f.sys isa SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing} ?
141-
nothing : f.sys
142-
obj_expr = f.expr
143-
cons_expr = f.cons_expr
144-
# end
145-
146-
# if sys === nothing
147-
expr = obj_expr
148-
_cons_expr = cons_expr
149-
# else
150-
# error("Expressions are not supported")
151-
# expr_map = get_expr_map(sys)
152-
# expr = convert_to_expr(obj_expr, expr_map; expand_expr = false)
153-
# expr = repl_getindex!(expr)
154-
# cons = MTK.constraints(sys)
155-
# _cons_expr = Vector{Expr}(undef, length(cons))
156-
# for i in eachindex(cons)
157-
# _cons_expr[i] = repl_getindex!(convert_to_expr(cons_expr[i],
158-
# expr_map;
159-
# expand_expr = false))
160-
# end
161-
# end
162122
solver_args = NamedTuple(kwargs)
163123

164124
return IpoptCache(
@@ -180,8 +140,8 @@ function IpoptCache(prob, opt;
180140
0,
181141
0,
182142
Cint(0),
183-
expr,
184-
_cons_expr,
143+
obj_expr,
144+
cons_expr,
185145
opt,
186146
solver_args
187147
)

0 commit comments

Comments
 (0)