Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pyomo 6.9.0 release broke solver interface #3487

Open
chemrgineer opened this issue Feb 22, 2025 · 4 comments
Open

Pyomo 6.9.0 release broke solver interface #3487

chemrgineer opened this issue Feb 22, 2025 · 4 comments
Labels

Comments

@chemrgineer
Copy link

Summary

I just updated pyomo 6.8.2 to 6.9.0, than I can not use any ASL solver for my MINLP problem.

Steps to reproduce the issue

from pyomo.environ import *

m = ConcreteModel()
m.xi = RangeSet(2)
m.yi = RangeSet(3)
m.x = Var(m.xi, within=NonNegativeReals)
m.y = Var(m.yi, within=Binary)

m.x1ub = Constraint(expr= m.x[1] <= 1.12)
m.x2ub = Constraint(expr= m.x[2] <= 2.10)

m.c1 = Constraint(expr= (m.x[1])**2 + m.y[1] == 1.25)
m.c2 = Constraint(expr= m.x[2]**(1.5) + 1.5*m.y[2] == 3)
m.c3 = Constraint(expr= m.x[1] + m.y[1] <= 1.6)
m.c4 = Constraint(expr= 1.333*m.x[2] + m.y[2] <= 3)
m.c5 = Constraint(expr= -m.y[1]-m.y[2]+m.y[3] <= 0)

m.obj = Objective(expr= 2*m.x[1] + 3*m.x[2] + 1.5*m.y[1] + 2*m.y[2] - 0.5*m.y[3])

solver = SolverFactory("scip")
result = solver.solve(m, tee=True)

m.pprint()

Error Message

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 21
     18 m.obj = Objective(expr= 2*m.x[1] + 3*m.x[2] + 1.5*m.y[1] + 2*m.y[2] - 0.5*m.y[3])
     20 solver = SolverFactory("scip")
---> 21 result = solver.solve(m, tee=True)
     23 m.pprint()

File [~/miniconda3/envs/pyomo_env/lib/python3.12/site-packages/pyomo/opt/base/solvers.py:610](http://localhost:8888/lab/tree/pCloudDrive/pyomo_ornek/miniconda3/envs/pyomo_env/lib/python3.12/site-packages/pyomo/opt/base/solvers.py#line=609), in OptSolver.solve(self, *args, **kwds)
    607 if not _model is None:
    608     self._initialize_callbacks(_model)
--> 610 _status = self._apply_solver()
    611 if hasattr(self, '_transformation_data'):
    612     del self._transformation_data

File [~/miniconda3/envs/pyomo_env/lib/python3.12/site-packages/pyomo/opt/solver/shellcmd.py:266](http://localhost:8888/lab/tree/pCloudDrive/pyomo_ornek/miniconda3/envs/pyomo_env/lib/python3.12/site-packages/pyomo/opt/solver/shellcmd.py#line=265), in SystemCallSolver._apply_solver(self)
    263         print("Solver problem files: %s" % str(self._problem_files))
    265 sys.stdout.flush()
--> 266 self._rc, self._log = self._execute_command(self._command)
    267 sys.stdout.flush()
    268 return Bunch(rc=self._rc, log=self._log)

File [~/miniconda3/envs/pyomo_env/lib/python3.12/site-packages/pyomo/opt/solver/shellcmd.py:333](http://localhost:8888/lab/tree/pCloudDrive/pyomo_ornek/miniconda3/envs/pyomo_env/lib/python3.12/site-packages/pyomo/opt/solver/shellcmd.py#line=332), in SystemCallSolver._execute_command(self, command)
    330     ostreams.append(sys.stdout)
    332 try:
--> 333     with TeeStream(*ostreams) as t:
    334         results = subprocess.run(
    335             command.cmd,
    336             input=_input,
   (...)
    342             cwd=command.cwd if "cwd" in command else None,
    343         )
    344         t.STDOUT.flush()

File [~/miniconda3/envs/pyomo_env/lib/python3.12/site-packages/pyomo/common/tee.py:418](http://localhost:8888/lab/tree/pCloudDrive/pyomo_ornek/miniconda3/envs/pyomo_env/lib/python3.12/site-packages/pyomo/common/tee.py#line=417), in TeeStream.__init__(self, encoding, buffering, *ostreams)
    416     self.ostreams.append((user_stream, user_stream))
    417     continue
--> 418 local_stream = os.fdopen(
    419     os.dup(fileno), mode=getattr(user_stream, 'mode', None), closefd=True
    420 )
    421 self.ostreams.append((local_stream, user_stream))

File [~/miniconda3/envs/pyomo_env/lib/python3.12/os.py:1035](http://localhost:8888/lab/tree/pCloudDrive/pyomo_ornek/miniconda3/envs/pyomo_env/lib/python3.12/os.py#line=1034), in fdopen(fd, mode, buffering, encoding, *args, **kwargs)
   1033     raise TypeError("invalid fd type (%s, expected integer)" % type(fd))
   1034 import io
-> 1035 if "b" not in mode:
   1036     encoding = io.text_encoding(encoding)
   1037 return io.open(fd, mode, buffering, encoding, *args, **kwargs)

TypeError: argument of type 'NoneType' is not iterable

Information on your system

Pyomo version: 6.9.0
Python version: 3.12.2
Operating system: Linux
How Pyomo was installed (PyPI, conda, source): conda-forge
Solver (if applicable): scip, bonmin, gurobi (12)

@blnicho
Copy link
Member

blnicho commented Feb 25, 2025

How are you running Python? Are you using a terminal or an IDE?

@chemrgineer
Copy link
Author

I used Jupyter. I'm sure that jupyter can reach solvers. In addition to that 6.8.2 version works.

@kglowack
Copy link

kglowack commented Feb 26, 2025

I get the exact same error (with CBC solver) running in Databricks. 6.8.2 works without problems

@jsiirola
Copy link
Member

This appears to be an issue when running within Jupyter. It looks like Jupyter is replacing stdout with an instance of ipykernel.iostream.OutStream, which does not define mode.

A workaround (until we get a patch in) is to run:

import sys
sys.stdout.mode = 'w'

The catch is that the output will go to the terminal that you used to launch Jupyter and not into the Jupyter output cell (it is unclear why this is happening).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants