Skip to content

Commit

Permalink
Bug fixes: name and solutions attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmundt committed Apr 9, 2024
1 parent 43ff36c commit 9bf6531
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pyomo/contrib/solver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ def __init__(self, **kwds) -> None:
# We allow the user and/or developer to name the solver something else,
# if they really desire. Otherwise it defaults to the class name (all lowercase)
if "name" in kwds:
self.name = kwds["name"]
kwds.pop('name')
else:
self.name = type(self).__name__.lower()
self.name = kwds.pop('name')
self.config = self.CONFIG(value=kwds)

#
Expand Down Expand Up @@ -499,6 +496,12 @@ def _solution_handler(
"""Method to handle the preferred action for the solution"""
symbol_map = SymbolMap()
symbol_map.default_labeler = NumericLabeler('x')
if not hasattr(model, 'solutions'):
# This logic gets around Issue #2130 in which
# solutions is not an attribute on Blocks
from pyomo.core.base.PyomoModel import ModelSolutions

setattr(model, 'solutions', ModelSolutions(model))
model.solutions.add_symbol_map(symbol_map)
legacy_results._smap_id = id(symbol_map)
delete_legacy_soln = True
Expand Down
1 change: 1 addition & 0 deletions pyomo/contrib/solver/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class LegacySolver(LegacySolverWrapper, cls):
LegacySolver
)

cls.name = name
return cls

return decorator
Expand Down

0 comments on commit 9bf6531

Please sign in to comment.