Skip to content

Pyomo 6.9.0 TeeStream broken in Jupyter #3487

@chemrgineer

Description

@chemrgineer

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions