Pyomo / pyomo

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

Can't solve subblock with gurobi_direct #2130

Open emma58 opened 2 years ago

emma58 commented 2 years ago

Summary

Hopefully this isn't a duplicate issue, but it is not possible to solve a ScalarBlock with gurobi_direct.

Steps to reproduce the issue

from pyomo.environ import *

m = ConcreteModel()
m.b = Block()
m.b.v = Var(bounds=(0,10))
m.b.c = Constraint(expr=m.b.v >= 2)
m.b.obj = Objective(expr=m.b.v)

results = SolverFactory('gurobi_direct').solve(m.b)

Error Message

Traceback (most recent call last):
  File "solve_scalar_block.py", line 9, in <module>
    results = SolverFactory('gurobi_direct').solve(m.b)
  File "/home/esjohn/src/pyomo/pyomo/solvers/plugins/solvers/direct_solver.py", line 119, in solve
    self._presolve(*args, **kwds)
  File "/home/esjohn/src/pyomo/pyomo/solvers/plugins/solvers/direct_solver.py", line 64, in _presolve
    DirectOrPersistentSolver._presolve(self, **kwds)
  File "/home/esjohn/src/pyomo/pyomo/solvers/plugins/solvers/direct_or_persistent_solver.py", line 149, in _presolve
    self._pyomo_model.solutions.add_symbol_map(self._symbol_map)
  File "/home/esjohn/src/pyomo/pyomo/core/base/block.py", line 522, in __getattr__
    % (self.__class__.__name__, val))
AttributeError: 'ScalarBlock' object has no attribute 'solutions'

Information on your system

Pyomo version: main Python version: 3.6.5 Operating system: linux How Pyomo was installed (PyPI, conda, source): source Solver (if applicable): Gurobi

michaelbynum commented 2 years ago

This will work if you use save_results=False in the call to solve.