Pyomo / pyomo

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

APPSI-IPOPT: NLWriter currently only supports continuous variables. #2375

Closed ZedongPeng closed 2 years ago

ZedongPeng commented 2 years ago

Summary

I using appsi_ipopt to solve fixed-NLP subplem in MindtPy.
I know that in APPSI-IPOPT, NLWriter currently only supports continuous variables. I manually tested that NLWriter now can support fixed discrete variables. For example, the following code works well.

from pyomo.environ import *
from pyomo.contrib.mindtpy.tests.MINLP2_simple import SimpleMINLP as SimpleMINLP2

model = SimpleMINLP2()
TransformationFactory('core.fix_integer_vars').apply_to(model)
opt = SolverFactory('appsi_ipopt')
result = opt.solve(model, tee=True)
print(result)

Steps to reproduce the issue

However, if I change SimpleMINLP2 to SimpleMINLP5, the continuous variables not supported ERROR will be reported.

# example.py
from pyomo.environ import *
from pyomo.contrib.mindtpy.tests.MINLP2_simple import SimpleMINLP as SimpleMINLP2
from pyomo.contrib.mindtpy.tests.MINLP5_simple import SimpleMINLP5

model = SimpleMINLP5()
TransformationFactory('core.fix_integer_vars').apply_to(model)
opt = SolverFactory('appsi_ipopt')
result = opt.solve(model, tee=True)
print(result)

Error Message

$ # Output message here, including entire stack trace, if available
Traceback (most recent call last):
  File "/Users/zedongpeng/Github/pyomo-MINLP-benchmarking/test5.py", line 8, in <module>
    result = opt.solve(model, tee=True)
  File "/Users/zedongpeng/Github/pyomo/pyomo/contrib/appsi/base.py", line 1230, in solve
    results: Results = super(LegacySolverInterface, self).solve(model)
  File "/Users/zedongpeng/Github/pyomo/pyomo/contrib/appsi/solvers/ipopt.py", line 264, in solve
    self._writer.write(model, self._filename+'.nl', timer=timer)
  File "/Users/zedongpeng/Github/pyomo/pyomo/contrib/appsi/writers/nl_writer.py", line 187, in write
    self._writer.write(filename)
ValueError: NLWriter currently only supports continuous variables.

Information on your system

Pyomo version: 6.4.1.dev0 Python version: Python 3.7.7 Operating system: MacOS How Pyomo was installed (PyPI, conda, source): Solver (if applicable): appsi_ipopt

Additional information

michaelbynum commented 2 years ago

I have this fixed on a branch. I'll try to get it into a PR next week.

ZedongPeng commented 2 years ago

Hi @michaelbynum . How is the PR going?

I have this fixed on a branch. I'll try to get it into a PR next week.