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

Baron writer refuses to solve a deactivated block #3313

Open
emma58 opened this issue Jul 10, 2024 · 0 comments
Open

Baron writer refuses to solve a deactivated block #3313

emma58 opened this issue Jul 10, 2024 · 0 comments

Comments

@emma58
Copy link
Contributor

emma58 commented Jul 10, 2024

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.

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

No branches or pull requests

1 participant