Pyomo / pyomo

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

Pyomo throwing error: ERROR: Solver (ipopt) returned non-zero return code (-6) #2974

Closed abadithela closed 1 year ago

abadithela commented 1 year ago

Summary

I ran the following command to solve a bilevel optimization on my MacOS with Apple Silicon M2. I ran this code inside a conda environment.

with Solver('pao.pyomo.REG') as solver:
        results = solver.solve(model, tee=True)

Steps to reproduce the issue

Python script to reproduce this issue:

from ipdb import set_trace as st
from pao.pyomo import *
import pyomo.environ as pyo
from pyomo.opt import SolverFactory
import pao

def solve_bilevel():
    model = pyo.ConcreteModel()
    # 'ft': tester flow, and d: cut values
    model.x = pyo.Var(bounds=(2,6))
    model.y = pyo.Var()

    # Introduce SUBMODEL
    # fixed variables defined by the upper level
    fixed_variables = [model.x, model.y]

    # Submodel - variables defined in the inner problem
    model.L = SubModel(fixed=fixed_variables)
    model.L.z = pyo.Var(bounds=(0,None)) 

    # Upper level objective and constraints:
    model.o = pyo.Objective(expr=model.x + 3*model.L.z, sense=pyo.minimize)
    model.c = pyo.Constraint(expr= model.x + model.y == 10)

    # Lower level objective and constraints:
    model.L.o = pyo.Objective(expr=model.L.z, sense=pyo.maximize)
    model.L.c1 = pyo.Constraint(expr= model.x + model.L.z <= 8)
    model.L.c2 = pyo.Constraint(expr= model.x + 4*model.L.z >= 8)
    model.L.c3 = pyo.Constraint(expr= model.x + 2*model.L.z <= 13)

    with Solver('pao.pyomo.REG') as solver:
        results = solver.solve(model, tee=True)

    # model.pprint()
    x = model.x.value
    y = model.y.value
    z = model.L.z.value

    return x,y,z

if __name__ == "__main__":
    solve_bilevel()

The command to run:

$ python bilevel_debug.py

Error Message

WARNING: DEPRECATED: add_docstring_list is deprecated.  Please use the
@document_kwargs_from_configdict() decorator.  (deprecated in 6.6.0) (called
from /Users/apurvabadithela/anaconda3/envs/automata/lib/python3.10/site-
packages/pao/common/solver.py:189)
dyld[75213]: Library not loaded: /usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib
  Referenced from: <893AC18D-BE46-33FC-BC81-20EE67422F90> /usr/local/Cellar/ipopt/3.14.5/lib/libdmumps.dylib
  Reason: tried: '/libgfortran.5.dylib' (no such file), '/Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home/bin/libgfortran.5.dylib' (no such file), '/usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib' (no such file), '/usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib' (no such file), '/usr/local/lib/libgfortran.5.dylib' (no such file), '/usr/lib/libgfortran.5.dylib' (no such file, not in dyld cache)Library not loaded: /usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib
  Referenced from: <7837AC63-45D4-382E-AFF7-A073DF40653B> /usr/local/Cellar/ipopt/3.14.5/lib/libmpiseq.dylib
  Reason: tried: '/libgfortran.5.dylib' (no such file), '/Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home/bin/libgfortran.5.dylib' (no such file), '/usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib' (no such file), '/usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib' (no such file), '/usr/local/lib/libgfortran.5.dylib' (no such file), '/usr/lib/libgfortran.5.dylib' (no such file, not in dyld cache)Library not loaded: /usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib
  Referenced from: <A1448882-6487-3C62-A8D2-1A5EDB3ABD91> /usr/local/Cellar/ipopt/3.14.5/lib/libmumps_common.dylib
  Reason: tried: '/libgfortran.5.dylib' (no such file), '/Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home/bin/libgfortran.5.dylib' (no such file), '/usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib' (no such file), '/usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib' (no such file), '/usr/local/lib/libgfortran.5.dylib' (no such file), '/usr/lib/libgfortran.5.dylib' (no such file, not in dyld cache)Library not loaded: /usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib
  Referenced from: <6601C04B-305C-3306-8E0D-A84CFE897D57> /usr/local/Cellar/ipopt/3.14.5/lib/libpord.dylib
  Reason: tried: '/libgfortran.5.dylib' (no such file), '/Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home/bin/libgfortran.5.dylib' (no such file), '/usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib' (no such file), '/usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib' (no such file), '/usr/local/lib/libgfortran.5.dylib' (no such file), '/usr/lib/libgfortran.5.dylib' (no such file, not in dyld cache)
ERROR: Solver (ipopt) returned non-zero return code (-6)
ERROR: See the solver log above for diagnostic information.
Traceback (most recent call last):
  File "/Users/apurvabadithela/software/VisualizeAutomata/quadruped_single_agent/find_cuts_two_flows/bilevel_debug.py", line 49, in <module>
    solve_bilevel()
  File "/Users/apurvabadithela/software/VisualizeAutomata/quadruped_single_agent/find_cuts_two_flows/bilevel_debug.py", line 39, in solve_bilevel
    results = solver.solve(model, tee=True)
  File "/Users/apurvabadithela/anaconda3/envs/automata/lib/python3.10/site-packages/pao/pyomo/solvers/mpr_solvers.py", line 88, in solve
    return super().solve(model, **options)
  File "/Users/apurvabadithela/anaconda3/envs/automata/lib/python3.10/site-packages/pao/pyomo/solver.py", line 66, in solve
    lmp_results = opt.solve(lmp, **solver_options)
  File "/Users/apurvabadithela/anaconda3/envs/automata/lib/python3.10/site-packages/pao/mpr/solvers/reg.py", line 159, in solve
    pyomo_results = opt.solve(M, tee=self.config.tee, 
  File "/Users/apurvabadithela/anaconda3/envs/automata/lib/python3.10/site-packages/pyomo/opt/base/solvers.py", line 627, in solve
    raise ApplicationError("Solver (%s) did not exit normally" % self.name)
pyomo.common.errors.ApplicationError: Solver (ipopt) did not exit normally

Information on your system

Pyomo version: 6.6.2 (CPython 3.10.11 on Darwin 22.5.0) Python version: 3.10.11 Operating system: MacOS Venture 13.4 on Apple M2 Pro chip How Pyomo was installed (PyPI, conda, source): Pyomo was installed in my conda environment with the command: python -m pip install pyomo Solver (if applicable): pao.pyomo.REG, but the error trace shows ipopt.

Additional Information

The above script is a simple illustration of the problem I'm facing. For my application, I need to use the pao.pyomo.REG solver. This simple script successfully runs if the solver is replaced by pao.pyomo.FA as follows:

opt = pao.Solver("pao.pyomo.FA")
results = opt.solve(model)
jsiirola commented 1 year ago

This looks like an error in your Ipopt installation, and not a problem with Pyomo: Ipopt is linked against gfortran, and it looks like OSX cannot find a compatible gfortran library. You can verify this by trying to run ipopt at the command line and seeing if you get the same error.