Skip to content

Baron writer refuses to solve a deactivated block #3313

Open
@emma58

Description

@emma58

Summary

If you pass a deactivated Block to baron, then it will die on an UnboundedLocalError. This is inconsistent with other solvers.

Steps to reproduce the issue

from pyomo.environ import *
m = ConcreteModel()
m.b = Block()
m.b.x = Var()
m.b.c = Constraint(expr=m.b.x >= 9)
m.b.o = Objective(expr=m.b.x)
m.b.deactivate()
SolverFactory('baron').solve(m.b, tee=True)

Error Message

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/esjohn/src/pyomo/pyomo/opt/base/solvers.py", line 598, in solve
    self._presolve(*args, **kwds)
  File "/home/esjohn/src/pyomo/pyomo/opt/solver/shellcmd.py", line 223, in _presolve
    OptSolver._presolve(self, *args, **kwds)
  File "/home/esjohn/src/pyomo/pyomo/opt/base/solvers.py", line 704, in _presolve
    self._convert_problem(
  File "/home/esjohn/src/pyomo/pyomo/solvers/plugins/solvers/BARON.py", line 273, in _convert_problem
    return OptSolver._convert_problem(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/esjohn/src/pyomo/pyomo/opt/base/solvers.py", line 756, in _convert_problem
    return convert_problem(
           ^^^^^^^^^^^^^^^^
  File "/home/esjohn/src/pyomo/pyomo/opt/base/convert.py", line 97, in convert_problem
    problem_files, symbol_map = converter.apply(*tmp, **tmpkw)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/esjohn/src/pyomo/pyomo/solvers/plugins/converter/model.py", line 126, in apply
    (problem_filename, symbol_map_id) = instance.write(
                                        ^^^^^^^^^^^^^^^
  File "/home/esjohn/src/pyomo/pyomo/core/base/block.py", line 1927, in write
    (filename, smap) = problem_writer(self, filename, solver_capability, io_options)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/esjohn/src/pyomo/pyomo/repn/plugins/baron_writer.py", line 517, in __call__
    symbol_map = self._write_bar_file(
                 ^^^^^^^^^^^^^^^^^^^^^
  File "/home/esjohn/src/pyomo/pyomo/repn/plugins/baron_writer.py", line 661, in _write_bar_file
    self._write_equations_section(
  File "/home/esjohn/src/pyomo/pyomo/repn/plugins/baron_writer.py", line 498, in _write_equations_section
    output_file.write(obj_string + ";\n\n")
                      ^^^^^^^^^^
UnboundLocalError: cannot access local variable 'obj_string' where it is not associated with a value

Information on your system

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

Additional information

Replacing baron with gurobi, the model solves fine.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions