# JuMP dual model formulation and impact on performance

**URL:** <https://discourse.julialang.org/t/jump-dual-model-formulation-and-impact-on-performance/39124>\
**Category:** Optimization (Mathematical)\
**Created:** [May 8, 2020, 5:33pm UTC](https://discourse.julialang.org/t/jump-dual-model-formulation-and-impact-on-performance/39124 "2020-05-08T17:33:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![martincornejo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martincornejo/32/13436_2.png) [@martincornejo](https://discourse.julialang.org/u/martincornejo)\
**Post date:** [May 8, 2020, 5:33pm UTC](https://discourse.julialang.org/t/jump-dual-model-formulation-and-impact-on-performance/39124/1 "2020-05-08T17:33:39Z")

</div>

For context:

> [@YALMIP vs JuMP](https://discourse.julialang.org/t/yalmip-vs-jump/30776/10):
>
> Conic solvers usually don’t support both conic variables and conic constraints. They either have the primal form as interface (variables in cones and equality constraints): min c' x A x = b x in K or the dual form as interface (free variables and and affine constraints in cones): min c' x A x + b in K x free Mosek for instance uses the primal form. When you model, your model is sometimes closer to the primal or sometimes to the dual form. If your model is closer to the primal form, you sh…

I have a SDP problem that is formulated in the dual form (I don’t think its possible to formulate it in the primal form), for the solver to be able to optimize it I use Dualization.jl and apply it to the solver: `model = Model(Dualization.dual_optimizer(Mosek.Optimizer))`.

The optimzation problem is solved with an algorithm that iteratively updates the model’s objective function and solves it.

```julia
model = build_model(input_data) # Build variables and constraints

while no_convergence
    @objective(model, Min, ....) # Update objective function
    optimize!(model)
    # Do some computations with results and check convergence
end

```

The algorithm works fine and returns the correct results, but when profiling it I found out that the “dualization” of the model takes a significant time of the computation time, roughly summarized in this flame graph. Each iteration takes about ~0.35 s.

 ![flame2](https://global.discourse-cdn.com/julialang/original/3X/b/e/be4c51bc3b17ae833c3991af1870ee5186a73c99.png)

Is there a method to pre-dualize the model and then add the “primal cost function” to the dual objective function? I tried with `dualize(model)` instead of setting the `dual_optimizer`, but the following error is thrown: **`ERROR: Constraints of funtion MathOptInterface.ScalarAffineFunction{Float64} in the Set MathOptInterface.Interval{Float64} are not implemented`**  
(I’m not sure which constraints it is refering to)

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [May 8, 2020, 7:38pm UTC](https://discourse.julialang.org/t/jump-dual-model-formulation-and-impact-on-performance/39124/2 "2020-05-08T19:38:33Z")

</div>

Currently, Dualization.jl does not support yet changing the objective function hence the dualized model is dropped and we need to start from scratch at optimize.  
This is done silently as you use AUTOMATIC mode. You can try MANUAL mode so that you get an error instead of the the model being silently dropped; see [Solvers · JuMP](http://www.juliaopt.org/JuMP.jl/v0.21.1/solvers/#Automatic-and-Manual-modes-1).  
Could you open an issue on Dualization.jl asking to implement modifying the objective function for DualOptimizer?
