Pyomo / pyomo

An object-oriented algebraic modeling language in Python for structured optimization problems.
https://www.pyomo.org
Other
2.01k stars 518 forks source link

Pass options as part of the call to the solve function #2684

Closed ZedongPeng closed 1 year ago

ZedongPeng commented 1 year ago

Summary

I follow the example in the document. However, it failed. Does ipopt support this way of passing options?

Sometimes it is desirable to pass options as part of the call to the solve function as in this snippet: results = optimizer.solve(instance, options="threads=4", tee=True)

https://pyomo.readthedocs.io/en/stable/working_models.html#sending-options-to-the-solver

Steps to reproduce the issue

# example.py
from pyomo.environ import *
from pyomo.contrib.mindtpy.tests.eight_process_problem import EightProcessFlowsheet
model = EightProcessFlowsheet(convex=True)
opt = SolverFactory('ipopt')
result = opt.solve(model,tee=True,options="maxit=100")

Error Message

Traceback (most recent call last):
  File "/Users/zedongpeng/Github/sofc_models-main/test.py", line 33, in <module>
    result = opt.solve(model,tee=True,options="maxit=100")
  File "/Users/zedongpeng/Github/pyomo/pyomo/opt/base/solvers.py", line 562, in solve
    self.options.update(kwds.pop('options', {}))
  File "/Users/zedongpeng/Github/pyomo/pyomo/common/collections/bunch.py", line 51, in update
    if type(d[k]) is dict:
TypeError: string indices must be integers

Information on your system

Pyomo version: 6.4.3.dev0 Python version: 3.7.12 Operating system: MacOS Version 12.2 How Pyomo was installed (PyPI, conda, source): source Solver (if applicable): ipopt

Additional information

ZedongPeng commented 1 year ago

result = opt.solve(model,tee=True,options={'maxit':100}) worked.

Maybe the document needs to be updated. https://pyomo.readthedocs.io/en/stable/working_models.html#sending-options-to-the-solver