Skip to content

Commit

Permalink
Start towards correct dispatch on iip with Optimization problems
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarsh530 committed Dec 11, 2023
1 parent 493e695 commit c760582
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/systems/optimization/optimizationsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,20 +325,21 @@ function DiffEqBase.OptimizationProblem{iip}(sys::OptimizationSystem, u0map,
end
end

idx = iip ? 2 : 1
if length(cstr) > 0
@named cons_sys = ConstraintsSystem(cstr, dvs, ps)
cons, lcons_, ucons_ = generate_function(cons_sys, checkbounds = checkbounds,
linenumbers = linenumbers,
expression = Val{false})
if cons_j
_cons_j = generate_jacobian(cons_sys; expression = Val{false},
sparse = cons_sparse)[2]
sparse = cons_sparse)[idx]
else
_cons_j = nothing
end
if cons_h
_cons_h = generate_hessian(cons_sys; expression = Val{false},
sparse = cons_sparse)[2]
sparse = cons_sparse)[idx]
else
_cons_h = nothing
end
Expand Down Expand Up @@ -374,7 +375,7 @@ function DiffEqBase.OptimizationProblem{iip}(sys::OptimizationSystem, u0map,
hess_prototype = hess_prototype,
syms = Symbol.(states(sys)),
paramsyms = Symbol.(parameters(sys)),
cons = cons[2],
cons = cons[idx],
cons_j = _cons_j,
cons_h = _cons_h,
cons_jac_prototype = cons_jac_prototype,
Expand Down Expand Up @@ -554,7 +555,7 @@ function OptimizationProblemExpr{iip}(sys::OptimizationSystem, u0map,
lb = $lb
ub = $ub
int = $int
cons = $cons[1]
cons = $cons[idx]

Check warning on line 558 in src/systems/optimization/optimizationsystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/optimization/optimizationsystem.jl#L558

Added line #L558 was not covered by tests
lcons = $lcons
ucons = $ucons
cons_j = $_cons_j
Expand Down

0 comments on commit c760582

Please sign in to comment.