I am trying to solve a nonlinear feasibility problem on Pyomo using ipopt solver. The problem has 2 RangeSet declarations of a combined size 28, 4 Param declarations of a combined size 68, and 5 Var declarations of a combined size 88. There's also 90 constraint declarations (2 redundant) of which some are linear and some are non-linear.
This model is supposed to be simulating a chemical system. Calling model.pprint() gives all the information that it must: all the declarations as stated above. This is the error output I received:
Traceback (most recent call last):
File "sample.py", line 420, in <module>
main()
File "sample.py", line 416, in main
org_n, aq_n, org, aq = _equilibrium_solver(inputfile, T, org_n, aq_n, org, aq)
File "sample.py", line 370, in _equilibrium_solver
opt.solve(model, tee=True)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/opt/base/solvers.py", line 569, in solve
self._presolve(*args, **kwds)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/opt/solver/shellcmd.py", line 200, in _presolve
OptSolver._presolve(self, *args, **kwds)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/opt/base/solvers.py", line 669, in _presolve
**kwds)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/opt/base/solvers.py", line 740, in _convert_problem
**kwds)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/opt/base/convert.py", line 105, in convert_problem
problem_files, symbol_map = converter.apply(*tmp, **tmpkw)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/solvers/plugins/converter/model.py", line 191, in apply
io_options=io_options)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/core/base/block.py", line 1716, in write
io_options)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/repn/plugins/ampl/ampl_.py", line 378, in __call__
include_all_variable_bounds=include_all_variable_bounds)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/repn/plugins/ampl/ampl_.py", line 1528, in _print_model_NL
wrapped_repn.repn.nonlinear_expr)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/repn/plugins/ampl/ampl_.py", line 527, in _print_nonlinear_terms_NL
self._print_nonlinear_terms_NL(exp.arg(1))
File "$HOME/.local/lib/python3.6/site-packages/pyomo/repn/plugins/ampl/ampl_.py", line 637, in _print_nonlinear_terms_NL
% (exp_type))
ValueError: Unsupported expression type (<class 'pyomo.core.expr.expr_pyomo5.LinearExpression'>) in _print_nonlinear_terms_NL
I thought it was a fairly simple calculation that shouldn't have any problems, but now I am out of ideas as to what went wrong. I am not sure what it means by that value error it raises. Am I asking it to print some linear expression in nonlinear terms? There is only thing I can think of: I used quicksum twice, which uses the linear_expression object. Should I replace it with some other sum expression like summation (not sure if summation uses the same object)?
Edit: I traced the error back to this specific constraint. The constraint gives the relationship between mole fractions and moles.
def x2n_org(m,i):
return model.org[i]*sum_product(model.org_n) == model.org_n[i]
model.xton_org = Constraint(model.nc, rule=x2n_org)
Somehow, sum_product or Summation are the reason for the raised ValueError. It would be nice if someone can see what is wrong with the expression.
If I disable this constraint, the solver returns a different error:
ValueError: Cannot load a SolverResults object with bad status: error
However, this error at least tells me that the solver is trying to solve the model even though it couldn't find a solution.