Skip to content

Commit d792a10

Browse files
fix: fix cons_expr and expr fields of OptimizationFunction
1 parent ec533e1 commit d792a10

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/problems/optimizationproblem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ function SciMLBase.OptimizationFunction{iip}(sys::System;
5858
else
5959
_cons_h = cons_hess_prototype = nothing
6060
end
61-
cons_expr = cstr
61+
cons_expr = Code.toexpr.(expand.([eq.lhs for eq in Symbolics.canonical_form.(cstr)]))
6262
end
6363

64-
obj_expr = cost(sys)
64+
obj_expr = Code.toexpr(expand(cost(sys)))
6565

6666
observedfun = ObservedFunctionCache(
6767
sys; expression, eval_expression, eval_module, checkbounds, cse)

test/optimizationsystem.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ end
6464
sys = complete(sys)
6565
prob = OptimizationProblem(sys, [x => 0.0, y => 0.0, a => 1.0, b => 1.0],
6666
grad = true, hess = true, cons_j = true, cons_h = true)
67+
@test prob.f.cons_expr isa Vector{Expr}
68+
@test prob.f.expr isa Expr
6769
@test prob.f.sys === sys
6870
sol = solve(prob, IPNewton())
6971
@test sol.objective < 1.0

0 commit comments

Comments
 (0)