# Print optimization problem using Ipopt

**URL:** https://discourse.julialang.org/t/print-optimization-problem-using-ipopt/89786
**Category:** Optimization (Mathematical)
**Tags:** nlp, ipopt
**Created:** [November 4, 2022, 5:23pm UTC](https://discourse.julialang.org/t/print-optimization-problem-using-ipopt/89786 "2022-11-04T17:23:33Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Katti](https://avatars.discourse-cdn.com/v4/letter/k/6de8d8/32.png) [@Katti](https://discourse.julialang.org/u/Katti)
#### Post date: [November 4, 2022, 5:23pm UTC](https://discourse.julialang.org/t/print-optimization-problem-using-ipopt/89786/1 "2022-11-04T17:23:33Z")

</div>

Hello all,

I am building a pretty complex optimization problem with the Ipopt solver (NLP). Since the results are not as I expected, I guess that I made a mistake in the model definition. Therefore, I would like to print out the optimization problem to get a better overview of the model.

I used a macro function to create the model and used print(model) within the function. When I run the function, Julia breaks down - I think because of the print(model) command.

Is there any other way to see the whole optimization problem printed in a nice way?

Thanks a lot for your help (and sorry if my question is confusing you - I am new to Julia)

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [November 4, 2022, 6:15pm UTC](https://discourse.julialang.org/t/print-optimization-problem-using-ipopt/89786/2 "2022-11-04T18:15:56Z")

</div>

When happens when you call print? Can you post the error?

---

<div class="post-metadata">

### Author: ![Katti](https://avatars.discourse-cdn.com/v4/letter/k/6de8d8/32.png) [@Katti](https://discourse.julialang.org/u/Katti)
#### Post date: [November 7, 2022, 9:01am UTC](https://discourse.julialang.org/t/print-optimization-problem-using-ipopt/89786/3 "2022-11-07T09:01:34Z")

</div>

Hey, so I tried to do the same for a linear problem with CPLEX at the same happens - either Julia breaks down (page is frozen) or it solves the problem and returns [Math Processing Error] and therefore doesn’t return the printed optimization problem.

The model structure of the linear version is the following:

> function example(Set, Results, size::Int, limit::Int)
> 
> m = direct\_model(CPLEX.Optimizer())
> 
> [at]variables(m, begin  
> …  
> end)
> 
> [at]expression(m, …)  
> [at]expression(m, …)  
> OBJ\_VAR = [at]expression(m, …)
> 
> [at]constraints(m, begin  
> …  
> end)
> 
> [at]constraints(m, begin  
> …  
> end)
> 
> [at]objective(m, Max, OBJ\_VAR)
> 
> optimize!(m)
> 
> print(m)
> 
> end

Then I call the function at a later point after having scaled the model and would expect to get the printed model displayed. What am I doing wrong?

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [November 7, 2022, 6:51pm UTC](https://discourse.julialang.org/t/print-optimization-problem-using-ipopt/89786/4 "2022-11-07T18:51:59Z")

</div>

> Julia breaks down (page is frozen) or it solves the problem and returns [Math Processing Error]

How are you running the problem? Is this in IJulia? Where is the [Math Processing Error] coming from?

How big is your model (# of variables and constraints)?

Do you have a reproducible example?

---

<div class="post-metadata">

### Author: ![Katti](https://avatars.discourse-cdn.com/v4/letter/k/6de8d8/32.png) [@Katti](https://discourse.julialang.org/u/Katti)
#### Post date: [November 8, 2022, 3:35pm UTC](https://discourse.julialang.org/t/print-optimization-problem-using-ipopt/89786/5 "2022-11-08T15:35:44Z")

</div>

Hello,

yes I am running the problem in IJulia in the Jupyter notebook.

Concerning your question on the size of the model - it is pretty big, here the Ipopt output after having solved it:

> Number of nonzeros in equality constraint Jacobian…: 3840  
> Number of nonzeros in inequality constraint Jacobian.: 960  
> Number of nonzeros in Lagrangian Hessian…: 0
> 
> Total number of variables…: 10206  
> variables with only lower bounds: 10206  
> variables with lower and upper bounds: 0  
> variables with only upper bounds: 0  
> Total number of equality constraints…: 1056  
> Total number of inequality constraints…: 576  
> inequality constraints with only lower bounds: 192  
> inequality constraints with lower and upper bounds: 0  
> inequality constraints with only upper bounds: 384

And I do not really have a reproducible example unfortunately as the model is very big (how-ever it is non-convex).

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [November 8, 2022, 7:42pm UTC](https://discourse.julialang.org/t/print-optimization-problem-using-ipopt/89786/6 "2022-11-08T19:42:59Z")

</div>

In IJulia we use Javascript to render the formulation as LaTeX. It seems that the model is too big and so the Javascript backend crashes [Math Processing Error].

However, do you expect that printing a 10^4 by 10^3 size problem would be readable? Why do you want to print it? There are likely too many constraints and too many terms to read to find the mistake.

The printing really only works for models with ~10 variables and constraints.

---

<div class="post-metadata">

### Author: ![Katti](https://avatars.discourse-cdn.com/v4/letter/k/6de8d8/32.png) [@Katti](https://discourse.julialang.org/u/Katti)
#### Post date: [November 9, 2022, 1:18pm UTC](https://discourse.julialang.org/t/print-optimization-problem-using-ipopt/89786/7 "2022-11-09T13:18:57Z")

</div>

Thanks for your help! Indeed it probably doesn’t make sense to print the problem like that.
