diff --git a/pyomo/solver/IPOPT.py b/pyomo/solver/IPOPT.py index 30f4cfc60a9..74b0ae25358 100644 --- a/pyomo/solver/IPOPT.py +++ b/pyomo/solver/IPOPT.py @@ -13,7 +13,7 @@ import subprocess import io import sys -from typing import Mapping +from typing import Mapping, Dict from pyomo.common import Executable from pyomo.common.config import ConfigValue, NonNegativeInt @@ -153,6 +153,7 @@ class IPOPT(SolverBase): def __init__(self, **kwds): self._config = self.CONFIG(kwds) + self.ipopt_options = ipopt_command_line_options def available(self): if self.config.executable.path() is None: diff --git a/pyomo/solver/base.py b/pyomo/solver/base.py index 8c6ef0bddef..d4b46ebe5d4 100644 --- a/pyomo/solver/base.py +++ b/pyomo/solver/base.py @@ -37,6 +37,16 @@ class SolverBase(abc.ABC): + # + # Support "with" statements. Forgetting to call deactivate + # on Plugins is a common source of memory leaks + # + def __enter__(self): + return self + + def __exit__(self, t, v, traceback): + pass + class Availability(enum.IntEnum): FullLicense = 2 LimitedLicense = 1 diff --git a/pyomo/solver/factory.py b/pyomo/solver/factory.py index 84b6cf02eac..23a66acd9cb 100644 --- a/pyomo/solver/factory.py +++ b/pyomo/solver/factory.py @@ -9,6 +9,7 @@ # This software is distributed under the 3-clause BSD License. # ___________________________________________________________________________ + from pyomo.opt.base import SolverFactory as LegacySolverFactory from pyomo.common.factory import Factory from pyomo.solver.base import LegacySolverInterface @@ -20,10 +21,10 @@ def decorator(cls): self._cls[name] = cls self._doc[name] = doc - # class LegacySolver(LegacySolverInterface, cls): - # pass + class LegacySolver(LegacySolverInterface, cls): + pass - # LegacySolverFactory.register(name, doc)(LegacySolver) + LegacySolverFactory.register(name, doc)(LegacySolver) return cls