diff --git a/src/problems/optimizationproblem.jl b/src/problems/optimizationproblem.jl index 978f973d83..97882092e5 100644 --- a/src/problems/optimizationproblem.jl +++ b/src/problems/optimizationproblem.jl @@ -58,10 +58,10 @@ function SciMLBase.OptimizationFunction{iip}(sys::System; else _cons_h = cons_hess_prototype = nothing end - cons_expr = cstr + cons_expr = Code.toexpr.(expand.([eq.lhs for eq in Symbolics.canonical_form.(cstr)])) end - obj_expr = cost(sys) + obj_expr = Code.toexpr(expand(cost(sys))) observedfun = ObservedFunctionCache( sys; expression, eval_expression, eval_module, checkbounds, cse) diff --git a/test/initializationsystem.jl b/test/initializationsystem.jl index 19209b5e46..c98b60bd57 100644 --- a/test/initializationsystem.jl +++ b/test/initializationsystem.jl @@ -1293,7 +1293,7 @@ end @test SciMLBase.successful_retcode(solve(prob)) seta = setsym_oop(prob, [a]) - (newu0, newp) = seta(prob, ForwardDiff.Dual{ForwardDiff.Tag{:tag, Float64}}.([1.0], 1)) + (newu0, newp) = seta(prob, ForwardDiff.Dual{ForwardDiff.Tag{:tag, Float64}}.([1.0], 0)) newprob = remake(prob, u0 = newu0, p = newp) @test SciMLBase.successful_retcode(solve(newprob)) diff --git a/test/optimizationsystem.jl b/test/optimizationsystem.jl index e78ebfe9ee..26c7bdbbf2 100644 --- a/test/optimizationsystem.jl +++ b/test/optimizationsystem.jl @@ -64,6 +64,8 @@ end sys = complete(sys) prob = OptimizationProblem(sys, [x => 0.0, y => 0.0, a => 1.0, b => 1.0], grad = true, hess = true, cons_j = true, cons_h = true) + @test prob.f.cons_expr isa Vector{Expr} + @test prob.f.expr isa Expr @test prob.f.sys === sys sol = solve(prob, IPNewton()) @test sol.objective < 1.0 @@ -98,10 +100,10 @@ end prob = OptimizationProblem(sys, [x => 0.0, y => 0.0, z => 0.0, a => 1.0, b => 1.0], grad = false, hess = false, cons_j = false, cons_h = false) - @test_broken sol = solve(prob, AmplNLWriter.Optimizer(Ipopt_jll.amplexe)) - @test_skip sol.objective < 1.0 - @test_skip sol.uā‰ˆ[0.808, -0.064] atol=1e-3 - @test_skip sol[x]^2 + sol[y]^2 ā‰ˆ 1.0 + sol = solve(prob, AmplNLWriter.Optimizer(Ipopt_jll.amplexe)) + @test sol.objective < 1.0 + @test_broken sol.uā‰ˆ[0.808, -0.064] atol=1e-3 + @test_broken sol[x]^2 + sol[y]^2 ā‰ˆ 1.0 end @testset "rosenbrock" begin @@ -289,9 +291,8 @@ end sys = complete(sys) prob = OptimizationProblem(sys, [x => 0.0, y => 0.0, a => 1.0, b => 100.0]) - @test prob.f.expr isa Symbolics.Symbolic - @test all(prob.f.cons_expr[i].lhs isa Symbolics.Symbolic - for i in 1:length(prob.f.cons_expr)) + @test prob.f.expr isa Expr + @test all(x -> x isa Expr, prob.f.cons_expr) end @testset "Derivatives, iip and oop" begin