# Print optimization problem using Ipopt

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)

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

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?

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?

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).

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.

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

1 Like