|
196 | 196 |
|
197 | 197 | hessian_sparsity(sys::OptimizationSystem) = hessian_sparsity(get_op(sys), states(sys)) |
198 | 198 |
|
199 | | -function rep_pars_vals!(e::Expr, p) |
200 | | - rep_pars_vals!.(e.args, Ref(p)) |
201 | | - replace!(e.args, p...) |
202 | | -end |
203 | | - |
204 | | -function rep_pars_vals!(e, p) end |
205 | | - |
206 | 199 | """ |
207 | 200 | ```julia |
208 | 201 | DiffEqBase.OptimizationProblem{iip}(sys::OptimizationSystem, u0map, |
@@ -275,14 +268,8 @@ function DiffEqBase.OptimizationProblem{iip}(sys::OptimizationSystem, u0map, |
275 | 268 | f = generate_function(sys, checkbounds = checkbounds, linenumbers = linenumbers, |
276 | 269 | expression = Val{false}) |
277 | 270 |
|
278 | | - obj_expr = toexpr(subs_constants(objective(sys))) |
279 | | - pairs_arr = if p isa SciMLBase.NullParameters |
280 | | - [Symbol(_s) => Expr(:ref, :x, i) for (i, _s) in enumerate(dvs)] |
281 | | - else |
282 | | - vcat([Symbol(_s) => Expr(:ref, :x, i) for (i, _s) in enumerate(dvs)], |
283 | | - [Symbol(_p) => p[i] for (i, _p) in enumerate(ps)]) |
284 | | - end |
285 | | - rep_pars_vals!(obj_expr, pairs_arr) |
| 271 | + obj_expr = subs_constants(objective(sys)) |
| 272 | + |
286 | 273 | if grad |
287 | 274 | grad_oop, grad_iip = generate_gradient(sys, checkbounds = checkbounds, |
288 | 275 | linenumbers = linenumbers, |
@@ -342,14 +329,13 @@ function DiffEqBase.OptimizationProblem{iip}(sys::OptimizationSystem, u0map, |
342 | 329 | else |
343 | 330 | _cons_h = nothing |
344 | 331 | end |
345 | | - cons_expr = toexpr.(subs_constants(constraints(cons_sys))) |
346 | | - rep_pars_vals!.(cons_expr, Ref(pairs_arr)) |
| 332 | + cons_expr = subs_constants(constraints(cons_sys)) |
347 | 333 |
|
348 | 334 | if !haskey(kwargs, :lcons) && !haskey(kwargs, :ucons) # use the symbolically specified bounds |
349 | 335 | lcons = lcons_ |
350 | 336 | ucons = ucons_ |
351 | 337 | else # use the user supplied constraints bounds |
352 | | - haskey(kwargs, :lcons) && haskey(kwargs, :ucons) && |
| 338 | + (haskey(kwargs, :lcons) ⊻ haskey(kwargs, :ucons)) && |
353 | 339 | throw(ArgumentError("Expected both `ucons` and `lcons` to be supplied")) |
354 | 340 | haskey(kwargs, :lcons) && length(kwargs[:lcons]) != length(cstr) && |
355 | 341 | throw(ArgumentError("Expected `lcons` to be of the same length as the vector of constraints")) |
@@ -527,7 +513,7 @@ function OptimizationProblemExpr{iip}(sys::OptimizationSystem, u0map, |
527 | 513 | lcons = lcons_ |
528 | 514 | ucons = ucons_ |
529 | 515 | else # use the user supplied constraints bounds |
530 | | - !haskey(kwargs, :lcons) && !haskey(kwargs, :ucons) && |
| 516 | + (haskey(kwargs, :lcons) ⊻ haskey(kwargs, :ucons)) && |
531 | 517 | throw(ArgumentError("Expected both `ucons` and `lcons` to be supplied")) |
532 | 518 | haskey(kwargs, :lcons) && length(kwargs[:lcons]) != length(cstr) && |
533 | 519 | throw(ArgumentError("Expected `lcons` to be of the same length as the vector of constraints")) |
|
0 commit comments