Skip to content

Commit

Permalink
switch to nl_v1 (for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
bknueven committed Feb 17, 2023
1 parent 1a93235 commit f062086
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions watertap/core/plugins/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
###############################################################################

import pyomo.environ as pyo
from pyomo.opt import WriterFactory
from pyomo.core.base.block import _BlockData
from pyomo.core.kernel.block import IBlock
from pyomo.solvers.plugins.solvers.IPOPT import IPOPT
Expand All @@ -25,6 +26,7 @@
from idaes.logger import getLogger

_log = getLogger("watertap.core")
_default_nl_writer = WriterFactory.get_class("nl")


@pyo.SolverFactory.register(
Expand Down Expand Up @@ -55,6 +57,9 @@ def _presolve(self, *args, **kwds):
if "constr_viol_tol" not in self.options:
self.options["constr_viol_tol"] = 1e-08

# temporarily switch to nl_v1 writer
WriterFactory.register("nl")(WriterFactory.get_class("nl_v1"))

if not self._is_user_scaling():
self._cleanup_needed = False
return super()._presolve(*args, **kwds)
Expand Down Expand Up @@ -148,6 +153,7 @@ def _presolve(self, *args, **kwds):
raise

def _cleanup(self):
WriterFactory.register("nl")(_default_nl_writer)
if self._cleanup_needed:
self._reset_scaling_factors()
self._reset_bounds()
Expand Down
8 changes: 8 additions & 0 deletions watertap/core/plugins/tests/test_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pyomo.environ as pyo
import idaes.core.util.scaling as iscale

from pyomo.opt import WriterFactory
from pyomo.solvers.plugins.solvers.IPOPT import IPOPT
from pyomo.common.errors import ApplicationError
from idaes.core.util.scaling import (
Expand All @@ -24,6 +25,8 @@
from idaes.core.solvers import get_solver
from watertap.core.plugins.solvers import IpoptWaterTAP

_default_nl_writer = WriterFactory.get_class("nl")


class TestIpoptWaterTAP:
@pytest.fixture(scope="class")
Expand Down Expand Up @@ -61,6 +64,11 @@ def _test_bounds(self, m):
def s(self):
return pyo.SolverFactory("ipopt-watertap")

@pytest.mark.unit
def test_nl_writer_held_harmless(self, m, s):
s.solve(m, tee=True)
assert _default_nl_writer == WriterFactory.get_class("nl")

@pytest.mark.unit
def test_pyomo_registration(self, s):
assert s.__class__ is IpoptWaterTAP
Expand Down

0 comments on commit f062086

Please sign in to comment.