1
votes

I am using ipopt in pyomo, I have the next error:

Error evaluating constraint 15: can't compute -1.65898/0.
halt_on_ampl_error=yes

How can I print the constraint name that causes the error in pyomo?

Something like the AMPL command: print _sconname[15];

Thanks, M.

2

2 Answers

2
votes

That error is being thrown by the ASL when evaluating an expression during the solution process (i.e., it is not a Pyomo error).

The trick to making the error more intelligible is to ask Pyomo to pass "symbolic" labels to the solver. This is disabled by default for efficiency reasons: generating human-readable labels is more expensive than simply numbering constraints and variables and users rarely interact with the raw model that is sent to the solver.

  • If you are using the pyomo command, then you can pass the --symbolic-solver-labels option:

    pyomo solve --solver ipopt --stream-solver --symbolic-solver-labels #...
    
  • If you are scripting, then you want to set the symbolic_solver_labels=True in the solve() call:

    SolverFactory('ipopt').solve(model, tee=True, symbolic_solver_labels=True)
    
0
votes

I don't know how to do the mapping to specifically identify the constraint you want but another option is to go through your model and reformulate any constraints that divide by a variable that is not bounded away from zero. You should also provide a good initialization for all of your variables or at the very least initialize them to a value other than zero.